13 #include <init/Ionit_Initializer.h> 14 #include <Ioss_SubSystem.h> 15 #include <Ioss_NullEntity.h> 17 #include <stk_util/util/tokenize.hpp> 18 #include <stk_io/IossBridge.hpp> 20 #include <stk_util/parallel/Parallel.hpp> 22 #include <stk_mesh/base/Types.hpp> 23 #include <stk_mesh/base/Field.hpp> 24 #include <stk_mesh/base/GetEntities.hpp> 25 #include <stk_mesh/base/FieldData.hpp> 26 #include <stk_mesh/base/MetaData.hpp> 27 #include <stk_mesh/base/BulkData.hpp> 28 #include <stk_mesh/fem/FEMHelpers.hpp> 30 #include <Shards_BasicTopologies.hpp> 34 stk::mesh::EntityRank get_entity_rank(
const Ioss::GroupingEntity *entity,
37 switch (entity->type()) {
39 return stk::io::node_rank(meta);
42 return stk::io::node_rank(meta);
44 case Ioss::ELEMENTBLOCK:
45 return stk::io::element_rank(meta);
47 case Ioss::SUPERELEMENT:
48 return stk::io::element_rank(meta);
52 const Ioss::SideSet *sset =
dynamic_cast<const Ioss::SideSet*
>(entity);
54 int my_rank = sset->max_parametric_dimension();
56 return stk::io::face_rank(meta);
58 return stk::io::edge_rank(meta);
60 return stk::io::node_rank(meta);
62 return stk::mesh::InvalidEntityRank;
67 const Ioss::SideBlock *sblk =
dynamic_cast<const Ioss::SideBlock*
>(entity);
69 int rank = sblk->topology()->parametric_dimension();
71 return stk::io::face_rank(meta);
73 return stk::io::edge_rank(meta);
75 return stk::io::node_rank(meta);
77 return stk::mesh::InvalidEntityRank;
80 return stk::mesh::InvalidEntityRank;
84 const CellTopologyData *map_ioss_to_topology(
const std::string &element_type ,
90 const CellTopologyData* celltopo = NULL ;
92 const char *etype = element_type.c_str();
93 if ( 0 == strncasecmp(
"circle" , etype , 6 ) ) {
94 celltopo = shards::getCellTopologyData< shards::Particle >();
96 else if ( 0 == strncasecmp(
"sphere" , etype , 6) ) {
97 celltopo = shards::getCellTopologyData< shards::Particle >();
100 else if ( 0 == strncasecmp(
"bar" , etype , 3 ) ) {
101 if ( node_count == 2 ) {
102 celltopo = shards::getCellTopologyData< shards::Beam<2> >();
104 else if ( node_count == 3 ) {
105 celltopo = shards::getCellTopologyData< shards::Beam<3> >();
108 else if ( 0 == strncasecmp(
"shellline2d" , etype , 11 ) ) {
109 if ( node_count == 2) {
110 celltopo = shards::getCellTopologyData< shards::ShellLine<2> >();
112 else if ( node_count == 3) {
113 celltopo = shards::getCellTopologyData< shards::ShellLine<3> >();
115 }
else if ( 0 == strncasecmp(
"shell" , etype , 5 ) ) {
117 if ( node_count == 4 ) {
118 celltopo = shards::getCellTopologyData< shards::ShellQuadrilateral<4> >();
120 else if ( node_count == 8 ) {
121 celltopo = shards::getCellTopologyData< shards::ShellQuadrilateral<8> >();
123 else if ( node_count == 9 ) {
124 celltopo = shards::getCellTopologyData< shards::ShellQuadrilateral<9> >();
127 else if ( 0 == strncasecmp(
"quad" , etype , 3 ) ) {
131 if ( node_count == 4 ) {
132 celltopo = shards::getCellTopologyData< shards::Quadrilateral<4> >();
134 else if ( node_count == 8 ) {
135 celltopo = shards::getCellTopologyData< shards::Quadrilateral<8> >();
137 else if ( node_count == 9 ) {
138 celltopo = shards::getCellTopologyData< shards::Quadrilateral<9> >();
141 else if ( 0 == strncasecmp(
"trishell" , etype , 8 ) ) {
142 if ( node_count == 3 ) {
143 celltopo = shards::getCellTopologyData< shards::ShellTriangle<3> >();
145 else if ( node_count == 6 ) {
146 celltopo = shards::getCellTopologyData< shards::ShellTriangle<6> >();
150 else if (0 == strncasecmp(
"triface", etype, 7) ||
151 0 == strncasecmp(
"tri", etype, 3)) {
152 if ( node_count == 3 ) {
153 celltopo = shards::getCellTopologyData< shards::Triangle<3> >();
155 else if ( node_count == 4 ) {
156 celltopo = shards::getCellTopologyData< shards::Triangle<4> >();
158 else if ( node_count == 6 ) {
159 celltopo = shards::getCellTopologyData< shards::Triangle<6> >();
163 else if ( 0 == strncasecmp(
"pyramid" , etype , 7 ) ) {
164 if ( node_count == 5 ) {
165 celltopo = shards::getCellTopologyData< shards::Pyramid<5> >();
167 else if ( node_count == 13 ) {
168 celltopo = shards::getCellTopologyData< shards::Pyramid<13> >();
170 else if ( node_count == 14 ) {
171 celltopo = shards::getCellTopologyData< shards::Pyramid<14> >();
176 else if ( 0 == strncasecmp(
"tetra" , etype , 5 ) ) {
177 if ( node_count == 4 ) {
178 celltopo = shards::getCellTopologyData< shards::Tetrahedron<4> >();
180 else if ( node_count == 8 ) {
181 celltopo = shards::getCellTopologyData< shards::Tetrahedron<8> >();
183 else if ( node_count == 10 ) {
184 celltopo = shards::getCellTopologyData< shards::Tetrahedron<10> >();
187 else if ( 0 == strncasecmp(
"wedge" , etype , 5 ) ) {
188 if ( node_count == 6 ) {
189 celltopo = shards::getCellTopologyData< shards::Wedge<6> >();
191 else if ( node_count == 15 ) {
192 celltopo = shards::getCellTopologyData< shards::Wedge<15> >();
194 else if ( node_count == 18 ) {
195 celltopo = shards::getCellTopologyData< shards::Wedge<18> >();
198 else if ( 0 == strncasecmp(
"hex" , etype , 3 ) ) {
199 if ( node_count == 8 ) {
200 celltopo = shards::getCellTopologyData< shards::Hexahedron<8> >();
202 else if ( node_count == 20 ) {
203 celltopo = shards::getCellTopologyData< shards::Hexahedron<20> >();
205 else if ( node_count == 27 ) {
206 celltopo = shards::getCellTopologyData< shards::Hexahedron<27> >();
210 else if (0 == strncasecmp(
"edge", etype, 4)) {
211 if ( node_count == 2) {
213 celltopo = shards::getCellTopologyData< shards::Line<2> >();
215 else if ( node_count == 3) {
217 celltopo = shards::getCellTopologyData< shards::Line<3> >();
221 else if (0 == strncasecmp(
"node", etype, 4)) {
222 celltopo = shards::getCellTopologyData< shards::Node >();
225 if ( NULL == celltopo ) {
226 std::ostringstream oss;
227 oss <<
"ERROR, unsupported topology name = '" << element_type
228 <<
"' , node_count = " << node_count;
229 throw std::runtime_error(oss.str());
235 template <
typename T>
237 stk::mesh::EntityRank type,
239 const Ioss::Field &io_field,
240 bool use_cartesian_for_scalar, T )
243 std::string field_type = io_field.transformed_storage()->name();
244 std::string name = io_field.get_name();
245 size_t num_components = io_field.transformed_storage()->component_count();
247 if (field_type ==
"scalar" || num_components == 1) {
248 if (!use_cartesian_for_scalar) {
259 else if (field_type ==
"vector_2d") {
265 else if (field_type ==
"vector_3d") {
272 else if (field_type ==
"sym_tensor_33") {
279 else if (field_type ==
"full_tensor_36") {
294 if (field_ptr != NULL) {
301 stk::mesh::EntityRank type,
303 const Ioss::Field &io_field,
304 bool use_cartesian_for_scalar)
307 if (io_field.get_type() == Ioss::Field::INTEGER) {
308 field_ptr = declare_ioss_field_internal(meta, type, part, io_field, use_cartesian_for_scalar, (
int)1);
309 }
else if (io_field.get_type() == Ioss::Field::REAL) {
310 field_ptr = declare_ioss_field_internal(meta, type, part, io_field, use_cartesian_for_scalar, (
double)1.0);
311 }
else if (io_field.get_type() == Ioss::Field::COMPLEX) {
312 field_ptr = declare_ioss_field_internal(meta, type, part, io_field, use_cartesian_for_scalar, std::complex<double>(0.0,0.0));
314 std::ostringstream errmsg;
315 errmsg <<
"ERROR: Unrecognized field type for IO field '" 316 << io_field.get_name() <<
"'.";
317 throw std::runtime_error(errmsg.str());
322 template <
typename T>
323 void internal_field_data_from_ioss(
const Ioss::Field &io_field,
325 std::vector<stk::mesh::Entity*> &entities,
326 Ioss::GroupingEntity *io_entity,
329 size_t field_component_count = io_field.transformed_storage()->component_count();
331 std::vector<T> io_field_data;
332 size_t io_entity_count = io_entity->get_field_data(io_field.get_name(), io_field_data);
333 assert(io_field_data.size() == entities.size() * field_component_count);
335 size_t entity_count = entities.size();
337 if (io_entity_count != entity_count) {
338 std::ostringstream errmsg;
339 errmsg <<
"ERROR: Field count mismatch for IO field '" 340 << io_field.get_name() <<
"'. The IO system has " << io_entity_count
341 <<
" entries, but the stk:mesh system has " << entity_count
342 <<
" entries. The two counts must match.";
343 throw std::runtime_error(errmsg.str());
346 for (
size_t i=0; i < entity_count; ++i) {
349 if (entities[i] != NULL) {
351 assert(fld_data != NULL);
352 for(
size_t j=0; j<field_component_count; ++j) {
353 fld_data[j] = io_field_data[i*field_component_count+j];
359 template <
typename T>
360 void internal_field_data_to_ioss(
const Ioss::Field &io_field,
362 std::vector<stk::mesh::Entity*> &entities,
363 Ioss::GroupingEntity *io_entity,
366 size_t field_component_count = io_field.transformed_storage()->component_count();
367 size_t entity_count = entities.size();
369 std::vector<T> io_field_data(entity_count*field_component_count);
371 for (
size_t i=0; i < entity_count; ++i) {
374 if (entities[i] != NULL) {
376 assert(fld_data != NULL);
377 for(
size_t j=0; j<field_component_count; ++j) {
378 io_field_data[i*field_component_count+j] = fld_data[j];
381 for(
size_t j=0; j<field_component_count; ++j) {
382 io_field_data[i*field_component_count+j] = 0;
387 size_t io_entity_count = io_entity->put_field_data(io_field.get_name(), io_field_data);
388 assert(io_field_data.size() == entities.size() * field_component_count);
390 if (io_entity_count != entity_count) {
391 std::ostringstream errmsg;
392 errmsg <<
"ERROR: Field count mismatch for IO field '" 393 << io_field.get_name() <<
"'. The IO system has " << io_entity_count
394 <<
" entries, but the stk:mesh system has " << entity_count
395 <<
" entries. The two counts must match.";
396 throw std::runtime_error(errmsg.str());
405 size_t db_api_int_size(
const Ioss::GroupingEntity *entity)
407 return entity->get_database()->int_byte_size_api();
410 bool invalid_rank(stk::mesh::EntityRank rank)
412 return rank == mesh::InvalidEntityRank;
415 stk::mesh::EntityRank part_primary_entity_rank(
const stk::mesh::Part &part)
417 if (mesh::MetaData::get(part).universal_part() == part) {
418 return stk::mesh::fem::FEMMetaData::NODE_RANK;
447 return stk::mesh::fem::FEMMetaData::NODE_RANK;
450 void set_cell_topology(
stk::mesh::Part &part,
const CellTopologyData *
const cell_topology)
452 stk::mesh::fem::set_cell_topology(part, cell_topology);
461 const std::vector<std::string> &entity_rank_names)
469 const std::vector<std::string> &entity_rank_names)
472 initialize_spatial_dimension(fem_meta, spatial_dimension, entity_rank_names);
477 std::pair<std::string, Ioss::Field::BasicType> *result)
479 static const std::string invalid(
"invalid");
480 static const std::string scalar(
"scalar");
481 static const std::string vector_2d(
"vector_2d");
482 static const std::string vector_3d(
"vector_3d");
483 static const std::string quaternion_2d(
"quaternion_2d");
484 static const std::string quaternion_3d(
"quaternion_3d");
485 static const std::string full_tensor_36(
"full_tensor_36");
486 static const std::string full_tensor_32(
"full_tensor_32");
487 static const std::string full_tensor_22(
"full_tensor_22");
488 static const std::string full_tensor_16(
"full_tensor_16");
489 static const std::string full_tensor_12(
"full_tensor_12");
490 static const std::string sym_tensor_33(
"sym_tensor_33");
491 static const std::string sym_tensor_31(
"sym_tensor_31");
492 static const std::string sym_tensor_21(
"sym_tensor_21");
493 static const std::string sym_tensor_13(
"sym_tensor_13");
494 static const std::string sym_tensor_11(
"sym_tensor_11");
495 static const std::string sym_tensor_10(
"sym_tensor_10");
496 static const std::string asym_tensor_03(
"asym_tensor_03");
497 static const std::string asym_tensor_02(
"asym_tensor_02");
498 static const std::string asym_tensor_01(
"asym_tensor_01");
499 static const std::string matrix_22(
"matrix_22");
500 static const std::string matrix_33(
"matrix_33");
502 const unsigned rank = field->
rank();
503 const shards::ArrayDimTag *
const *
const tags = field->
dimension_tags();
505 result->second = Ioss::Field::INVALID;
507 if ( field->
type_is<
double>() ) {
508 result->second = Ioss::Field::REAL;
510 else if ( field->
type_is<
int>() ) {
511 result->second = Ioss::Field::INTEGER;
515 result->first = scalar ;
517 else if ( 1 == rank ) {
518 size_t num_comp = res.stride(0);
520 result->first = scalar ;
523 result->first = vector_2d ;
526 result->first = vector_3d ;
529 result->first = full_tensor_36 ;
532 result->first = full_tensor_32 ;
535 result->first = full_tensor_22 ;
538 result->first = full_tensor_12 ;
541 result->first = sym_tensor_33 ;
544 result->first = sym_tensor_31 ;
547 result->first = sym_tensor_21 ;
551 if ( result->first.empty() ) {
552 size_t num_comp = res.stride(rank-1);
553 std::ostringstream tmp ;
554 tmp <<
"Real[" << num_comp <<
"]" ;
555 result->first = tmp.str();
560 const Ioss::GroupingEntity *get_associated_ioss_entity(
const mesh::Part &part)
562 const Ioss::GroupingEntity *entity = part.
attribute<Ioss::GroupingEntity>();
563 if (!entity || entity->type() == Ioss::INVALID_TYPE) {
572 if (part.
attribute<Ioss::GroupingEntity>() != NULL) {
573 std::string msg =
"stk::io::put_io_part_attribute( ";
576 msg +=
" io_part_attribute is already defined";
577 throw std::runtime_error( msg );
582 meta.declare_attribute_no_delete(part, entity);
584 Ioss::GroupingEntity *attr =
new Ioss::NullEntity();
591 const Ioss::GroupingEntity *entity = part.
attribute<Ioss::GroupingEntity>();
592 if (entity == NULL) {
593 std::string msg =
"stk::io::remove_io_part_attribute( ";
596 msg +=
" io_part_attribute is not defined on this part";
597 throw std::runtime_error( msg );
600 bool success = meta.remove_attribute(part, entity);
602 std::string msg =
"stk::io::remove_io_part_attribute( ";
605 msg +=
" meta.remove_attribute(..) returned failure.";
606 throw std::runtime_error( msg );
609 if (entity->type() == Ioss::INVALID_TYPE) {
621 const stk::mesh::EntityRank part_type,
624 const Ioss::Field::RoleType filter_role,
629 if (!add_all && role == NULL) {
633 if (role != NULL && *role != filter_role)
637 if (res.dimension() > 0) {
652 if (part_type != node_rank(mesh::MetaData::get(part)) || part == universal) {
657 if (res_universe.dimension() <= 0) {
679 std::string name = topology->name();
680 int io_nodes_per_element = topology->number_nodes();
682 const CellTopologyData *cell_topology = map_ioss_to_topology(name, io_nodes_per_element);
684 return cell_topology;
688 int spatial_dimension)
690 std::string extype =
"unknown";
692 if (cell_top == NULL)
695 if(strcmp(cell_top->name,
"super") == 0) {
696 std::stringstream oss;
697 oss <<
"super" << cell_top->node_count;
700 else if(strncasecmp(cell_top->name,
"super", 5) == 0) {
701 return cell_top->name;
704 switch( cell_top->key ) {
705 case shards::Node::key : extype.assign(
"node" ); break ;
706 case shards::Particle::key :
707 if (spatial_dimension == 2) extype =
"circle1";
708 else extype =
"sphere1";
711 case shards::Beam<2>::key :
715 case shards::Beam<3>::key :
719 case shards::Line<2>::key :
722 case shards::Line<3>::key :
726 case shards::ShellLine<2>::key : extype.assign(
"shellline2d2" ); break ;
727 case shards::ShellLine<3>::key : extype.assign(
"shellline2d3" ); break ;
729 case shards::Triangle<3>::key :
732 case shards::Triangle<4>::key :
735 case shards::Triangle<6>::key :
739 case shards::ShellTriangle<3>::key : extype.assign(
"trishell3" ); break ;
740 case shards::ShellTriangle<6>::key : extype.assign(
"trishell6" ); break ;
742 case shards::Quadrilateral<4>::key :
745 case shards::Quadrilateral<8>::key :
748 case shards::Quadrilateral<9>::key :
752 case shards::ShellQuadrilateral<4>::key : extype.assign(
"shell4" ); break ;
753 case shards::ShellQuadrilateral<8>::key : extype.assign(
"shell8" ); break ;
754 case shards::ShellQuadrilateral<9>::key : extype.assign(
"shell9" ); break ;
756 case shards::Tetrahedron< 4>::key : extype.assign(
"tetra4" ); break ;
757 case shards::Tetrahedron<8>::key : extype.assign(
"tetra8" ); break ;
758 case shards::Tetrahedron<10>::key : extype.assign(
"tetra10" ); break ;
760 case shards::Pyramid< 5>::key : extype.assign(
"pyramid5" ); break ;
761 case shards::Pyramid<13>::key : extype.assign(
"pyramid13" ); break ;
762 case shards::Pyramid<14>::key : extype.assign(
"pyramid14" ); break ;
764 case shards::Wedge< 6>::key : extype.assign(
"wedge6" ); break ;
765 case shards::Wedge<15>::key : extype.assign(
"wedge15" ); break ;
766 case shards::Wedge<18>::key : extype.assign(
"wedge18" ); break ;
768 case shards::Hexahedron< 8>::key : extype.assign(
"hex8" ); break ;
769 case shards::Hexahedron<20>::key : extype.assign(
"hex20" ); break ;
770 case shards::Hexahedron<27>::key : extype.assign(
"hex27" ); break ;
773 std::ostringstream oss;
774 oss <<
"stk::io::map_topology_to_ioss( '" << cell_top->name
775 <<
"' ) ERROR unmapped topology" << std::endl ;
776 throw std::runtime_error(oss.str());
796 mesh::EntityRank type = get_entity_rank(entity, meta);
810 mesh::EntityRank type = get_entity_rank(entity, meta);
820 const Ioss::ElementTopology *topology = entity->topology();
827 if (entity->type() == Ioss::ELEMENTBLOCK) {
828 assert(topology != NULL);
829 if (fem_meta && (topology->spatial_dimension() < (int)fem_meta->
spatial_dimension())) {
834 std::ostringstream msg ;
835 msg <<
"\n\nERROR: Element Block " << entity->name()
836 <<
" contains " << topology->name() <<
" elements with spatial dimension " 837 << topology->spatial_dimension()
838 <<
"\n which does not match the spatial dimension of the model which is " 840 throw std::runtime_error( msg.str() );
850 if (cell_topology != NULL) {
852 const stk::mesh::fem::CellTopology cell_topo(cell_topology);
853 stk::mesh::fem::set_cell_topology(*part, cell_topo);
855 stk::io::set_cell_topology(*part, cell_topology);
869 const stk::mesh::EntityRank part_type,
870 Ioss::GroupingEntity *entity,
871 const Ioss::Field::RoleType filter_role,
877 const std::vector<mesh::FieldBase*> &fields = meta.
get_fields();
879 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
880 while (I != fields.end()) {
884 std::pair<std::string, Ioss::Field::BasicType> field_type;
885 get_io_field_type(f, res, &field_type);
886 if (field_type.second != Ioss::Field::INVALID) {
887 size_t entity_size = entity->get_property(
"entity_count").get_int();
888 const std::string& name = f->
name();
889 entity->field_add(Ioss::Field(name, field_type.second, field_type.first,
890 filter_role, entity_size));
906 Ioss::Field::RoleType role,
908 stk::mesh::EntityRank part_type)
912 bool use_cartesian_for_scalar =
false;
913 if (role == Ioss::Field::ATTRIBUTE)
914 use_cartesian_for_scalar =
true;
916 Ioss::NameList names;
917 entity->field_describe(role, &names);
919 for (Ioss::NameList::const_iterator I = names.begin(); I != names.end(); ++I) {
925 if (*I ==
"attribute" && names.size() > 1)
930 Ioss::Field io_field = entity->get_field(*I);
931 declare_ioss_field(meta, part_type, part, io_field, use_cartesian_for_scalar);
935 template <
typename INT>
936 void get_entity_list(Ioss::GroupingEntity *io_entity,
937 stk::mesh::EntityRank part_type,
939 std::vector<stk::mesh::Entity*> &entities, INT )
941 std::vector<INT> ids ;
942 io_entity->get_field_data(
"ids", ids);
944 size_t count = ids.size();
945 entities.reserve(count);
947 for(
size_t i=0; i<count; ++i) {
948 entities.push_back(bulk.
get_entity( part_type, ids[i] ));
952 void get_entity_list(Ioss::GroupingEntity *io_entity,
953 stk::mesh::EntityRank part_type,
955 std::vector<stk::mesh::Entity*> &entities)
957 if (db_api_int_size(io_entity) == 4) {
958 get_entity_list(io_entity, part_type, bulk, entities, (
int)0);
960 get_entity_list(io_entity, part_type, bulk, entities, (int64_t)0);
965 std::vector<stk::mesh::Entity*> &entities,
966 Ioss::GroupingEntity *io_entity,
967 const std::string &io_fld_name)
972 if (field != NULL && io_entity->field_exists(io_fld_name)) {
973 const Ioss::Field &io_field = io_entity->get_fieldref(io_fld_name);
974 if (field->
type_is<
double>()) {
975 internal_field_data_from_ioss(io_field, field, entities, io_entity,
976 static_cast<double>(1.0));
977 }
else if (field->
type_is<
int>()) {
980 if (db_api_int_size(io_entity) == 4) {
981 if (io_field.get_type() != Ioss::Field::INTEGER) {
982 Ioss::Field &tmp =
const_cast<Ioss::Field&
>(io_field);
983 tmp.reset_type(Ioss::Field::INTEGER);
985 internal_field_data_from_ioss(io_field, field, entities, io_entity,
986 static_cast<int>(1));
988 if (io_field.get_type() != Ioss::Field::INT64) {
989 Ioss::Field &tmp =
const_cast<Ioss::Field&
>(io_field);
990 tmp.reset_type(Ioss::Field::INT64);
992 internal_field_data_from_ioss(io_field, field, entities, io_entity,
993 static_cast<int64_t>(1));
1000 std::vector<stk::mesh::Entity*> &entities,
1001 Ioss::GroupingEntity *io_entity,
1002 const std::string &io_fld_name,
1003 Ioss::Field::RoleType filter_role)
1008 if (field != NULL && io_entity->field_exists(io_fld_name)) {
1009 const Ioss::Field &io_field = io_entity->get_fieldref(io_fld_name);
1010 if (io_field.get_role() == filter_role) {
1011 if (field->
type_is<
double>()) {
1012 internal_field_data_to_ioss(io_field, field, entities, io_entity,
1013 static_cast<double>(1.0));
1014 }
else if (field->
type_is<
int>()) {
1015 if (io_field.get_type() != Ioss::Field::INTEGER) {
1016 Ioss::Field &tmp =
const_cast<Ioss::Field&
>(io_field);
1017 tmp.reset_type(Ioss::Field::INTEGER);
1020 internal_field_data_to_ioss(io_field, field, entities, io_entity,
1021 static_cast<int>(1));
1040 bool omitted = (entity->property_exists(
"omitted")) &&
1041 (entity->get_property(
"omitted").get_int() == 1);
1049 Ioss::SideSet *sset,
1050 stk::mesh::EntityRank type,
1051 size_t side_count,
int spatial_dimension)
1053 const stk::mesh::EntityRank siderank = side_rank(mesh::MetaData::get(part));
1054 const stk::mesh::EntityRank edgerank = edge_rank(mesh::MetaData::get(part));
1055 ThrowRequire(type == siderank || type == edgerank);
1057 const CellTopologyData *
const side_topology = stk::io::get_cell_topology(part) ?
1058 stk::io::get_cell_topology(part) :
1061 if (side_topology == NULL && side_count > 0) {
1063 std::ostringstream msg ;
1064 msg <<
" INTERNAL_ERROR: Part " << part.
name() <<
" returned NULL from get_cell_topology()";
1065 throw std::runtime_error( msg.str() );
1069 std::string element_topo_name =
"unknown";
1073 std::vector<std::string> tokens;
1074 stk::util::tokenize(part.
name(),
"_", tokens);
1075 if (tokens.size() >= 4) {
1079 const Ioss::ElementTopology *element_topo = Ioss::ElementTopology::factory(tokens[tokens.size()-3],
true);
1080 if (element_topo != NULL) {
1081 element_topo_name = element_topo->name();
1085 Ioss::SideBlock *side_block =
new Ioss::SideBlock( sset->get_database() ,
1087 io_topo, element_topo_name, side_count);
1088 assert(sset->get_side_block(part.
name()) == NULL);
1089 sset->add(side_block);
1093 int nodes_per_side = side_topology->node_count;
1094 std::string storage_type =
"Real[";
1096 storage_type +=
"]";
1097 side_block->field_add(Ioss::Field(
"distribution_factors", Ioss::Field::REAL, storage_type,
1098 Ioss::Field::MESH, side_count));
1102 ioss_add_fields(part, part_primary_entity_rank(part), side_block, Ioss::Field::ATTRIBUTE);
1107 Ioss::SideSet *sset,
1108 stk::mesh::EntityRank type,
1109 int spatial_dimension,
1113 ThrowRequire(type == face_rank(meta) || type == edge_rank(meta));
1116 if (blocks.size() > 0) {
1117 for (
size_t j = 0; j < blocks.size(); j++) {
1121 if (anded_selector) selector &= *anded_selector;
1125 define_side_block(side_block_part, sset, side_rank, num_side, spatial_dimension);
1130 if (anded_selector) selector &= *anded_selector;
1132 define_side_block(part, sset, side_rank, num_side, spatial_dimension);
1142 Ioss::Region &io_region,
1155 assert(coord_field != NULL);
1161 const int spatial_dim = res.dimension() ;
1162 io_region.property_add( Ioss::Property(
"spatial_dimension", spatial_dim));
1168 if (anded_selector) selector &= *anded_selector;
1172 const std::string name(
"nodeblock_1");
1174 Ioss::NodeBlock *
const nb =
new Ioss::NodeBlock(io_region.get_database(),
1175 name, num_nodes, spatial_dim);
1176 io_region.add( nb );
1179 ioss_add_fields(part, part_primary_entity_rank(part), nb, Ioss::Field::ATTRIBUTE);
1185 Ioss::Region &io_region,
1190 const stk::mesh::EntityRank elem_rank = element_rank(meta);
1192 const CellTopologyData *
const cell_top =
1193 stk::io::get_cell_topology(part) ?
1194 stk::io::get_cell_topology(part) :
1197 if (cell_top == NULL) {
1198 std::ostringstream msg ;
1199 msg <<
" INTERNAL_ERROR: Part " << part.
name() <<
" returned NULL from get_cell_topology()";
1200 throw std::runtime_error( msg.str() );
1204 if (anded_selector) selector &= *anded_selector;
1207 int spatial_dim = io_region.get_property(
"spatial_dimension").get_int();
1212 Ioss::ElementBlock *eb =
new Ioss::ElementBlock(io_region.get_database() ,
1219 ioss_add_fields(part, part_primary_entity_rank(part), eb, Ioss::Field::ATTRIBUTE);
1224 Ioss::Region &io_region,
1227 const stk::mesh::EntityRank si_rank = side_rank(mesh::MetaData::get(part));
1229 bool create_sideset =
true;
1235 for (
size_t i=0; i < supersets.size(); i++) {
1236 if (
is_part_io_part(*supersets[i]) && supersets[i]->primary_entity_rank() == si_rank) {
1237 create_sideset =
false;
1242 if (create_sideset) {
1243 Ioss::SideSet *
const ss =
new Ioss::SideSet(io_region.get_database(), part.
name());
1246 int spatial_dim = io_region.get_property(
"spatial_dimension").get_int();
1247 define_side_blocks(part, bulk, ss, si_rank, spatial_dim, anded_selector);
1253 Ioss::Region &io_region,
1259 if (anded_selector) selector &= *anded_selector;
1261 const size_t num_nodes =
1264 Ioss::NodeSet *
const ns =
1265 new Ioss::NodeSet( io_region.get_database(), part.
name(), num_nodes);
1269 ioss_add_fields(part, part_primary_entity_rank(part), ns, Ioss::Field::ATTRIBUTE);
1273 struct part_compare {
1279 const Ioss::Region *input_region,
1281 const bool sort_stk_parts)
1283 const mesh::MetaData & meta_data = mesh::MetaData::get(bulk_data);
1285 const stk::mesh::EntityRank no_rank = node_rank(meta_data);
1286 const stk::mesh::EntityRank el_rank = element_rank(meta_data);
1287 const stk::mesh::EntityRank fa_rank = face_rank(meta_data);
1288 const stk::mesh::EntityRank ed_rank = edge_rank(meta_data);
1290 io_region.begin_mode( Ioss::STATE_DEFINE_MODEL );
1292 define_node_block(meta_data.
universal_part(), bulk_data, io_region, anded_selector);
1301 std::sort(all_parts.begin(), all_parts.end(), part_compare());
1303 for (mesh::PartVector::const_iterator i = all_parts.begin();
1304 i != all_parts.end(); ++i) {
1312 define_node_set(*part, bulk_data, io_region, anded_selector);
1314 define_element_block(*part, bulk_data, io_region, anded_selector);
1316 define_side_set(*part, bulk_data, io_region, anded_selector);
1318 define_side_set(*part, bulk_data, io_region, anded_selector);
1322 if (input_region != NULL)
1323 io_region.synchronize_id_and_name(input_region,
true);
1331 for (mesh::PartVector::const_iterator i = all_parts.begin();
1332 i != all_parts.end(); ++i) {
1341 Ioss::GroupingEntity *element_block = io_region.get_entity(part->
name());
1344 if (element_block->property_exists(
"original_block_order")) {
1345 element_block->property_erase(
"original_block_order");
1347 element_block->property_add(Ioss::Property(
"original_block_order", offset));
1355 io_region.end_mode( Ioss::STATE_DEFINE_MODEL );
1364 std::vector<mesh::Entity*> &entities,
1365 bool include_shared,
1369 mesh::EntityRank type = part_primary_entity_rank(part);
1370 if (invalid_rank(type))
1371 type = node_rank(meta);
1378 if (anded_selector) selector &= *anded_selector;
1381 return entities.size();
1385 template <
typename INT>
1386 void write_side_data_to_ioss( Ioss::GroupingEntity & io ,
1394 std::vector<mesh::Entity *> sides ;
1395 size_t num_sides = get_entities(*part, bulk_data, sides,
false, anded_selector);
1397 std::vector<INT> elem_side_ids; elem_side_ids.reserve(num_sides*2);
1399 stk::mesh::EntityRank elem_rank = element_rank(meta_data);
1400 for(
size_t i=0; i<num_sides; ++i) {
1408 const size_t num_side_elem = side_elem.size();
1412 for (
size_t j = 0 ; j < num_side_elem && ! rel ; ++j ) {
1417 rel = &side_elem[j];
1422 std::ostringstream oss;
1423 oss <<
"ERROR, no suitable element found";
1424 throw std::runtime_error(oss.str());
1428 elem_side_ids.push_back(rel->
identifier() + 1) ;
1431 const size_t num_side_written = io.put_field_data(
"element_side",elem_side_ids);
1433 if ( num_sides != num_side_written ) {
1434 std::ostringstream msg ;
1436 msg <<
"stk::io::write_side_data_to_ioss FAILED for " ;
1438 msg <<
" in Ioss::GroupingEntity::put_field_data:" ;
1439 msg <<
" num_sides = " << num_sides ;
1440 msg <<
" , num_side_written = " << num_side_written ;
1441 throw std::runtime_error( msg.str() );
1449 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1450 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1451 while (I != fields.end()) {
1454 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1461 template <
typename INT>
1462 void output_node_block(Ioss::NodeBlock &nb,
1474 std::vector<mesh::Entity *> nodes ;
1475 size_t num_nodes = get_entities(part, bulk, nodes,
true, anded_selector);
1477 std::vector<INT> node_ids; node_ids.reserve(num_nodes);
1478 for(
size_t i=0; i<num_nodes; ++i) {
1483 size_t num_ids_written = nb.put_field_data(
"ids", node_ids);
1484 if ( num_nodes != num_ids_written) {
1485 std::ostringstream msg ;
1486 msg <<
" FAILED in Ioss::NodeBlock::put_field_data:" ;
1487 msg <<
" num_nodes = " << num_nodes ;
1488 msg <<
" , num_ids_written = " << num_ids_written ;
1489 throw std::runtime_error( msg.str() );
1499 assert(coord_field != NULL);
1500 field_data_to_ioss(coord_field, nodes, &nb,
"mesh_model_coordinates", Ioss::Field::MESH);
1502 const std::vector<mesh::FieldBase *> &fields = meta_data.get_fields();
1503 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1504 while (I != fields.end()) {
1507 meta_data.universal_part(), Ioss::Field::ATTRIBUTE,
false)) {
1513 template <
typename INT>
1514 void output_element_block(Ioss::ElementBlock *block,
1519 const std::string& name = block->name();
1522 assert(part != NULL);
1523 std::vector<mesh::Entity *> elements;
1524 size_t num_elems = get_entities(*part, bulk, elements,
false, anded_selector);
1526 const CellTopologyData * cell_topo =
1527 stk::io::get_cell_topology(*part) ?
1528 stk::io::get_cell_topology(*part) :
1530 if (cell_topo == NULL) {
1531 std::ostringstream msg ;
1532 msg <<
" INTERNAL_ERROR: Part " << part->
name() <<
" returned NULL from get_cell_topology()";
1533 throw std::runtime_error( msg.str() );
1535 size_t nodes_per_elem = cell_topo->node_count;
1537 std::vector<INT> elem_ids; elem_ids.reserve(num_elems);
1538 std::vector<INT> connectivity; connectivity.reserve(num_elems*nodes_per_elem);
1540 stk::mesh::EntityRank no_rank = node_rank(meta_data);
1541 for (
size_t i = 0; i < num_elems; ++i) {
1543 elem_ids.push_back(elements[i]->identifier());
1547 for (
size_t j = 0; j < nodes_per_elem; ++j) {
1548 connectivity.push_back(elem_nodes[j].entity()->identifier());
1552 const size_t num_ids_written = block->put_field_data(
"ids", elem_ids);
1553 const size_t num_con_written = block->put_field_data(
"connectivity", connectivity);
1555 if ( num_elems != num_ids_written || num_elems != num_con_written ) {
1556 std::ostringstream msg ;
1557 msg <<
" FAILED in Ioss::ElementBlock::put_field_data:" << std::endl ;
1558 msg <<
" num_elems = " << num_elems << std::endl ;
1559 msg <<
" num_ids_written = " << num_ids_written << std::endl ;
1560 msg <<
" num_connectivity_written = " << num_con_written << std::endl ;
1561 throw std::runtime_error( msg.str() );
1564 stk::mesh::EntityRank elem_rank = element_rank(meta_data);
1565 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1566 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1567 while (I != fields.end()) {
1570 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1572 if (res.dimension() > 0) {
1579 template <
typename INT>
1584 const std::string& name = ns->name();
1586 assert(part != NULL);
1588 std::vector<stk::mesh::Entity *> nodes ;
1589 size_t num_nodes = get_entities(*part, bulk, nodes,
true, anded_selector);
1591 std::vector<INT> node_ids; node_ids.reserve(num_nodes);
1592 for(
size_t i=0; i<num_nodes; ++i) {
1597 size_t num_ids_written = ns->put_field_data(
"ids", node_ids);
1598 if ( num_nodes != num_ids_written ) {
1599 std::ostringstream msg ;
1600 msg <<
" FAILED in Ioss::NodeSet::put_field_data:" 1601 <<
" num_nodes = " << num_nodes
1602 <<
", num_ids_written = " << num_ids_written;
1603 throw std::runtime_error( msg.str() );
1608 if (df_field != NULL) {
1612 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1613 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1614 while (I != fields.end()) {
1617 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1619 if (res.dimension() > 0) {
1626 template <
typename INT>
1627 void output_side_set(Ioss::SideSet *ss,
1632 size_t block_count = ss->block_count();
1633 for (
size_t i=0; i < block_count; i++) {
1634 Ioss::SideBlock *block = ss->get_block(i);
1637 stk::io::write_side_data_to_ioss(*block, part, bulk, anded_selector, dummy);
1650 bool ints64bit = db_api_int_size(&io_region) == 8;
1652 io_region.begin_mode( Ioss::STATE_MODEL );
1657 Ioss::NodeBlock & nb = *io_region.get_node_blocks()[0];
1659 output_node_block(nb, meta.
universal_part(), bulk, anded_selector, z64);
1661 output_node_block(nb, meta.
universal_part(), bulk, anded_selector, z32);
1664 const Ioss::ElementBlockContainer& elem_blocks = io_region.get_element_blocks();
1665 for(Ioss::ElementBlockContainer::const_iterator it = elem_blocks.begin();
1666 it != elem_blocks.end(); ++it) {
1668 output_element_block(*it, bulk, anded_selector, z64);
1670 output_element_block(*it, bulk, anded_selector, z32);
1674 const Ioss::NodeSetContainer& node_sets = io_region.get_nodesets();
1675 for(Ioss::NodeSetContainer::const_iterator it = node_sets.begin();
1676 it != node_sets.end(); ++it) {
1678 output_node_set(*it, bulk, anded_selector, z64);
1680 output_node_set(*it, bulk, anded_selector, z32);
1684 const Ioss::SideSetContainer& side_sets = io_region.get_sidesets();
1685 for(Ioss::SideSetContainer::const_iterator it = side_sets.begin();
1686 it != side_sets.end(); ++it) {
1688 output_side_set(*it, bulk, anded_selector, z64);
1690 output_side_set(*it, bulk, anded_selector, z32);
1693 io_region.end_mode( Ioss::STATE_MODEL );
1699 return NULL != part.
attribute<Ioss::GroupingEntity>();
1711 m.declare_attribute_no_delete(p,&df_field);
1716 return f.
attribute<Ioss::Field::RoleType>();
1721 Ioss::Field::RoleType *my_role =
new Ioss::Field::RoleType(role);
1724 if ( check != my_role ) {
1725 if (*check != *my_role) {
1726 std::ostringstream msg ;
1727 msg <<
" FAILED in IossBridge -- set_field_role:" 1728 <<
" The role type had already been set to " << *check
1729 <<
", so it is not possible to change it to " << *my_role;
1730 throw std::runtime_error( msg.str() );
bool is_part_io_part(stk::mesh::Part &part)
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.
static const FullTensor36 & tag()
Singleton.
const CellTopologyData * map_topology_ioss_to_cell(const Ioss::ElementTopology *topology)
This is a class for selecting buckets based on a set of meshparts and set logic.
void remove_io_part_attribute(mesh::Part &part)
static const Cartesian3d & tag()
Singleton.
void get_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets, std::vector< Entity * > &entities)
Get entities in selected buckets (selected by the given selector instance), and sorted by ID...
const std::string & name() const
Application-defined text name of this field.
Implement an shards::ArrayDimTag for Cartesian coordinate dimensions.
bool member(const Part &) const
Bucket is a subset of the given part.
unsigned rank() const
Multi-dimensional array rank of this field, which is zero for a scalar field.
const PartVector & supersets() const
Parts that are supersets of this part.
const Restriction & restriction(unsigned entity_rank, const Part &part) const
Query a field restriction, result is volatile until the owning meta data manager is committed...
bool include_entity(const Ioss::GroupingEntity *entity)
void set_distribution_factor_field(stk::mesh::Part &p, const stk::mesh::Field< double, stk::mesh::ElementNode > &df_field)
Entity * entity() const
The referenced entity.
static const SymmetricTensor33 & tag()
Singleton.
const PartVector & subsets() const
Parts that are subsets of this part.
const A * attribute() const
Query attribute that has been attached to this field.
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
A relation between two mesh entities with a relation identifier and kind .
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
void set_field_role(stk::mesh::FieldBase &f, const Ioss::Field::RoleType &role)
unsigned primary_entity_rank() const
The primary entity type for this part.
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
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)
const std::string & name() const
Application-defined text name of this part.
unsigned count_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets)
Count entities in selected buckets (selected by the given selector instance), and sorted by ID...
const stk::mesh::Field< double, stk::mesh::ElementNode > * get_distribution_factor_field(const stk::mesh::Part &p)
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.
void put_io_part_attribute(mesh::Part &part, Ioss::GroupingEntity *entity)
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.
An application-defined subset of a problem domain.
std::string map_topology_cell_to_ioss(const CellTopologyData *cell_top, int spatial_dimension)
Manager for an integrated collection of entities, entity relations, and buckets of field data...
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
const A * attribute() const
Query attribute that has been attached to this part.
void write_output_db(Ioss::Region &io_region, const stk::mesh::BulkData &bulk, const stk::mesh::Selector *anded_selector)
Implement an shards::ArrayDimTag for FullTensor.
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)
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
bool type_is() const
Query if the type is Type.
Implement an shards::ArrayDimTag for SymmetricTensor.
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 define_io_fields(Ioss::GroupingEntity *entity, Ioss::Field::RoleType role, stk::mesh::Part &part, stk::mesh::EntityRank part_type)
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
bool element_side_polarity(const Entity &elem, const Entity &side, int local_side_id)
Determine the polarity of the local side, more efficient if the local_side_id is known.
RelationIdentifier identifier() const
The local relation identifier.
const shards::ArrayDimTag *const * dimension_tags() const
Multi-dimensional array dimension tags of this field.
std::string to_string(const T &t)
const Ioss::Field::RoleType * get_field_role(const stk::mesh::FieldBase &f)