12 #include <stk_util/parallel/Parallel.hpp> 13 #include <init/Ionit_Initializer.h> 14 #include <Ioss_SubSystem.h> 16 #include <stk_mesh/base/Field.hpp> 17 #include <stk_mesh/base/FieldData.hpp> 18 #include <stk_mesh/base/BulkData.hpp> 20 #include <stk_mesh/fem/FEMMetaData.hpp> 21 #include <stk_mesh/fem/TopologyDimensions.hpp> 23 #include <stk_io/IossBridge.hpp> 163 const std::string& in_filename,
164 const std::string& out_filename,
165 const std::string& decomp_method)
169 Ioss::Init::Initializer init_db;
171 std::cout <<
"========================================================================\n" 172 <<
" Copy input mesh to output mesh. \n" 173 <<
"========================================================================\n";
175 std::string dbtype(
"exodusII");
176 Ioss::PropertyManager properties;
177 if (!decomp_method.empty()) {
178 properties.add(Ioss::Property(
"DECOMPOSITION_METHOD", Ioss::Utils::uppercase(decomp_method)));
180 Ioss::DatabaseIO *dbi = Ioss::IOFactory::create(dbtype, in_filename, Ioss::READ_MODEL,
182 if (dbi == NULL || !dbi->ok()) {
183 std::cerr <<
"ERROR: Could not open database '" << in_filename
184 <<
"' of type '" << dbtype <<
"'\n";
185 std::exit(EXIT_FAILURE);
188 std::cout <<
"Reading input file: " << in_filename <<
"\n";
190 Ioss::Region in_region(dbi,
"input_model");
199 std::cout <<
"\nWhen processing file multi-block.g for use case 2, the blocks below will be omitted:\n";
200 std::cout <<
"\tOMIT BLOCK Cblock Eblock I1 I2\n\n";
201 Ioss::ElementBlock *eb = in_region.get_element_block(
"cblock");
203 eb->property_add(Ioss::Property(std::string(
"omitted"), 1));
205 eb = in_region.get_element_block(
"eblock");
207 eb->property_add(Ioss::Property(std::string(
"omitted"), 1));
209 eb = in_region.get_element_block(
"i1");
211 eb->property_add(Ioss::Property(std::string(
"omitted"), 1));
213 eb = in_region.get_element_block(
"i2");
215 eb->property_add(Ioss::Property(std::string(
"omitted"), 1));
220 if (entity->type() == Ioss::ELEMENTBLOCK) {
221 int id = entity->get_property(
"id").get_int();
223 entity->property_add(Ioss::Property(std::string(
"omitted"), 1));
224 std::cout <<
"Skipping " << entity->type_string() <<
": " << entity->name() <<
"\n";
232 static size_t spatial_dimension = in_region.get_property(
"spatial_dimension").get_int();
259 std::cout <<
"Creating output file: " << out_filename <<
"\n";
260 Ioss::DatabaseIO *dbo = Ioss::IOFactory::create(dbtype, out_filename,
263 if (dbo == NULL || !dbo->ok()) {
264 std::cerr <<
"ERROR: Could not open results database '" << out_filename
265 <<
"' of type '" << dbtype <<
"'\n";
266 std::exit(EXIT_FAILURE);
274 for ( stk::mesh::PartVector::const_iterator ip = all_parts.begin(); ip != all_parts.end(); ++ip ) {
279 std::cout <<
"Removing part attribute from " << part->
name() <<
"\n";
287 Ioss::Region out_region(dbo,
"results_output");
307 out_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT);
311 out_region.get_node_blocks()[0],
312 Ioss::Field::TRANSIENT);
315 for ( stk::mesh::PartVector::const_iterator
316 ip = all_parts.begin(); ip != all_parts.end(); ++ip ) {
325 Ioss::GroupingEntity *entity = out_region.get_entity(part->
name());
326 if (entity != NULL) {
327 if (entity->type() == Ioss::SIDESET) {
328 Ioss::SideSet *sset =
dynamic_cast<Ioss::SideSet*
>(entity);
329 assert(sset != NULL);
330 int block_count = sset->block_count();
331 for (
int i=0; i < block_count; i++) {
332 Ioss::SideBlock *fb = sset->get_block(i);
334 fb, Ioss::Field::TRANSIENT);
338 entity, Ioss::Field::TRANSIENT);
346 out_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT);
350 out_region.begin_mode(Ioss::STATE_TRANSIENT);
351 int timestep_count = in_region.get_property(
"state_count").get_int();
352 for (
int step = 1; step <= timestep_count; step++) {
353 double time = in_region.get_state_time(step);
361 int out_step = out_region.add_state(time);
364 out_region.end_mode(Ioss::STATE_TRANSIENT);
370 const Ioss::NodeBlockContainer& node_blocks = region.get_node_blocks();
371 assert(node_blocks.size() == 1);
373 Ioss::NodeBlock *nb = node_blocks[0];
375 assert(nb->field_exists(
"mesh_model_coordinates"));
376 Ioss::Field coordinates = nb->get_field(
"mesh_model_coordinates");
377 int spatial_dim = coordinates.transformed_storage()->component_count();
396 const stk::mesh::EntityRank element_rank = fem_meta_data.
element_rank();
398 const Ioss::ElementBlockContainer& elem_blocks = region.get_element_blocks();
403 for(Ioss::ElementBlockContainer::const_iterator it = elem_blocks.begin();
404 it != elem_blocks.end(); ++it) {
405 Ioss::ElementBlock *entity = *it;
409 assert(part != NULL);
430 const CellTopologyData* cell_topo = fem_meta_data.
get_cell_topology(*part).getCellTopologyData();
431 std::string cell_topo_name =
"UNKNOWN";
432 if (cell_topo != NULL)
433 cell_topo_name = cell_topo->name;
441 const Ioss::NodeSetContainer& node_sets = region.get_nodesets();
456 for(Ioss::NodeSetContainer::const_iterator it = node_sets.begin();
457 it != node_sets.end(); ++it) {
458 Ioss::NodeSet *entity = *it;
462 assert(part != NULL);
463 assert(entity->field_exists(
"distribution_factors"));
465 stk::mesh::put_field(distribution_factors_field, stk::mesh::fem::FEMMetaData::NODE_RANK, *part);
480 stk::mesh::EntityRank sset_rank)
482 assert(sset->type() == Ioss::SIDESET);
483 Ioss::SideSet *fs =
dynamic_cast<Ioss::SideSet *
>(sset);
485 const Ioss::SideBlockContainer& blocks = fs->get_side_blocks();
489 assert(fs_part != NULL);
492 bool surface_df_defined =
false;
495 int block_count = sset->block_count();
496 for (
int i=0; i < block_count; i++) {
497 Ioss::SideBlock *side_block = sset->get_block(i);
500 assert(side_block_part != NULL);
505 if (side_block->field_exists(
"distribution_factors")) {
506 if (!surface_df_defined) {
507 std::string field_name = sset->name() +
"_distribution_factors";
508 distribution_factors_field =
511 surface_df_defined =
true;
514 int side_node_count = side_block->topology()->number_nodes();
517 *side_block_part, side_node_count);
535 const stk::mesh::EntityRank side_rank = fem.
side_rank();
537 const Ioss::SideSetContainer& side_sets = region.get_sidesets();
540 for(Ioss::SideSetContainer::const_iterator it = side_sets.begin();
541 it != side_sets.end(); ++it) {
542 Ioss::SideSet *entity = *it;
560 const Ioss::NodeBlockContainer& node_blocks = region.get_node_blocks();
561 assert(node_blocks.size() == 1);
563 Ioss::NodeBlock *nb = node_blocks[0];
565 std::vector<stk::mesh::Entity*> nodes;
566 stk::io::get_entity_list(nb, stk::mesh::fem::FEMMetaData::NODE_RANK, bulk, nodes);
582 const Ioss::ElementBlockContainer& elem_blocks = region.get_element_blocks();
584 for(Ioss::ElementBlockContainer::const_iterator it = elem_blocks.begin();
585 it != elem_blocks.end(); ++it) {
586 Ioss::ElementBlock *entity = *it;
589 const std::string &name = entity->name();
593 assert(part != NULL);
595 const CellTopologyData* cell_topo = fem_meta_data.
get_cell_topology(*part).getCellTopologyData();
596 if (cell_topo == NULL) {
597 std::ostringstream msg ;
598 msg <<
" INTERNAL_ERROR: Part " << part->
name() <<
" returned NULL from get_cell_topology()";
599 throw std::runtime_error( msg.str() );
602 std::vector<int> elem_ids ;
603 std::vector<int> connectivity ;
604 std::vector<stk::mesh::EntityId> connectivity2 ;
606 entity->get_field_data(
"ids", elem_ids);
607 entity->get_field_data(
"connectivity", connectivity);
608 connectivity2.reserve(connectivity.size());
609 std::copy(connectivity.begin(), connectivity.end(), std::back_inserter(connectivity2));
611 size_t element_count = elem_ids.size();
612 int nodes_per_elem = cell_topo->node_count ;
614 std::vector<stk::mesh::Entity*> elements(element_count);
615 for(
size_t i=0; i<element_count; ++i) {
616 stk::mesh::EntityId *conn = &connectivity2[i*nodes_per_elem];
624 Ioss::NameList names;
625 entity->field_describe(Ioss::Field::ATTRIBUTE, &names);
626 for (Ioss::NameList::const_iterator I = names.begin(); I != names.end(); ++I) {
627 if (*I ==
"attribute" && names.size() > 1)
642 const Ioss::NodeSetContainer& node_sets = region.get_nodesets();
644 for(Ioss::NodeSetContainer::const_iterator it = node_sets.begin();
645 it != node_sets.end(); ++it) {
646 Ioss::NodeSet *entity = *it;
649 const std::string & name = entity->name();
652 assert(part != NULL);
655 std::vector<int> node_ids ;
656 int node_count = entity->get_field_data(
"ids", node_ids);
658 std::vector<stk::mesh::Entity*> nodes(node_count);
659 for(
int i=0; i<node_count; ++i) {
660 nodes[i] = bulk.
get_entity( stk::mesh::fem::FEMMetaData::NODE_RANK, node_ids[i] );
661 if (nodes[i] != NULL)
662 bulk.
declare_entity(stk::mesh::fem::FEMMetaData::NODE_RANK, node_ids[i], add_parts );
672 if (df_field != NULL) {
683 assert(sset->type() == Ioss::SIDESET);
687 const stk::mesh::EntityRank element_rank = fem_meta_data.
element_rank();
689 int block_count = sset->block_count();
690 for (
int i=0; i < block_count; i++) {
691 Ioss::SideBlock *block = sset->get_block(i);
693 std::vector<int> side_ids ;
694 std::vector<int> elem_side ;
696 stk::mesh::Part *
const side_block_part = meta.get_part(block->name());
699 block->get_field_data(
"ids", side_ids);
700 block->get_field_data(
"element_side", elem_side);
702 assert(side_ids.size() * 2 == elem_side.size());
705 size_t side_count = side_ids.size();
706 std::vector<stk::mesh::Entity*> sides(side_count);
707 for(
size_t is=0; is<side_count; ++is) {
718 int side_ordinal = elem_side[is*2+1] - 1 ;
721 if (side_rank == 2) {
735 if (df_field != NULL) {
745 const Ioss::SideSetContainer& side_sets = region.get_sidesets();
747 for(Ioss::SideSetContainer::const_iterator it = side_sets.begin();
748 it != side_sets.end(); ++it) {
749 Ioss::SideSet *entity = *it;
760 stk::mesh::EntityRank part_type,
761 Ioss::GroupingEntity *io_entity,
762 Ioss::Field::RoleType filter_role)
764 std::vector<stk::mesh::Entity*> entities;
765 stk::io::get_entity_list(io_entity, part_type, bulk, entities);
769 const std::vector<stk::mesh::FieldBase*> &fields = meta.
get_fields();
771 std::vector<stk::mesh::FieldBase *>::const_iterator I = fields.begin();
772 while (I != fields.end()) {
784 region.begin_state(step);
790 get_field_data(bulk, meta.
universal_part(), stk::mesh::fem::FEMMetaData::NODE_RANK,
791 region.get_node_blocks()[0], Ioss::Field::TRANSIENT);
794 for ( stk::mesh::PartVector::const_iterator
795 ip = all_parts.begin(); ip != all_parts.end(); ++ip ) {
804 Ioss::GroupingEntity *entity = region.get_entity(part->
name());
805 if (entity != NULL) {
806 if (entity->type() == Ioss::SIDESET) {
807 Ioss::SideSet *sset =
dynamic_cast<Ioss::SideSet*
>(entity);
808 assert(sset != NULL);
809 int block_count = sset->block_count();
810 for (
int i=0; i < block_count; i++) {
811 Ioss::SideBlock *side_block = sset->get_block(i);
813 get_field_data(bulk, *part,
815 side_block, Ioss::Field::TRANSIENT);
818 get_field_data(bulk, *part,
820 entity, Ioss::Field::TRANSIENT);
829 region.end_state(step);
833 stk::mesh::EntityRank part_type,
834 Ioss::GroupingEntity *io_entity,
835 Ioss::Field::RoleType filter_role)
837 std::vector<stk::mesh::Entity*> entities;
838 stk::io::get_entity_list(io_entity, part_type, bulk, entities);
842 const std::vector<stk::mesh::FieldBase*> &fields = meta.
get_fields();
844 std::vector<stk::mesh::FieldBase *>::const_iterator I = fields.begin();
845 while (I != fields.end()) {
857 region.begin_state(step);
861 put_field_data(bulk, meta.
universal_part(), stk::mesh::fem::FEMMetaData::NODE_RANK,
862 region.get_node_blocks()[0], Ioss::Field::TRANSIENT);
865 for ( stk::mesh::PartVector::const_iterator
866 ip = all_parts.begin(); ip != all_parts.end(); ++ip ) {
876 Ioss::GroupingEntity *entity = region.get_entity(part->
name());
877 if (entity != NULL) {
879 if (entity->type() == Ioss::SIDESET) {
880 Ioss::SideSet *sset =
dynamic_cast<Ioss::SideSet*
>(entity);
881 assert(sset != NULL);
882 int block_count = sset->block_count();
884 for (
int i=0; i < block_count; i++) {
885 Ioss::SideBlock *side_block = sset->get_block(i);
887 put_field_data(bulk, *part, part_rank,
888 side_block, Ioss::Field::TRANSIENT);
891 put_field_data(bulk, *part, part_rank,
892 entity, Ioss::Field::TRANSIENT);
900 region.end_state(step);
905 #include <boost/program_options.hpp> 907 #include <stk_util/parallel/BroadcastArg.hpp> 908 #include <stk_util/environment/ProgramOptions.hpp> 910 namespace bopt = boost::program_options;
911 int main(
int argc,
char** argv)
923 bopt::options_description desc(
"options");
926 (
"help,h",
"produce help message")
927 (
"mesh", bopt::value<std::string>(),
"mesh file" )
928 (
"decomposition,D", bopt::value<std::string>(),
"decomposition method" )
929 (
"directory,d", bopt::value<std::string>(),
"working directory" )
930 (
"output-log,o", bopt::value<std::string>(),
"output log path" )
931 (
"runtest,r", bopt::value<std::string>(),
"runtest pid file" );
937 bopt::store(bopt::parse_command_line(b_arg.
m_argc, b_arg.
m_argv, desc), vm);
940 catch (std::exception & ) {
944 if (vm.count(
"help")) {
945 std::cout << desc <<
"\n";
946 std::exit(EXIT_SUCCESS);
951 if ( vm.count(
"mesh") ) {
952 std::string in_filename = boost::any_cast<std::string>(vm[
"mesh"].value());
953 std::string out_filename = in_filename +
".out";
954 std::string decomp_method;
955 if (vm.count(
"decomposition")) {
956 decomp_method = boost::any_cast<std::string>(vm[
"decomposition"].value());
960 std::cout <<
"OPTION ERROR: The '--mesh <filename>' option is required!\n";
961 std::exit(EXIT_FAILURE);
bool is_part_io_part(stk::mesh::Part &part)
void io_example(stk::ParallelMachine comm, const std::string &in_filename, const std::string &out_filename, const std::string &decomp_method)
void change_entity_parts(Entity &entity, const PartVector &add_parts, const PartVector &remove_parts=PartVector())
Change the parallel-locally-owned entity's part membership by adding and/or removing parts...
void field_data_to_ioss(const stk::mesh::FieldBase *field, std::vector< stk::mesh::Entity * > &entities, Ioss::GroupingEntity *io_entity, const std::string &io_fld_name, Ioss::Field::RoleType filter_role)
std::vector< Part * > PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
void process_nodeblocks(Ioss::Region ®ion, stk::mesh::MetaData &meta)
void remove_io_part_attribute(mesh::Part &part)
const std::string & name() const
Application-defined text name of this field.
Field with defined data type and multi-dimensions (if any)
boost::program_options::options_description & get_options_description()
Function get_options_description is a singleton used to store the command line option descriptions fo...
bool include_entity(const Ioss::GroupingEntity *entity)
ParallelMachine parallel_machine_init(int *argc, char ***argv)
parallel_machine_init calls MPI_Init.
void set_distribution_factor_field(stk::mesh::Part &p, const stk::mesh::Field< double, stk::mesh::ElementNode > &df_field)
void process_sidesets(Ioss::Region ®ion, stk::mesh::MetaData &meta)
void process_input_request(Ioss::Region ®ion, stk::mesh::BulkData &bulk, int step)
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
void parallel_machine_finalize()
parallel_machine_finalize calls MPI_Finalize.
void process_elementblocks(Ioss::Region ®ion, stk::mesh::MetaData &meta)
unsigned primary_entity_rank() const
The primary entity type for this part.
char ** m_argv
The broadcasted argv.
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
Class BroadcastArg creates a copy of argc and argv after broadcasting them from processor 0...
bool is_valid_part_field(const stk::mesh::FieldBase *field, const stk::mesh::EntityRank part_type, const stk::mesh::Part &part, const stk::mesh::Part &universal, const Ioss::Field::RoleType filter_role, bool add_all)
int m_argc
The broadcasted argc.
const std::string & name() const
Application-defined text name of this part.
const stk::mesh::Field< double, stk::mesh::ElementNode > * get_distribution_factor_field(const stk::mesh::Part &p)
void process_nodesets(Ioss::Region ®ion, stk::mesh::MetaData &meta)
void define_output_db(Ioss::Region &io_region, const mesh::BulkData &bulk_data, const Ioss::Region *input_region, const stk::mesh::Selector *anded_selector, const bool sort_stk_parts)
Field base class with an anonymous data type and anonymous multi-dimension.
field_type & put_field(field_type &field, EntityRank entity_rank, const Part &part, const void *init_value=NULL)
Declare a field to exist for a given entity type and Part.
void process_output_request(Ioss::Region ®ion, stk::mesh::BulkData &bulk, int step)
An application-defined subset of a problem domain.
void process_surface_entity(Ioss::SideSet *sset, stk::mesh::MetaData &meta, stk::mesh::EntityRank sset_rank)
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Entity & declare_element_side(Entity &elem, Entity &side, const unsigned local_side_id, Part *part)
Create (or find) an element side.
void write_output_db(Ioss::Region &io_region, const stk::mesh::BulkData &bulk, const stk::mesh::Selector *anded_selector)
Entity & declare_element(BulkData &mesh, Part &part, const EntityId elem_id, const EntityId node_id[])
Declare an element member of a Part with a CellTopology and nodes conformal to that topology...
boost::program_options::variables_map & get_variables_map()
Function get_variabel_map is a singleton used to store the variables parsed from the line option desc...
Entity & declare_entity(EntityRank ent_rank, EntityId ent_id, const PartVector &parts)
Create or retrieve a locally owned entity of a given rank and id.
void ioss_add_fields(const stk::mesh::Part &part, const stk::mesh::EntityRank part_type, Ioss::GroupingEntity *entity, const Ioss::Field::RoleType filter_role, const bool add_all)
void field_data_from_ioss(const stk::mesh::FieldBase *field, std::vector< stk::mesh::Entity * > &entities, Ioss::GroupingEntity *io_entity, const std::string &io_fld_name)
void default_part_processing(const std::vector< T * > &entities, stk::mesh::fem::FEMMetaData &fem_meta)
void define_io_fields(Ioss::GroupingEntity *entity, Ioss::Field::RoleType role, stk::mesh::Part &part, stk::mesh::EntityRank part_type)
Entity & declare_element_edge(Entity &elem, Entity &edge, const unsigned local_edge_id, Part *part)
Create (or find) an element edge.
bool modification_begin()
Begin a modification phase during which the mesh bulk data could become parallel inconsistent. This is a parallel synchronous call. The first time this method is called the mesh meta data is verified to be committed and parallel consistent. An exception is thrown if this verification fails.