Fluid structure interaction suite
constants.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 
18 #include "parsed_tools/constants.h"
19 
20 using namespace dealii;
21 
22 namespace ParsedTools
23 {
24  Constants::Constants(
25  const std::string &section_name,
26  const std::vector<std::string> &names,
27  const std::vector<double> &default_values,
28  const std::vector<std::string> &optional_names_for_parameter_file,
29  const std::vector<std::string> &optional_documentation_strings)
30  : ParameterAcceptor(section_name)
31  {
32  AssertDimension(names.size(), default_values.size());
33 
34  auto doc_strings = optional_documentation_strings;
35  if (doc_strings.size() == 0)
36  doc_strings.resize(names.size(), "");
37 
38  auto prm_names = optional_names_for_parameter_file;
39  if (prm_names.size() == 0)
40  prm_names = names;
41 
42  AssertDimension(names.size(), prm_names.size());
43 
44  AssertDimension(doc_strings.size(), default_values.size());
45 
46  // Before we do anything else, define standard math constants used in
47  // dealii::numbers namespace.
48  constants["E"] = numbers::E;
49  constants["LOG2E"] = numbers::LOG2E;
50  constants["LOG10E"] = numbers::LOG10E;
51  constants["LN2"] = numbers::LN2;
52  constants["LN10"] = numbers::LN10;
53  constants["PI"] = numbers::PI;
54  constants["PI_2"] = numbers::PI_2;
55  constants["PI_4"] = numbers::PI_4;
56  constants["SQRT2"] = numbers::SQRT2;
57  constants["SQRT1_2"] = numbers::SQRT1_2;
58 
59  for (unsigned int i = 0; i < names.size(); ++i)
60  {
61  constants[names[i]] = default_values[i];
62  constants_parameter_entries[names[i]] = prm_names[i];
63  constants_documentation[names[i]] = doc_strings[i];
64 
65  auto entry = prm_names[i] == names[i] ?
66  prm_names[i] :
67  prm_names[i] + " (" + names[i] + ")";
68 
69  add_parameter(entry, constants[names[i]], doc_strings[i]);
70  }
71  }
72 
73 
74 
75  Constants::operator const std::map<std::string, double> &() const
76  {
77  return constants;
78  }
79 
80 
81 
82  const double &
83  Constants::operator[](const std::string &key) const
84  {
85  return constants.at(key);
86  }
87 
88 
89 
90 #ifdef DEAL_II_WITH_SYMENGINE
95  Constants::operator const Differentiation::SD::types::substitution_map &()
96  const
97  {
98  constant_substitution_map.clear();
99  for (const auto &p : constants)
100  constant_substitution_map[Differentiation::SD::Expression(p.first,
101  true)] =
103  return constant_substitution_map;
104  }
105 #endif
106 
107 
108 
109 } // namespace ParsedTools
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
std::map< std::string, std::string > constants_documentation
The documentation of each constant.
Definition: constants.h:154
std::map< std::string, std::string > constants_parameter_entries
The documentation string used to parse the constants from the parameter file.
Definition: constants.h:149
std::map< std::string, double > constants
The actual constants.
Definition: constants.h:132
const double & operator[](const std::string &key) const
Return the constant associated with the given name.
Definition: constants.cc:83
#define AssertDimension(dim1, dim2)
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...
static constexpr double LOG10E
static constexpr double PI_2
static constexpr double E
static constexpr double PI
static constexpr double SQRT2
static constexpr double SQRT1_2
static constexpr double PI_4
static constexpr double LN10
static constexpr double LN2
static constexpr double LOG2E