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_classic::mesh::EntityRank get_entity_rank(
const Ioss::GroupingEntity *entity,
37 switch (entity->type()) {
39 return stk_classic::io::node_rank(meta);
42 return stk_classic::io::node_rank(meta);
44 case Ioss::ELEMENTBLOCK:
45 return stk_classic::io::element_rank(meta);
47 case Ioss::SUPERELEMENT:
48 return stk_classic::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_classic::io::face_rank(meta);
58 return stk_classic::io::edge_rank(meta);
60 return stk_classic::io::node_rank(meta);
62 return stk_classic::mesh::InvalidEntityRank;
67 const Ioss::SideBlock *sblk =
dynamic_cast<const Ioss::SideBlock*
>(entity);
69 int rank = sblk->topology()->parametric_dimension();
71 return stk_classic::io::face_rank(meta);
73 return stk_classic::io::edge_rank(meta);
75 return stk_classic::io::node_rank(meta);
77 return stk_classic::mesh::InvalidEntityRank;
80 return stk_classic::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_classic::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_classic::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_classic::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_classic::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_classic::mesh::EntityRank rank)
412 return rank == mesh::InvalidEntityRank;
417 if (mesh::MetaData::get(part).universal_part() == part) {
418 return stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
447 return stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
452 stk_classic::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_classic::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_classic::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_classic::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_classic::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_classic::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_classic::mesh::fem::CellTopology cell_topo(cell_topology);
853 stk_classic::mesh::fem::set_cell_topology(*part, cell_topo);
855 stk_classic::io::set_cell_topology(*part, cell_topology);
869 const stk_classic::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_classic::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_classic::mesh::EntityRank part_type,
939 std::vector<stk_classic::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_classic::mesh::EntityRank part_type,
955 std::vector<stk_classic::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_classic::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_classic::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_classic::mesh::EntityRank type,
1051 size_t side_count,
int spatial_dimension)
1053 const stk_classic::mesh::EntityRank siderank = side_rank(mesh::MetaData::get(part));
1054 const stk_classic::mesh::EntityRank edgerank = edge_rank(mesh::MetaData::get(part));
1055 ThrowRequire(type == siderank || type == edgerank);
1057 const CellTopologyData *
const side_topology = stk_classic::io::get_cell_topology(part) ?
1058 stk_classic::io::get_cell_topology(part) :
1059 stk_classic::mesh::fem::FEMMetaData::get(part).get_cell_topology(part).getCellTopologyData();
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_classic::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_classic::mesh::EntityRank type,
1109 int spatial_dimension,
1112 mesh::MetaData & meta = mesh::MetaData::get(part);
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++) {
1118 mesh::Part & side_block_part = *blocks[j];
1119 stk_classic::mesh::EntityRank side_rank = side_block_part.primary_entity_rank();
1120 mesh::Selector selector = meta.locally_owned_part() & side_block_part;
1121 if (anded_selector) selector &= *anded_selector;
1125 define_side_block(side_block_part, sset, side_rank, num_side, spatial_dimension);
1129 mesh::Selector selector = meta.locally_owned_part() & part;
1130 if (anded_selector) selector &= *anded_selector;
1132 define_side_block(part, sset, side_rank, num_side, spatial_dimension);
1142 Ioss::Region &io_region,
1147 mesh::MetaData & meta = mesh::MetaData::get(part);
1153 mesh::Field<double, mesh::Cartesian> *coord_field =
1155 assert(coord_field != NULL);
1156 const mesh::FieldBase::Restriction &res = coord_field->restriction(node_rank(meta), part);
1161 const int spatial_dim = res.dimension() ;
1166 mesh::Selector selector = meta.locally_owned_part() | meta.globally_shared_part();
1167 if (anded_selector) selector &= *anded_selector;
1171 const std::string name(
"nodeblock_1");
1173 Ioss::NodeBlock *
const nb =
new Ioss::NodeBlock(io_region.get_database(),
1174 name, num_nodes, spatial_dim);
1175 io_region.add( nb );
1178 ioss_add_fields(part, part_primary_entity_rank(part), nb, Ioss::Field::ATTRIBUTE);
1184 Ioss::Region &io_region,
1188 mesh::MetaData & meta = mesh::MetaData::get(part);
1189 const stk_classic::mesh::EntityRank elem_rank = element_rank(meta);
1191 const CellTopologyData *
const cell_top =
1192 stk_classic::io::get_cell_topology(part) ?
1193 stk_classic::io::get_cell_topology(part) :
1194 stk_classic::mesh::fem::FEMMetaData::get(part).get_cell_topology(part).getCellTopologyData();
1196 if (cell_top == NULL) {
1197 std::ostringstream msg ;
1198 msg <<
" INTERNAL_ERROR: Part " << part.
name() <<
" returned NULL from get_cell_topology()";
1199 throw std::runtime_error( msg.str() );
1202 mesh::Selector selector = meta.locally_owned_part() & part;
1203 if (anded_selector) selector &= *anded_selector;
1206 int spatial_dim = io_region.get_property(
"spatial_dimension").get_int();
1211 Ioss::ElementBlock *eb =
new Ioss::ElementBlock(io_region.get_database() ,
1218 ioss_add_fields(part, part_primary_entity_rank(part), eb, Ioss::Field::ATTRIBUTE);
1223 Ioss::Region &io_region,
1226 const stk_classic::mesh::EntityRank si_rank = side_rank(mesh::MetaData::get(part));
1228 bool create_sideset =
true;
1234 for (
size_t i=0; i < supersets.size(); i++) {
1235 if (
is_part_io_part(*supersets[i]) && supersets[i]->primary_entity_rank() == si_rank) {
1236 create_sideset =
false;
1241 if (create_sideset) {
1242 Ioss::SideSet *
const ss =
new Ioss::SideSet(io_region.get_database(), part.
name());
1245 int spatial_dim = io_region.get_property(
"spatial_dimension").get_int();
1246 define_side_blocks(part, bulk, ss, si_rank, spatial_dim, anded_selector);
1252 Ioss::Region &io_region,
1255 mesh::MetaData & meta = mesh::MetaData::get(part);
1257 mesh::Selector selector = ( meta.locally_owned_part() | meta.globally_shared_part() ) & part;
1258 if (anded_selector) selector &= *anded_selector;
1260 const size_t num_nodes =
1263 Ioss::NodeSet *
const ns =
1264 new Ioss::NodeSet( io_region.get_database(), part.
name(), num_nodes);
1268 ioss_add_fields(part, part_primary_entity_rank(part), ns, Ioss::Field::ATTRIBUTE);
1272 struct part_compare {
1278 const Ioss::Region *input_region,
1280 const bool sort_stk_parts)
1282 const mesh::MetaData & meta_data = mesh::MetaData::get(bulk_data);
1284 const stk_classic::mesh::EntityRank no_rank = node_rank(meta_data);
1285 const stk_classic::mesh::EntityRank el_rank = element_rank(meta_data);
1286 const stk_classic::mesh::EntityRank fa_rank = face_rank(meta_data);
1287 const stk_classic::mesh::EntityRank ed_rank = edge_rank(meta_data);
1289 io_region.begin_mode( Ioss::STATE_DEFINE_MODEL );
1291 define_node_block(meta_data.
universal_part(), bulk_data, io_region, anded_selector);
1300 std::sort(all_parts.begin(), all_parts.end(), part_compare());
1302 for (mesh::PartVector::const_iterator i = all_parts.begin();
1303 i != all_parts.end(); ++i) {
1311 define_node_set(*part, bulk_data, io_region, anded_selector);
1313 define_element_block(*part, bulk_data, io_region, anded_selector);
1315 define_side_set(*part, bulk_data, io_region, anded_selector);
1317 define_side_set(*part, bulk_data, io_region, anded_selector);
1321 if (input_region != NULL)
1322 io_region.synchronize_id_and_name(input_region,
true);
1330 for (mesh::PartVector::const_iterator i = all_parts.begin();
1331 i != all_parts.end(); ++i) {
1340 Ioss::GroupingEntity *element_block = io_region.get_entity(part->
name());
1343 if (element_block->property_exists(
"original_block_order")) {
1344 element_block->property_erase(
"original_block_order");
1346 element_block->property_add(Ioss::Property(
"original_block_order", offset));
1354 io_region.end_mode( Ioss::STATE_DEFINE_MODEL );
1363 std::vector<mesh::Entity*> &entities,
1364 bool include_shared,
1368 mesh::EntityRank type = part_primary_entity_rank(part);
1369 if (invalid_rank(type))
1370 type = node_rank(meta);
1377 if (anded_selector) selector &= *anded_selector;
1380 return entities.size();
1384 template <
typename INT>
1385 void write_side_data_to_ioss( Ioss::GroupingEntity & io ,
1386 mesh::Part *
const part ,
1387 const mesh::BulkData & bulk_data,
1391 const mesh::MetaData & meta_data = mesh::MetaData::get(*part);
1393 std::vector<mesh::Entity *> sides ;
1394 size_t num_sides = get_entities(*part, bulk_data, sides,
false, anded_selector);
1396 std::vector<INT> elem_side_ids; elem_side_ids.reserve(num_sides*2);
1398 stk_classic::mesh::EntityRank elem_rank = element_rank(meta_data);
1399 for(
size_t i=0; i<num_sides; ++i) {
1401 const mesh::Entity &side = *sides[i] ;
1402 const mesh::PairIterRelation side_elem = side.relations( elem_rank );
1407 const size_t num_side_elem = side_elem.size();
1409 const mesh::Relation *rel = NULL ;
1411 for (
size_t j = 0 ; j < num_side_elem && ! rel ; ++j ) {
1412 const mesh::Entity & elem = *side_elem[j].entity();
1414 if ( elem.bucket().member( meta_data.locally_owned_part() ) &&
1416 rel = &side_elem[j];
1421 std::ostringstream oss;
1422 oss <<
"ERROR, no suitable element found";
1423 throw std::runtime_error(oss.str());
1426 elem_side_ids.push_back(rel->entity()->identifier());
1427 elem_side_ids.push_back(rel->identifier() + 1) ;
1430 const size_t num_side_written = io.put_field_data(
"element_side",elem_side_ids);
1432 if ( num_sides != num_side_written ) {
1433 std::ostringstream msg ;
1435 msg <<
"stk_classic::io::write_side_data_to_ioss FAILED for " ;
1437 msg <<
" in Ioss::GroupingEntity::put_field_data:" ;
1438 msg <<
" num_sides = " << num_sides ;
1439 msg <<
" , num_side_written = " << num_side_written ;
1440 throw std::runtime_error( msg.str() );
1448 const std::vector<mesh::FieldBase *> &fields = meta_data.get_fields();
1449 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1450 while (I != fields.end()) {
1451 const mesh::FieldBase *f = *I ; ++I ;
1453 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1460 template <
typename INT>
1461 void output_node_block(Ioss::NodeBlock &nb,
1473 std::vector<mesh::Entity *> nodes ;
1474 size_t num_nodes =
get_entities(part, bulk, nodes,
true, anded_selector);
1476 std::vector<INT> node_ids; node_ids.reserve(num_nodes);
1477 for(
size_t i=0; i<num_nodes; ++i) {
1478 const mesh::Entity & node = * nodes[i] ;
1479 node_ids.push_back(node.identifier());
1482 size_t num_ids_written = nb.put_field_data(
"ids", node_ids);
1483 if ( num_nodes != num_ids_written) {
1484 std::ostringstream msg ;
1485 msg <<
" FAILED in Ioss::NodeBlock::put_field_data:" ;
1486 msg <<
" num_nodes = " << num_nodes ;
1487 msg <<
" , num_ids_written = " << num_ids_written ;
1488 throw std::runtime_error( msg.str() );
1496 mesh::Field<double, mesh::Cartesian> *coord_field =
1498 assert(coord_field != NULL);
1499 field_data_to_ioss(coord_field, nodes, &nb,
"mesh_model_coordinates", Ioss::Field::MESH);
1501 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1502 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1503 while (I != fields.end()) {
1504 const mesh::FieldBase *f = *I ; ++I ;
1512 template <
typename INT>
1513 void output_element_block(Ioss::ElementBlock *block,
1518 const std::string& name = block->name();
1519 mesh::Part* part = meta_data.
get_part(name);
1521 assert(part != NULL);
1522 std::vector<mesh::Entity *> elements;
1523 size_t num_elems =
get_entities(*part, bulk, elements,
false, anded_selector);
1525 const CellTopologyData * cell_topo =
1526 stk_classic::io::get_cell_topology(*part) ?
1527 stk_classic::io::get_cell_topology(*part) :
1528 stk_classic::mesh::fem::FEMMetaData::get(*part).get_cell_topology(*part).getCellTopologyData();
1529 if (cell_topo == NULL) {
1530 std::ostringstream msg ;
1531 msg <<
" INTERNAL_ERROR: Part " << part->name() <<
" returned NULL from get_cell_topology()";
1532 throw std::runtime_error( msg.str() );
1534 size_t nodes_per_elem = cell_topo->node_count;
1536 std::vector<INT> elem_ids; elem_ids.reserve(num_elems);
1537 std::vector<INT> connectivity; connectivity.reserve(num_elems*nodes_per_elem);
1539 stk_classic::mesh::EntityRank no_rank = node_rank(meta_data);
1540 for (
size_t i = 0; i < num_elems; ++i) {
1542 elem_ids.push_back(elements[i]->identifier());
1544 const mesh::PairIterRelation elem_nodes = elements[i]->relations(no_rank);
1546 for (
size_t j = 0; j < nodes_per_elem; ++j) {
1547 connectivity.push_back(elem_nodes[j].entity()->identifier());
1551 const size_t num_ids_written = block->put_field_data(
"ids", elem_ids);
1552 const size_t num_con_written = block->put_field_data(
"connectivity", connectivity);
1554 if ( num_elems != num_ids_written || num_elems != num_con_written ) {
1555 std::ostringstream msg ;
1556 msg <<
" FAILED in Ioss::ElementBlock::put_field_data:" << std::endl ;
1557 msg <<
" num_elems = " << num_elems << std::endl ;
1558 msg <<
" num_ids_written = " << num_ids_written << std::endl ;
1559 msg <<
" num_connectivity_written = " << num_con_written << std::endl ;
1560 throw std::runtime_error( msg.str() );
1563 stk_classic::mesh::EntityRank elem_rank = element_rank(meta_data);
1564 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1565 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1566 while (I != fields.end()) {
1567 const mesh::FieldBase *f = *I ; ++I ;
1569 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1570 const mesh::FieldBase::Restriction &res = f->restriction(elem_rank, *part);
1571 if (res.dimension() > 0) {
1578 template <
typename INT>
1583 const std::string& name = ns->name();
1585 assert(part != NULL);
1587 std::vector<stk_classic::mesh::Entity *> nodes ;
1588 size_t num_nodes =
get_entities(*part, bulk, nodes,
true, anded_selector);
1590 std::vector<INT> node_ids; node_ids.reserve(num_nodes);
1591 for(
size_t i=0; i<num_nodes; ++i) {
1596 size_t num_ids_written = ns->put_field_data(
"ids", node_ids);
1597 if ( num_nodes != num_ids_written ) {
1598 std::ostringstream msg ;
1599 msg <<
" FAILED in Ioss::NodeSet::put_field_data:" 1600 <<
" num_nodes = " << num_nodes
1601 <<
", num_ids_written = " << num_ids_written;
1602 throw std::runtime_error( msg.str() );
1607 if (df_field != NULL) {
1611 const std::vector<mesh::FieldBase *> &fields = meta_data.
get_fields();
1612 std::vector<mesh::FieldBase *>::const_iterator I = fields.begin();
1613 while (I != fields.end()) {
1614 const mesh::FieldBase *f = *I ; ++I ;
1616 if (role != NULL && *role == Ioss::Field::ATTRIBUTE) {
1617 const mesh::FieldBase::Restriction &res = f->restriction(0, *part);
1618 if (res.dimension() > 0) {
1625 template <
typename INT>
1626 void output_side_set(Ioss::SideSet *ss,
1631 size_t block_count = ss->block_count();
1632 for (
size_t i=0; i < block_count; i++) {
1633 Ioss::SideBlock *block = ss->get_block(i);
1636 stk_classic::io::write_side_data_to_ioss(*block, part, bulk, anded_selector, dummy);
1649 bool ints64bit = db_api_int_size(&io_region) == 8;
1651 io_region.begin_mode( Ioss::STATE_MODEL );
1656 Ioss::NodeBlock & nb = *io_region.get_node_blocks()[0];
1658 output_node_block(nb, meta.
universal_part(), bulk, anded_selector, z64);
1660 output_node_block(nb, meta.
universal_part(), bulk, anded_selector, z32);
1663 const Ioss::ElementBlockContainer& elem_blocks = io_region.get_element_blocks();
1664 for(Ioss::ElementBlockContainer::const_iterator it = elem_blocks.begin();
1665 it != elem_blocks.end(); ++it) {
1667 output_element_block(*it, bulk, anded_selector, z64);
1669 output_element_block(*it, bulk, anded_selector, z32);
1673 const Ioss::NodeSetContainer& node_sets = io_region.get_nodesets();
1674 for(Ioss::NodeSetContainer::const_iterator it = node_sets.begin();
1675 it != node_sets.end(); ++it) {
1677 output_node_set(*it, bulk, anded_selector, z64);
1679 output_node_set(*it, bulk, anded_selector, z32);
1683 const Ioss::SideSetContainer& side_sets = io_region.get_sidesets();
1684 for(Ioss::SideSetContainer::const_iterator it = side_sets.begin();
1685 it != side_sets.end(); ++it) {
1687 output_side_set(*it, bulk, anded_selector, z64);
1689 output_side_set(*it, bulk, anded_selector, z32);
1692 io_region.end_mode( Ioss::STATE_MODEL );
1698 return NULL != part.
attribute<Ioss::GroupingEntity>();
1710 m.declare_attribute_no_delete(p,&df_field);
1715 return f.
attribute<Ioss::Field::RoleType>();
1720 Ioss::Field::RoleType *my_role =
new Ioss::Field::RoleType(role);
1723 if ( check != my_role ) {
1724 if (*check != *my_role) {
1725 std::ostringstream msg ;
1726 msg <<
" FAILED in IossBridge -- set_field_role:" 1727 <<
" The role type had already been set to " << *check
1728 <<
", so it is not possible to change it to " << *my_role;
1729 throw std::runtime_error( msg.str() );
void write_output_db(Ioss::Region &io_region, const stk_classic::mesh::BulkData &bulk, const stk_classic::mesh::Selector *anded_selector)
Field base class with an anonymous data type and anonymous multi-dimension.
static const SymmetricTensor33 & tag()
Singleton.
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 Restriction & restriction(unsigned entity_rank, const Part &part) const
Query a field restriction, result is volatile until the owning meta data manager is committed...
void field_data_from_ioss(const stk_classic::mesh::FieldBase *field, std::vector< stk_classic::mesh::Entity *> &entities, Ioss::GroupingEntity *io_entity, const std::string &io_fld_name)
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
void define_output_db(Ioss::Region &io_region, const mesh::BulkData &bulk_data, const Ioss::Region *input_region, const stk_classic::mesh::Selector *anded_selector, const bool sort_stk_parts)
const Ioss::Field::RoleType * get_field_role(const stk_classic::mesh::FieldBase &f)
Implement an shards::ArrayDimTag for FullTensor.
void put_io_part_attribute(mesh::Part &part, Ioss::GroupingEntity *entity)
This is a class for selecting buckets based on a set of meshparts and set logic.
Implement an shards::ArrayDimTag for SymmetricTensor.
static const FullTensor36 & tag()
Singleton.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
unsigned primary_entity_rank() const
The primary entity type for this part.
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.
bool include_entity(const Ioss::GroupingEntity *entity)
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
static const Cartesian3d & tag()
Singleton.
std::string map_topology_cell_to_ioss(const CellTopologyData *cell_top, int spatial_dimension)
An application-defined subset of a problem domain.
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...
bool is_part_io_part(stk_classic::mesh::Part &part)
Implement an shards::ArrayDimTag for Cartesian coordinate dimensions.
const std::string & name() const
Application-defined text name of this part.
void get_entities(const BulkData &mesh, EntityRank entity_rank, std::vector< Entity *> &entities)
Get all entities of the specified type, sorted by ID.
const PartVector & supersets() const
Parts that are supersets of this part.
const A * attribute() const
Query attribute that has been attached to this part.
const stk_classic::mesh::Field< double, stk_classic::mesh::ElementNode > * get_distribution_factor_field(const stk_classic::mesh::Part &p)
Manager for an integrated collection of entities, entity relations, and buckets of field data...
const std::string & name() const
Application-defined text name of this field.
const CellTopologyData * map_topology_ioss_to_cell(const Ioss::ElementTopology *topology)
const PartVector & subsets() const
Parts that are subsets of this part.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
bool is_valid_part_field(const stk_classic::mesh::FieldBase *field, const stk_classic::mesh::EntityRank part_type, const stk_classic::mesh::Part &part, const stk_classic::mesh::Part &universal, const Ioss::Field::RoleType filter_role, bool add_all)
void field_data_to_ioss(const stk_classic::mesh::FieldBase *field, std::vector< stk_classic::mesh::Entity *> &entities, Ioss::GroupingEntity *io_entity, const std::string &io_fld_name, Ioss::Field::RoleType filter_role)
void set_field_role(stk_classic::mesh::FieldBase &f, const Ioss::Field::RoleType &role)
const A * attribute() const
Query attribute that has been attached to this field.
void ioss_add_fields(const stk_classic::mesh::Part &part, const stk_classic::mesh::EntityRank part_type, Ioss::GroupingEntity *entity, const Ioss::Field::RoleType filter_role, const bool add_all)
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
void define_io_fields(Ioss::GroupingEntity *entity, Ioss::Field::RoleType role, stk_classic::mesh::Part &part, stk_classic::mesh::EntityRank part_type)
void remove_io_part_attribute(mesh::Part &part)
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.
void set_distribution_factor_field(stk_classic::mesh::Part &p, const stk_classic::mesh::Field< double, stk_classic::mesh::ElementNode > &df_field)
std::string to_string(const T &t)