| 1 |
// Copyright(C) 1999-2023 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "Ioss_DatabaseIO.h" |
| 8 |
#include "Ioss_ElementTopology.h" |
| 9 |
#include "Ioss_EntityBlock.h" |
| 10 |
#include "Ioss_Field.h" |
| 11 |
#include "Ioss_Property.h" |
| 12 |
#include <cstddef> |
| 13 |
#include <fmt/ostream.h> |
| 14 |
#include <ostream> |
| 15 |
#include <string> |
| 16 |
|
| 17 |
#include "Ioss_FieldManager.h" |
| 18 |
#include "Ioss_GroupingEntity.h" |
| 19 |
#include "Ioss_PropertyManager.h" |
| 20 |
#include "Ioss_Utils.h" |
| 21 |
|
| 22 |
/** \brief Constructor adds "name" and "entity_count" properties to the entity |
| 23 |
* and specifies the topology type for the entity block. |
| 24 |
* |
| 25 |
* \param[in] io_database The database associated with the block. |
| 26 |
* \param[in] my_name The block name. |
| 27 |
* \param[in] entity_type The topology type for the block. |
| 28 |
* \param[in] entity_cnt The number of subentities in the block. |
| 29 |
* |
| 30 |
*/ |
| 31 |
Ioss::EntityBlock::EntityBlock(Ioss::DatabaseIO *io_database, const std::string &my_name, |
| 32 |
const std::string &entity_type, size_t entity_cnt) |
| 33 |
: Ioss::GroupingEntity(io_database, my_name, entity_cnt) |
| 34 |
|
| 35 |
{ |
| 36 |
// The 'true' means it is ok for the factory to return |
| 37 |
// nullptr. This is done here just so we can output a better |
| 38 |
// error message. |
| 39 |
topology_ = ElementTopology::factory(entity_type, true); |
| 40 |
if (topology_ == nullptr) { |
| 41 |
std::ostringstream errmsg; |
| 42 |
fmt::print(errmsg, "ERROR: The topology type '{}' is not supported on '{}' in file '{}'", |
| 43 |
entity_type, name(), io_database->get_filename()); |
| 44 |
IOSS_ERROR(errmsg); |
| 45 |
} |
| 46 |
|
| 47 |
if (topology()->master_element_name() != entity_type && topology()->name() != entity_type) { |
| 48 |
// Maintain original element type on output database if possible. |
| 49 |
properties.add(Ioss::Property("original_topology_type", entity_type)); |
| 50 |
} |
| 51 |
|
| 52 |
properties.add(Ioss::Property(this, "topology_node_count", Ioss::Property::INTEGER)); |
| 53 |
properties.add(Ioss::Property(this, "topology_type", Ioss::Property::STRING)); |
| 54 |
fields.add(Ioss::Field("connectivity", field_int_type(), topology_->name(), Ioss::Field::MESH, |
| 55 |
entity_cnt)); |
| 56 |
|
| 57 |
// Returns connectivity in local id space |
| 58 |
fields.add(Ioss::Field("connectivity_raw", field_int_type(), topology()->name(), |
| 59 |
Ioss::Field::MESH, entity_cnt)); |
| 60 |
} |
| 61 |
|
| 62 |
/** \brief Calculate and get an implicit property. |
| 63 |
* |
| 64 |
* These are calculated from data stored in the EntityBlock instead of having |
| 65 |
* an explicit value assigned. An example would be 'topology_node_count' for an ElementBlock. |
| 66 |
* Note that even though this is a pure virtual function, an implementation |
| 67 |
* is provided to return properties that are common to all 'block'-type grouping entities. |
| 68 |
* Derived classes should call 'EntityBlock::get_implicit_property' |
| 69 |
* if the requested property is not specific to their type. |
| 70 |
*/ |
| 71 |
Ioss::Property Ioss::EntityBlock::get_implicit_property(const std::string &my_name) const |
| 72 |
{ |
| 73 |
if (my_name == "topology_node_count") { |
| 74 |
return {my_name, topology()->number_nodes()}; |
| 75 |
} |
| 76 |
if (my_name == "topology_type") { |
| 77 |
return {my_name, topology()->name()}; |
| 78 |
} |
| 79 |
|
| 80 |
return Ioss::GroupingEntity::get_implicit_property(my_name); |
| 81 |
} |
| 82 |
|
| 83 |
bool Ioss::EntityBlock::equal_(const Ioss::EntityBlock &rhs, bool quiet) const |
| 84 |
{ |
| 85 |
bool same = true; |
| 86 |
/* COMPARE element topologies */ |
| 87 |
if (*(this->topology_) != *(rhs.topology_)) { |
| 88 |
if (quiet) { |
| 89 |
return false; |
| 90 |
} |
| 91 |
fmt::print(Ioss::OUTPUT(), "{} {}: TOPOLOGY mismatch\n", type_string(), name()); |
| 92 |
same = false; |
| 93 |
} |
| 94 |
|
| 95 |
if (this->idOffset != rhs.idOffset) { |
| 96 |
if (quiet) { |
| 97 |
return false; |
| 98 |
} |
| 99 |
fmt::print(Ioss::OUTPUT(), "{} {}: idOffset mismatch ({} vs. {})\n", type_string(), name(), |
| 100 |
this->idOffset, rhs.idOffset); |
| 101 |
same = false; |
| 102 |
} |
| 103 |
|
| 104 |
if (!Ioss::GroupingEntity::equal_(rhs, quiet)) { |
| 105 |
if (quiet) { |
| 106 |
return false; |
| 107 |
} |
| 108 |
fmt::print(Ioss::OUTPUT(), "{} {}: mismatch\n", type_string(), name()); |
| 109 |
same = false; |
| 110 |
} |
| 111 |
return same; |
| 112 |
} |
| 113 |
|
| 114 |
bool Ioss::EntityBlock::operator==(const Ioss::EntityBlock &rhs) const { return equal_(rhs, true); } |
| 115 |
|
| 116 |
bool Ioss::EntityBlock::operator!=(const Ioss::EntityBlock &rhs) const { return !(*this == rhs); } |
| 117 |
|
| 118 |
bool Ioss::EntityBlock::equal(const Ioss::EntityBlock &rhs) const { return equal_(rhs, false); } |