| 1 |
// Copyright(C) 1999-2020, 2022, 2023, 2024 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_CodeTypes.h" // for Int64Vector, IntVector |
| 8 |
#include "Ioss_SideBlock.h" // for SideBlock |
| 9 |
#include "Ioss_Utils.h" // for Utils, IOSS_ERROR |
| 10 |
#include "gen_struc/Iogs_DatabaseIO.h" |
| 11 |
#include "gen_struc/Iogs_GeneratedMesh.h" // for GeneratedMesh |
| 12 |
#include <cassert> // for assert |
| 13 |
#include <cmath> // for sqrt |
| 14 |
#include <fmt/format.h> |
| 15 |
#include <iostream> // for ostringstream, operator<<, etc |
| 16 |
#include <stdlib.h> |
| 17 |
#include <string> // for string, operator==, etc |
| 18 |
|
| 19 |
#include "Ioss_CommSet.h" // for CommSet |
| 20 |
#include "Ioss_DBUsage.h" // for DatabaseUsage |
| 21 |
#include "Ioss_DatabaseIO.h" // for DatabaseIO |
| 22 |
#include "Ioss_EntityType.h" // for EntityType, etc |
| 23 |
#include "Ioss_Field.h" // for Field, etc |
| 24 |
#include "Ioss_GroupingEntity.h" // for GroupingEntity |
| 25 |
#include "Ioss_IOFactory.h" // for IOFactory |
| 26 |
#include "Ioss_Map.h" // for Map, MapContainer |
| 27 |
#include "Ioss_NodeBlock.h" // for NodeBlock |
| 28 |
#include "Ioss_ParallelUtils.h" // for ParallelUtils |
| 29 |
#include "Ioss_Property.h" // for Property |
| 30 |
#include "Ioss_PropertyManager.h" // for PropertyManager |
| 31 |
#include "Ioss_Region.h" // for Region |
| 32 |
#include "Ioss_SideSet.h" // for SideSet |
| 33 |
#include "Ioss_StructuredBlock.h" |
| 34 |
#include "Ioss_VariableType.h" // for VariableType |
| 35 |
|
| 36 |
namespace { |
| 37 |
template <typename INT> |
| 38 |
void map_global_to_local(const Ioss::Map &map, size_t count, size_t stride, INT *data) |
| 39 |
{ |
| 40 |
for (size_t i = 0; i < count; i += stride) { |
| 41 |
int64_t local = map.global_to_local(data[i], true); |
| 42 |
data[i] = local; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
template <typename INT> |
| 47 |
void fill_transient_data(size_t component_count, double *data, INT *ids, size_t count, |
| 48 |
double offset = 0.0) |
| 49 |
{ |
| 50 |
if (component_count == 1) { |
| 51 |
for (size_t i = 0; i < count; i++) { |
| 52 |
data[i] = std::sqrt((double)ids[i]) + offset; |
| 53 |
} |
| 54 |
} |
| 55 |
else { |
| 56 |
for (size_t i = 0; i < count; i++) { |
| 57 |
for (size_t j = 0; j < component_count; j++) { |
| 58 |
data[i * component_count + j] = j + std::sqrt((double)ids[i]) + offset; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void fill_transient_data(const Ioss::GroupingEntity *entity, const Ioss::Field &field, void *data, |
| 65 |
void *id_data, size_t count, double offset = 0.0) |
| 66 |
{ |
| 67 |
const Ioss::Field &ids = entity->get_fieldref("ids"); |
| 68 |
if (ids.is_type(Ioss::Field::INTEGER)) { |
| 69 |
fill_transient_data(field.raw_storage()->component_count(), reinterpret_cast<double *>(data), |
| 70 |
reinterpret_cast<int *>(id_data), count, offset); |
| 71 |
} |
| 72 |
else { |
| 73 |
fill_transient_data(field.raw_storage()->component_count(), reinterpret_cast<double *>(data), |
| 74 |
reinterpret_cast<int64_t *>(id_data), count, offset); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
void fill_constant_data(const Ioss::Field &field, void *data, double value) |
| 79 |
{ |
| 80 |
auto *rdata = reinterpret_cast<double *>(data); |
| 81 |
size_t count = field.raw_count(); |
| 82 |
size_t component_count = field.raw_storage()->component_count(); |
| 83 |
for (size_t i = 0; i < count * component_count; i++) { |
| 84 |
rdata[i] = value; |
| 85 |
} |
| 86 |
} |
| 87 |
} // namespace |
| 88 |
namespace Iogs { |
| 89 |
|
| 90 |
// ======================================================================== |
| 91 |
const IOFactory *IOFactory::factory() |
| 92 |
{ |
| 93 |
static IOFactory registerThis; |
| 94 |
return ®isterThis; |
| 95 |
} |
| 96 |
|
| 97 |
IOFactory::IOFactory() : Ioss::IOFactory("gen_struc") {} |
| 98 |
|
| 99 |
Ioss::DatabaseIO *IOFactory::make_IO(const std::string &filename, Ioss::DatabaseUsage db_usage, |
| 100 |
Ioss_MPI_Comm communicator, |
| 101 |
const Ioss::PropertyManager &props) const |
| 102 |
{ |
| 103 |
return new DatabaseIO(nullptr, filename, db_usage, communicator, props); |
| 104 |
} |
| 105 |
|
| 106 |
// ======================================================================== |
| 107 |
DatabaseIO::DatabaseIO(Ioss::Region *region, const std::string &filename, |
| 108 |
Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator, |
| 109 |
const Ioss::PropertyManager &props) |
| 110 |
: Ioss::DatabaseIO(region, filename, db_usage, communicator, props) |
| 111 |
{ |
| 112 |
if (is_input()) { |
| 113 |
dbState = Ioss::STATE_UNKNOWN; |
| 114 |
} |
| 115 |
else { |
| 116 |
IOSS_ERROR("ERROR: Structured Generated mesh option is only valid for input mesh."); |
| 117 |
} |
| 118 |
if (props.exists("USE_CONSTANT_DF")) { |
| 119 |
m_useVariableDf = false; |
| 120 |
} |
| 121 |
if (util().parallel_size() > 1) { |
| 122 |
IOSS_ERROR("ERROR: Structured Generated mesh option is not valid for parallel yet."); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
DatabaseIO::~DatabaseIO() { delete m_generatedMesh; } |
| 127 |
|
| 128 |
void DatabaseIO::read_meta_data_nl() |
| 129 |
{ |
| 130 |
if (m_generatedMesh == nullptr) { |
| 131 |
if (get_filename() == "external") { |
| 132 |
IOSS_ERROR("ERROR: (gen_struc mesh) 'external' specified for mesh, but " |
| 133 |
"getGeneratedMesh was not called to set the external mesh.\n"); |
| 134 |
} |
| 135 |
else { |
| 136 |
m_generatedMesh = |
| 137 |
new GeneratedMesh(get_filename(), util().parallel_size(), util().parallel_rank()); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
assert(m_generatedMesh != nullptr); |
| 142 |
|
| 143 |
Ioss::Region *this_region = get_region(); |
| 144 |
this_region->property_add(Ioss::Property("global_node_count", m_generatedMesh->node_count())); |
| 145 |
this_region->property_add( |
| 146 |
Ioss::Property("global_element_count", m_generatedMesh->element_count())); |
| 147 |
|
| 148 |
spatialDimension = 3; |
| 149 |
nodeCount = m_generatedMesh->node_count_proc(); |
| 150 |
elementCount = m_generatedMesh->element_count_proc(); |
| 151 |
|
| 152 |
get_step_times_nl(); |
| 153 |
|
| 154 |
add_transient_fields(this_region); |
| 155 |
get_nodeblocks(); |
| 156 |
get_structured_blocks(); |
| 157 |
get_sidesets(); |
| 158 |
|
| 159 |
this_region->property_add( |
| 160 |
Ioss::Property(std::string("title"), std::string("GeneratedMesh: ") += get_filename())); |
| 161 |
} |
| 162 |
|
| 163 |
bool DatabaseIO::begin_nl(Ioss::State /* state */) { return true; } |
| 164 |
|
| 165 |
bool DatabaseIO::end_nl(Ioss::State /* state */) { return true; } |
| 166 |
|
| 167 |
bool DatabaseIO::begin_state_nl(int /* state */, double time) |
| 168 |
{ |
| 169 |
currentTime = time; |
| 170 |
return true; |
| 171 |
} |
| 172 |
|
| 173 |
int64_t DatabaseIO::get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, |
| 174 |
void *data, size_t data_size) const |
| 175 |
{ |
| 176 |
size_t num_to_get = field.verify(data_size); |
| 177 |
|
| 178 |
Ioss::Field::RoleType role = field.get_role(); |
| 179 |
if (role == Ioss::Field::MESH) { |
| 180 |
if (field.get_name() == "mesh_model_coordinates") { |
| 181 |
// Cast 'data' to correct size -- double |
| 182 |
auto *rdata = static_cast<double *>(data); |
| 183 |
m_generatedMesh->coordinates(rdata); |
| 184 |
} |
| 185 |
|
| 186 |
// NOTE: The implicit_ids field is ONLY provided for backward- |
| 187 |
// compatibility and should not be used unless absolutely |
| 188 |
// required. For gen_struc mesh, the implicit_ids and ids are the same. |
| 189 |
else if (field.get_name() == "ids" || field.get_name() == "implicit_ids") { |
| 190 |
// Map the local ids in this node block |
| 191 |
// (1...node_count) to global node ids. |
| 192 |
get_node_map().map_implicit_data(data, field, num_to_get, 0); |
| 193 |
} |
| 194 |
else if (field.get_name() == "owning_processor") { |
| 195 |
int *owner = static_cast<int *>(data); |
| 196 |
m_generatedMesh->owning_processor(owner, num_to_get); |
| 197 |
} |
| 198 |
else if (field.get_name() == "connectivity") { |
| 199 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 200 |
} |
| 201 |
else if (field.get_name() == "connectivity_raw") { |
| 202 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 203 |
} |
| 204 |
else { |
| 205 |
num_to_get = Ioss::Utils::field_warning(nb, field, "input"); |
| 206 |
} |
| 207 |
return num_to_get; |
| 208 |
} |
| 209 |
|
| 210 |
const Ioss::Field &id_fld = nb->get_fieldref("ids"); |
| 211 |
std::vector<char> ids(id_fld.get_size()); |
| 212 |
get_field_internal(nb, id_fld, Data(ids), id_fld.get_size()); |
| 213 |
fill_transient_data(nb, field, data, Data(ids), num_to_get, currentTime); |
| 214 |
|
| 215 |
return num_to_get; |
| 216 |
} |
| 217 |
|
| 218 |
int64_t DatabaseIO::get_field_internal(const Ioss::Region * /*region*/, const Ioss::Field &field, |
| 219 |
void *data, size_t /*data_size*/) const |
| 220 |
{ |
| 221 |
Ioss::Field::RoleType role = field.get_role(); |
| 222 |
if (role == Ioss::Field::TRANSIENT) { |
| 223 |
// Fill the field with arbitrary data... |
| 224 |
(reinterpret_cast<double *>(data))[0] = static_cast<double>(rand()); |
| 225 |
} |
| 226 |
return 1; |
| 227 |
} |
| 228 |
|
| 229 |
int64_t DatabaseIO::get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, |
| 230 |
void *data, size_t data_size) const |
| 231 |
{ |
| 232 |
Ioss::Field::RoleType role = field.get_role(); |
| 233 |
int zone = sb->get_property("zone").get_int(); |
| 234 |
|
| 235 |
int64_t num_to_get = field.verify(data_size); |
| 236 |
auto *rdata = static_cast<double *>(data); |
| 237 |
|
| 238 |
if (role == Ioss::Field::MESH) { |
| 239 |
if (field.get_name() == "mesh_model_coordinates_x") { |
| 240 |
m_generatedMesh->coordinates(1, zone, rdata); |
| 241 |
} |
| 242 |
|
| 243 |
else if (field.get_name() == "mesh_model_coordinates_y") { |
| 244 |
m_generatedMesh->coordinates(2, zone, rdata); |
| 245 |
} |
| 246 |
|
| 247 |
else if (field.get_name() == "mesh_model_coordinates_z") { |
| 248 |
m_generatedMesh->coordinates(3, zone, rdata); |
| 249 |
} |
| 250 |
|
| 251 |
else if (field.get_name() == "mesh_model_coordinates") { |
| 252 |
m_generatedMesh->coordinates(0, zone, rdata); |
| 253 |
} |
| 254 |
else if (field.get_name() == "cell_node_ids") { |
| 255 |
if (field.get_type() == Ioss::Field::INT64) { |
| 256 |
auto *idata = static_cast<int64_t *>(data); |
| 257 |
sb->get_cell_node_ids(idata, true); |
| 258 |
} |
| 259 |
else { |
| 260 |
assert(field.get_type() == Ioss::Field::INT32); |
| 261 |
auto *idata = static_cast<int *>(data); |
| 262 |
sb->get_cell_node_ids(idata, true); |
| 263 |
} |
| 264 |
} |
| 265 |
else if (field.get_name() == "cell_ids") { |
| 266 |
if (field.get_type() == Ioss::Field::INT64) { |
| 267 |
auto *idata = static_cast<int64_t *>(data); |
| 268 |
sb->get_cell_ids(idata, true); |
| 269 |
} |
| 270 |
else { |
| 271 |
assert(field.get_type() == Ioss::Field::INT32); |
| 272 |
auto *idata = static_cast<int *>(data); |
| 273 |
sb->get_cell_ids(idata, true); |
| 274 |
} |
| 275 |
} |
| 276 |
else { |
| 277 |
num_to_get = Ioss::Utils::field_warning(sb, field, "input"); |
| 278 |
} |
| 279 |
} |
| 280 |
else if (role == Ioss::Field::TRANSIENT) { |
| 281 |
} |
| 282 |
else { |
| 283 |
num_to_get = Ioss::Utils::field_warning(sb, field, "input"); |
| 284 |
} |
| 285 |
return num_to_get; |
| 286 |
} |
| 287 |
|
| 288 |
int64_t DatabaseIO::get_field_internal(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, |
| 289 |
void *data, size_t data_size) const |
| 290 |
{ |
| 291 |
size_t num_to_get = field.verify(data_size); |
| 292 |
|
| 293 |
int64_t id = sd_blk->get_property("id").get_int(); |
| 294 |
size_t entity_count = sd_blk->entity_count(); |
| 295 |
if (num_to_get != entity_count) { |
| 296 |
IOSS_ERROR("ERROR: Partial field input not implemented for side blocks"); |
| 297 |
} |
| 298 |
|
| 299 |
Ioss::Field::RoleType role = field.get_role(); |
| 300 |
if (role == Ioss::Field::MESH) { |
| 301 |
|
| 302 |
if (field.get_name() == "ids") { |
| 303 |
// A sideset' is basically an exodus sideset. A |
| 304 |
// sideset has a list of elements and a corresponding local |
| 305 |
// element side (1-based) The side id is: side_id = |
| 306 |
// 10*element_id + local_side_number This assumes that all |
| 307 |
// sides in a sideset are boundary sides. |
| 308 |
std::vector<int64_t> elem_side; |
| 309 |
m_generatedMesh->sideset_elem_sides(id, elem_side); |
| 310 |
if (field.is_type(Ioss::Field::INTEGER)) { |
| 311 |
auto *ids = static_cast<int *>(data); |
| 312 |
for (size_t i = 0; i < num_to_get; i++) { |
| 313 |
ids[i] = 10 * elem_side[2 * i + 0] + elem_side[2 * i + 1] + 1; |
| 314 |
} |
| 315 |
} |
| 316 |
else { |
| 317 |
auto *ids = static_cast<int64_t *>(data); |
| 318 |
for (size_t i = 0; i < num_to_get; i++) { |
| 319 |
ids[i] = 10 * elem_side[2 * i + 0] + elem_side[2 * i + 1] + 1; |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
else if (field.get_name() == "element_side" || field.get_name() == "element_side_raw") { |
| 325 |
// Since we only have a single array, we need to allocate an extra |
| 326 |
// array to store all of the data. Note also that the element_id |
| 327 |
// is the global id but only the local id is stored so we need to |
| 328 |
// map from local_to_global prior to generating the side id... |
| 329 |
|
| 330 |
std::vector<int64_t> elem_side; |
| 331 |
m_generatedMesh->sideset_elem_sides(id, elem_side); |
| 332 |
if (field.get_name() == "element_side_raw") { |
| 333 |
map_global_to_local(get_element_map(), elem_side.size(), 2, Data(elem_side)); |
| 334 |
} |
| 335 |
|
| 336 |
if (field.is_type(Ioss::Field::INTEGER)) { |
| 337 |
auto *element_side = static_cast<int *>(data); |
| 338 |
for (size_t i = 0; i < num_to_get; i++) { |
| 339 |
element_side[2 * i + 0] = elem_side[2 * i + 0]; |
| 340 |
element_side[2 * i + 1] = elem_side[2 * i + 1] + 1; |
| 341 |
} |
| 342 |
} |
| 343 |
else { |
| 344 |
auto *element_side = static_cast<int64_t *>(data); |
| 345 |
for (size_t i = 0; i < num_to_get; i++) { |
| 346 |
element_side[2 * i + 0] = elem_side[2 * i + 0]; |
| 347 |
element_side[2 * i + 1] = elem_side[2 * i + 1] + 1; |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
else if (field.get_name() == "distribution_factors") { |
| 353 |
if (m_useVariableDf) { |
| 354 |
const Ioss::Field &id_fld = sd_blk->get_fieldref("ids"); |
| 355 |
std::vector<char> ids(id_fld.get_size()); |
| 356 |
get_field_internal(sd_blk, id_fld, Data(ids), id_fld.get_size()); |
| 357 |
fill_transient_data(sd_blk, field, data, Data(ids), num_to_get); |
| 358 |
} |
| 359 |
else { |
| 360 |
fill_constant_data(field, data, 1.0); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
else { |
| 365 |
num_to_get = Ioss::Utils::field_warning(sd_blk, field, "input"); |
| 366 |
} |
| 367 |
} |
| 368 |
else if (role == Ioss::Field::TRANSIENT) { |
| 369 |
const Ioss::Field &id_fld = sd_blk->get_fieldref("ids"); |
| 370 |
std::vector<char> ids(id_fld.get_size()); |
| 371 |
get_field_internal(sd_blk, id_fld, Data(ids), id_fld.get_size()); |
| 372 |
fill_transient_data(sd_blk, field, data, Data(ids), num_to_get, currentTime); |
| 373 |
} |
| 374 |
return num_to_get; |
| 375 |
} |
| 376 |
|
| 377 |
int64_t DatabaseIO::get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, |
| 378 |
void *data, size_t data_size) const |
| 379 |
{ |
| 380 |
size_t num_to_get = field.verify(data_size); |
| 381 |
size_t entity_count = cs->entity_count(); |
| 382 |
assert(num_to_get == entity_count); |
| 383 |
|
| 384 |
// Return the <entity (node or face), processor> pair |
| 385 |
if (field.get_name() == "entity_processor" || field.get_name() == "entity_processor_raw") { |
| 386 |
|
| 387 |
// Check type -- node or face |
| 388 |
std::string type = cs->get_property("entity_type").get_string(); |
| 389 |
|
| 390 |
if (type == "node") { |
| 391 |
// Allocate temporary storage space |
| 392 |
Ioss::Int64Vector entities(num_to_get); |
| 393 |
Ioss::IntVector procs(num_to_get); |
| 394 |
m_generatedMesh->node_communication_map(entities, procs); |
| 395 |
|
| 396 |
// and store in 'data' ... |
| 397 |
if (field.is_type(Ioss::Field::INTEGER)) { |
| 398 |
int *entity_proc = static_cast<int *>(data); |
| 399 |
|
| 400 |
size_t j = 0; |
| 401 |
for (size_t i = 0; i < entity_count; i++) { |
| 402 |
assert(entities[i] > 0); |
| 403 |
entity_proc[j++] = entities[i]; |
| 404 |
entity_proc[j++] = procs[i]; |
| 405 |
} |
| 406 |
|
| 407 |
if (field.get_name() == "entity_processor_raw") { |
| 408 |
map_global_to_local(get_node_map(), 2 * entity_count, 2, entity_proc); |
| 409 |
} |
| 410 |
} |
| 411 |
else { |
| 412 |
auto *entity_proc = static_cast<int64_t *>(data); |
| 413 |
|
| 414 |
size_t j = 0; |
| 415 |
for (size_t i = 0; i < entity_count; i++) { |
| 416 |
assert(entities[i] > 0); |
| 417 |
entity_proc[j++] = entities[i]; |
| 418 |
entity_proc[j++] = procs[i]; |
| 419 |
} |
| 420 |
|
| 421 |
if (field.get_name() == "entity_processor_raw") { |
| 422 |
map_global_to_local(get_node_map(), 2 * entity_count, 2, entity_proc); |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
else { |
| 427 |
IOSS_ERROR(fmt::format("Invalid commset type {}", type)); |
| 428 |
} |
| 429 |
} |
| 430 |
else if (field.get_name() == "ids") { |
| 431 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 432 |
} |
| 433 |
else { |
| 434 |
num_to_get = Ioss::Utils::field_warning(cs, field, "input"); |
| 435 |
} |
| 436 |
return num_to_get; |
| 437 |
} |
| 438 |
|
| 439 |
const Ioss::Map &DatabaseIO::get_node_map() const |
| 440 |
{ |
| 441 |
// Allocate space for node number map and read it in... |
| 442 |
// Can be called multiple times, allocate 1 time only |
| 443 |
if (nodeMap.map().empty()) { |
| 444 |
nodeMap.set_size(nodeCount); |
| 445 |
std::vector<int64_t> map; |
| 446 |
m_generatedMesh->node_map(map); |
| 447 |
nodeMap.set_map(Data(map), map.size(), 0, true); |
| 448 |
} |
| 449 |
return nodeMap; |
| 450 |
} |
| 451 |
|
| 452 |
const Ioss::Map &DatabaseIO::get_element_map() const |
| 453 |
{ |
| 454 |
// Allocate space for element number map and read it in... |
| 455 |
// Can be called multiple times, allocate 1 time only |
| 456 |
if (elemMap.map().empty()) { |
| 457 |
elemMap.set_size(elementCount); |
| 458 |
std::vector<int64_t> map; |
| 459 |
m_generatedMesh->element_map(map); |
| 460 |
elemMap.set_map(Data(map), map.size(), 0, true); |
| 461 |
} |
| 462 |
return elemMap; |
| 463 |
} |
| 464 |
|
| 465 |
void DatabaseIO::get_nodeblocks() |
| 466 |
{ |
| 467 |
std::string block_name = "nodeblock_1"; |
| 468 |
auto block = new Ioss::NodeBlock(this, block_name, m_generatedMesh->node_count_proc(), 3); |
| 469 |
block->property_add(Ioss::Property("id", 1)); |
| 470 |
block->property_add(Ioss::Property("guid", util().generate_guid(1))); |
| 471 |
get_region()->add(block); |
| 472 |
add_transient_fields(block); |
| 473 |
} |
| 474 |
|
| 475 |
void DatabaseIO::get_step_times_nl() |
| 476 |
{ |
| 477 |
int time_step_count = m_generatedMesh->timestep_count(); |
| 478 |
for (int i = 0; i < time_step_count; i++) { |
| 479 |
get_region()->add_state(i); |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
std::vector<double> DatabaseIO::get_db_step_times_nl() |
| 484 |
{ |
| 485 |
std::vector<double> timesteps; |
| 486 |
|
| 487 |
int time_step_count = m_generatedMesh->timestep_count(); |
| 488 |
timesteps.reserve(time_step_count); |
| 489 |
|
| 490 |
for (int i = 0; i < time_step_count; i++) { |
| 491 |
timesteps.push_back(i); |
| 492 |
} |
| 493 |
|
| 494 |
return timesteps; |
| 495 |
} |
| 496 |
|
| 497 |
void DatabaseIO::get_structured_blocks() |
| 498 |
{ |
| 499 |
// Name, global range, local offset, local range. |
| 500 |
int block_count = m_generatedMesh->structured_block_count(); |
| 501 |
for (int i = 0; i < block_count; i++) { |
| 502 |
std::string name = Ioss::Utils::encode_entity_name("block", i + 1); |
| 503 |
Ioss::IJK_t global = m_generatedMesh->block_range(i + 1); |
| 504 |
auto block = new Ioss::StructuredBlock(this, name, 3, global[0], global[1], global[2]); |
| 505 |
|
| 506 |
block->property_add(Ioss::Property("base", 1)); |
| 507 |
block->property_add(Ioss::Property("zone", i + 1)); |
| 508 |
block->property_add(Ioss::Property("id", i + 1)); |
| 509 |
block->property_add(Ioss::Property("guid", i + 1)); |
| 510 |
get_region()->add(block); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
void DatabaseIO::get_sidesets() |
| 515 |
{ |
| 516 |
m_sideset_names.reserve(sidesetCount); |
| 517 |
for (int ifs = 0; ifs < sidesetCount; ifs++) { |
| 518 |
std::string name = Ioss::Utils::encode_entity_name("surface", ifs + 1); |
| 519 |
m_sideset_names.push_back(name); |
| 520 |
auto sideset = new Ioss::SideSet(this, name); |
| 521 |
sideset->property_add(Ioss::Property("id", ifs + 1)); |
| 522 |
sideset->property_add(Ioss::Property("guid", util().generate_guid(ifs + 1))); |
| 523 |
get_region()->add(sideset); |
| 524 |
|
| 525 |
Ioss::NameList touching_blocks = m_generatedMesh->sideset_touching_blocks(ifs + 1); |
| 526 |
if (touching_blocks.size() == 1) { |
| 527 |
std::string sd_block_name = name + "_quad4"; |
| 528 |
std::string side_topo_name = "quad4"; |
| 529 |
std::string elem_topo_name = "unknown"; |
| 530 |
int64_t number_faces = m_generatedMesh->sideset_side_count_proc(ifs + 1); |
| 531 |
|
| 532 |
auto sd_block = |
| 533 |
new Ioss::SideBlock(this, sd_block_name, side_topo_name, elem_topo_name, number_faces); |
| 534 |
sideset->add(sd_block); |
| 535 |
sd_block->property_add(Ioss::Property("id", ifs + 1)); |
| 536 |
sd_block->property_add(Ioss::Property("guid", util().generate_guid(ifs + 1))); |
| 537 |
|
| 538 |
std::string storage = "Real["; |
| 539 |
storage += std::to_string(4); |
| 540 |
storage += "]"; |
| 541 |
sd_block->field_add(Ioss::Field("distribution_factors", Ioss::Field::REAL, storage, |
| 542 |
Ioss::Field::MESH, number_faces)); |
| 543 |
|
| 544 |
Ioss::ElementBlock *el_block = get_region()->get_element_block(touching_blocks[0]); |
| 545 |
sd_block->set_parent_element_block(el_block); |
| 546 |
add_transient_fields(sd_block); |
| 547 |
} |
| 548 |
else { |
| 549 |
for (auto &touching_block : touching_blocks) { |
| 550 |
std::string sd_block_name = |
| 551 |
"surface_" + touching_block + "_edge2_" + std::to_string(ifs + 1); |
| 552 |
std::string side_topo_name = "quad4"; |
| 553 |
std::string elem_topo_name = "unknown"; |
| 554 |
int64_t number_faces = m_generatedMesh->sideset_side_count_proc(ifs + 1); |
| 555 |
|
| 556 |
auto sd_block = new Ioss::SideBlock(this, sd_block_name, side_topo_name, elem_topo_name, |
| 557 |
number_faces); |
| 558 |
sideset->add(sd_block); |
| 559 |
sd_block->property_add(Ioss::Property("id", ifs + 1)); |
| 560 |
sd_block->property_add(Ioss::Property("guid", util().generate_guid(ifs + 1))); |
| 561 |
|
| 562 |
std::string storage = "Real["; |
| 563 |
storage += std::to_string(4); |
| 564 |
storage += "]"; |
| 565 |
sd_block->field_add(Ioss::Field("distribution_factors", Ioss::Field::REAL, storage, |
| 566 |
Ioss::Field::MESH, number_faces)); |
| 567 |
|
| 568 |
Ioss::ElementBlock *el_block = get_region()->get_element_block(touching_block); |
| 569 |
sd_block->set_parent_element_block(el_block); |
| 570 |
add_transient_fields(sd_block); |
| 571 |
} |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
unsigned DatabaseIO::entity_field_support() const |
| 577 |
{ |
| 578 |
return Ioss::NODEBLOCK | Ioss::STRUCTUREDBLOCK | Ioss::REGION | Ioss::SIDESET; |
| 579 |
} |
| 580 |
|
| 581 |
void DatabaseIO::add_transient_fields(Ioss::GroupingEntity *entity) |
| 582 |
{ |
| 583 |
Ioss::EntityType type = entity->type(); |
| 584 |
size_t entity_count = entity->entity_count(); |
| 585 |
size_t var_count = m_generatedMesh->get_variable_count(type); |
| 586 |
for (size_t i = 0; i < var_count; i++) { |
| 587 |
std::string var_name = entity->type_string() + "_" + std::to_string(i + 1); |
| 588 |
entity->field_add(Ioss::Field(std::move(var_name), Ioss::Field::REAL, "scalar", |
| 589 |
Ioss::Field::TRANSIENT, entity_count)); |
| 590 |
} |
| 591 |
} |
| 592 |
} // namespace Iogs |