Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panzer: implemet a method to add IOSS information records to the output #9437

Merged
merged 2 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ void STK_Interface::addMeshCoordFields(const std::string & blockId,
}
}

void STK_Interface::addInformationRecords(const std::vector<std::string> & info_records)
{
informationRecords_.insert(info_records.begin(), info_records.end());
}

void STK_Interface::initialize(stk::ParallelMachine parallelMach,bool setupIO,
const bool buildRefinementSupport)
{
Expand Down Expand Up @@ -711,6 +716,10 @@ setupExodusFile(const std::string& filename,
meshData_->add_field(meshIndex_, *fields[i]);
}
}

// convert the set to a vector
std::vector<std::string> deduped_info_records(informationRecords_.begin(),informationRecords_.end());
meshData_->add_info_records(meshIndex_, deduped_info_records);
#else
TEUCHOS_ASSERT(false)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ class STK_Interface {
const std::vector<std::string> & coordField,
const std::string & dispPrefix);

/** Add a vector of strings to the Information Records block. Each string
* will be it's own record. The info records will be deduped before they
* are added to IOSS.
*/
void addInformationRecords(const std::vector<std::string> & info_records);

//////////////////////////////////////////

/** Initialize the mesh with the current dimension This also calls
Expand Down Expand Up @@ -1317,6 +1323,9 @@ class STK_Interface {
std::map<std::pair<std::string,std::string>,SolutionFieldType*> fieldNameToEdgeField_;
std::map<std::pair<std::string,std::string>,SolutionFieldType*> fieldNameToFaceField_;

// use a set to maintain a list of unique information records
std::set<std::string> informationRecords_;

unsigned dimension_;

bool initialized_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@
#include "Panzer_STK_Version.hpp"
#include "PanzerAdaptersSTK_config.hpp"
#include "Panzer_STK_Interface.hpp"
#include "Panzer_STK_CubeHexMeshFactory.hpp"
#include "Panzer_STK_SquareQuadMeshFactory.hpp"
#include "Panzer_STK_ExodusReaderFactory.hpp"
#include "Kokkos_ViewFactory.hpp"

#include "Kokkos_DynRankView.hpp"

#include "Ioss_DatabaseIO.h"
#include "Ioss_IOFactory.h"
#include "Ioss_Region.h"


#ifdef PANZER_HAVE_IOSS

using Teuchos::RCP;
Expand Down Expand Up @@ -237,6 +243,85 @@ TEUCHOS_UNIT_TEST(tSTK_IO, transient_fields)
TEST_EQUALITY(mesh_read->getCurrentStateTime(),0.0); // writeToExodus has not yet been called
}

TEUCHOS_UNIT_TEST(tSTK_IO, addInformationRecords)
{
using Teuchos::RCP;

std::vector<std::string> info_records_1 = {
"DG::eblock-0_0_0::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-0_0_0::field::Ex"
};
std::vector<std::string> info_records_2 = {
"DG::eblock-0_0_0::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-0_0_0::field::Ey"
};
std::vector<std::string> info_records_3 = {
"DG::eblock-0_0_0::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-0_0_0::field::Ez"
};
std::vector<std::string> info_records_4 = {
"DG::eblock-1_1_1::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-1_1_1::field::Ex"
};
std::vector<std::string> info_records_5 = {
"DG::eblock-1_1_1::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-1_1_1::field::Ey"
};
std::vector<std::string> info_records_6 = {
"DG::eblock-1_1_1::basis::Basis_HGRAD_HEX_C1_FEM",
"DG::eblock-1_1_1::field::Ez"
};

RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
pl->set("X Blocks",1);
pl->set("Y Blocks",1);
pl->set("Z Blocks",1);
pl->set("X Elements",2);
pl->set("Y Elements",4);
pl->set("Z Elements",5);

CubeHexMeshFactory factory;
factory.setParameterList(pl);
RCP<STK_Interface> mesh = factory.buildUncommitedMesh(MPI_COMM_WORLD);
mesh->addInformationRecords(info_records_1);
mesh->addInformationRecords(info_records_2);
mesh->addInformationRecords(info_records_3);
mesh->addInformationRecords(info_records_4);
mesh->addInformationRecords(info_records_5);
mesh->addInformationRecords(info_records_6);
factory.completeMeshConstruction(*mesh,MPI_COMM_WORLD);

TEST_ASSERT(mesh!=Teuchos::null);

mesh->writeToExodus("info_records.exo");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test just writes the file, but it doesn't check that the info was actually written. Should it open the exodus file, read out the strings and check that the info is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I pushed an update that checks that the info records were written to the Exodus file.


{
Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus",
"info_records.exo",
Ioss::READ_MODEL);
TEST_ASSERT(db_io);

Ioss::Region region(db_io);
TEST_ASSERT(db_io->ok() == true);

auto info_records_from_ioss = db_io->get_information_records();

// put all the info records in one vector to make them easier to iterate over
std::vector<std::string> all_expected_records;
all_expected_records.insert(all_expected_records.end(), info_records_1.begin(), info_records_1.end());
all_expected_records.insert(all_expected_records.end(), info_records_2.begin(), info_records_2.end());
all_expected_records.insert(all_expected_records.end(), info_records_3.begin(), info_records_3.end());
all_expected_records.insert(all_expected_records.end(), info_records_4.begin(), info_records_4.end());
all_expected_records.insert(all_expected_records.end(), info_records_5.begin(), info_records_5.end());
all_expected_records.insert(all_expected_records.end(), info_records_6.begin(), info_records_6.end());
// make sure all the input records appear in the results returned from IOSS
for ( auto r : all_expected_records ) {
auto iter = std::find(info_records_from_ioss.begin(), info_records_from_ioss.end(), r);
TEST_ASSERT(iter != info_records_from_ioss.end());
}
}
}

RCP<STK_Interface> buildMesh(int xElements,int yElements)
{
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
Expand Down