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

#include <nimble_exodus_output.h>

Public Member Functions

 ExodusOutput ()
 
void Initialize (std::string const &filename, GenesisMesh const &genesis_mesh)
 
virtual ~ExodusOutput ()
 
std::string GetFileName () const
 
void InitializeDatabase (GenesisMesh const &genesis_mesh, std::vector< std::string > const &global_data_names, std::vector< std::string > const &node_data_names, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::string > > const &derived_elem_data_names)
 
void WriteStep (double time, std::vector< double > const &global_data, std::vector< std::vector< double > > const &node_data, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::vector< double > > > const &elem_data, std::map< int, std::vector< std::string > > const &derived_elem_data_names, std::map< int, std::vector< std::vector< double > > > const &derived_elem_data)
 
void InitializeDatabaseTextFile (GenesisMesh const &genesis_mesh, std::vector< std::string > const &global_data_names, std::vector< std::string > const &node_data_names, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::string > > const &derived_elem_data_names)
 
void WriteStepTextFile (double time, std::vector< double > const &global_data, std::vector< std::vector< double > > const &node_data, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::vector< double > > > const &elem_data, std::map< int, std::vector< std::string > > const &derived_elem_data_names, std::map< int, std::vector< std::vector< double > > > const &derived_elem_data)
 

Protected Member Functions

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

Protected Attributes

std::string filename_
 
int CPU_word_size_
 
int IO_word_size_
 
int dim_
 
int num_nodes_
 
int num_elements_
 
int num_blocks_
 
int num_global_blocks_
 
std::vector< int > all_block_ids_
 
std::vector< int > block_ids_
 
int num_node_sets_
 
int num_side_sets_
 
int exodus_write_count_
 
std::map< std::string, int > elem_data_index_
 

Constructor & Destructor Documentation

◆ ExodusOutput()

nimble::ExodusOutput::ExodusOutput ( )
inline
62 : filename_("none"),
63 CPU_word_size_(sizeof(double)),
64 IO_word_size_(sizeof(double)),
65 dim_(0),
66 num_nodes_(0),
68 num_blocks_(0),
72 {
73 }
int num_side_sets_
Definition nimble_exodus_output.h:150
int num_nodes_
Definition nimble_exodus_output.h:143
int num_node_sets_
Definition nimble_exodus_output.h:149
int CPU_word_size_
Definition nimble_exodus_output.h:140
int num_blocks_
Definition nimble_exodus_output.h:145
int exodus_write_count_
Definition nimble_exodus_output.h:151
int num_elements_
Definition nimble_exodus_output.h:144
std::string filename_
Definition nimble_exodus_output.h:139
int dim_
Definition nimble_exodus_output.h:142
int IO_word_size_
Definition nimble_exodus_output.h:141

◆ ~ExodusOutput()

virtual nimble::ExodusOutput::~ExodusOutput ( )
inlinevirtual
88{}

Member Function Documentation

◆ GetFileName()

std::string nimble::ExodusOutput::GetFileName ( ) const
inline
92 {
93 return filename_;
94 }

◆ Initialize()

void nimble::ExodusOutput::Initialize ( std::string const & filename,
GenesisMesh const & genesis_mesh )
66{
67 filename_ = filename;
68 dim_ = genesis_mesh.GetDim();
69 num_nodes_ = static_cast<int>(genesis_mesh.GetNumNodes());
70 num_elements_ = static_cast<int>(genesis_mesh.GetNumElements());
71 num_blocks_ = static_cast<int>(genesis_mesh.GetNumBlocks());
72 num_global_blocks_ = static_cast<int>(genesis_mesh.GetNumGlobalBlocks());
73 all_block_ids_ = genesis_mesh.GetAllBlockIds();
74 block_ids_ = genesis_mesh.GetBlockIds();
75 num_node_sets_ = genesis_mesh.GetNumNodeSets();
76}
std::vector< int > all_block_ids_
Definition nimble_exodus_output.h:147
std::vector< int > block_ids_
Definition nimble_exodus_output.h:148
int num_global_blocks_
Definition nimble_exodus_output.h:146

◆ InitializeDatabase()

void nimble::ExodusOutput::InitializeDatabase ( GenesisMesh const & genesis_mesh,
std::vector< std::string > const & global_data_names,
std::vector< std::string > const & node_data_names,
std::map< int, std::vector< std::string > > const & elem_data_names,
std::map< int, std::vector< std::string > > const & derived_elem_data_names )
85{
86#ifndef NIMBLE_HAVE_EXODUS
88 genesis_mesh, global_data_names, node_data_names, elem_data_names, derived_elem_data_names);
89#else
90
91 int num_global_data = static_cast<int>(global_data_names.size());
92 int num_node_data = static_cast<int>(node_data_names.size());
93
94 // Initialize exodus database; Overwrite any existing file with this name
95 int exodus_file_id = ex_create(filename_.c_str(), EX_CLOBBER, &CPU_word_size_, &IO_word_size_);
96 if (exodus_file_id < 0) ReportExodusError(exodus_file_id, "InitializeDatabase", "ex_create");
97
98 // Write the Quality Assurance (QA) record
99 int retval = ex_put_init(
101 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_init");
102 WriteQARecord(exodus_file_id);
103
104 // Write nodal coordinate names to database
105 const char* coord_names[3] = {"x", "y", "z"};
106 retval = ex_put_coord_names(exodus_file_id, const_cast<char**>(coord_names));
107 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_coord_names");
108
109 // Write the coordinates
110 retval = ex_put_coord(
111 exodus_file_id, genesis_mesh.GetCoordinatesX(), genesis_mesh.GetCoordinatesY(), genesis_mesh.GetCoordinatesZ());
112 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_coord");
113
114 // Get the list of global IDs for element blocks
115 std::set<int> gid_list;
116 for (int i = 0; i < num_blocks_; ++i) gid_list.insert(block_ids_[i]);
117
118 // Write element block parameters
119 //
120 // Note: EPU expects to see all the global blocks in each file.
121 // It is allowed to have 0 elements in a block in a processor.
122 //
123 for (int i = 0; i < num_global_blocks_; ++i) {
124 const auto& gblock_list = genesis_mesh.GetAllBlockIds();
125 int gid = gblock_list[i];
126 int num_elements_in_block = 0;
127 int num_nodes_per_elem = 0;
128 std::string elem_type;
129 if (gid_list.count(gid) > 0) {
130 num_elements_in_block = genesis_mesh.GetNumElementsInBlock(gid);
131 num_nodes_per_elem = genesis_mesh.GetNumNodesPerElement(gid);
132 elem_type = genesis_mesh.GetElementType(gid);
133 }
134 retval = ex_put_block(
135 exodus_file_id, EX_ELEM_BLOCK, gid, elem_type.c_str(), num_elements_in_block, num_nodes_per_elem, 0, 0, 0);
136 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_block");
137 }
138
139 // Write the block names
140 char** block_names = new char*[num_global_blocks_];
141 for (int i = 0; i < num_global_blocks_; ++i) {
142 block_names[i] = new char[MAX_STR_LENGTH + 1];
143 const int id = all_block_ids_[i];
144 const std::string block_name = genesis_mesh.GetBlockName(id);
145 strcpy(block_names[i], block_name.c_str());
146 }
147 retval = ex_put_names(exodus_file_id, EX_ELEM_BLOCK, block_names);
148 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_names EX_ELEM_BLOCK");
149
150 // Write element connectivity
151 for (int i = 0; i < num_blocks_; ++i) {
152 int id = block_ids_[i];
153 int num_elements_in_block = genesis_mesh.GetNumElementsInBlock(id);
154 if (num_elements_in_block > 0) {
155 const int* conn = genesis_mesh.GetConnectivity(id);
156 // Switch from 0-based indexing to 1-based indexing
157 int num_node_in_elem = genesis_mesh.GetNumNodesPerElement(id);
158 std::vector<int> exodus_conn(num_elements_in_block * num_node_in_elem);
159 for (int j = 0; j < num_elements_in_block * num_node_in_elem; j++) { exodus_conn[j] = conn[j] + 1; }
160 retval = ex_put_conn(exodus_file_id, EX_ELEM_BLOCK, id, &exodus_conn[0], nullptr, nullptr);
161 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_conn");
162 }
163 }
164
165 // Write global node number map (global node IDs)
166 const int* node_global_ids = genesis_mesh.GetNodeGlobalIds();
167 // Switch to 1-based indexing
168 std::vector<int> temp_node_global_ids(num_nodes_);
169 for (int i = 0; i < num_nodes_; ++i) { temp_node_global_ids[i] = node_global_ids[i] + 1; }
170 retval = ex_put_id_map(exodus_file_id, EX_NODE_MAP, &temp_node_global_ids[0]);
171 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_id_map");
172
173 // Write global element number map (global element IDs)
174 const int* elem_global_ids = genesis_mesh.GetElementGlobalIds();
175 // Switch to 1-based indexing
176 std::vector<int> temp_elem_global_ids(num_elements_);
177 for (int i = 0; i < num_elements_; ++i) { temp_elem_global_ids[i] = elem_global_ids[i] + 1; }
178 retval = ex_put_id_map(exodus_file_id, EX_ELEM_MAP, &temp_elem_global_ids[0]);
179 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_id_map");
180
181 // Write node sets
182 if (num_node_sets_ > 0) {
183 std::vector<int> node_set_ids = genesis_mesh.GetNodeSetIds();
184 std::map<int, std::string> node_set_names = genesis_mesh.GetNodeSetNames();
185 std::map<int, std::vector<int>> node_sets = genesis_mesh.GetNodeSets();
186 std::map<int, std::vector<double>> ns_distribution_factors = genesis_mesh.GetNodeSetDistributionFactors();
187 std::vector<int> num_nodes_per_set(num_node_sets_);
188 std::vector<int> num_ns_distribution_factors_per_set(num_node_sets_);
189 int total_num_node(0);
190 int total_num_dist(0);
191 for (int i = 0; i < num_node_sets_; i++) {
192 int id = node_set_ids[i];
193 int nn = static_cast<int>(node_sets[id].size());
194 int ndf = static_cast<int>(ns_distribution_factors[id].size());
195 num_nodes_per_set[i] = nn;
196 num_ns_distribution_factors_per_set[i] = ndf;
197 total_num_node += nn;
198 total_num_dist += ndf;
199 }
200 std::vector<int> node_sets_node_index(num_node_sets_);
201 std::vector<int> node_sets_dist_index(num_node_sets_);
202 std::vector<int> node_sets_node_list(total_num_node);
203 std::vector<double> node_sets_dist_fact(total_num_dist);
204 int node_index(0);
205 int dist_index(0);
206 for (int i = 0; i < num_node_sets_; i++) {
207 int id = node_set_ids[i];
208 node_sets_node_index[i] = node_index;
209 node_sets_dist_index[i] = dist_index;
210 for (const auto& n_set : node_sets[id]) {
211 // Switch from 0-based indexing to 1-based indexing
212 node_sets_node_list[node_index++] = n_set + 1;
213 }
214 for (const auto& j_factor : ns_distribution_factors[id]) { node_sets_dist_fact[dist_index++] = j_factor; }
215 }
216
217 ex_set_specs set_specs;
218 set_specs.sets_ids = node_set_ids.data();
219 set_specs.num_entries_per_set = num_nodes_per_set.data();
220 set_specs.num_dist_per_set = num_ns_distribution_factors_per_set.data();
221 set_specs.sets_entry_index = node_sets_node_index.data();
222 set_specs.sets_dist_index = node_sets_dist_index.data();
223 set_specs.sets_entry_list = node_sets_node_list.data();
224 set_specs.sets_extra_list = nullptr;
225 set_specs.sets_dist_fact = node_sets_dist_fact.data();
226 retval = ex_put_concat_sets(exodus_file_id, EX_NODE_SET, &set_specs);
227 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_concat_sets");
228 }
229
230 // Write global data info
231 char** global_var_names = nullptr;
232 if (num_global_data > 0) {
233 global_var_names = new char*[num_global_data];
234 for (int i = 0; i < num_global_data; i++) {
235 global_var_names[i] = new char[MAX_STR_LENGTH + 1];
236 strcpy(global_var_names[i], global_data_names[i].c_str());
237 }
238 retval = ex_put_variable_param(exodus_file_id, EX_GLOBAL, num_global_data);
239 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_param");
240 retval = ex_put_variable_names(exodus_file_id, EX_GLOBAL, num_global_data, global_var_names);
241 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_names");
242 }
243
244 // Write node data info
245 char** node_var_names = nullptr;
246 if (num_node_data > 0 && num_nodes_ > 0) {
247 node_var_names = new char*[num_node_data];
248 for (int i = 0; i < num_node_data; i++) {
249 node_var_names[i] = new char[MAX_STR_LENGTH + 1];
250 strcpy(node_var_names[i], node_data_names[i].c_str());
251 }
252 retval = ex_put_variable_param(exodus_file_id, EX_NODAL, num_node_data);
253 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_param");
254 retval = ex_put_variable_names(exodus_file_id, EX_NODAL, num_node_data, node_var_names);
255 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_names");
256 }
257
258 // Write element data info
259 std::set<std::string> unique_elem_var_names;
260 for (int i = 0; i < num_blocks_; ++i) {
261 int id = block_ids_[i];
262 for (const auto& jname : elem_data_names.at(id)) { unique_elem_var_names.insert(jname); }
263 for (const auto& jname : derived_elem_data_names.at(id)) { unique_elem_var_names.insert(jname); }
264 }
265
266 // Create map from data name to exodus element data index
267 std::vector<std::string> elem_var_names;
268 for (std::set<std::string>::const_iterator it = unique_elem_var_names.begin(); it != unique_elem_var_names.end();
269 it++) {
270 elem_var_names.push_back(*it);
271 elem_data_index_[*it] = static_cast<int>(elem_var_names.size());
272 }
273
274 int num_element_vars = elem_var_names.size();
275 char** element_var_names = nullptr;
276 if (num_element_vars > 0) {
277 element_var_names = new char*[num_element_vars];
278 for (int i = 0; i < num_element_vars; i++) {
279 element_var_names[i] = new char[MAX_STR_LENGTH + 1];
280 strcpy(element_var_names[i], elem_var_names[i].c_str());
281 }
282 retval = ex_put_variable_param(exodus_file_id, EX_ELEM_BLOCK, num_element_vars);
283 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_param");
284 retval = ex_put_variable_names(exodus_file_id, EX_ELEM_BLOCK, num_element_vars, element_var_names);
285 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_put_variable_names");
286 }
287
288 // Close exodus file
289 retval = ex_update(exodus_file_id);
290 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_update");
291 retval = ex_close(exodus_file_id);
292 if (retval != 0) ReportExodusError(retval, "InitializeDatabase", "ex_close");
293
294 // Clean up
295 if (block_names != nullptr) {
296 for (int i = num_blocks_; i > 0; i--) { delete[] block_names[i - 1]; }
297 delete[] block_names;
298 }
299 if (global_var_names != nullptr) {
300 for (int i = num_global_data; i > 0; i--) { delete[] global_var_names[i - 1]; }
301 delete[] global_var_names;
302 }
303 if (node_var_names != nullptr) {
304 for (int i = num_node_data; i > 0; i--) { delete[] node_var_names[i - 1]; }
305 delete[] node_var_names;
306 }
307 if (element_var_names != nullptr) {
308 for (int i = num_element_vars; i > 0; i--) { delete[] element_var_names[i - 1]; }
309 delete[] element_var_names;
310 }
311#endif
312}
void ReportExodusError(int error_code, const char *method_name, const char *exodus_method_name)
Definition nimble_exodus_output.cc:592
std::map< std::string, int > elem_data_index_
Definition nimble_exodus_output.h:152
void WriteQARecord(int exodus_file_id)
Definition nimble_exodus_output.cc:552
void InitializeDatabaseTextFile(GenesisMesh const &genesis_mesh, std::vector< std::string > const &global_data_names, std::vector< std::string > const &node_data_names, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::string > > const &derived_elem_data_names)
Definition nimble_exodus_output.cc:399

◆ InitializeDatabaseTextFile()

void nimble::ExodusOutput::InitializeDatabaseTextFile ( GenesisMesh const & genesis_mesh,
std::vector< std::string > const & global_data_names,
std::vector< std::string > const & node_data_names,
std::map< int, std::vector< std::string > > const & elem_data_names,
std::map< int, std::vector< std::string > > const & derived_elem_data_names )
405{
406 std::string text_filename = filename_ + ".txt";
407 std::ofstream output_file;
408 output_file.open(text_filename);
409 output_file << "number_of_nodes " << num_nodes_ << std::endl;
410 output_file << "number_of_elements " << num_elements_ << std::endl;
411 output_file << "number_of_blocks " << num_blocks_ << std::endl;
412 output_file << "number_of_node_sets " << num_node_sets_ << std::endl;
413 output_file << "node_coordinates" << std::endl;
414
415 // Write the coordinates
416 const int* node_global_ids = genesis_mesh.GetNodeGlobalIds();
417 const double* const x_coord = genesis_mesh.GetCoordinatesX();
418 const double* const y_coord = genesis_mesh.GetCoordinatesY();
419 const double* const z_coord = genesis_mesh.GetCoordinatesZ();
420 for (int i = 0; i < num_nodes_; ++i) {
421 // switch to 1-based indexing
422 int global_id = node_global_ids[i] + 1;
423 output_file << std::setprecision(16) << global_id << " " << x_coord[i] << " " << y_coord[i] << " " << z_coord[i]
424 << std::endl;
425 }
426
427 // Write the element blocks
428 for (int i_block = 0; i_block < num_blocks_; ++i_block) {
429 int block_id = block_ids_[i_block];
430 std::string block_name = genesis_mesh.GetBlockName(block_id);
431 int num_elem_in_block = genesis_mesh.GetNumElementsInBlock(block_id);
432 int num_nodes_per_elem = genesis_mesh.GetNumNodesPerElement(block_id);
433 output_file << "element_block\n"
434 << block_id << " " << block_name << " " << num_elem_in_block << " " << num_nodes_per_elem << std::endl;
435 std::vector<int> const& global_elem_ids = genesis_mesh.GetElementGlobalIdsInBlock(block_id);
436 const int* const elem_conn = genesis_mesh.GetConnectivity(block_id);
437 for (int i_elem = 0; i_elem < num_elem_in_block; i_elem++) {
438 // switch to 1-based indexing
439 int global_id = global_elem_ids[i_elem] + 1;
440 output_file << global_id;
441 for (int i_node = 0; i_node < num_nodes_per_elem; ++i_node) {
442 // switch to 1-based indexing
443 int node_id = elem_conn[i_elem * num_nodes_per_elem + i_node] + 1;
444 output_file << " " << node_id;
445 }
446 output_file << std::endl;
447 }
448 }
449
450 // Write node sets
451 std::vector<int> node_set_ids = genesis_mesh.GetNodeSetIds();
452 std::map<int, std::string> node_set_names = genesis_mesh.GetNodeSetNames();
453 std::map<int, std::vector<int>> node_sets = genesis_mesh.GetNodeSets();
454 for (auto& node_set_id : node_set_ids) {
455 std::vector<int> const& node_set = node_sets[node_set_id];
456 output_file << "nodeset" << std::endl;
457 output_file << node_set_id << " " << node_set_names[node_set_id] << " " << node_set.size() << std::endl;
458 for (auto& node_id : node_set) {
459 // switch to 1-based indexing
460 output_file << node_id + 1 << std::endl;
461 }
462 }
463
464 // Write information on global data
465 output_file << "global_data" << std::endl;
466 output_file << global_data_names.size() << std::endl;
467 for (auto& name : global_data_names) { output_file << name << std::endl; }
468
469 // Write information on node data
470 output_file << "node_data" << std::endl;
471 output_file << node_data_names.size() << std::endl;
472 for (auto& name : node_data_names) { output_file << name << std::endl; }
473
474 // Write information on element data
475 std::set<std::string> unique_elem_var_names;
476 for (int i = 0; i < num_blocks_; ++i) {
477 int id = block_ids_[i];
478 for (const auto& my_name : elem_data_names.at(id)) unique_elem_var_names.insert(my_name);
479 for (const auto& my_name : derived_elem_data_names.at(id)) unique_elem_var_names.insert(my_name);
480 }
481 // Create map from data name to exodus element data index
482 std::vector<std::string> elem_var_names;
483 for (std::set<std::string>::const_iterator it = unique_elem_var_names.begin(); it != unique_elem_var_names.end();
484 it++) {
485 elem_var_names.push_back(*it);
486 elem_data_index_[*it] = static_cast<int>(elem_var_names.size());
487 }
488 int num_element_vars = elem_var_names.size();
489 output_file << "element_data" << std::endl;
490 output_file << num_element_vars << std::endl;
491 for (auto const& name : elem_var_names) { output_file << name << std::endl; }
492
493 output_file.close();
494}

◆ ReportExodusError()

void nimble::ExodusOutput::ReportExodusError ( int error_code,
const char * method_name,
const char * exodus_method_name )
protected
593{
594 std::stringstream ss;
595 if (error_code < 0) {
596 ss << "**Error ExodusOutput::" << method_name << "(), Error code: " << error_code << " (" << exodus_method_name
597 << ")\n";
598 NIMBLE_ABORT(ss.str());
599 } else {
600 ss << "**Warning ExodusOutput::" << method_name << "(), Warning code: " << error_code << " (" << exodus_method_name
601 << ")\n";
602 std::cout << ss.str() << std::endl;
603 }
604}
#define NIMBLE_ABORT(...)
Definition nimble_macros.h:87

◆ WriteQARecord()

void nimble::ExodusOutput::WriteQARecord ( int exodus_file_id)
protected
553{
554#ifdef NIMBLE_HAVE_EXODUS
555 // Get the current system date and time
556 // DJL: NOT THREAD SAFE, SO JUST PRINT NOTHING FOR THE DATE AND TIME
557 // std::chrono::time_point<std::chrono::system_clock> time_now =
558 // std::chrono::system_clock::now(); std::time_t time_now_t =
559 // std::chrono::system_clock::to_time_t(time_now);
560 std::stringstream datestream, timestream;
561 // datestream << std::put_time(std::localtime(&time_now_t), "%F");
562 // timestream << std::put_time(std::localtime(&time_now_t), "%T");
563
564 // Quality assurance (QA) data
565 std::string qa_name_string, qa_descriptor_string, qa_date_string, qa_time_string;
566 qa_name_string = "NimbleSM";
567 qa_descriptor_string = "unknown";
568 qa_date_string = datestream.str();
569 qa_time_string = timestream.str();
570
571 // Copy to required c-style arrays
572 int num_qa_records = 1;
573 char* qa_records[1][4];
574 char qa_name[MAX_STR_LENGTH + 1], qa_descriptor[MAX_STR_LENGTH + 1], qa_date[MAX_STR_LENGTH + 1],
575 qa_time[MAX_STR_LENGTH + 1];
576 qa_records[0][0] = qa_name;
577 qa_records[0][1] = qa_descriptor;
578 qa_records[0][2] = qa_date;
579 qa_records[0][3] = qa_time;
580
581 strcpy(qa_name, qa_name_string.c_str());
582 strcpy(qa_descriptor, qa_descriptor_string.c_str());
583 strcpy(qa_date, qa_date_string.c_str());
584 strcpy(qa_time, qa_time_string.c_str());
585
586 int retval = ex_put_qa(exodus_file_id, num_qa_records, qa_records);
587 if (retval != 0) ReportExodusError(retval, "WriteQARecord", "ex_put_qa");
588#endif
589}

◆ WriteStep()

void nimble::ExodusOutput::WriteStep ( double time,
std::vector< double > const & global_data,
std::vector< std::vector< double > > const & node_data,
std::map< int, std::vector< std::string > > const & elem_data_names,
std::map< int, std::vector< std::vector< double > > > const & elem_data,
std::map< int, std::vector< std::string > > const & derived_elem_data_names,
std::map< int, std::vector< std::vector< double > > > const & derived_elem_data )
323{
325
326#ifndef NIMBLE_HAVE_EXODUS
328 time, global_data, node_data, elem_data_names, elem_data, derived_elem_data_names, derived_elem_data);
329#else
330
331 float exodus_version;
332 int exodus_file_id = ex_open(filename_.c_str(), EX_WRITE, &CPU_word_size_, &IO_word_size_, &exodus_version);
333 if (exodus_file_id < 0) ReportExodusError(exodus_file_id, "WriteStep", "ex_open");
334
335 // Write time value
336 int retval = ex_put_time(exodus_file_id, exodus_write_count_, &time);
337 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_put_time");
338
339 // Write global data
340 int num_global_vars = static_cast<int>(global_data.size());
341 if (num_global_vars > 0) {
342 retval = ex_put_var(exodus_file_id, exodus_write_count_, EX_GLOBAL, 1, 0, num_global_vars, &global_data[0]);
343 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_put_var");
344 }
345
346 // Write node data
347 if (num_nodes_ > 0) {
348 for (unsigned int i = 0; i < node_data.size(); ++i) {
349 int variable_index = static_cast<int>(i + 1);
350 retval =
351 ex_put_var(exodus_file_id, exodus_write_count_, EX_NODAL, variable_index, 1, num_nodes_, &node_data[i][0]);
352 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_put_var");
353 }
354 }
355
356 // Write element data
357 for (int i = 0; i < num_blocks_; ++i) {
358 int block_id = block_ids_[i];
359 int num_elem_data = elem_data_names.at(block_id).size();
360 for (int j = 0; j < num_elem_data; ++j) {
361 std::string data_name = elem_data_names.at(block_id).at(j);
362 int variable_index = elem_data_index_.at(data_name);
363 int block_num_elem = static_cast<int>(elem_data.at(block_id).at(j).size());
364 retval = ex_put_var(
365 exodus_file_id,
367 EX_ELEM_BLOCK,
368 variable_index,
369 block_id,
370 block_num_elem,
371 &elem_data.at(block_id).at(j)[0]);
372 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_put_var");
373 }
374 int num_derived_elem_data = derived_elem_data_names.at(block_id).size();
375 for (int j = 0; j < num_derived_elem_data; ++j) {
376 std::string data_name = derived_elem_data_names.at(block_id).at(j);
377 int variable_index = elem_data_index_.at(data_name);
378 int block_num_elem = static_cast<int>(derived_elem_data.at(block_id).at(j).size());
379 retval = ex_put_var(
380 exodus_file_id,
382 EX_ELEM_BLOCK,
383 variable_index,
384 block_id,
385 block_num_elem,
386 &derived_elem_data.at(block_id).at(j)[0]);
387 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_put_var");
388 }
389 }
390
391 retval = ex_update(exodus_file_id);
392 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_update");
393 retval = ex_close(exodus_file_id);
394 if (retval != 0) ReportExodusError(retval, "WriteStep", "ex_close");
395#endif
396}
void WriteStepTextFile(double time, std::vector< double > const &global_data, std::vector< std::vector< double > > const &node_data, std::map< int, std::vector< std::string > > const &elem_data_names, std::map< int, std::vector< std::vector< double > > > const &elem_data, std::map< int, std::vector< std::string > > const &derived_elem_data_names, std::map< int, std::vector< std::vector< double > > > const &derived_elem_data)
Definition nimble_exodus_output.cc:497

◆ WriteStepTextFile()

void nimble::ExodusOutput::WriteStepTextFile ( double time,
std::vector< double > const & global_data,
std::vector< std::vector< double > > const & node_data,
std::map< int, std::vector< std::string > > const & elem_data_names,
std::map< int, std::vector< std::vector< double > > > const & elem_data,
std::map< int, std::vector< std::string > > const & derived_elem_data_names,
std::map< int, std::vector< std::vector< double > > > const & derived_elem_data )
505{
506 std::string text_filename = filename_ + ".txt";
507 std::ofstream output_file;
508 output_file.open(text_filename, std::ios_base::app);
509
510 // Write the time
511 output_file << "time" << std::endl;
512 output_file << std::setprecision(16) << time << std::endl;
513
514 // Global data
515 output_file << "global_data_values" << std::endl;
516 for (auto const& datum : global_data) { output_file << datum << std::endl; }
517
518 // Node data
519 output_file << "node_data_values" << std::endl;
520 for (auto const& data : node_data) {
521 for (auto const& datum : data) { output_file << std::setprecision(16) << datum << std::endl; }
522 }
523
524 // Element data
525 output_file << "element_data_values" << std::endl;
526 for (int i = 0; i < num_blocks_; ++i) {
527 int block_id = block_ids_[i];
528 int num_elem_data = elem_data_names.at(block_id).size();
529 for (int j = 0; j < num_elem_data; ++j) {
530 std::string data_name = elem_data_names.at(block_id).at(j);
531 int variable_index = elem_data_index_.at(data_name);
532 int block_num_elem = static_cast<int>(elem_data.at(block_id).at(j).size());
533 output_file << data_name << " " << variable_index << " " << block_id << " " << block_num_elem << std::endl;
534 std::vector<double> const& data = elem_data.at(block_id).at(j);
535 for (auto const& datum : data) { output_file << std::setprecision(16) << datum << std::endl; }
536 }
537 int num_derived_elem_data = derived_elem_data_names.at(block_id).size();
538 for (int j = 0; j < num_derived_elem_data; ++j) {
539 std::string data_name = derived_elem_data_names.at(block_id).at(j);
540 int variable_index = elem_data_index_.at(data_name);
541 int block_num_elem = static_cast<int>(derived_elem_data.at(block_id).at(j).size());
542 output_file << data_name << " " << variable_index << " " << block_id << " " << block_num_elem << std::endl;
543 std::vector<double> const& data = derived_elem_data.at(block_id).at(j);
544 for (auto const& datum : data) { output_file << std::setprecision(16) << datum << std::endl; }
545 }
546 }
547
548 output_file.close();
549}

Member Data Documentation

◆ all_block_ids_

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

◆ block_ids_

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

◆ CPU_word_size_

int nimble::ExodusOutput::CPU_word_size_
protected

◆ dim_

int nimble::ExodusOutput::dim_
protected

◆ elem_data_index_

std::map<std::string, int> nimble::ExodusOutput::elem_data_index_
protected

◆ exodus_write_count_

int nimble::ExodusOutput::exodus_write_count_
protected

◆ filename_

std::string nimble::ExodusOutput::filename_
protected

◆ IO_word_size_

int nimble::ExodusOutput::IO_word_size_
protected

◆ num_blocks_

int nimble::ExodusOutput::num_blocks_
protected

◆ num_elements_

int nimble::ExodusOutput::num_elements_
protected

◆ num_global_blocks_

int nimble::ExodusOutput::num_global_blocks_
protected

◆ num_node_sets_

int nimble::ExodusOutput::num_node_sets_
protected

◆ num_nodes_

int nimble::ExodusOutput::num_nodes_
protected

◆ num_side_sets_

int nimble::ExodusOutput::num_side_sets_
protected

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