SPHinXsys  alpha version
parameterization.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------*
2 * SPHinXsys *
3 * --------------------------------------------------------------------------*
4 * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5 * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6 * physical accurate simulation and aims to model coupled industrial dynamic *
7 * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8 * (smoothed particle hydrodynamics), a meshless computational method using *
9 * particle discretization. *
10 * *
11 * SPHinXsys is partially funded by German Research Foundation *
12 * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13 * and HU1527/12-1. *
14 * *
15 * Portions copyright (c) 2017-2020 Technical University of Munich and *
16 * the authors' affiliations. *
17 * *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19 * not use this file except in compliance with the License. You may obtain a *
20 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21 * *
22 * --------------------------------------------------------------------------*/
30 #ifndef SPHINXSYS_PARAMETERIZATION_H
31 #define SPHINXSYS_PARAMETERIZATION_H
32 
33 #include "base_data_package.h"
34 #include "xml_engine.h"
35 
36 #include <string>
37 
38 namespace SPH
39 {
41  {
42  public:
43  XmlEngine xml_paremeters_;
44  std::string filefullpath_;
45 
46  explicit ParameterizationIO(const std::string &input_path);
47  ~ParameterizationIO() {};
48 
49  void writeProjectParameters();
50  };
51 
52  template<class BaseClassType>
54  {
55  public:
56  template<typename... ConstructorArgs>
57  explicit BaseParameterization(ParameterizationIO& parameterization_io, ConstructorArgs... args) :
58  BaseClassType(std::forward<ConstructorArgs>(args)...), xml_paremeters_(parameterization_io.xml_paremeters_),
59  filefullpath_(parameterization_io.filefullpath_) {};
61  protected:
62  XmlEngine& xml_paremeters_;
63  std::string filefullpath_;
64 
65  template<typename VariableType>
66  void getAParameter(const std::string& element_name, const std::string& variable_name, VariableType& variable_addrs)
67  {
68  SimTK::Xml::element_iterator ele_ite =
69  xml_paremeters_.root_element_.element_begin(element_name);
70  if(ele_ite != xml_paremeters_.root_element_.element_end())
71  {
72  xml_paremeters_.getRequiredAttributeValue(ele_ite, variable_name, variable_addrs);
73  }
74  else {
75  std::cout << "\n Error: the variable '" << variable_name << "' is given not in project_parameters.dat !" << std::endl;
76  std::cout << __FILE__ << ':' << __LINE__ << std::endl;
77  exit(1);
78  }
79  };
80 
81  template<typename VariableType>
82  void setAParameter(const std::string& element_name, const std::string& variable_name, VariableType& variable_addrs)
83  {
84  SimTK::Xml::element_iterator ele_ite =
85  xml_paremeters_.root_element_.element_begin(element_name);
86  if (ele_ite == xml_paremeters_.root_element_.element_end())
87  {
88  xml_paremeters_.addElementToXmlDoc(element_name);
89  ele_ite = xml_paremeters_.root_element_.element_begin(element_name);
90  }
91  xml_paremeters_.setAttributeToElement(ele_ite, variable_name, variable_addrs);
92  };
93  };
94 }
95 #endif //SPHINXSYS_PARAMETERIZATION_H
void getRequiredAttributeValue(SimTK::Xml::element_iterator &ele_ite_, const std::string &attrib_name, T &value)
Definition: xml_engine.h:88
SimTK::Xml::Element root_element_
Definition: xml_engine.h:66
XML class for xml input and output, this is GUI of simbody xml parser.
void addElementToXmlDoc(const std::string &element_name)
Definition: xml_engine.cpp:18
void setAttributeToElement(const SimTK::Xml::element_iterator &ele_ite, const std::string &attrib_name, const T &value)
Definition: xml_engine.h:78
Definition: parameterization.h:40
Definition: xml_engine.h:56
Definition: parameterization.h:53
Definition: solid_body_supplementary.cpp:9