NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble::GenesisMesh Class Reference

#include <nimble_genesis_mesh.h>

Public Member Functions

 GenesisMesh ()
 
 ~GenesisMesh ()=default
 
bool IsValid () const
 
std::string FileName () const
 
unsigned int GetNumNodes () const
 
const int * GetNodeGlobalIds () const
 
std::size_t GetNumNodeGlobalIds () const
 
int GetMaxNodeGlobalId () const
 
unsigned int GetNumElements () const
 
const int * GetElementGlobalIds () const
 
std::vector< int > const & GetElementGlobalIdsInBlock (int block_id) const
 
unsigned int GetNumBlocks () const
 
unsigned int GetNumGlobalBlocks () const
 
bool HasBlock (std::string const &block_name) const
 
std::vector< int > GetBlockIds () const
 
std::vector< int > GetAllBlockIds () const
 
int GetNumElementsInBlock (int block_id) const
 
std::map< int, int > GetNumElementsInBlock () const
 
int GetNumNodesPerElement (int block_id) const
 
std::map< int, int > GetNumNodesPerElement () const
 
std::string GetElementType (int block_id) const
 
std::string GetBlockName (int block_id) const
 
int GetBlockId (std::string const &block_name) const
 
void BlockNamesToOnProcessorBlockIds (std::vector< std::string > const &block_names, std::vector< int > &block_ids)
 
int GetDim () const
 
const double * GetCoordinatesX () const
 
const double * GetCoordinatesY () const
 
const double * GetCoordinatesZ () const
 
const int * GetConnectivity (int block_id) const
 
std::map< int, std::vector< int > > & GetConnectivity ()
 
int GetNumNodeSets () const
 
std::vector< int > GetNodeSetIds () const
 
std::map< int, std::string > GetNodeSetNames () const
 
std::map< int, std::vector< int > > GetNodeSets () const
 
std::map< int, std::vector< double > > GetNodeSetDistributionFactors () const
 
int GetNumSideSets () const
 
std::vector< int > GetSideSetIds () const
 
std::map< int, std::string > GetSideSetNames () const
 
std::map< int, std::vector< int > > GetSideSets () const
 
std::map< int, std::vector< double > > GetSideSetDistributionFactors () const
 
void BoundingBox (double &x_min, double &x_max, double &y_min, double &y_max, double &z_min, double &z_max) const
 
std::vector< double > BoundingBoxCenter () const
 
void AppendPeriodicPair (int local_primary_node_id, int local_secondary_node_id, const int *global_node_ids, std::map< int, int > &global_node_id_secondary_to_primary) const
 
void Print (bool verbose=false, int my_rank=0) const
 
void ReadFile (std::string file_name)
 
void ReadTextFile (std::string file_name)
 
void Initialize (std::string const &file_name, std::vector< int > const &node_global_id, std::vector< double > const &node_x, std::vector< double > const &node_y, std::vector< double > const &node_z, std::vector< int > const &elem_global_id, std::vector< int > const &block_ids, std::map< int, std::string > const &block_names, std::map< int, std::vector< int > > const &block_elem_global_ids, std::map< int, int > const &block_num_nodes_per_elem, std::map< int, std::vector< int > > const &block_elem_connectivity)
 

Protected Member Functions

void ReportExodusError (int error_code, const char *method_name, const char *exodus_method_name) const
 

Protected Attributes

std::string file_name_
 
int dim_
 
std::vector< int > node_global_id_
 
std::vector< double > node_x_
 
std::vector< double > node_y_
 
std::vector< double > node_z_
 
std::vector< int > elem_global_id_
 
std::vector< int > all_block_ids_
 
std::vector< int > block_ids_
 
std::map< int, std::string > all_block_names_
 
std::map< int, std::string > block_names_
 
std::map< int, std::vector< int > > block_elem_global_ids_
 
std::map< int, int > block_num_nodes_per_elem_
 
std::map< int, std::vector< int > > block_elem_connectivity_
 
std::vector< int > node_set_ids_
 
std::map< int, std::string > node_set_names_
 
std::map< int, std::vector< int > > node_sets_
 
std::map< int, std::vector< double > > ns_distribution_factors_
 
std::vector< int > side_set_ids_
 
std::map< int, std::string > side_set_names_
 
std::map< int, std::vector< int > > side_sets_
 
std::map< int, std::vector< double > > ss_distribution_factors_
 

Constructor & Destructor Documentation

◆ GenesisMesh()

nimble::GenesisMesh::GenesisMesh ( )
inline
61: file_name_("undefined"), dim_(-1) {}
std::string file_name_
Definition nimble_genesis_mesh.h:332
int dim_
Definition nimble_genesis_mesh.h:333

◆ ~GenesisMesh()

nimble::GenesisMesh::~GenesisMesh ( )
default

Member Function Documentation

◆ AppendPeriodicPair()

void nimble::GenesisMesh::AppendPeriodicPair ( int local_primary_node_id,
int local_secondary_node_id,
const int * global_node_ids,
std::map< int, int > & global_node_id_secondary_to_primary ) const
580{
581 int global_primary_node_id = global_node_ids[local_primary_node_id];
582 int global_secondary_node_id = global_node_ids[local_secondary_node_id];
583 global_node_id_secondary_to_primary[global_secondary_node_id] = global_primary_node_id;
584}

◆ BlockNamesToOnProcessorBlockIds()

void nimble::GenesisMesh::BlockNamesToOnProcessorBlockIds ( std::vector< std::string > const & block_names,
std::vector< int > & block_ids )
527{
528 block_ids.clear();
529 for (auto& name : block_names) {
530 // if the block name is not on this processor, do not add it to the list of
531 // block ids
532 if (HasBlock(name)) { block_ids.push_back(GetBlockId(name)); }
533 }
534}
bool HasBlock(std::string const &block_name) const
Definition nimble_genesis_mesh.cc:508
int GetBlockId(std::string const &block_name) const
Definition nimble_genesis_mesh.cc:517

◆ BoundingBox()

void nimble::GenesisMesh::BoundingBox ( double & x_min,
double & x_max,
double & y_min,
double & y_max,
double & z_min,
double & z_max ) const
538{
539 // THIS WORKS ONLY IN SERIAL
540
541 unsigned int num_nodes = GetNumNodes();
542 double big = std::numeric_limits<double>::max();
543 x_min = big;
544 x_max = -1.0 * big;
545 y_min = big;
546 y_max = -1.0 * big;
547 z_min = big;
548 z_max = -1.0 * big;
549 for (unsigned int n = 0; n < num_nodes; n++) {
550 double x = node_x_[n];
551 double y = node_y_[n];
552 double z = node_z_[n];
553 if (x < x_min) x_min = x;
554 if (x > x_max) x_max = x;
555 if (y < y_min) y_min = y;
556 if (y > y_max) y_max = y;
557 if (z < z_min) z_min = z;
558 if (z > z_max) z_max = z;
559 }
560}
unsigned int GetNumNodes() const
Definition nimble_genesis_mesh.h:90
std::vector< double > node_x_
Definition nimble_genesis_mesh.h:336
std::vector< double > node_z_
Definition nimble_genesis_mesh.h:338
std::vector< double > node_y_
Definition nimble_genesis_mesh.h:337

◆ BoundingBoxCenter()

std::vector< double > nimble::GenesisMesh::BoundingBoxCenter ( ) const
564{
565 double x_min, x_max, y_min, y_max, z_min, z_max;
566 BoundingBox(x_min, x_max, y_min, y_max, z_min, z_max);
567 std::vector<double> center(3);
568 center[0] = (x_max + x_min) / 2.0;
569 center[1] = (y_max + y_min) / 2.0;
570 center[2] = (z_max + z_min) / 2.0;
571 return center;
572}
void BoundingBox(double &x_min, double &x_max, double &y_min, double &y_max, double &z_min, double &z_max) const
Definition nimble_genesis_mesh.cc:537

◆ FileName()

std::string nimble::GenesisMesh::FileName ( ) const
inline
85 {
86 return file_name_;
87 }

◆ GetAllBlockIds()

std::vector< int > nimble::GenesisMesh::GetAllBlockIds ( ) const
inline
157 {
158 return all_block_ids_;
159 }
std::vector< int > all_block_ids_
Definition nimble_genesis_mesh.h:340

◆ GetBlockId()

int nimble::GenesisMesh::GetBlockId ( std::string const & block_name) const
518{
519 for (auto& entry : block_names_) {
520 if (entry.second == block_name) { return entry.first; }
521 }
522 throw std::invalid_argument("\n**** Error in GenesisMesh::GetBlockId(), block name not found.\n");
523}
std::map< int, std::string > block_names_
Definition nimble_genesis_mesh.h:343

◆ GetBlockIds()

std::vector< int > nimble::GenesisMesh::GetBlockIds ( ) const
inline
151 {
152 return block_ids_;
153 }
std::vector< int > block_ids_
Definition nimble_genesis_mesh.h:341

◆ GetBlockName()

std::string nimble::GenesisMesh::GetBlockName ( int block_id) const
inline
184 {
185 return all_block_names_.at(block_id);
186 }
std::map< int, std::string > all_block_names_
Definition nimble_genesis_mesh.h:342

◆ GetConnectivity() [1/2]

std::map< int, std::vector< int > > & nimble::GenesisMesh::GetConnectivity ( )
inline
226 {
228 }
std::map< int, std::vector< int > > block_elem_connectivity_
Definition nimble_genesis_mesh.h:346

◆ GetConnectivity() [2/2]

const int * nimble::GenesisMesh::GetConnectivity ( int block_id) const
inline
220 {
221 return &block_elem_connectivity_.at(block_id)[0];
222 }

◆ GetCoordinatesX()

const double * nimble::GenesisMesh::GetCoordinatesX ( ) const
inline
202 {
203 return &node_x_[0];
204 }

◆ GetCoordinatesY()

const double * nimble::GenesisMesh::GetCoordinatesY ( ) const
inline
208 {
209 return &node_y_[0];
210 }

◆ GetCoordinatesZ()

const double * nimble::GenesisMesh::GetCoordinatesZ ( ) const
inline
214 {
215 return &node_z_[0];
216 }

◆ GetDim()

int nimble::GenesisMesh::GetDim ( ) const
inline
196 {
197 return dim_;
198 }

◆ GetElementGlobalIds()

const int * nimble::GenesisMesh::GetElementGlobalIds ( ) const
inline
124 {
125 return &elem_global_id_[0];
126 }
std::vector< int > elem_global_id_
Definition nimble_genesis_mesh.h:339

◆ GetElementGlobalIdsInBlock()

std::vector< int > const & nimble::GenesisMesh::GetElementGlobalIdsInBlock ( int block_id) const
inline
130 {
131 return block_elem_global_ids_.at(block_id);
132 }
std::map< int, std::vector< int > > block_elem_global_ids_
Definition nimble_genesis_mesh.h:344

◆ GetElementType()

std::string nimble::GenesisMesh::GetElementType ( int block_id) const
481{
482 int dim = GetDim();
483 int num_node_per_elem = GetNumNodesPerElement(block_id);
484 std::string elem_type = "UNKNOWN";
485
486 if (dim == 2) {
487 switch (num_node_per_elem) {
488 case 3: elem_type = "TRIANGLE:"; break;
489 case 4: elem_type = "QUAD"; break;
490 default: elem_type = "UNKNOWN"; break;
491 }
492 } else if (dim == 3) {
493 switch (num_node_per_elem) {
494 case 1: elem_type = "SPHERE"; break;
495 case 3: elem_type = "TRIANGLE"; break;
496 case 4: elem_type = "TETRA"; break;
497 case 8: elem_type = "HEX"; break;
498 default: elem_type = "UNKNOWN"; break;
499 }
500 }
501
502 if (elem_type == "UNKNOWN") throw std::invalid_argument("Error processing input mesh, unknown element type.");
503
504 return elem_type;
505}
std::map< int, int > GetNumNodesPerElement() const
Definition nimble_genesis_mesh.h:174
int GetDim() const
Definition nimble_genesis_mesh.h:195

◆ GetMaxNodeGlobalId()

int nimble::GenesisMesh::GetMaxNodeGlobalId ( ) const
inline
108 {
109 int max_id = -1;
110 for (auto id : node_global_id_) {
111 if (id > max_id) { max_id = id; }
112 }
113 return max_id;
114 }
std::vector< int > node_global_id_
Definition nimble_genesis_mesh.h:335

◆ GetNodeGlobalIds()

const int * nimble::GenesisMesh::GetNodeGlobalIds ( ) const
inline
97 {
98 return &node_global_id_[0];
99 }

◆ GetNodeSetDistributionFactors()

std::map< int, std::vector< double > > nimble::GenesisMesh::GetNodeSetDistributionFactors ( ) const
inline
256 {
258 }
std::map< int, std::vector< double > > ns_distribution_factors_
Definition nimble_genesis_mesh.h:350

◆ GetNodeSetIds()

std::vector< int > nimble::GenesisMesh::GetNodeSetIds ( ) const
inline
238 {
239 return node_set_ids_;
240 }
std::vector< int > node_set_ids_
Definition nimble_genesis_mesh.h:347

◆ GetNodeSetNames()

std::map< int, std::string > nimble::GenesisMesh::GetNodeSetNames ( ) const
inline
244 {
245 return node_set_names_;
246 }
std::map< int, std::string > node_set_names_
Definition nimble_genesis_mesh.h:348

◆ GetNodeSets()

std::map< int, std::vector< int > > nimble::GenesisMesh::GetNodeSets ( ) const
inline
250 {
251 return node_sets_;
252 }
std::map< int, std::vector< int > > node_sets_
Definition nimble_genesis_mesh.h:349

◆ GetNumBlocks()

unsigned int nimble::GenesisMesh::GetNumBlocks ( ) const
inline
136 {
137 return block_ids_.size();
138 }

◆ GetNumElements()

unsigned int nimble::GenesisMesh::GetNumElements ( ) const
inline
118 {
119 return elem_global_id_.size();
120 }

◆ GetNumElementsInBlock() [1/2]

std::map< int, int > nimble::GenesisMesh::GetNumElementsInBlock ( ) const
471{
472 std::map<int, int> num_elem_in_each_block;
473 for (std::vector<int>::const_iterator it = block_ids_.begin(); it != block_ids_.end(); it++) {
474 num_elem_in_each_block[*it] = GetNumElementsInBlock(*it);
475 }
476 return num_elem_in_each_block;
477}
std::map< int, int > GetNumElementsInBlock() const
Definition nimble_genesis_mesh.cc:470

◆ GetNumElementsInBlock() [2/2]

int nimble::GenesisMesh::GetNumElementsInBlock ( int block_id) const
461{
462 unsigned int conn_size = block_elem_connectivity_.at(block_id).size();
463 int num_nodes_per_elem = block_num_nodes_per_elem_.at(block_id);
464 int num_elem_in_block = 0;
465 if (conn_size > 0) { num_elem_in_block = static_cast<int>(conn_size) / num_nodes_per_elem; }
466 return num_elem_in_block;
467}
std::map< int, int > block_num_nodes_per_elem_
Definition nimble_genesis_mesh.h:345

◆ GetNumGlobalBlocks()

unsigned int nimble::GenesisMesh::GetNumGlobalBlocks ( ) const
inline
142 {
143 return all_block_ids_.size();
144 }

◆ GetNumNodeGlobalIds()

std::size_t nimble::GenesisMesh::GetNumNodeGlobalIds ( ) const
inline
102 {
103 return node_global_id_.size();
104 }

◆ GetNumNodes()

unsigned int nimble::GenesisMesh::GetNumNodes ( ) const
inline
91 {
92 return node_x_.size();
93 }

◆ GetNumNodeSets()

int nimble::GenesisMesh::GetNumNodeSets ( ) const
inline
232 {
233 return static_cast<int>(node_set_ids_.size());
234 }

◆ GetNumNodesPerElement() [1/2]

std::map< int, int > nimble::GenesisMesh::GetNumNodesPerElement ( ) const
inline
175 {
177 }

◆ GetNumNodesPerElement() [2/2]

int nimble::GenesisMesh::GetNumNodesPerElement ( int block_id) const
inline
169 {
170 return block_num_nodes_per_elem_.at(block_id);
171 }

◆ GetNumSideSets()

int nimble::GenesisMesh::GetNumSideSets ( ) const
inline
262 {
263 return static_cast<int>(side_set_ids_.size());
264 }
std::vector< int > side_set_ids_
Definition nimble_genesis_mesh.h:351

◆ GetSideSetDistributionFactors()

std::map< int, std::vector< double > > nimble::GenesisMesh::GetSideSetDistributionFactors ( ) const
inline
286 {
288 }
std::map< int, std::vector< double > > ss_distribution_factors_
Definition nimble_genesis_mesh.h:354

◆ GetSideSetIds()

std::vector< int > nimble::GenesisMesh::GetSideSetIds ( ) const
inline
268 {
269 return side_set_ids_;
270 }

◆ GetSideSetNames()

std::map< int, std::string > nimble::GenesisMesh::GetSideSetNames ( ) const
inline
274 {
275 return side_set_names_;
276 }
std::map< int, std::string > side_set_names_
Definition nimble_genesis_mesh.h:352

◆ GetSideSets()

std::map< int, std::vector< int > > nimble::GenesisMesh::GetSideSets ( ) const
inline
280 {
281 return side_sets_;
282 }
std::map< int, std::vector< int > > side_sets_
Definition nimble_genesis_mesh.h:353

◆ HasBlock()

bool nimble::GenesisMesh::HasBlock ( std::string const & block_name) const
509{
510 for (auto& entry : block_names_) {
511 if (entry.second == block_name) { return true; }
512 }
513 return false;
514}

◆ Initialize()

void nimble::GenesisMesh::Initialize ( std::string const & file_name,
std::vector< int > const & node_global_id,
std::vector< double > const & node_x,
std::vector< double > const & node_y,
std::vector< double > const & node_z,
std::vector< int > const & elem_global_id,
std::vector< int > const & block_ids,
std::map< int, std::string > const & block_names,
std::map< int, std::vector< int > > const & block_elem_global_ids,
std::map< int, int > const & block_num_nodes_per_elem,
std::map< int, std::vector< int > > const & block_elem_connectivity )

Create a genesis mesh object using existing data (intended for contact visualization).

442{
443 file_name_ = file_name;
444 dim_ = 3;
445 node_global_id_ = node_global_id;
446 node_x_ = node_x;
447 node_y_ = node_y;
448 node_z_ = node_z;
449 elem_global_id_ = elem_global_id;
450 block_ids_ = block_ids;
451 all_block_ids_ = block_ids;
452 block_names_ = block_names;
453 all_block_names_ = block_names;
454 block_elem_global_ids_ = block_elem_global_ids;
455 block_num_nodes_per_elem_ = block_num_nodes_per_elem;
456 block_elem_connectivity_ = block_elem_connectivity;
457}

◆ IsValid()

bool nimble::GenesisMesh::IsValid ( ) const
inline
78 {
79 if (file_name_ == "none") { return false; }
80 return true;
81 }

◆ Print()

void nimble::GenesisMesh::Print ( bool verbose = false,
int my_rank = 0 ) const
588{
589 int num_elem = GetNumElements();
590
591 std::cout << "\nExodus mesh on rank " << my_rank << ":" << std::endl;
592 std::cout << " file name: " << file_name_ << std::endl;
593 std::cout << " dimension: " << dim_ << std::endl;
594 std::cout << " num nodes: " << node_x_.size() << std::endl;
595 std::cout << " num elems: " << num_elem << std::endl;
596 std::cout << " num blocks: " << block_ids_.size() << std::endl;
597
598 if (verbose) {
599 std::cout << " Block information:" << std::endl;
600 for (int i = 0; i < block_ids_.size(); i++) {
601 int block_id = block_ids_[i];
602 std::cout << " block id: " << block_id << std::endl;
603 std::cout << " block name: " << block_names_.at(block_id) << std::endl;
604 std::cout << " elem type: " << GetElementType(block_id) << std::endl;
605 std::cout << " num elems: "
606 << block_elem_connectivity_.at(block_id).size() / block_num_nodes_per_elem_.at(block_id) << std::endl;
607 }
608 }
609 std::cout << std::endl;
610 std::cout << std::flush;
611}
std::string GetElementType(int block_id) const
Definition nimble_genesis_mesh.cc:480
unsigned int GetNumElements() const
Definition nimble_genesis_mesh.h:117

◆ ReadFile()

void nimble::GenesisMesh::ReadFile ( std::string file_name)
64{
65#ifndef NIMBLE_HAVE_EXODUS
66 ReadTextFile(file_name);
67#else
68
69 file_name_ = file_name;
70
71 if (!IsValid()) { return; }
72
73 // Open the genesis file
74 int word_size = sizeof(double);
75 int io_word_size = 0;
76 float exodus_version;
77 int exodus_file_id = ex_open(file_name_.c_str(), EX_READ, &word_size, &io_word_size, &exodus_version);
78 if (exodus_file_id < 0) {
79 std::cout << "\n****Error: unable to open file: " << file_name_.c_str() << "\n" << std::endl;
80 ReportExodusError(exodus_file_id, "GenesisMesh::ReadFile", "ex_open");
81 }
82
83 // Read the initialization parameters
84 int num_nodes, num_elem, num_blocks, num_node_sets, num_side_sets;
85 char title[MAX_LINE_LENGTH + 1];
86 int retval =
87 ex_get_init(exodus_file_id, title, &dim_, &num_nodes, &num_elem, &num_blocks, &num_node_sets, &num_side_sets);
88 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_init");
89
90 // Node coordinates
91 node_x_.resize(num_nodes);
92 node_y_.resize(num_nodes);
93 if (dim_ == 3) { node_z_.resize(num_nodes); }
94 retval = ex_get_coord(exodus_file_id, &node_x_[0], &node_y_[0], &node_z_[0]);
95 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_coord");
96
97 // Global node numbering (default map name)
98 node_global_id_.resize(num_nodes);
99 retval = ex_get_id_map(exodus_file_id, EX_NODE_MAP, &node_global_id_[0]);
100 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_id_map");
101 for (int i = 0; i < num_nodes; ++i) {
102 node_global_id_[i] -= 1; // Switch from 1-based indexing to 0-based indexing
103 }
104
105 // Global element numbering (default map name)
106 elem_global_id_.resize(num_elem);
107 retval = ex_get_id_map(exodus_file_id, EX_ELEM_MAP, &elem_global_id_[0]);
108 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_id_map");
109 for (int i = 0; i < num_elem; ++i) {
110 elem_global_id_[i] -= 1; // Switch from 1-based indexing to 0-based indexing
111 }
112
113 // Check for auxiliary node maps and element maps
114 int num_node_maps, num_elem_maps;
115 retval = ex_get_map_param(exodus_file_id, &num_node_maps, &num_elem_maps);
116 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_map_param");
117 if (num_node_maps > 1 || num_elem_maps > 1) {
119 "GenesisMesh::ReadFile(), multiple auxiliary node/element maps not "
120 "supported!");
121 }
122
123 // If maps are named "original_global_id_map", use them instead of the maps
124 // obtained above The name "original_global_id_map" is used by seacas
125 // utilities like decomp
126 if (num_node_maps > 0) {
127 char map_name[MAX_STR_LENGTH + 1];
128 retval = ex_get_name(exodus_file_id, EX_NODE_MAP, 1, map_name);
129 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_name");
130 if (std::string(map_name) != std::string("original_global_id_map")) {
131 NIMBLE_ABORT("GenesisMesh::ReadFile(), unsupported auxiliary node map!");
132 }
133 retval = ex_get_num_map(exodus_file_id, EX_NODE_MAP, 1, &node_global_id_[0]);
134 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_num_map");
135 for (int i = 0; i < num_nodes; ++i) {
136 node_global_id_[i] -= 1; // Switch from 1-based indexing to 0-based indexing
137 }
138 }
139 if (num_elem_maps > 0) {
140 char map_name[MAX_STR_LENGTH + 1];
141 retval = ex_get_name(exodus_file_id, EX_ELEM_MAP, 1, map_name);
142 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_name");
143 if (std::string(map_name) != std::string("original_global_id_map")) {
144 NIMBLE_ABORT("GenesisMesh::ReadFile(), unsupported auxiliary element map!");
145 }
146 retval = ex_get_num_map(exodus_file_id, EX_ELEM_MAP, 1, &elem_global_id_[0]);
147 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_num_map");
148 for (int i = 0; i < num_elem; ++i) {
149 elem_global_id_[i] -= 1; // Switch from 1-based indexing to 0-based indexing
150 }
151 }
152
153 // Read the node sets
154 if (num_node_sets > 0) {
155 node_set_ids_.resize(num_node_sets);
156 retval = ex_get_ids(exodus_file_id, EX_NODE_SET, &node_set_ids_[0]);
157 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_ids");
158 }
159 for (int i = 0; i < num_node_sets; ++i) {
160 int id = node_set_ids_[i];
161 char name[MAX_STR_LENGTH + 1];
162 retval = ex_get_name(exodus_file_id, EX_NODE_SET, id, name);
163 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_name");
164 // If the node set name came back blank, create one that looks like
165 // "nodelist_1", "nodelist_2", etc.
166 std::string node_set_name(name);
167 if (node_set_name.size() == 0) {
168 std::stringstream ss;
169 ss << "nodelist_" << id;
170 node_set_name = ss.str();
171 }
172 node_set_names_[id] = node_set_name;
173
174 int num_nodes_in_ns;
175 int num_dist_factors_in_ns;
176 retval = ex_get_set_param(exodus_file_id, EX_NODE_SET, id, &num_nodes_in_ns, &num_dist_factors_in_ns);
177 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set_param");
178 node_sets_[id] = std::vector<int>();
179 if (num_nodes_in_ns > 0 && num_dist_factors_in_ns == num_nodes_in_ns) {
180 node_sets_[id] = std::vector<int>(num_nodes_in_ns);
181 retval = ex_get_set(exodus_file_id, EX_NODE_SET, id, &node_sets_[id][0], NULL);
182 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set");
183 // convert from 1-based indexing to 0-based indexing
184 for (unsigned int j = 0; j < node_sets_[id].size(); j++) { node_sets_[id][j] -= 1; }
185 }
186 ns_distribution_factors_[id] = std::vector<double>();
187 if (num_nodes_in_ns > 0) {
188 ns_distribution_factors_[id] = std::vector<double>(num_dist_factors_in_ns);
189 retval = ex_get_set_dist_fact(exodus_file_id, EX_NODE_SET, id, &ns_distribution_factors_[id][0]);
190 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set_dist_fact");
191 }
192 }
193
194 // Read the side sets
195 if (num_side_sets > 0) {
196 side_set_ids_.resize(num_side_sets);
197 retval = ex_get_ids(exodus_file_id, EX_SIDE_SET, &side_set_ids_[0]);
198 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_ids");
199 }
200 for (int i = 0; i < num_side_sets; ++i) {
201 int id = side_set_ids_[i];
202 char name[MAX_STR_LENGTH + 1];
203 retval = ex_get_name(exodus_file_id, EX_SIDE_SET, id, name);
204 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_name");
205 // If the side set name came back blank, create one that looks like
206 // "sideset_1", "sideset_2", etc.
207 std::string side_set_name(name);
208 if (side_set_name.size() == 0) {
209 std::stringstream ss;
210 ss << "sideset_" << id;
211 side_set_name = ss.str();
212 }
213 side_set_names_[id] = side_set_name;
214
215 int num_nodes_in_ss;
216 int num_dist_factors_in_ss;
217 retval = ex_get_set_param(exodus_file_id, EX_SIDE_SET, id, &num_nodes_in_ss, &num_dist_factors_in_ss);
218 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set_param");
219 side_sets_[id] = std::vector<int>();
220 if (num_nodes_in_ss > 0 && num_dist_factors_in_ss == num_nodes_in_ss) {
221 side_sets_[id] = std::vector<int>(num_nodes_in_ss);
222 retval = ex_get_set(exodus_file_id, EX_SIDE_SET, id, &side_sets_[id][0], NULL);
223 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set");
224 // convert from 1-based indexing to 0-based indexing
225 for (unsigned int j = 0; j < side_sets_[id].size(); j++) { side_sets_[id][j] -= 1; }
226 }
227 ss_distribution_factors_[id] = std::vector<double>();
228 if (num_nodes_in_ss > 0) {
229 ss_distribution_factors_[id] = std::vector<double>(num_dist_factors_in_ss);
230 retval = ex_get_set_dist_fact(exodus_file_id, EX_SIDE_SET, id, &ss_distribution_factors_[id][0]);
231 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_set_dist_fact");
232 }
233 }
234
235 // Process the element blocks
236 std::vector<int> all_block_ids(num_blocks);
237 retval = ex_get_ids(exodus_file_id, EX_ELEM_BLOCK, &all_block_ids[0]);
238 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_ids");
239
240 // Load information only for blocks with elements on this partition
241 for (auto block_id : all_block_ids) {
242 int num_elem_this_block(0), num_nodes_per_elem(0), num_edges_per_elem(0), num_faces_per_elem(0), num_attributes(0);
243 char elem_type[MAX_STR_LENGTH + 1];
244 retval = ex_get_block(
245 exodus_file_id,
246 EX_ELEM_BLOCK,
247 block_id,
248 elem_type,
249 &num_elem_this_block,
250 &num_nodes_per_elem,
251 &num_edges_per_elem,
252 &num_faces_per_elem,
253 &num_attributes);
254 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_block");
255 if (num_elem_this_block > 0) { block_ids_.push_back(block_id); }
256 all_block_ids_.push_back(block_id);
257
258 // Get the block name, if there is one
259 char exodus_block_name[MAX_STR_LENGTH + 1];
260 retval = ex_get_name(exodus_file_id, EX_ELEM_BLOCK, block_id, exodus_block_name);
261 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_name");
262 // If the block name came back blank, create one that looks like "block_1",
263 // "block_2", etc.
264 std::string block_name(exodus_block_name);
265 if (block_name.size() == 0) {
266 std::stringstream ss;
267 ss << "block_" << block_id;
268 block_name = ss.str();
269 }
270 if (num_elem_this_block > 0) { block_names_[block_id] = block_name; }
271 all_block_names_[block_id] = block_name;
272 }
273
274 num_blocks = static_cast<int>(block_ids_.size());
275
276 int elem_local_index = 0;
277
278 for (int i_block = 0; i_block < num_blocks; i_block++) {
279 int block_id = block_ids_.at(i_block);
280
281 // Get the block parameters and the element connectivity
282 int num_elem_this_block(0), num_nodes_per_elem(0), num_edges_per_elem(0), num_faces_per_elem(0), num_attributes(0);
283 char elem_type[MAX_STR_LENGTH + 1];
284 retval = ex_get_block(
285 exodus_file_id,
286 EX_ELEM_BLOCK,
287 block_id,
288 elem_type,
289 &num_elem_this_block,
290 &num_nodes_per_elem,
291 &num_edges_per_elem,
292 &num_faces_per_elem,
293 &num_attributes);
294 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_block");
295 block_num_nodes_per_elem_[block_id] = num_nodes_per_elem;
296
297 // global element ids for this block
298 block_elem_global_ids_[block_id] = std::vector<int>(num_elem_this_block);
299 for (int i = 0; i < num_elem_this_block; i++) {
300 block_elem_global_ids_.at(block_id).at(i) = elem_global_id_[elem_local_index++];
301 }
302
303 // element connectivity for this block
304 block_elem_connectivity_[block_id] = std::vector<int>(num_elem_this_block * num_nodes_per_elem);
305 retval = ex_get_conn(exodus_file_id, EX_ELEM_BLOCK, block_id, &block_elem_connectivity_.at(block_id)[0], 0, 0);
306 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_get_conn");
307 // Switch from 1-based indexing to 0-based indexing
308 for (unsigned int i = 0; i < block_elem_connectivity_.at(block_id).size(); i++) {
309 block_elem_connectivity_.at(block_id).at(i) -= 1;
310 }
311 }
312
313 retval = ex_close(exodus_file_id);
314 if (retval != 0) ReportExodusError(retval, "GenesisMesh::ReadFile()", "ex_close");
315#endif
316}
bool IsValid() const
Definition nimble_genesis_mesh.h:77
void ReportExodusError(int error_code, const char *method_name, const char *exodus_method_name) const
Definition nimble_genesis_mesh.cc:614
void ReadTextFile(std::string file_name)
Definition nimble_genesis_mesh.cc:319
#define NIMBLE_ABORT(...)
Definition nimble_macros.h:87

◆ ReadTextFile()

void nimble::GenesisMesh::ReadTextFile ( std::string file_name)
320{
321 file_name_ = file_name;
322 dim_ = 3;
323
324 if (!IsValid()) { return; }
325
326 std::stringstream error_msg_ss;
327
328 std::string text_file_name = file_name + ".txt";
329 std::ifstream mesh_file(text_file_name.c_str());
330
331 if (!mesh_file.is_open()) {
332 std::stringstream error_msg_ss;
333 error_msg_ss << "\n** Error, failed to open mesh file " << text_file_name << "\n";
334 throw std::invalid_argument(error_msg_ss.str());
335 }
336
337 int num_nodes, num_elem, num_blocks, num_node_sets;
338
339 int global_elem_index = 0;
340
341 while (mesh_file.good()) {
342 std::string str;
343 getline(mesh_file, str);
344
345 std::string key;
346 std::stringstream key_ss(str);
347 key_ss >> key;
348
349 std::stringstream ss(str);
350
351 if (key == "number_of_nodes") {
352 ss >> key;
353 ss >> num_nodes;
354 } else if (key == "number_of_elements") {
355 ss >> key;
356 ss >> num_elem;
357 elem_global_id_.resize(num_elem);
358 } else if (key == "number_of_blocks") {
359 ss >> key;
360 ss >> num_blocks;
361 } else if (key == "number_of_node_sets") {
362 ss >> key;
363 ss >> num_node_sets;
364 } else if (key == "node_coordinates") {
365 node_global_id_.resize(num_nodes);
366 node_x_.resize(num_nodes);
367 node_y_.resize(num_nodes);
368 node_z_.resize(num_nodes);
369 for (int i = 0; i < num_nodes; i++) {
370 getline(mesh_file, str);
371 std::stringstream ss(str);
372 int global_node_id;
373 double x, y, z;
374 ss >> global_node_id >> x >> y >> z;
375 // switch to 0-based indexing
376 node_global_id_[i] = global_node_id - 1;
377 node_x_[i] = x;
378 node_y_[i] = y;
379 node_z_[i] = z;
380 }
381 } else if (key == "element_block") {
382 getline(mesh_file, str);
383 std::stringstream ss(str);
384 int block_id, num_elem_in_block, num_nodes_per_elem;
385 std::string block_name;
386 ss >> block_id >> block_name >> num_elem_in_block >> num_nodes_per_elem;
387 block_ids_.push_back(block_id);
388 block_names_[block_id] = block_name;
389 block_num_nodes_per_elem_[block_id] = num_nodes_per_elem;
390 block_elem_connectivity_[block_id] = std::vector<int>(num_elem_in_block * num_nodes_per_elem);
391 block_elem_global_ids_[block_id] = std::vector<int>(num_elem_in_block);
392 std::vector<int>& conn = block_elem_connectivity_[block_id];
393 for (int i = 0; i < num_elem_in_block; i++) {
394 getline(mesh_file, str);
395 std::stringstream ss(str);
396 int elem_global_id;
397 ss >> elem_global_id;
398 // switch to 0-based indexing
399 elem_global_id -= 1;
400 elem_global_id_[global_elem_index++] = elem_global_id;
401 block_elem_global_ids_[block_id][i] = elem_global_id;
402 for (int j = 0; j < num_nodes_per_elem; j++) {
403 ss >> conn[i * num_nodes_per_elem + j];
404 // switch to 0-based indexing
405 conn[i * num_nodes_per_elem + j] -= 1;
406 }
407 }
408 } else if (key == "nodeset") {
409 getline(mesh_file, str);
410 std::stringstream ss(str);
411 int node_set_id, node_set_number_of_nodes;
412 std::string node_set_name;
413 ss >> node_set_id >> node_set_name >> node_set_number_of_nodes;
414 node_set_ids_.push_back(node_set_id);
415 node_set_names_[node_set_id] = node_set_name;
416 node_sets_[node_set_id] = std::vector<int>(node_set_number_of_nodes);
417 std::vector<int>& node_set = node_sets_[node_set_id];
418 for (int i = 0; i < node_set_number_of_nodes; i++) {
419 getline(mesh_file, str);
420 std::stringstream ss(str);
421 ss >> node_set[i];
422 // switch to 0-based indexing
423 node_set[i] -= 1;
424 }
425 }
426 }
427}

◆ ReportExodusError()

void nimble::GenesisMesh::ReportExodusError ( int error_code,
const char * method_name,
const char * exodus_method_name ) const
protected
615{
616 std::stringstream ss;
617 if (error_code < 0) {
618 ss << "\n**Error GenesisMesh::" << method_name << ", Error code: " << error_code << " (" << exodus_method_name
619 << ")\n";
620 NIMBLE_ABORT(ss.str());
621 } else {
622 ss << "\n**Warning GenesisMesh::" << method_name << ", Warning code: " << error_code << " (" << exodus_method_name
623 << ")\n";
624 std::cout << ss.str() << std::endl;
625 }
626}

Member Data Documentation

◆ all_block_ids_

std::vector<int> nimble::GenesisMesh::all_block_ids_
protected

◆ all_block_names_

std::map<int, std::string> nimble::GenesisMesh::all_block_names_
protected

◆ block_elem_connectivity_

std::map<int, std::vector<int> > nimble::GenesisMesh::block_elem_connectivity_
protected

◆ block_elem_global_ids_

std::map<int, std::vector<int> > nimble::GenesisMesh::block_elem_global_ids_
protected

◆ block_ids_

std::vector<int> nimble::GenesisMesh::block_ids_
protected

◆ block_names_

std::map<int, std::string> nimble::GenesisMesh::block_names_
protected

◆ block_num_nodes_per_elem_

std::map<int, int> nimble::GenesisMesh::block_num_nodes_per_elem_
protected

◆ dim_

int nimble::GenesisMesh::dim_
protected

◆ elem_global_id_

std::vector<int> nimble::GenesisMesh::elem_global_id_
protected

◆ file_name_

std::string nimble::GenesisMesh::file_name_
protected

◆ node_global_id_

std::vector<int> nimble::GenesisMesh::node_global_id_
protected

◆ node_set_ids_

std::vector<int> nimble::GenesisMesh::node_set_ids_
protected

◆ node_set_names_

std::map<int, std::string> nimble::GenesisMesh::node_set_names_
protected

◆ node_sets_

std::map<int, std::vector<int> > nimble::GenesisMesh::node_sets_
protected

◆ node_x_

std::vector<double> nimble::GenesisMesh::node_x_
protected

◆ node_y_

std::vector<double> nimble::GenesisMesh::node_y_
protected

◆ node_z_

std::vector<double> nimble::GenesisMesh::node_z_
protected

◆ ns_distribution_factors_

std::map<int, std::vector<double> > nimble::GenesisMesh::ns_distribution_factors_
protected

◆ side_set_ids_

std::vector<int> nimble::GenesisMesh::side_set_ids_
protected

◆ side_set_names_

std::map<int, std::string> nimble::GenesisMesh::side_set_names_
protected

◆ side_sets_

std::map<int, std::vector<int> > nimble::GenesisMesh::side_sets_
protected

◆ ss_distribution_factors_

std::map<int, std::vector<double> > nimble::GenesisMesh::ss_distribution_factors_
protected

The documentation for this class was generated from the following files: