NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_parser.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLE_PARSER_H
45#define NIMBLE_PARSER_H
46
47#include <sstream>
48#include <stdexcept>
49
50#include "nimble_macros.h"
51
52#ifdef NIMBLE_HAVE_DARMA
53#include "darma.h"
54#else
55#include <map>
56#include <string>
57#include <vector>
58#endif
59
60#ifdef NIMBLE_HAVE_TRILINOS
61#include <Tpetra_Core.hpp>
62#endif
63
64namespace nimble {
65
66constexpr int MAX_C_STR_SIZE = 256;
67
68std::string
70 std::string const& serial_name,
71 std::string const& extension,
72 std::string const& label = std::string(),
73 int my_rank = 0,
74 int num_ranks = 0);
75
76void
78 char const* const serial_file_name,
79 char const* const extension,
80 char const* const label,
81 int my_mpi_rank,
82 int mpi_num_ranks,
83 int my_thread_rank,
84 int num_threads,
85 char* const file_name);
86
88{
90 BlockProperties(std::string props);
91
92#ifdef NIMBLE_HAVE_DARMA
93 template <typename ArchiveType>
94 void
95 serialize(ArchiveType& ar)
96 {
98 }
99#endif
100
101 std::string block_name_;
103 std::string material_key_;
104};
105
107{
108 public:
109 Parser();
110
111 virtual ~Parser() = default;
112
113 void
114 Initialize();
115
116 std::string
118 {
119 return genesis_file_name_;
120 }
121
122 std::string
124 {
125 return exodus_file_name_;
126 }
127
128 bool
133
134 bool
136 {
138 }
139
140 std::string
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 }
152
153 double
158
159 int
164
165 double
167 {
168 return initial_time_;
169 }
170
171 double
172 FinalTime() const
173 {
174 return final_time_;
175 }
176
177 int
179 {
180 return num_load_steps_;
181 }
182
183 int
185 {
186 return output_frequency_;
187 }
188
189 bool
191 {
192 return (!contact_string_.empty());
193 }
194
195 bool
197 {
199 return visualize_contact;
200 }
201
202 std::string
207
208 std::string
210 {
211 return contact_string_;
212 }
213
214 std::string
215 GetModelMaterialParameters(int block_id) const
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 }
226
227 int
228 GetBlockIdFromMaterial(const std::string& material_key) const
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 }
244
245 std::vector<std::string> const&
250
251 std::string
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 }
262
263 /// \brief Set that Tpetra is used for the simulation
264 ///
265 /// \note The function will abort when an environment
266 /// has been set previously
267 void
269 {
270 use_tpetra_ = true;
271 }
272
273 /// \brief Set that UQ is used for the simulation
274 ///
275 void
277 {
278 use_uq_ = true;
279 }
280
281 /// \brief Set that VT is used for the simulation
282 ///
283 /// \note The function will abort when an environment
284 /// has been set previously
285 void
287 {
288 use_vt_ = true;
289 }
290
291 /// \brief Indicate whether Tpetra is used for the simulation
292 bool
293 UseTpetra() const
294 {
295 return use_tpetra_;
296 }
297
298 /// \brief Indicate whether UQ is used for the simulation
299 bool
300 UseUQ() const
301 {
302 return use_uq_;
303 }
304
305 /// \brief Indicate whether VT is used
306 bool
307 UseVT() const
308 {
309 return use_vt_;
310 }
311
312 /// \brief Set the rank index
313 /// \param[in] myrank Rank index
314 void
315 SetRankID(int myrank)
316 {
317 my_rank_ = myrank;
318 }
319
320 /// \brief Get the rank index
321 int
322 GetRankID() const
323 {
324 return my_rank_;
325 }
326
327 /// \brief Set the number of ranks
328 /// \param[in] nrank Number of MPI ranks
329 void
330 SetNumRanks(int nrank)
331 {
332 num_ranks_ = nrank;
333 }
334
335 /// \brief Get the number of ranks
336 int
338 {
339 return num_ranks_;
340 }
341
342 /// \brief Set the string for the input file
343 /// \param[in] name Input filename
344 void
345 SetInputFilename(const std::string& name)
346 {
347 file_name_ = name;
348 }
349
350#ifdef NIMBLE_HAVE_TRILINOS
351 void
352 ResetTpetraScope(Tpetra::ScopeGuard* ptr_scope)
353 {
354 tpetra_scope_.reset(ptr_scope);
355 }
356#endif
357
358#ifdef NIMBLE_HAVE_BVH
359 int
360 ContactDicing() const noexcept
361 {
362 return contact_dicing_;
363 }
364
365 std::string
366 ContactSplitting() const noexcept
367 {
368 return contact_splitting_;
369 }
370#endif
371
372#ifdef NIMBLE_HAVE_UQ
373 std::string const&
374 UqModelString() const
375 {
376 return uq_model_string_;
377 }
378 std::map<std::string, std::string> const&
379 UqParamsStrings() const
380 {
381 return uq_parameters_strings_;
382 }
383
384 bool
385 HasUq() const
386 {
387 if (uq_model_string_.size() == 0 || uq_parameters_strings_.size() == 0)
388 return false;
389 else
390 return true;
391 }
392#endif
393
394 protected:
395 virtual void
396 ParseKeyValue(const std::string& k, const std::string& v);
397
398 void
399 ReadFile();
400
402 std::string exodus_file_name_;
408 double initial_time_{0.0};
409 double final_time_{0.0};
412 std::string contact_string_;
417 std::map<std::string, std::string> material_strings_;
418 std::map<int, BlockProperties> model_blocks_;
419 std::vector<std::string> boundary_condition_strings_;
421
422#ifdef NIMBLE_HAVE_BVH
423 int contact_dicing_ = 1;
424 std::string contact_splitting_ = "geom_axis";
425#endif
426
427#ifdef NIMBLE_HAVE_UQ
428 std::map<std::string, std::string> uq_parameters_strings_;
429 std::string uq_model_string_;
430#endif
431
432 //--- Variables related to environment
433
434 /// \brief Boolean indicating whether the environment has been set
435 bool env_set_ = false;
436
437 /// \brief Filename for input file to read
438 std::string file_name_ = std::string("none");
439
440 /// \brief Boolean setting the usage of VT
441 bool use_vt_ = false;
442
443 /// \brief Boolean setting the usage of Tpetra
444 bool use_tpetra_ = false;
445
446 /// \brief Boolean setting the usage of UQ
447 bool use_uq_ = false;
448
449 /// \brief Rank ID when running with MPI
450 int my_rank_ = 0;
451
452 /// \brief Number of ranks when running with MPI
453 int num_ranks_ = 1;
454
455#ifdef NIMBLE_HAVE_TRILINOS
456 std::unique_ptr<Tpetra::ScopeGuard> tpetra_scope_ = nullptr;
457#endif
458};
459} // namespace nimble
460
461#endif // NIMBLE_PARSER_H
double NonlinearSolverRelativeTolerance() const
Definition nimble_parser.h:154
double nonlinear_solver_relative_tolerance_
Definition nimble_parser.h:405
virtual ~Parser()=default
bool visualize_contact_entities_
Definition nimble_parser.h:414
int nonlinear_solver_max_iterations_
Definition nimble_parser.h:406
bool use_tpetra_
Boolean setting the usage of Tpetra.
Definition nimble_parser.h:444
std::string contact_string_
Definition nimble_parser.h:412
std::string TimeIntegrationScheme() const
Definition nimble_parser.h:141
bool write_timing_data_file_
Definition nimble_parser.h:404
std::string ContactVisualizationFileName() const
Definition nimble_parser.h:203
double initial_time_
Definition nimble_parser.h:408
std::string ExodusFileName() const
Definition nimble_parser.h:123
void SetNumRanks(int nrank)
Set the number of ranks.
Definition nimble_parser.h:330
void SetToUseUQ()
Set that UQ is used for the simulation.
Definition nimble_parser.h:276
int output_frequency_
Definition nimble_parser.h:411
bool ContactVisualization() const
Definition nimble_parser.h:196
double FinalTime() const
Definition nimble_parser.h:172
int num_load_steps_
Definition nimble_parser.h:410
std::string GetModelMaterialParameters(int block_id) const
Definition nimble_parser.h:215
bool HasContact() const
Definition nimble_parser.h:190
std::vector< std::string > boundary_condition_strings_
Definition nimble_parser.h:419
void SetToUseVT()
Set that VT is used for the simulation.
Definition nimble_parser.h:286
std::vector< std::string > const & GetBoundaryConditionStrings() const
Definition nimble_parser.h:246
std::string genesis_file_name_
Definition nimble_parser.h:401
void SetToUseTpetra()
Set that Tpetra is used for the simulation.
Definition nimble_parser.h:268
virtual void ParseKeyValue(const std::string &k, const std::string &v)
Definition nimble_parser.cc:239
bool WriteTimingDataFile() const
Definition nimble_parser.h:135
bool UseUQ() const
Indicate whether UQ is used for the simulation.
Definition nimble_parser.h:300
void Initialize()
Definition nimble_parser.cc:191
int GetNumRanks() const
Get the number of ranks.
Definition nimble_parser.h:337
int NumLoadSteps() const
Definition nimble_parser.h:178
int NonlinearSolverMaxIterations() const
Definition nimble_parser.h:160
double final_time_
Definition nimble_parser.h:409
void SetInputFilename(const std::string &name)
Set the string for the input file.
Definition nimble_parser.h:345
void ReadFile()
Definition nimble_parser.cc:197
int num_ranks_
Number of ranks when running with MPI.
Definition nimble_parser.h:453
bool use_vt_
Boolean setting the usage of VT.
Definition nimble_parser.h:441
std::map< std::string, std::string > material_strings_
Definition nimble_parser.h:417
std::string file_name_
Filename for input file to read.
Definition nimble_parser.h:438
bool UseTpetra() const
Indicate whether Tpetra is used for the simulation.
Definition nimble_parser.h:293
bool use_two_level_mesh_decomposition_
Definition nimble_parser.h:403
int GetBlockIdFromMaterial(const std::string &material_key) const
Definition nimble_parser.h:228
std::string contact_visualization_file_name_
Definition nimble_parser.h:416
bool visualize_contact_bounding_boxes_
Definition nimble_parser.h:415
std::string contact_backend_string_
Definition nimble_parser.h:413
std::string ContactString() const
Definition nimble_parser.h:209
double InitialTime() const
Definition nimble_parser.h:166
std::string exodus_file_name_
Definition nimble_parser.h:402
bool env_set_
Boolean indicating whether the environment has been set.
Definition nimble_parser.h:435
void SetRankID(int myrank)
Set the rank index.
Definition nimble_parser.h:315
Parser()
Definition nimble_parser.cc:171
int my_rank_
Rank ID when running with MPI.
Definition nimble_parser.h:450
bool UseTwoLevelMeshDecomposition() const
Definition nimble_parser.h:129
std::string GetOutputFieldString() const
Definition nimble_parser.h:252
int OutputFrequency() const
Definition nimble_parser.h:184
std::string GenesisFileName() const
Definition nimble_parser.h:117
bool UseVT() const
Indicate whether VT is used.
Definition nimble_parser.h:307
int GetRankID() const
Get the rank index.
Definition nimble_parser.h:322
std::map< int, BlockProperties > model_blocks_
Definition nimble_parser.h:418
bool use_uq_
Boolean setting the usage of UQ.
Definition nimble_parser.h:447
std::string output_field_string_
Definition nimble_parser.h:420
std::string time_integration_scheme_
Definition nimble_parser.h:407
Definition kokkos_contact_manager.h:49
std::string IOFileName(std::string const &serial_name, std::string const &extension, std::string const &label, int my_rank, int num_ranks)
Definition nimble_parser.cc:58
constexpr int MAX_C_STR_SIZE
Definition nimble_parser.h:66
void IOFileNameThreadSafe(char const *const serial_file_name, char const *const extension, char const *const label, int my_mpi_rank, int mpi_num_ranks, int my_thread_rank, int num_threads, char *const file_name)
Definition nimble_parser.cc:91
Definition nimble_parser.h:88
std::string material_key_
Definition nimble_parser.h:103
BlockProperties()
Definition nimble_parser.h:89
int block_id_
Definition nimble_parser.h:102
std::string block_name_
Definition nimble_parser.h:101