45 #include <PanzerAdaptersSTK_config.hpp>
50 #ifdef PANZER_HAVE_IOSS
52 #include <Ionit_Initializer.h>
53 #include <Ioss_ElementBlock.h>
54 #include <Ioss_Region.h>
55 #include <stk_io/StkMeshIoBroker.hpp>
56 #include <stk_io/IossBridge.hpp>
58 #include "Teuchos_StandardParameterEntryValidators.hpp"
60 namespace panzer_stk {
62 STK_PamgenReaderFactory::STK_PamgenReaderFactory()
63 : fileName_(
""), restartIndex_(0)
66 STK_PamgenReaderFactory::STK_PamgenReaderFactory(
const std::string & fileName,
int restartIndex)
67 : fileName_(fileName), restartIndex_(restartIndex)
72 PANZER_FUNC_TIME_MONITOR(
"panzer::STK_PamgenReaderFactory::buildMesh()");
77 RCP<STK_Interface> mesh = buildUncommitedMesh(parallelMach);
83 mesh->initialize(parallelMach,
false);
85 completeMeshConstruction(*mesh,parallelMach);
96 PANZER_FUNC_TIME_MONITOR(
"panzer::STK_PamgenReaderFactory::buildUncomittedMesh()");
102 stk::io::StkMeshIoBroker* meshData =
new stk::io::StkMeshIoBroker(parallelMach);
103 meshData->property_add(Ioss::Property(
"LOWER_CASE_VARIABLE_NAMES",
false));
104 meshData->add_mesh_database(fileName_,
"pamgen", stk::io::READ_MESH);
105 meshData->create_input_mesh();
106 RCP<stk::mesh::MetaData> metaData = meshData->meta_data_rcp();
108 RCP<STK_Interface> mesh =
rcp(
new STK_Interface(metaData));
109 mesh->initializeFromMetaData();
110 mesh->instantiateBulkData(parallelMach);
111 meshData->set_bulk_data(mesh->getBulkData());
115 meshData->add_all_mesh_fields_as_input_fields();
119 mesh->getMetaData()->declare_attribute_with_delete(meshData);
122 registerElementBlocks(*mesh,*meshData);
123 registerSidesets(*mesh);
124 registerNodesets(*mesh);
126 mesh->addPeriodicBCs(periodicBCVec_);
131 void STK_PamgenReaderFactory::completeMeshConstruction(STK_Interface & mesh,stk::ParallelMachine parallelMach)
const
133 PANZER_FUNC_TIME_MONITOR(
"panzer::STK_PamgenReaderFactory::completeMeshConstruction()");
138 if(not mesh.isInitialized())
139 mesh.initialize(parallelMach);
142 stk::mesh::MetaData & metaData = *mesh.getMetaData();
143 stk::io::StkMeshIoBroker * meshData =
144 const_cast<stk::io::StkMeshIoBroker *
>(metaData.get_attribute<stk::io::StkMeshIoBroker>());
152 meshData->populate_bulk_data();
156 int restartIndex = restartIndex_;
158 std::pair<int,double> lastTimeStep = meshData->get_input_io_region()->get_max_time();
159 restartIndex = 1+restartIndex+lastTimeStep.first;
163 meshData->read_defined_input_fields(restartIndex);
165 mesh.buildSubcells();
166 mesh.buildLocalElementIDs();
169 mesh.setInitialStateTime(meshData->get_input_io_region()->get_state_time(restartIndex));
171 mesh.setInitialStateTime(0.0);
177 this->rebalance(mesh);
186 "Error, either parameter {name=\"File Name\","
187 "or the parameter {name=\"Text Input\","
189 "\nis required in parameter (sub)list \""<< paramList->
name() <<
"\"."
195 setMyParamList(paramList);
197 fileName_ = paramList->
get<std::string>(
"File Name");
199 restartIndex_ = paramList->
get<
int>(
"Restart Index");
202 parsePeriodicBCList(Teuchos::rcpFromRef(paramList->
sublist(
"Periodic BCs")),periodicBCVec_);
210 if(validParams==Teuchos::null) {
212 validParams->
set<std::string>(
"File Name",
"<file name not set>",
"Name of pamgen file to be read",
215 validParams->
set<
int>(
"Restart Index",-1,
"Index of solution to read in",
219 bcs.
set<
int>(
"Count",0);
225 void STK_PamgenReaderFactory::registerElementBlocks(STK_Interface & mesh,stk::io::StkMeshIoBroker & meshData)
const
229 RCP<stk::mesh::MetaData> femMetaData = mesh.getMetaData();
234 const Ioss::ElementBlockContainer & elem_blocks = meshData.get_input_io_region()->get_element_blocks();
235 for(Ioss::ElementBlockContainer::const_iterator itr=elem_blocks.begin();itr!=elem_blocks.end();++itr) {
236 Ioss::GroupingEntity * entity = *itr;
237 const std::string & name = entity->name();
239 const stk::mesh::Part * part = femMetaData->get_part(name);
240 const CellTopologyData * ct = femMetaData->get_cell_topology(*part).getCellTopologyData();
243 mesh.addElementBlock(part->name(),ct);
247 template <
typename SetType>
248 void buildSetNames(
const SetType & setData,std::vector<std::string> & names)
251 for(
typename SetType::const_iterator itr=setData.begin();itr!=setData.end();++itr) {
252 Ioss::GroupingEntity * entity = *itr;
253 names.push_back(entity->name());
257 void STK_PamgenReaderFactory::registerSidesets(STK_Interface & mesh)
const
261 RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
262 const stk::mesh::PartVector & parts = metaData->get_parts();
264 stk::mesh::PartVector::const_iterator partItr;
265 for(partItr=parts.begin();partItr!=parts.end();++partItr) {
266 const stk::mesh::Part * part = *partItr;
267 const stk::mesh::PartVector & subsets = part->subsets();
269 const CellTopologyData * ct = metaData->get_cell_topology(*part).getCellTopologyData();
273 if(part->primary_entity_rank()==mesh.getSideRank() && ct==0 && subsets.size()>0) {
275 "STK_PamgenReaderFactory::registerSidesets error - part \"" << part->name() <<
276 "\" has more than one subset");
279 const stk::mesh::Part * ss_part = subsets[0];
281 const CellTopologyData * ss_ct = metaData->get_cell_topology(*ss_part).getCellTopologyData();
285 mesh.addSideset(part->name(),ss_ct);
290 void STK_PamgenReaderFactory::registerNodesets(STK_Interface & mesh)
const
294 RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
295 const stk::mesh::PartVector & parts = metaData->get_parts();
297 stk::mesh::PartVector::const_iterator partItr;
298 for(partItr=parts.begin();partItr!=parts.end();++partItr) {
299 const stk::mesh::Part * part = *partItr;
300 const CellTopologyData * ct = metaData->get_cell_topology(*part).getCellTopologyData();
304 if(part->primary_entity_rank()==mesh.getNodeRank() && ct==0) {
308 mesh.addNodeset(part->name());
RCP< const T > getConst() const
const std::string & name() const
std::string currentParametersString() const
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static const std::string nodesString
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)