Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
mu_parser_internal.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
18 
19 #include <cmath>
20 #include <ctime>
21 #include <map>
22 #include <mutex>
23 #include <random>
24 #include <vector>
25 
26 
28 
29 
30 
31 #ifdef DEAL_II_WITH_MUPARSER
32 
33 namespace internal
34 {
35  namespace FunctionParser
36  {
37  int
38  mu_round(double val)
39  {
40  return static_cast<int>(val + ((val >= 0.0) ? 0.5 : -0.5));
41  }
42 
43  double
44  mu_if(double condition, double thenvalue, double elsevalue)
45  {
46  if (mu_round(condition))
47  return thenvalue;
48  else
49  return elsevalue;
50  }
51 
52  double
53  mu_or(double left, double right)
54  {
55  return (mu_round(left)) || (mu_round(right));
56  }
57 
58  double
59  mu_and(double left, double right)
60  {
61  return (mu_round(left)) && (mu_round(right));
62  }
63 
64  double
65  mu_int(double value)
66  {
67  return static_cast<double>(mu_round(value));
68  }
69 
70  double
71  mu_ceil(double value)
72  {
73  return std::ceil(value);
74  }
75 
76  double
77  mu_floor(double value)
78  {
79  return std::floor(value);
80  }
81 
82  double
83  mu_cot(double value)
84  {
85  return 1.0 / std::tan(value);
86  }
87 
88  double
89  mu_csc(double value)
90  {
91  return 1.0 / std::sin(value);
92  }
93 
94  double
95  mu_sec(double value)
96  {
97  return 1.0 / std::cos(value);
98  }
99 
100  double
101  mu_log(double value)
102  {
103  return std::log(value);
104  }
105 
106  double
107  mu_pow(double a, double b)
108  {
109  return std::pow(a, b);
110  }
111 
112  double
113  mu_erfc(double value)
114  {
115  return std::erfc(value);
116  }
117 
118  // returns a random value in the range [0,1] initializing the generator
119  // with the given seed
120  double
121  mu_rand_seed(double seed)
122  {
123  static std::mutex rand_mutex;
124  std::lock_guard<std::mutex> lock(rand_mutex);
125 
126  std::uniform_real_distribution<> uniform_distribution(0., 1.);
127 
128  // for each seed a unique random number generator is created,
129  // which is initialized with the seed itself
130  static std::map<double, std::mt19937> rng_map;
131 
132  if (rng_map.find(seed) == rng_map.end())
133  rng_map[seed] = std::mt19937(static_cast<unsigned int>(seed));
134 
135  return uniform_distribution(rng_map[seed]);
136  }
137 
138  // returns a random value in the range [0,1]
139  double
141  {
142  static std::mutex rand_mutex;
143  std::lock_guard<std::mutex> lock(rand_mutex);
144  std::uniform_real_distribution<> uniform_distribution(0., 1.);
145  const unsigned int seed = static_cast<unsigned long>(std::time(nullptr));
146  static std::mt19937 rng(seed);
147  return uniform_distribution(rng);
148  }
149 
150  std::vector<std::string> function_names = {
151  // functions predefined by muparser
152  "sin",
153  "cos",
154  "tan",
155  "asin",
156  "acos",
157  "atan",
158  "sinh",
159  "cosh",
160  "tanh",
161  "asinh",
162  "acosh",
163  "atanh",
164  "atan2",
165  "log2",
166  "log10",
167  "log",
168  "ln",
169  "exp",
170  "sqrt",
171  "sign",
172  "rint",
173  "abs",
174  "min",
175  "max",
176  "sum",
177  "avg",
178  // functions we define ourselves above
179  "if",
180  "int",
181  "ceil",
182  "cot",
183  "csc",
184  "floor",
185  "sec",
186  "pow",
187  "erfc",
188  "rand",
189  "rand_seed"};
190 
191  } // namespace FunctionParser
192 
193 } // namespace internal
194 #endif
195 
196 
197 
internal::FunctionParser::mu_pow
double mu_pow(double a, double b)
Definition: mu_parser_internal.cc:107
Differentiation::SD::floor
Expression floor(const Expression &x)
Definition: symengine_math.cc:294
internal::FunctionParser::mu_rand_seed
double mu_rand_seed(double seed)
Definition: mu_parser_internal.cc:121
internal::FunctionParser::mu_cot
double mu_cot(double value)
Definition: mu_parser_internal.cc:83
Differentiation::SD::erfc
Expression erfc(const Expression &x)
Definition: symengine_math.cc:329
internal::FunctionParser::mu_rand
double mu_rand()
Definition: mu_parser_internal.cc:140
internal::FunctionParser::mu_log
double mu_log(double value)
Definition: mu_parser_internal.cc:101
internal::FunctionParser::mu_csc
double mu_csc(double value)
Definition: mu_parser_internal.cc:89
internal::FunctionParser::mu_erfc
double mu_erfc(double value)
Definition: mu_parser_internal.cc:113
internal::FunctionParser::mu_and
double mu_and(double left, double right)
Definition: mu_parser_internal.cc:59
internal::FunctionParser::mu_or
double mu_or(double left, double right)
Definition: mu_parser_internal.cc:53
internal::FunctionParser::mu_floor
double mu_floor(double value)
Definition: mu_parser_internal.cc:77
thread_management.h
internal::FunctionParser::mu_round
int mu_round(double val)
Definition: mu_parser_internal.cc:38
internal::FunctionParser::mu_if
double mu_if(double condition, double thenvalue, double elsevalue)
Definition: mu_parser_internal.cc:44
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Differentiation::SD::ceil
Expression ceil(const Expression &x)
Definition: symengine_math.cc:301
value
static const bool value
Definition: dof_tools_constraints.cc:433
internal::FunctionParser::mu_ceil
double mu_ceil(double value)
Definition: mu_parser_internal.cc:71
internal::FunctionParser::mu_int
double mu_int(double value)
Definition: mu_parser_internal.cc:65
mu_parser_internal.h
internal::FunctionParser::mu_sec
double mu_sec(double value)
Definition: mu_parser_internal.cc:95
internal
Definition: aligned_vector.h:369
internal::FunctionParser::function_names
std::vector< std::string > function_names
Definition: mu_parser_internal.cc:150
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
FunctionParser
Definition: function_parser.h:224