svFSIplus
Parameters.h
1 /**
2  * Copyright (c) Stanford University, The Regents of the University of California, and others.
3  *
4  * All Rights Reserved.
5  *
6  * See Copyright-SimVascular.txt for additional details.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject
14  * to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef PARAMETERS_H
33 #define PARAMETERS_H
34 
35 #include <any>
36 #include <functional>
37 #include <iostream>
38 #include <map>
39 #include <regex>
40 #include <set>
41 #include <sstream>
42 #include <string>
43 #include <tuple>
44 #include <variant>
45 #include <vector>
46 
47 #include "tinyxml2.h"
48 
49 template<typename T>
50 
51 /// @brief The Parameter class template is used to store a named
52 /// paramater and its scalar value as a basic type: bool, double,
53 /// int and string.
54 ///
55 /// The classes defined here are used to process svFSIplus simulation parameters read in
56 /// from an Extensible Markup Language (XML) format file. XML is a simple text-based format
57 /// for representing structured information.
58 ///
59 /// An XML document is formed as an element tree. The XML tree starts at a root element and
60 /// branches from the root to sub-elements. All elements can have sub-elements:
61 ///
62 /// \code{.cpp}
63 /// <svFSIFile>
64 /// <element>
65 /// <subelement>.....</subelement>
66 /// </element>
67 /// </svFSIFile>
68 /// \endcode
69 ///
70 /// The elements in the svFSIplus simulation file are represented by sections of
71 /// related parameters. Sub-elements are refered to as sub-sections.
72 ///
73 ///-----------------
74 /// Parameters class
75 ///-----------------
76 /// The Parameters class is the top level class. It contains objects used to store
77 /// parameters for the sections making up an XML simulation parameters file
78 ///
79 /// 1) General (GeneralSimulationParameters)
80 /// 2) Mesh (MeshParameters)
81 /// 3) Equation (EquationParameters)
82 /// 4) Projection (ProjectionParameters)
83 ///
84 /// Each object contains methods to parse the XML file for the parameters defined for it.
85 /// These section objects may also contain objects representing the sub-sections defined
86 /// for each section.
87 ///
88 ///-----------------
89 /// Section objects
90 ///-----------------
91 /// Each section object contains objects representing parameters. A parameter's name and value
92 /// is stored using either a Parameter and VectorParamater template objects. A parameter
93 /// value is stored as a basic type: bool, double, int and string.
94 ///
95 /// Parameter objects in a section class are named using the same XML element name with the 1st
96 /// character lower case.
97 ///
98 /// Example: GeneralSimulationParameters class
99 ///
100 /// \code{.cpp}
101 /// Parameter<bool> verbose; // <Verbose>
102 /// Parameter<double> spectral_radius_of_infinite_time_step; // <Spectral_radius_of_infinite_time_step>
103 /// Parameter<double> time_step_size; // <Time_step_size>
104 /// \endcode
105 ///
106 /// The name and default value for each parameter is defined in a section object's constructor.
107 ///
108 /// Parameter values are set using the set_values() method which contains calls to tinyxml2
109 /// to parse parameter values from an XML file.
110 ///
111 /// Each section object inherits from the ParameterLists class. This class provides methods to
112 /// store parameters in a map and process iterated over them for setting values and other operations.
114 {
115  public:
116  Parameter() {};
117 
118  Parameter(const std::string& name, T value, bool required, std::vector<T> range = {}) :
119  value_(value), name_(name), required_(required)
120  {
121  value_ = value;
122  range_ = range;
123  };
124 
125  std::string name() const { return name_; };
126  T value() const { return value_; };
127  T operator()() const { return value_; };
128  bool defined() const { return value_set_; };
129 
130  /// @brief Get the value of a parameter as a string.
131  std::string svalue()
132  {
133  std::ostringstream str_stream;
134  str_stream << value_;
135  return str_stream.str();
136  }
137 
138  friend std::ostream& operator << (std::ostream& out, const Parameter<T>& param)
139  {
140  out << param.value();
141  return out;
142  }
143 
144  /// @brief Set the parameter name and value, and if it is required.
145  void set(const std::string& name, bool required, T value) {
146  name_ = name;
147  required_ = required;
148  value_ = value;
149  }
150 
151  /// @brief Set the parameter value from a string.
152  void set(const std::string& str_value)
153  {
154  if (str_value == "") {
155  value_ = T{0};
156  }
157 
158  auto str = str_value;
159  std::string::iterator end_pos = std::remove(str.begin(), str.end(), ' ');
160  str.erase(end_pos, str.end());
161 
162  std::istringstream str_stream(str);
163  if (!(str_stream >> value_)) {
164  std::istringstream str_stream(str);
165  if (!(str_stream >> std::boolalpha >> value_)) {
166  throw std::runtime_error("Incorrect value '" + str + "' for '" + name_ + "'.");
167  }
168  }
169 
170  value_set_ = true;
171  }
172 
173  bool check_required_set()
174  {
175  if (!required_) {
176  return true;
177  }
178  return value_set_;
179  }
180 
181  T value_ = T{0};
182  std::string name_ = "";
183  bool required_ = false;
184  bool value_set_ = false;
185  std::vector<T> range_;
186 };
187 
188 /// @brief The VectorParameter class template is used to store a named
189 /// paramater and its vector of values as a basic type: bool, double,
190 /// int and string.
191 template<typename T>
193 {
194  public:
195  VectorParameter() {};
196 
197  VectorParameter(const std::string& name, const std::vector<T>& value, bool required, std::vector<T> range = {}) :
198  value_(value), name_(name), required_(required)
199  {
200  value_ = value;
201  range_ = range;
202  };
203 
204  std::string name() const { return name_; };
205  std::vector<T> value() const { return value_; };
206  bool defined() const { return value_set_; };
207  int size() const { return value_.size(); };
208 
209  std::vector<T> operator()() const { return value_; };
210  const double& operator[](const int i) const { return value_[i]; };
211 
212  /// @brief Get the string representation of the parameter value.
213  std::string svalue()
214  {
215  std::string str;
216 
217  if constexpr (std::is_same<T, std::string>::value) {
218  for (auto v : value_) {
219  str += " " + v + " ";
220  }
221  } else {
222  for (auto v : value_) {
223  str += " " + std::to_string(v);
224  }
225  }
226 
227  return str;
228  }
229 
230  friend std::ostream& operator << (std::ostream& out, const VectorParameter<T>& param)
231  {
232  for (int i = 0; i < param.size(); i++) {
233  out << param.value_[i];
234  }
235  return out;
236  }
237 
238  /// @brief Set the parameter name and value, and if it is required.
239  void set(const std::string& name, bool required, const std::vector<T>& value)
240  {
241  name_ = name;
242  required_ = required;
243  value_ = value;
244  }
245 
246  /// @brief Set the parameter value from a string.
247  void set(const std::string& str_value)
248  {
249  if (str_value == "") {
250  return;
251  }
252 
253  std::string error_msg = "Improper vector format '" + str_value + "' found in '" + name_ + "'." + " Vector format is: (x,y,z)";
254  std::regex sep("\\(|\\)|\\,");
255  auto str = std::regex_replace(str_value, sep, " ");
256 
257  if constexpr (std::is_same<T, std::string>::value) {
258  std::stringstream ssin(str);
259  std::string value;
260  while (ssin >> value) {
261  value_.push_back(value);
262  }
263  } else {
264  T value;
265  std::istringstream ssin(str);
266  while (ssin >> value) {
267  value_.push_back(value);
268  }
269  }
270  }
271 
272  bool check_required_set()
273  {
274  if (!required_) {
275  return true;
276  }
277  return value_set_;
278  }
279 
280  std::vector<T> value_;
281  std::string name_;
282  bool required_ = false;
283  bool value_set_ = false;
284  std::vector<T> range_;
285 };
286 
287 /// @brief Defines parameter name and value, and stores them in
288 /// maps for settng values from XML.
290 {
291  public:
292 
293  ParameterLists() { }
294 
295  void set_xml_element_name(const std::string& name)
296  {
297  xml_element_name = name;
298  }
299 
300  /// @brief Set the name, default value and the parameter required flag.
301  void set_parameter(const std::string& name, const bool value, bool required, Parameter<bool>& param)
302  {
303  param.set(name, required, value);
304  params_map[name] = &param;
305  }
306 
307  void set_parameter(const std::string& name, const double value, bool required, Parameter<double>& param)
308  {
309  param.set(name, required, value);
310  params_map[name] = &param;
311  }
312 
313  void set_parameter(const std::string& name, std::initializer_list<double> value, bool required, VectorParameter<double>& param)
314  {
315  param.set(name, required, value);
316  params_map[name] = &param;
317  }
318 
319  void set_parameter(const std::string& name, std::initializer_list<int> value, bool required, VectorParameter<int>& param)
320  {
321  param.set(name, required, value);
322  params_map[name] = &param;
323  }
324 
325  void set_parameter(const std::string& name, std::initializer_list<std::string> value, bool required,
327  {
328  param.set(name, required, value);
329  params_map[name] = &param;
330  }
331 
332  void set_parameter(const std::string& name, const int value, bool required, Parameter<int>& param, std::vector<int> range = {})
333  {
334  param.set(name, required, value);
335  params_map[name] = &param;
336  }
337 
338  void set_parameter(const std::string& name, const std::string& value, bool required, Parameter<std::string>& param)
339  {
340  param.set(name, required, value);
341  params_map[name] = &param;
342  }
343 
344  /// @brief Set the value of a paramter from a string.
345  void set_parameter_value(const std::string& name, const std::string& value)
346  {
347  if (params_map.count(name) == 0) {
348  throw std::runtime_error("Unknown " + xml_element_name + " XML element '" + name + "'.");
349  }
350 
351  std::visit([value](auto&& p) { p->set(value); }, params_map[name]);
352  }
353 
354  /// @brief Check if any required parameters have not been set.
356  {
357  bool unset_found = false;
358 
359  for (auto& [ key, param ] : params_map) {
360  if (std::visit([](auto&& p) {
361  return !p->check_required_set();
362  }, param)) {
363  throw std::runtime_error(xml_element_name + " XML element '" + key + "' has not been set.");
364  }
365  }
366  }
367 
368  /// @brief Get the defined parameters as a map of strings.
369  std::map<std::string,std::string> get_parameter_list()
370  {
371  std::map<std::string,std::string> params;
372 
373  for (auto& [ key, param ] : params_map) {
374  std::visit([&params](auto&& p) {
375  params[p->name()] = p->svalue();
376  }, param);
377  }
378 
379  return params;
380  }
381 
382  /// @brief Print the parameters.
384  {
385  for (auto& [ key, param ] : params_map) {
386  std::cout << key << ": ";
387  std::visit([](auto& p) {
388  std::cout << p->name_ << std::endl;
389  std::cout << p->svalue() << std::endl;
390  }, param);
391  }
392  }
393 
394  /// @brief Map used for storing parameters by name / Parameter template union.
395  std::map<std::string, std::variant<Parameter<bool>*, Parameter<double>*, Parameter<int>*,
398 
399  std::string xml_element_name = "";
400 };
401 
402 //////////////////////////////////////////////////////////
403 // ConstitutiveModelParameters //
404 //////////////////////////////////////////////////////////
405 
406 // The following classes are used to store parameters for
407 // various constitutive models.
408 
410 {
411  public:
413  bool defined() const { return value_set; };
414  void set_values(tinyxml2::XMLElement* con_model_params);
415  void print_parameters();
420  Parameter<double> mu0;
421  bool value_set = false;
422 };
423 
425 {
426  public:
428  bool defined() const { return value_set; };
429  void set_values(tinyxml2::XMLElement* con_model_params);
430  void print_parameters();
432  Parameter<double> bfs;
435  bool value_set = false;
436 };
437 
438 //---------------------
439 // HolzapfelParameters
440 //---------------------
442 {
443  public:
445  bool defined() const { return value_set; };
446  void set_values(tinyxml2::XMLElement* con_model_params);
447  void print_parameters();
448 
451  Parameter<double> a4f;
452  Parameter<double> b4f;
453  Parameter<double> a4s;
454  Parameter<double> b4s;
455  Parameter<double> afs;
456  Parameter<double> bfs;
457 
458  bool value_set = false;
459 };
460 
462 {
463  public:
465  bool defined() const { return value_set; };
466  void set_values(tinyxml2::XMLElement* con_model_params);
467  void print_parameters();
472  Parameter<double> kappa;
473  bool value_set = false;
474 };
475 
477 {
478  public:
480  bool defined() const { return value_set; };
481  void set_values(tinyxml2::XMLElement* con_model_params);
482  void print_parameters();
485  bool value_set = false;
486 };
487 
489 {
490  public:
492  void set_values(tinyxml2::XMLElement* modl_params);
493  void print_parameters();
494  bool value_set = false;
495 };
496 
498 {
499  public:
501  void set_values(tinyxml2::XMLElement* modl_params);
502  void print_parameters();
503  bool value_set = false;
504 };
505 
506 /// @brief The ConstitutiveModelParameters class store parameters
507 /// for various constitutive models.
509 {
510  public:
512  void print_parameters();
513  bool defined() const { return value_set; };
514  void set_values(tinyxml2::XMLElement* modl_params);
515  static const std::string xml_element_name_;
516 
517  // Model types supported.
518  static const std::string GUCCIONE_MODEL;
519  static const std::string HGO_MODEL;
520  static const std::string LEE_SACKS;
521  static const std::string NEOHOOKEAN_MODEL;
522  static const std::string STVENANT_KIRCHHOFF_MODEL;
523  static const std::map<std::string, std::string> constitutive_model_types;
524 
525  // Constitutive model type.
527 
528  GuccioneParameters guccione;
529  HolzapfelParameters holzapfel;
530  HolzapfelGasserOgdenParameters holzapfel_gasser_ogden;
531  LeeSacksParameters lee_sacks;
532  MooneyRivlinParameters mooney_rivlin;
533  NeoHookeanParameters neo_hookean;
534  StVenantKirchhoffParameters stvenant_kirchhoff;
535 
536  bool value_set = false;
537 };
538 
539 /// @brief Couple to reduced-order models.
541 {
542  public:
544 
545  static const std::string xml_element_name_;
546 
547  bool defined() const { return value_set; };
548  void set_values(tinyxml2::XMLElement* xml_elem);
549  void print_parameters();
550 
551  // attribute.
553 
554  Parameter<std::string> file_name_for_0D_3D_communication;
555  Parameter<std::string> file_name_for_saving_unknowns;
556  Parameter<int> number_of_unknowns;
557  Parameter<int> number_of_user_defined_outputs;
558  Parameter<std::string> unknowns_initialization_file_path;
559 
560  Parameter<std::string> zerod_code_file_path;
561 
562  bool value_set = false;
563 };
564 
565 /// @brief Coupling to GenBC.
567 {
568  public:
570 
571  static const std::string xml_element_name_;
572 
573  bool defined() const { return value_set; };
574  void set_values(tinyxml2::XMLElement* xml_elem);
575 
576  // attributes.
578 
579  // String parameters.
580  Parameter<std::string> zerod_code_file_path;
581 
582  bool value_set = false;
583 };
584 
585 /// @brief Body force over a mesh using the "Add_BF" command.
586 ///
587 /// \code {.xml}
588 /// <Add_BF mesh="msh" >
589 /// <Type> volumetric </Type>
590 /// <Time_dependence> general </Time_dependence>
591 /// <Temporal_and_spatial_values_file_path> bforce.dat </Temporal_and_spatial_values_file_path>
592 /// </Add_BF>
593 /// \endcode
595 {
596  public:
598  void print_parameters();
599  void set_values(tinyxml2::XMLElement* xml_elem);
600  static const std::string xml_element_name_;
601 
602  // Attributes.
603  Parameter<std::string> mesh_name;
604 
605  // Boolean parameters.
606  Parameter<bool> ramp_function;
607 
608  // Double parameters.
609  Parameter<double> value;
610 
611  // String parameters.
612  Parameter<std::string> fourier_coefficients_file_path;
613  Parameter<std::string> spatial_values_file_path;
614  Parameter<std::string> temporal_and_spatial_values_file_path;
615  Parameter<std::string> temporal_values_file_path;
616  Parameter<std::string> time_dependence;
618 };
619 
620 /// @brief RCR values for Neumann BC type.
621 ///
622 /// \code {.xml}
623 /// <RCR_values>
624 /// <Proximal_resistance> 121.0 </Proximal_resistance>
625 /// <Capacitance> 1.5e-5 </Capacitance>
626 /// <Distal_resistance> 1212.0 </Distal_resistance>
627 /// </RCR_values>
628 /// \endcode
630 {
631  public:
633 
634  static const std::string xml_element_name_;
635 
636  void set_values(tinyxml2::XMLElement* xml_elem);
637  void print_parameters();
638 
639  Parameter<double> capacitance;
640  Parameter<double> distal_pressure;
641  Parameter<double> distal_resistance;
642  Parameter<double> initial_pressure;
643  Parameter<double> proximal_resistance;
644 
645  bool value_set = false;
646 };
647 
648 /// @brief The BoundaryConditionParameters stores paramaters for various
649 /// type of boundary conditions under the Add_BC XML element.
651 {
652  public:
654  void print_parameters();
655  void set_values(tinyxml2::XMLElement* bc_params);
656  static const std::string xml_element_name_;
657 
658  // RCR parameters sub-element.
660 
661  // Add_BC name= attribute.
663 
664  // Add_BC XML elements.
665  //
666  Parameter<bool> apply_along_normal_direction;
667  Parameter<std::string> bct_file_path;
668 
669  Parameter<double> damping;
670  Parameter<double> distal_pressure;
671  VectorParameter<int> effective_direction;
672  Parameter<bool> follower_pressure_load;
673  Parameter<std::string> fourier_coefficients_file_path;
674 
675  Parameter<bool> impose_flux;
676  Parameter<bool> impose_on_state_variable_integral;
677  Parameter<std::string> initial_displacements_file_path;
678 
679  Parameter<double> penalty_parameter;
680  Parameter<double> penalty_parameter_normal;
681  Parameter<double> penalty_parameter_tangential;
682  Parameter<std::string> prestress_file_path;
683  Parameter<std::string> profile;
684  Parameter<bool> ramp_function;
685 
686  Parameter<std::string> cst_shell_bc_type;
687  Parameter<std::string> spatial_profile_file_path;
688  Parameter<std::string> spatial_values_file_path;
689  Parameter<double> stiffness;
690 
691  Parameter<std::string> temporal_and_spatial_values_file_path;
692  Parameter<std::string> temporal_values_file_path;
693  Parameter<std::string> time_dependence;
694  Parameter<std::string> traction_values_file_path;
695  Parameter<double> traction_multiplier;
697 
698  Parameter<bool> undeforming_neu_face;
699  Parameter<double> value;
700  Parameter<bool> weakly_applied;
701  Parameter<bool> zero_out_perimeter;
702 };
703 
704 /// @brief The OutputParameters class stores parameters for the
705 /// Output XML element under Add_equation.
706 ///
707 /// \code {.xml}
708 /// <Output type="Volume_integral" >
709 /// <Temperature> true </Temperature>
710 /// </Output>
711 /// \endcode
713 {
714  public:
716 
717  static const std::string xml_element_name_;
718 
719  void print_parameters();
720  void set_values(tinyxml2::XMLElement* xml_elem);
721  bool get_output_value(const std::string& name);
722  std::string get_alias_value(const std::string& name);
723 
725 
726  // List of output names.
727  std::vector<Parameter<bool>> output_list;
728 
729  // List of alias output names.
730  std::vector<Parameter<std::string>> alias_list;
731 };
732 
733 /// @brief The ProjectionParameters class stores parameters for the
734 /// 'Add_projection' XML element used for fluid-structure interaction
735 /// simulations.
736 /// \code {.xml}
737 /// <Add_projection name="wall_inner" >
738 /// <Project_from_face> lumen_wall </Project_from_face>
739 /// </Add_projection>
740 /// \endcode
742 {
743  public:
745 
746  void set_values(tinyxml2::XMLElement* xml_elem);
747 
748  static const std::string xml_element_name_;
749 
751 
752  Parameter<std::string> project_from_face;
753  Parameter<double> projection_tolerance;
754 };
755 
756 /// @brief The VariableWallPropsParameters class stores parameters for
757 /// variable wall properties for the CMM equation.
759 {
760  public:
762  static const std::string xml_element_name_;
763  bool defined() const { return value_set; };
764  void set_values(tinyxml2::XMLElement* xml_elemnt);
765 
766  Parameter<std::string> mesh_name;
767  Parameter<std::string> wall_properties_file_path;
768  bool value_set = false;
769 };
770 
771 
772 //////////////////////////////////////////////////////////
773 // Viscosity //
774 //////////////////////////////////////////////////////////
775 
776 // The following classes are used to store parameters for
777 // various viscosity models.
778 
780 {
781  public:
783  void print_parameters();
784  void set_values(tinyxml2::XMLElement* equation_params);
785  Parameter<double> constant_value;
786 };
787 
789 {
790  public:
792  void print_parameters();
793  void set_values(tinyxml2::XMLElement* xml_elem);
794 
795  Parameter<double> limiting_high_shear_rate_viscosity;
796  Parameter<double> limiting_low_shear_rate_viscosity;
797  Parameter<double> power_law_index;
798  Parameter<double> shear_rate_tensor_multipler;
799  Parameter<double> shear_rate_tensor_exponent;
800 };
801 
803 {
804  public:
806  void print_parameters();
807  void set_values(tinyxml2::XMLElement* xml_elem);
808  Parameter<double> asymptotic_viscosity;
809  Parameter<double> yield_stress;
810  Parameter<double> low_shear_rate_threshold;
811 };
812 
814 {
815  public:
817 
818  static const std::string xml_element_name_;
819 
820  static const std::string CONSTANT_MODEL;
821  static const std::string CARREAU_YASUDA_MODEL;
822  static const std::string CASSONS_MODEL;
823  static const std::set<std::string> model_names;
824 
825  void print_parameters();
826  void set_values(tinyxml2::XMLElement* xml_elem);
827 
829 
830  ViscosityNewtonianParameters newtonian_model;
831  ViscosityCarreauYasudaParameters carreau_yasuda_model;
832  ViscosityCassonsParameters cassons_model;
833 };
834 
835 /// @brief The LinearSolverParameters class stores parameters for
836 /// the 'LS' XML element.
838 {
839  public:
841 
842  void print_parameters();
843  void set_values(tinyxml2::XMLElement* fsi_file);
844 
845  static const std::string xml_element_name_;
846 
848 
849  Parameter<double> absolute_tolerance;
850  Parameter<int> krylov_space_dimension;
851 
852  Parameter<int> max_iterations;
853  Parameter<int> ns_cg_max_iterations;
854  Parameter<double> ns_cg_tolerance;
855  Parameter<int> ns_gm_max_iterations;
856  Parameter<double> ns_gm_tolerance;
857 
858  Parameter<std::string> preconditioner;
859 
860  Parameter<double> tolerance;
861 
862  Parameter<bool> use_trilinos_for_assembly;
863 };
864 
865 /// @brief The StimulusParameters class stores parameters for
866 /// 'Stimulus' XML element used to parameters for
867 /// pacemaker cells.
868 ///
869 /// \code {.xml}
870 /// <Stimulus type="Istim" >
871 /// <Amplitude> -52.0 </Amplitude>
872 /// <Start_time> 0.0 </Start_time>
873 /// <Duration> 1.0 </Duration>
874 /// <Cycle_length> 10000.0 </Cycle_length>
875 /// </Stimulus>
876 /// \endcode
878 {
879  public:
881 
882  static const std::string xml_element_name_;
883 
884  bool defined() const { return value_set; };
885  void print_parameters();
886  void set_values(tinyxml2::XMLElement* xml_elem);
887 
889 
890  Parameter<double> amplitude;
891  Parameter<double> cycle_length;
892  Parameter<double> duration;
893  Parameter<double> start_time;
894 
895  bool value_set = false;
896 };
897 
899 {
900  public:
902 
903  static const std::string xml_element_name_;
904 
905  bool defined() const { return value_set; };
906  void print_parameters();
907  void set_values(tinyxml2::XMLElement* xml_elem);
908 
909  Parameter<std::string> x_coords_file_path;
910  Parameter<std::string> y_coords_file_path;
911  Parameter<std::string> z_coords_file_path;
912 
913  bool value_set = false;
914 };
915 
916 /// @brief The FiberReinforcementStressParameters class stores fiber
917 /// reinforcement stress parameters for the 'Fiber_reinforcement_stress`
918 /// XML element.
919 ///
920 /// \code {.xml}
921 /// <Fiber_reinforcement_stress type="Unsteady" >
922 /// <Temporal_values_file_path> fib_stress.dat </Temporal_values_file_path>
923 /// <Ramp_function> true </Ramp_function>
924 /// </Fiber_reinforcement_stress>
925 /// \endcode
927 {
928  public:
930 
931  static const std::string xml_element_name_;
932 
933  bool defined() const { return value_set; };
934  void print_parameters();
935  void set_values(tinyxml2::XMLElement* xml_elem);
936 
938 
939  Parameter<bool> ramp_function;
940  Parameter<std::string> temporal_values_file_path;
941  Parameter<double> value;
942 
943  bool value_set = false;
944 };
945 
946 /// @brief The DomainParameters class stores parameters for the XML
947 /// 'Domain' element to specify properties for solving equations.
948 ///
949 /// \code {.xml}
950 /// <Domain id="1" >
951 /// <Equation> fluid </Equation>
952 /// <Density> 1.06 </Density>
953 /// <Viscosity model="Constant" >
954 /// <Value> 0.04 </Value>
955 /// </Viscosity>
956 /// <Backflow_stabilization_coefficient> 0.2 </Backflow_stabilization_coefficient>
957 /// </Domain>
958 /// \endcode
960 {
961  public:
963 
964  static const std::string xml_element_name_;
965 
966  void print_parameters();
967  void set_values(tinyxml2::XMLElement* xml_elem);
968 
969  // Parameters for sub-elements under the Domain element.
970  ConstitutiveModelParameters constitutive_model;
971  FiberReinforcementStressParameters fiber_reinforcement_stress;
972  StimulusParameters stimulus;
973  ViscosityParameters viscosity;
974 
975  // Attributes.
977 
978  Parameter<double> absolute_tolerance;
979  VectorParameter<double> anisotropic_conductivity;
980  Parameter<double> backflow_stabilization_coefficient;
981 
982  Parameter<double> conductivity;
983  //Parameter<std::string> constitutive_model_name;
984  Parameter<double> continuity_stabilization_coefficient;
985 
986  Parameter<double> density;
987  Parameter<std::string> dilational_penalty_model;
988 
989  Parameter<std::string> equation;
990  Parameter<double> elasticity_modulus;
991  Parameter<std::string> electrophysiology_model;
992 
993  Parameter<double> feedback_parameter_for_stretch_activated_currents;
994  Parameter<double> fluid_density;
995  Parameter<double> force_x;
996  Parameter<double> force_y;
997  Parameter<double> force_z;
998 
999  Parameter<double> isotropic_conductivity;
1000 
1001  Parameter<double> mass_damping;
1002  Parameter<int> maximum_iterations;
1003  Parameter<double> momentum_stabilization_coefficient;
1004  Parameter<std::string> myocardial_zone;
1005 
1006  Parameter<double> G_Na;
1007  Parameter<double> G_CaL;
1008  Parameter<double> G_Kr;
1009  Parameter<double> G_Ks;
1010  Parameter<double> G_to;
1011 
1012  Parameter<double> tau_fi;
1013  Parameter<double> tau_si;
1014 
1015  Parameter<std::string> ode_solver;
1016  Parameter<double> penalty_parameter;
1017  Parameter<double> poisson_ratio;
1018  Parameter<double> relative_tolerance;
1019 
1020  Parameter<double> shell_thickness;
1021  Parameter<double> solid_density;
1022  Parameter<double> solid_viscosity;
1023  Parameter<double> source_term;
1024  Parameter<double> time_step_for_integration;
1025 };
1026 
1027 /// @brief The RemesherParameters class stores parameters for the
1028 /// 'Remesher' XML element used for remeshing.
1029 ///
1030 /// \code {.xml}
1031 /// <Remesher type="Tetgen" >
1032 /// <Max_edge_size name="lumen" value="0.7"> </Max_edge_size>
1033 /// <Max_edge_size name="wall" value="0.5"> </Max_edge_size>
1034 /// <Min_dihedral_angle> 10.0 </Min_dihedral_angle>
1035 /// <Max_radius_ratio> 1.1 </Max_radius_ratio>
1036 /// <Remesh_frequency> 1000 </Remesh_frequency>
1037 /// <Frequency_for_copying_data> 1 </Frequency_for_copying_data>
1038 /// </Remesher>
1039 /// \endcode
1041 {
1042  public:
1044 
1045  static const std::string xml_element_name_;
1046  bool values_set_ = false;
1047 
1048  bool defined() const { return values_set_; };
1049  void print_parameters();
1050  double get_edge_size(const std::string& name) const { return max_edge_sizes_.at(name); }
1051  bool has_edge_size(const std::string& name) const { return max_edge_sizes_.count(name) == 1; }
1052  void set_values(tinyxml2::XMLElement* mesh_elem);
1053 
1054  // Values given in the 'Max_edge_size' element.
1055  std::map<std::string, double> max_edge_sizes_;
1056 
1058  Parameter<double> min_dihedral_angle;
1059  Parameter<double> max_radius_ratio;
1060  Parameter<int> remesh_frequency;
1061  Parameter<int> frequency_for_copying_data;
1062 };
1063 
1064 /// @brief The ContactParameters class stores parameters for the 'Contact''
1065 /// XML element used to specify parameter values for contact
1066 /// computations.
1068 {
1069  public:
1071 
1072  static const std::string xml_element_name_;
1073 
1074  void print_parameters();
1075  void set_values(tinyxml2::XMLElement* xml_elem);
1076 
1077  Parameter<double> closest_gap_to_activate_penalty;
1078 
1079  Parameter<double> desired_separation;
1080 
1081  Parameter<double> min_norm_of_face_normals;
1082 
1083  Parameter<std::string> model;
1084 
1085  Parameter<double> penalty_constant;
1086 };
1087 
1088 /// @brief The EquationParameters class stores parameters for the 'Add_equation'
1089 /// XML element used to specify an equation to be solved (e.g. fluid).
1090 ///
1091 /// \code {.xml}
1092 /// <Add_equation type="FSI" >
1093 /// <Coupled> true </Coupled>
1094 /// <Min_iterations> 1 </Min_iterations>
1095 /// <Max_iterations> 1 </Max_iterations>
1096 /// .
1097 /// .
1098 /// .
1099 /// </Add_equation>
1100 /// \endcode
1102 {
1103  public:
1105 
1106  static const std::string xml_element_name_;
1107 
1108  void print_parameters();
1109  void set_values(tinyxml2::XMLElement* xml_elem);
1110 
1111  Parameter<double> backflow_stabilization_coefficient;
1112 
1113  Parameter<double> conductivity;
1114  Parameter<double> continuity_stabilization_coefficient;
1115  Parameter<bool> coupled;
1116 
1117  Parameter<double> density;
1118  Parameter<std::string> dilational_penalty_model;
1119 
1120  Parameter<double> elasticity_modulus;
1121 
1122  Parameter<std::string> initialize;
1123  Parameter<bool> initialize_rcr_from_flow;
1124 
1125  Parameter<int> max_iterations;
1126  Parameter<int> min_iterations;
1127  Parameter<double> momentum_stabilization_coefficient;
1128 
1129  Parameter<double> penalty_parameter;
1130  Parameter<double> poisson_ratio;
1131  Parameter<bool> prestress;
1132 
1133  Parameter<double> source_term;
1134  Parameter<double> tolerance;
1135 
1137  Parameter<bool> use_taylor_hood_type_basis;
1138 
1139  // Sub-element parameters.
1140  //
1141  std::vector<BodyForceParameters*> body_forces;
1142 
1143  std::vector<BoundaryConditionParameters*> boundary_conditions;
1144 
1145  CoupleCplBCParameters couple_to_cplBC;
1146  CoupleGenBCParameters couple_to_genBC;
1147 
1148  DomainParameters* default_domain = nullptr;
1149 
1150  std::vector<DomainParameters*> domains;
1151 
1152  LinearSolverParameters linear_solver;
1153 
1154  std::vector<OutputParameters*> outputs;
1155 
1156  RemesherParameters remesher;
1157 
1158  VariableWallPropsParameters variable_wall_properties;
1159 
1160  ViscosityParameters viscosity;
1161 
1162  ECGLeadsParameters ecg_leads;
1163 };
1164 
1165 /// @brief The GeneralSimulationParameters class stores paramaters for the
1166 /// 'GeneralSimulationParameters' XML element.
1167 ///
1168 /// \code {.xml}
1169 /// <GeneralSimulationParameters>
1170 /// <Continue_previous_simulation> 0 </Continue_previous_simulation>
1171 /// <Number_of_spatial_dimensions> 3 </Number_of_spatial_dimensions>
1172 /// <Number_of_time_steps> 1 </Number_of_time_steps>
1173 /// <Time_step_size> 1e-4 </Time_step_size>
1174 /// <Spectral_radius_of_infinite_time_step> 0.50 </Spectral_radius_of_infinite_time_step>
1175 /// <Searched_file_name_to_trigger_stop> STOP_SIM </Searched_file_name_to_trigger_stop>
1176 /// <Save_results_to_VTK_format> true </Save_results_to_VTK_format>
1177 /// <Name_prefix_of_saved_VTK_files> result </Name_prefix_of_saved_VTK_files>
1178 /// <Increment_in_saving_VTK_files> 1 </Increment_in_saving_VTK_files>
1179 /// <Start_saving_after_time_step> 1 </Start_saving_after_time_step>
1180 /// <Increment_in_saving_restart_files> 1 </Increment_in_saving_restart_files>
1181 /// <Convert_BIN_to_VTK_format> 0 </Convert_BIN_to_VTK_format>
1182 /// <Verbose> 1 </Verbose>
1183 /// <Warning> 0 </Warning>
1184 /// <Debug> 0 </Debug>
1185 /// <Simulation_requires_remeshing> true </Simulation_requires_remeshing>
1186 /// </GeneralSimulationParameters>
1187 /// \endcode
1189 {
1190  public:
1192 
1193  void print_parameters();
1194  void set_values(tinyxml2::XMLElement* xml_element);
1195 
1196  std::string xml_element_name;
1197 
1198  Parameter<bool> check_ien_order;
1199  Parameter<bool> continue_previous_simulation;
1200  Parameter<bool> convert_bin_to_vtk_format;
1201  Parameter<bool> debug;
1202  Parameter<bool> overwrite_restart_file;
1203  Parameter<bool> save_averaged_results;
1204  Parameter<bool> save_results_to_vtk_format;
1205  Parameter<bool> simulation_requires_remeshing;
1206  Parameter<bool> start_averaging_from_zero;
1207  Parameter<bool> verbose;
1208  Parameter<bool> warning;
1209 
1210  Parameter<double> spectral_radius_of_infinite_time_step;
1211  Parameter<double> time_step_size;
1212 
1213  Parameter<int> increment_in_saving_restart_files;
1214  Parameter<int> increment_in_saving_vtk_files;
1215  Parameter<int> number_of_spatial_dimensions;
1216  Parameter<int> number_of_initialization_time_steps;
1217  Parameter<int> start_saving_after_time_step;
1218  Parameter<int> starting_time_step;
1219  Parameter<int> number_of_time_steps;
1220 
1221  Parameter<std::string> name_prefix_of_saved_vtk_files;
1222  Parameter<std::string> restart_file_name;
1223  Parameter<std::string> searched_file_name_to_trigger_stop;
1224  Parameter<std::string> save_results_in_folder;
1225  Parameter<std::string> simulation_initialization_file_path;
1226 };
1227 
1228 /// @brief The FaceParameters class is used to store parameters for the
1229 /// 'Add_face' XML element.
1231 {
1232  public:
1233  FaceParameters();
1234 
1235  void print_parameters();
1236  void set_values(tinyxml2::XMLElement* xml_elem);
1237 
1238  static const std::string xml_element_name_;
1239 
1240  Parameter<std::string> end_nodes_face_file_path;
1241  Parameter<std::string> face_file_path;
1243 
1244  Parameter<double> quadrature_modifier_TRI3;
1245 };
1246 
1247 /// @brief The MeshParameters class is used to store paramaters for the
1248 /// 'Add_mesh' XML element.
1249 ///
1250 /// \code {.xml}
1251 /// <Add_mesh name="lumen" >
1252 /// <Mesh_file_path> mesh/lumen/mesh-complete.mesh.vtu </Mesh_file_path>
1253 ///
1254 /// <Add_face name="lumen_inlet">
1255 /// <Face_file_path> mesh/lumen/mesh-surfaces/lumen_inlet.vtp </Face_file_path>
1256 /// </Add_face>
1257 ///
1258 /// <Add_face name="lumen_outlet">
1259 /// <Face_file_path> mesh/lumen/mesh-surfaces/lumen_outlet.vtp </Face_file_path>
1260 /// </Add_face>
1261 ///
1262 /// <Add_face name="lumen_wall">
1263 /// <Face_file_path> mesh/lumen/mesh-surfaces/lumen_wall.vtp </Face_file_path>
1264 /// </Add_face>
1265 ///
1266 /// <Domain> 0 </Domain>
1267 ///
1268 /// </Add_mesh>
1269 /// \endcode
1271 {
1272  public:
1273  MeshParameters();
1274 
1275  static const std::string xml_element_name_;
1276 
1277  void print_parameters();
1278  void set_values(tinyxml2::XMLElement* mesh_elem);
1279  std::string get_name() const { return name.value(); };
1280  std::string get_path() const { return mesh_file_path.value(); };
1281 
1282  std::vector<FaceParameters*> face_parameters;
1283 
1284  // Add_mesh name=
1286 
1287  // Parameters under Add_mesh
1288  //
1289  Parameter<int> domain_id;
1290  Parameter<std::string> domain_file_path;
1291 
1292  VectorParameter<std::string> fiber_direction_file_paths;
1293  //Parameter<std::string> fiber_direction_file_path;
1294  std::vector<VectorParameter<double>> fiber_directions;
1295  //VectorParameter<double> fiber_direction;
1296 
1297  Parameter<std::string> initial_displacements_file_path;
1298  Parameter<std::string> initial_pressures_file_path;
1299  Parameter<bool> initialize_rcr_from_flow;
1300  Parameter<std::string> initial_velocities_file_path;
1301 
1302  Parameter<std::string> mesh_file_path;
1303  Parameter<double> mesh_scale_factor;
1304  Parameter<std::string> prestress_file_path;
1305 
1306  Parameter<bool> set_mesh_as_fibers;
1307  Parameter<bool> set_mesh_as_shell;
1308 
1309  Parameter<double> quadrature_modifier_TET4;
1310 };
1311 
1312 /// @brief The Parameters class stores parameter values read in from a solver input file.
1313 class Parameters {
1314 
1315  public:
1316  Parameters();
1317 
1318  static const std::set<std::string> constitutive_model_names;
1319  static const std::set<std::string> equation_names;
1320  static const std::string FSI_FILE;
1321 
1322  void get_logging_levels(int& verbose, int& warning, int& debug);
1323  void print_parameters();
1324  void read_xml(std::string file_name);
1325 
1326  void set_contact_values(tinyxml2::XMLElement* root_element);
1327  void set_equation_values(tinyxml2::XMLElement* root_element);
1328  void set_mesh_values(tinyxml2::XMLElement* root_element);
1329  void set_projection_values(tinyxml2::XMLElement* root_element);
1330 
1331  // Objects representing each parameter section of XML file.
1332  ContactParameters contact_parameters;
1333  GeneralSimulationParameters general_simulation_parameters;
1334  std::vector<MeshParameters*> mesh_parameters;
1335  std::vector<EquationParameters*> equation_parameters;
1336  std::vector<ProjectionParameters*> projection_parameters;
1337 };
1338 
1339 #endif
1340 
Body force over a mesh using the "Add_BF" command.
Definition: Parameters.h:595
static const std::string xml_element_name_
Define the XML element name for boundary condition parameters.
Definition: Parameters.h:600
The BoundaryConditionParameters stores paramaters for various type of boundary conditions under the A...
Definition: Parameters.h:651
static const std::string xml_element_name_
Define the XML element name for equation boundary condition parameters.
Definition: Parameters.h:656
RCR values for Neumann BC type.
Definition: Parameters.h:630
BoundaryConditionRCRParameters()
RCR values for Neumann BC type.
Definition: Parameters.cpp:309
The ConstitutiveModelParameters class store parameters for various constitutive models.
Definition: Parameters.h:509
static const std::map< std::string, std::string > constitutive_model_types
Supported constitutive model types and their aliases.
Definition: Parameters.h:523
static const std::string xml_element_name_
Process parameters for various constitutive models.
Definition: Parameters.h:515
The ContactParameters class stores parameters for the 'Contact'' XML element used to specify paramete...
Definition: Parameters.h:1068
static const std::string xml_element_name_
Process parameters for the 'Contact' XML element used to specify parameters for contact computation.
Definition: Parameters.h:1072
Couple to reduced-order models.
Definition: Parameters.h:541
static const std::string xml_element_name_
Couple to reduced-order models.
Definition: Parameters.h:545
Coupling to GenBC.
Definition: Parameters.h:567
static const std::string xml_element_name_
Coupling to GenBC.
Definition: Parameters.h:571
The DomainParameters class stores parameters for the XML 'Domain' element to specify properties for s...
Definition: Parameters.h:960
static const std::string xml_element_name_
Define the XML element name for domain parameters.
Definition: Parameters.h:964
Definition: Parameters.h:899
static const std::string xml_element_name_
Define the XML element name for ECG leads parameters.
Definition: Parameters.h:903
The EquationParameters class stores parameters for the 'Add_equation' XML element used to specify an ...
Definition: Parameters.h:1102
static const std::string xml_element_name_
Define the XML element name for equation parameters.
Definition: Parameters.h:1106
The FaceParameters class is used to store parameters for the 'Add_face' XML element.
Definition: Parameters.h:1231
static const std::string xml_element_name_
Process parameters for the 'Add_face' XML element.
Definition: Parameters.h:1238
The FiberReinforcementStressParameters class stores fiber reinforcement stress parameters for the 'Fi...
Definition: Parameters.h:927
static const std::string xml_element_name_
Define the XML element name for fiber reinforcement stress parameters.
Definition: Parameters.h:931
The GeneralSimulationParameters class stores paramaters for the 'GeneralSimulationParameters' XML ele...
Definition: Parameters.h:1189
GeneralSimulationParameters()
Process paramaters for the 'GeneralSimulationParameters' XML element.
Definition: Parameters.cpp:1757
void set_values(tinyxml2::XMLElement *xml_element)
Set general parameters values from XML.
Definition: Parameters.cpp:1817
Definition: Parameters.h:425
Definition: Parameters.h:462
Definition: Parameters.h:442
Definition: Parameters.h:410
The LinearSolverParameters class stores parameters for the 'LS' XML element.
Definition: Parameters.h:838
static const std::string xml_element_name_
Define the XML element name for equation output parameters.
Definition: Parameters.h:845
The MeshParameters class is used to store paramaters for the 'Add_mesh' XML element.
Definition: Parameters.h:1271
static const std::string xml_element_name_
Define the XML element name for mesh parameters.
Definition: Parameters.h:1275
Definition: Parameters.h:477
Definition: Parameters.h:489
NeoHookeanParameters()
There are no parameters associated with a Neohookean model.
Definition: Parameters.cpp:692
The OutputParameters class stores parameters for the Output XML element under Add_equation.
Definition: Parameters.h:713
std::string get_alias_value(const std::string &name)
Get the value of an alias by name.
Definition: Parameters.cpp:949
bool get_output_value(const std::string &name)
Get the value of an output by name.
Definition: Parameters.cpp:961
static const std::string xml_element_name_
Define the XML element name for equation output parameters.
Definition: Parameters.h:717
The Parameter class template is used to store a named paramater and its scalar value as a basic type:...
Definition: Parameters.h:114
void set(const std::string &name, bool required, T value)
Set the parameter name and value, and if it is required.
Definition: Parameters.h:145
void set(const std::string &str_value)
Set the parameter value from a string.
Definition: Parameters.h:152
std::string svalue()
Get the value of a parameter as a string.
Definition: Parameters.h:131
Defines parameter name and value, and stores them in maps for settng values from XML.
Definition: Parameters.h:290
void check_required()
Check if any required parameters have not been set.
Definition: Parameters.h:355
void set_parameter(const std::string &name, const bool value, bool required, Parameter< bool > &param)
Set the name, default value and the parameter required flag.
Definition: Parameters.h:301
void set_parameter_value(const std::string &name, const std::string &value)
Set the value of a paramter from a string.
Definition: Parameters.h:345
std::map< std::string, std::variant< Parameter< bool > *, Parameter< double > *, Parameter< int > *, Parameter< std::string > *, VectorParameter< double > *, VectorParameter< int > *, VectorParameter< std::string > * > > params_map
Map used for storing parameters by name / Parameter template union.
Definition: Parameters.h:397
std::map< std::string, std::string > get_parameter_list()
Get the defined parameters as a map of strings.
Definition: Parameters.h:369
void print_parameter_list()
Print the parameters.
Definition: Parameters.h:383
The Parameters class stores parameter values read in from a solver input file.
Definition: Parameters.h:1313
void read_xml(std::string file_name)
Set the simulation parameter values given in an XML format file.
Definition: Parameters.cpp:141
The ProjectionParameters class stores parameters for the 'Add_projection' XML element used for fluid-...
Definition: Parameters.h:742
static const std::string xml_element_name_
Define the XML element name for mesh parameters.
Definition: Parameters.h:748
The RemesherParameters class stores parameters for the 'Remesher' XML element used for remeshing.
Definition: Parameters.h:1041
static const std::string xml_element_name_
Define the XML element name for mesh parameters.
Definition: Parameters.h:1045
Definition: Parameters.h:498
StVenantKirchhoffParameters()
There are no parameters associated with a StVenantKirchhoff model.
Definition: Parameters.cpp:706
The StimulusParameters class stores parameters for 'Stimulus' XML element used to parameters for pace...
Definition: Parameters.h:878
static const std::string xml_element_name_
Define the XML element name for equation output parameters.
Definition: Parameters.h:882
The VariableWallPropsParameters class stores parameters for variable wall properties for the CMM equa...
Definition: Parameters.h:759
static const std::string xml_element_name_
The VariableWallPropsParameters class stores parameters for variable wall properties for the CMM equa...
Definition: Parameters.h:762
The VectorParameter class template is used to store a named paramater and its vector of values as a b...
Definition: Parameters.h:193
void set(const std::string &str_value)
Set the parameter value from a string.
Definition: Parameters.h:247
void set(const std::string &name, bool required, const std::vector< T > &value)
Set the parameter name and value, and if it is required.
Definition: Parameters.h:239
std::string svalue()
Get the string representation of the parameter value.
Definition: Parameters.h:213
Definition: Parameters.h:789
Definition: Parameters.h:803
Definition: Parameters.h:780
Definition: Parameters.h:814
static const std::string xml_element_name_
Process parameters for various viscosity models.
Definition: Parameters.h:818
Definition: bf.cpp:48