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

#include <nimble_parser.h>

Public Member Functions

 Parser ()
 
virtual ~Parser ()=default
 
void Initialize ()
 
std::string GenesisFileName () const
 
std::string ExodusFileName () const
 
bool UseTwoLevelMeshDecomposition () const
 
bool WriteTimingDataFile () const
 
std::string TimeIntegrationScheme () const
 
double NonlinearSolverRelativeTolerance () const
 
int NonlinearSolverMaxIterations () const
 
double InitialTime () const
 
double FinalTime () const
 
int NumLoadSteps () const
 
int OutputFrequency () const
 
bool HasContact () const
 
bool ContactVisualization () const
 
std::string ContactVisualizationFileName () const
 
std::string ContactString () const
 
std::string GetModelMaterialParameters (int block_id) const
 
int GetBlockIdFromMaterial (const std::string &material_key) const
 
std::vector< std::string > const & GetBoundaryConditionStrings () const
 
std::string GetOutputFieldString () const
 
void SetToUseTpetra ()
 Set that Tpetra is used for the simulation.
 
void SetToUseUQ ()
 Set that UQ is used for the simulation.
 
void SetToUseVT ()
 Set that VT is used for the simulation.
 
bool UseTpetra () const
 Indicate whether Tpetra is used for the simulation.
 
bool UseUQ () const
 Indicate whether UQ is used for the simulation.
 
bool UseVT () const
 Indicate whether VT is used.
 
void SetRankID (int myrank)
 Set the rank index.
 
int GetRankID () const
 Get the rank index.
 
void SetNumRanks (int nrank)
 Set the number of ranks.
 
int GetNumRanks () const
 Get the number of ranks.
 
void SetInputFilename (const std::string &name)
 Set the string for the input file.
 

Protected Member Functions

virtual void ParseKeyValue (const std::string &k, const std::string &v)
 
void ReadFile ()
 

Protected Attributes

std::string genesis_file_name_
 
std::string exodus_file_name_
 
bool use_two_level_mesh_decomposition_
 
bool write_timing_data_file_
 
double nonlinear_solver_relative_tolerance_
 
int nonlinear_solver_max_iterations_
 
std::string time_integration_scheme_
 
double initial_time_ {0.0}
 
double final_time_ {0.0}
 
int num_load_steps_
 
int output_frequency_
 
std::string contact_string_
 
std::string contact_backend_string_
 
bool visualize_contact_entities_
 
bool visualize_contact_bounding_boxes_
 
std::string contact_visualization_file_name_
 
std::map< std::string, std::string > material_strings_
 
std::map< int, BlockPropertiesmodel_blocks_
 
std::vector< std::string > boundary_condition_strings_
 
std::string output_field_string_
 
bool env_set_ = false
 Boolean indicating whether the environment has been set.
 
std::string file_name_ = std::string("none")
 Filename for input file to read.
 
bool use_vt_ = false
 Boolean setting the usage of VT.
 
bool use_tpetra_ = false
 Boolean setting the usage of Tpetra.
 
bool use_uq_ = false
 Boolean setting the usage of UQ.
 
int my_rank_ = 0
 Rank ID when running with MPI.
 
int num_ranks_ = 1
 Number of ranks when running with MPI.
 

Constructor & Destructor Documentation

◆ Parser()

nimble::Parser::Parser ( )
172 : genesis_file_name_("none"),
175 exodus_file_name_("none"),
176 time_integration_scheme_("explicit"),
179 initial_time_(0.0),
180 final_time_(0.0),
186
187{
188}
double nonlinear_solver_relative_tolerance_
Definition nimble_parser.h:405
bool visualize_contact_entities_
Definition nimble_parser.h:414
int nonlinear_solver_max_iterations_
Definition nimble_parser.h:406
bool write_timing_data_file_
Definition nimble_parser.h:404
double initial_time_
Definition nimble_parser.h:408
int output_frequency_
Definition nimble_parser.h:411
int num_load_steps_
Definition nimble_parser.h:410
std::string genesis_file_name_
Definition nimble_parser.h:401
double final_time_
Definition nimble_parser.h:409
bool use_two_level_mesh_decomposition_
Definition nimble_parser.h:403
std::string contact_visualization_file_name_
Definition nimble_parser.h:416
bool visualize_contact_bounding_boxes_
Definition nimble_parser.h:415
std::string exodus_file_name_
Definition nimble_parser.h:402
std::string time_integration_scheme_
Definition nimble_parser.h:407

◆ ~Parser()

virtual nimble::Parser::~Parser ( )
virtualdefault

Member Function Documentation

◆ ContactString()

std::string nimble::Parser::ContactString ( ) const
inline
210 {
211 return contact_string_;
212 }
std::string contact_string_
Definition nimble_parser.h:412

◆ ContactVisualization()

bool nimble::Parser::ContactVisualization ( ) const
inline
197 {
199 return visualize_contact;
200 }

◆ ContactVisualizationFileName()

std::string nimble::Parser::ContactVisualizationFileName ( ) const
inline
204 {
206 }

◆ ExodusFileName()

std::string nimble::Parser::ExodusFileName ( ) const
inline
124 {
125 return exodus_file_name_;
126 }

◆ FinalTime()

double nimble::Parser::FinalTime ( ) const
inline
173 {
174 return final_time_;
175 }

◆ GenesisFileName()

std::string nimble::Parser::GenesisFileName ( ) const
inline
118 {
119 return genesis_file_name_;
120 }

◆ GetBlockIdFromMaterial()

int nimble::Parser::GetBlockIdFromMaterial ( const std::string & material_key) const
inline
229 {
230 int block_id = -1;
231 // std::map<int, BlockProperties>::iterator it;
232 // for(it = model_blocks_.begin(); it != model_blocks_.end();
233 // it++){
234 for (auto const& entry : model_blocks_) {
235 BlockProperties const& block_props = entry.second; // it->second;
236 if (material_key == block_props.material_key_) {
237 block_id = entry.first; // it->first; //Found the block id with the
238 // material string
239 break;
240 }
241 }
242 return block_id;
243 }
std::map< int, BlockProperties > model_blocks_
Definition nimble_parser.h:418

◆ GetBoundaryConditionStrings()

std::vector< std::string > const & nimble::Parser::GetBoundaryConditionStrings ( ) const
inline
247 {
249 }
std::vector< std::string > boundary_condition_strings_
Definition nimble_parser.h:419

◆ GetModelMaterialParameters()

std::string nimble::Parser::GetModelMaterialParameters ( int block_id) const
inline
216 {
217 if (model_blocks_.find(block_id) == model_blocks_.end()) {
218 std::string none_str("none");
219 return none_str;
220 }
221 BlockProperties const& block = model_blocks_.at(block_id);
222 std::string const& material_key = block.material_key_;
223 std::string const& material_props = material_strings_.at(material_key);
224 return material_props;
225 }
std::map< std::string, std::string > material_strings_
Definition nimble_parser.h:417

◆ GetNumRanks()

int nimble::Parser::GetNumRanks ( ) const
inline

Get the number of ranks.

338 {
339 return num_ranks_;
340 }
int num_ranks_
Number of ranks when running with MPI.
Definition nimble_parser.h:453

◆ GetOutputFieldString()

std::string nimble::Parser::GetOutputFieldString ( ) const
inline
253 {
254 if (output_field_string_.empty()) {
255 std::string msg =
256 "\n**** Error in Parser::GetOutputFieldString(), output fields not "
257 "found (possible input deck error?).";
258 throw std::invalid_argument(msg);
259 }
261 }
std::string output_field_string_
Definition nimble_parser.h:420

◆ GetRankID()

int nimble::Parser::GetRankID ( ) const
inline

Get the rank index.

323 {
324 return my_rank_;
325 }
int my_rank_
Rank ID when running with MPI.
Definition nimble_parser.h:450

◆ HasContact()

bool nimble::Parser::HasContact ( ) const
inline
191 {
192 return (!contact_string_.empty());
193 }

◆ Initialize()

void nimble::Parser::Initialize ( )
192{
193 ReadFile();
194}
void ReadFile()
Definition nimble_parser.cc:197

◆ InitialTime()

double nimble::Parser::InitialTime ( ) const
inline
167 {
168 return initial_time_;
169 }

◆ NonlinearSolverMaxIterations()

int nimble::Parser::NonlinearSolverMaxIterations ( ) const
inline
161 {
163 }

◆ NonlinearSolverRelativeTolerance()

double nimble::Parser::NonlinearSolverRelativeTolerance ( ) const
inline
155 {
157 }

◆ NumLoadSteps()

int nimble::Parser::NumLoadSteps ( ) const
inline
179 {
180 return num_load_steps_;
181 }

◆ OutputFrequency()

int nimble::Parser::OutputFrequency ( ) const
inline
185 {
186 return output_frequency_;
187 }

◆ ParseKeyValue()

void nimble::Parser::ParseKeyValue ( const std::string & k,
const std::string & v )
protectedvirtual
240{
241 if (key == "genesis input file") {
242 genesis_file_name_ = value;
243 } else if (key == "exodus output file") {
244 exodus_file_name_ = value;
245 } else if (key == "use two level mesh decomposition") {
246 std::string value_upper_case(value);
247 std::transform(
248 value_upper_case.begin(), value_upper_case.end(), value_upper_case.begin(), (int (*)(int))std::toupper);
249 if (value_upper_case == "TRUE" || value_upper_case == "YES" || value_upper_case == "ON") {
251 } else if (value_upper_case == "FALSE" || value_upper_case == "NO" || value_upper_case == "OFF") {
253 } else {
254 std::string msg =
255 "\n**** Error in Parser::ReadFile(), unexpected value for \"use two "
256 "level mesh decomposition\" " +
257 value + "\n";
258 throw std::invalid_argument(msg);
259 }
260 } else if (key == "write timing data file") {
261 std::string value_upper_case(value);
262 std::transform(
263 value_upper_case.begin(), value_upper_case.end(), value_upper_case.begin(), (int (*)(int))std::toupper);
264 if (value_upper_case == "TRUE" || value_upper_case == "YES" || value_upper_case == "ON") {
266 } else if (value_upper_case == "FALSE" || value_upper_case == "NO" || value_upper_case == "OFF") {
268 } else {
269 std::string msg =
270 "\n**** Error in Parser::ReadFile(), unexpected value for \"write "
271 "timing data file\" " +
272 value + "\n";
273 throw std::invalid_argument(msg);
274 }
275 } else if (key == "time integration scheme") {
277 } else if (key == "nonlinear solver relative tolerance") {
278 nonlinear_solver_relative_tolerance_ = std::atof(value.c_str());
279 } else if (key == "nonlinear solver maximum iterations") {
280 nonlinear_solver_max_iterations_ = std::atoi(value.c_str());
281 } else if (key == "initial time") {
282 initial_time_ = std::atof(value.c_str());
283 } else if (key == "final time") {
284 final_time_ = std::atof(value.c_str());
285 } else if (key == "number of load steps") {
286 num_load_steps_ = std::atoi(value.c_str());
287 } else if (key == "output frequency") {
288 output_frequency_ = std::atoi(value.c_str());
289 } else if (key == "contact") {
290 contact_string_ = value;
291 } else if (key == "contact backend") {
293 } else if (key == "contact visualization") {
294 std::stringstream ss(value);
295 std::string val;
296 std::vector<std::string> vals;
297 while (ss >> val) { vals.push_back(val); }
298
299 if (vals.size() != 6 || vals[0] != "visualize_contact_entities" || (vals[1] != "on" && vals[1] != "off") ||
300 vals[2] != "visualize_bounding_boxes" || (vals[3] != "on" && vals[3] != "off") || vals[4] != "file_name") {
301 std::string msg =
302 "\n**** Error in Parser::ReadFile(), unexpected value for \"contact "
303 "visualization\"\n";
304 msg +=
305 "**** Allowable syntax is \"visualize_contact_entities <on/off> "
306 "visualize_bounding_boxes <on/off> file_name <file_name.e>\"\n";
307 throw std::invalid_argument(msg);
308 }
309
311 if (vals[1] == "on") { visualize_contact_entities_ = true; }
312
314 if (vals[3] == "on") { visualize_contact_bounding_boxes_ = true; }
315
317 } else if (key == "material parameters") {
318 size_t space_pos = value.find(" ");
319 std::string material_key = value.substr(0, space_pos);
320 std::string material_props = value.substr(space_pos + 1, value.size());
321 material_strings_[material_key] = material_props;
322 } else if (key == "element block") {
323 BlockProperties block_props(value);
324 model_blocks_[block_props.block_id_] = block_props;
325 } else if (key == "boundary condition") {
326 boundary_condition_strings_.push_back(value);
327 } else if (key == "output fields") {
328 output_field_string_ = value;
329 } else if (key == "contact dicing") {
330 int tmp = std::atoi(value.c_str());
331#ifdef NIMBLE_HAVE_BVH
332 contact_dicing_ = tmp;
333#else
334 std::cout << " **** Parser::ReadFile(), skipping key " + key + "\n";
335#endif
336 } else if (key == "contact splitting") {
337 size_t space_pos = value.find(" ");
338 std::string split_key = value.substr(0, space_pos);
339 std::string split_alg = value.substr(space_pos + 1, value.size());
340#ifdef NIMBLE_HAVE_BVH
341 contact_splitting_ = split_alg;
342#else
343 std::cout << " **** Parser::ReadFile(), skipping key " + key + "\n";
344#endif
345 }
346#ifdef NIMBLE_HAVE_UQ
347 else if (key == "uq parameters") {
348 size_t space_pos = value.find(" ");
349 std::string material_key = value.substr(0, space_pos);
350 std::string uq_params = value.substr(space_pos + 1, value.size());
351 uq_parameters_strings_[material_key] = uq_params;
352 } else if (key == "uq model") {
353 uq_model_string_ = value;
354 }
355#endif
356 else {
357 std::string msg = "\n**** Error in Parser::ReadFile(), unknown key " + key + "\n";
358 throw std::invalid_argument(msg);
359 }
360}
std::string contact_backend_string_
Definition nimble_parser.h:413

◆ ReadFile()

void nimble::Parser::ReadFile ( )
protected
198{
199 int max_chars_per_line = 1000;
200 std::string delimiter(" ");
201
202 std::ifstream fin;
203 fin.open(file_name_.c_str());
204 if (!fin.good()) {
205 std::string msg = "\n**** Error in Parser::ReadFile(), unable to read file " + file_name_ + "\n";
206 throw std::invalid_argument(msg);
207 }
208
209 while (!fin.eof()) {
210 char buf[max_chars_per_line];
211 fin.getline(buf, max_chars_per_line);
212 std::string line(buf);
213
214 // Strip out comments (# character)
215 size_t pound_pos = line.find("#");
216 if (pound_pos != std::string::npos) { line = line.substr(0, pound_pos); }
217 // Strip out leading and trailing whitespace
218 if (line.size() > 0) {
219 size_t start_pos = line.find_first_not_of(" \t");
220 size_t end_pos = line.find_last_not_of(" \t");
221 line = line.substr(start_pos, end_pos - start_pos + 1);
222 }
223
224 if (line.size() > 0) {
225 // Obtain key and value
226 // Commands are delimited with a colon
227 size_t colon_pos = line.find(":");
228 std::string key = line.substr(0, colon_pos);
229 key = key.substr(key.find_first_not_of(" "), key.find_last_not_of(" ") + 1);
230 std::string value = line.substr(colon_pos + 1, line.size());
231 value = value.substr(value.find_first_not_of(" "), value.find_last_not_of(" ") + 1);
232
233 ParseKeyValue(key, value);
234 }
235 }
236}
virtual void ParseKeyValue(const std::string &k, const std::string &v)
Definition nimble_parser.cc:239
std::string file_name_
Filename for input file to read.
Definition nimble_parser.h:438

◆ SetInputFilename()

void nimble::Parser::SetInputFilename ( const std::string & name)
inline

Set the string for the input file.

Parameters
[in]nameInput filename
346 {
347 file_name_ = name;
348 }

◆ SetNumRanks()

void nimble::Parser::SetNumRanks ( int nrank)
inline

Set the number of ranks.

Parameters
[in]nrankNumber of MPI ranks
331 {
332 num_ranks_ = nrank;
333 }

◆ SetRankID()

void nimble::Parser::SetRankID ( int myrank)
inline

Set the rank index.

Parameters
[in]myrankRank index
316 {
317 my_rank_ = myrank;
318 }

◆ SetToUseTpetra()

void nimble::Parser::SetToUseTpetra ( )
inline

Set that Tpetra is used for the simulation.

Note
The function will abort when an environment has been set previously
269 {
270 use_tpetra_ = true;
271 }
bool use_tpetra_
Boolean setting the usage of Tpetra.
Definition nimble_parser.h:444

◆ SetToUseUQ()

void nimble::Parser::SetToUseUQ ( )
inline

Set that UQ is used for the simulation.

277 {
278 use_uq_ = true;
279 }
bool use_uq_
Boolean setting the usage of UQ.
Definition nimble_parser.h:447

◆ SetToUseVT()

void nimble::Parser::SetToUseVT ( )
inline

Set that VT is used for the simulation.

Note
The function will abort when an environment has been set previously
287 {
288 use_vt_ = true;
289 }
bool use_vt_
Boolean setting the usage of VT.
Definition nimble_parser.h:441

◆ TimeIntegrationScheme()

std::string nimble::Parser::TimeIntegrationScheme ( ) const
inline
142 {
143 if (time_integration_scheme_ != "explicit" && time_integration_scheme_ != "quasistatic") {
144 std::string msg =
145 "\n**** Error in Parser::TimeIntegrationScheme(), invalid "
146 "integration scheme " +
148 throw std::invalid_argument(msg);
149 }
151 }

◆ UseTpetra()

bool nimble::Parser::UseTpetra ( ) const
inline

Indicate whether Tpetra is used for the simulation.

294 {
295 return use_tpetra_;
296 }

◆ UseTwoLevelMeshDecomposition()

bool nimble::Parser::UseTwoLevelMeshDecomposition ( ) const
inline
130 {
132 }

◆ UseUQ()

bool nimble::Parser::UseUQ ( ) const
inline

Indicate whether UQ is used for the simulation.

301 {
302 return use_uq_;
303 }

◆ UseVT()

bool nimble::Parser::UseVT ( ) const
inline

Indicate whether VT is used.

308 {
309 return use_vt_;
310 }

◆ WriteTimingDataFile()

bool nimble::Parser::WriteTimingDataFile ( ) const
inline
136 {
138 }

Member Data Documentation

◆ boundary_condition_strings_

std::vector<std::string> nimble::Parser::boundary_condition_strings_
protected

◆ contact_backend_string_

std::string nimble::Parser::contact_backend_string_
protected

◆ contact_string_

std::string nimble::Parser::contact_string_
protected

◆ contact_visualization_file_name_

std::string nimble::Parser::contact_visualization_file_name_
protected

◆ env_set_

bool nimble::Parser::env_set_ = false
protected

Boolean indicating whether the environment has been set.

◆ exodus_file_name_

std::string nimble::Parser::exodus_file_name_
protected

◆ file_name_

std::string nimble::Parser::file_name_ = std::string("none")
protected

Filename for input file to read.

◆ final_time_

double nimble::Parser::final_time_ {0.0}
protected
409{0.0};

◆ genesis_file_name_

std::string nimble::Parser::genesis_file_name_
protected

◆ initial_time_

double nimble::Parser::initial_time_ {0.0}
protected
408{0.0};

◆ material_strings_

std::map<std::string, std::string> nimble::Parser::material_strings_
protected

◆ model_blocks_

std::map<int, BlockProperties> nimble::Parser::model_blocks_
protected

◆ my_rank_

int nimble::Parser::my_rank_ = 0
protected

Rank ID when running with MPI.

◆ nonlinear_solver_max_iterations_

int nimble::Parser::nonlinear_solver_max_iterations_
protected

◆ nonlinear_solver_relative_tolerance_

double nimble::Parser::nonlinear_solver_relative_tolerance_
protected

◆ num_load_steps_

int nimble::Parser::num_load_steps_
protected

◆ num_ranks_

int nimble::Parser::num_ranks_ = 1
protected

Number of ranks when running with MPI.

◆ output_field_string_

std::string nimble::Parser::output_field_string_
protected

◆ output_frequency_

int nimble::Parser::output_frequency_
protected

◆ time_integration_scheme_

std::string nimble::Parser::time_integration_scheme_
protected

◆ use_tpetra_

bool nimble::Parser::use_tpetra_ = false
protected

Boolean setting the usage of Tpetra.

◆ use_two_level_mesh_decomposition_

bool nimble::Parser::use_two_level_mesh_decomposition_
protected

◆ use_uq_

bool nimble::Parser::use_uq_ = false
protected

Boolean setting the usage of UQ.

◆ use_vt_

bool nimble::Parser::use_vt_ = false
protected

Boolean setting the usage of VT.

◆ visualize_contact_bounding_boxes_

bool nimble::Parser::visualize_contact_bounding_boxes_
protected

◆ visualize_contact_entities_

bool nimble::Parser::visualize_contact_entities_
protected

◆ write_timing_data_file_

bool nimble::Parser::write_timing_data_file_
protected

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