GRINS-0.7.0
parameter_user.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // This class
27 #include "grins/parameter_user.h"
28 
29 // libMesh
30 #include "libmesh/getpot.h"
31 #include "libmesh/parameter_multiaccessor.h"
32 #include "libmesh/parameter_pointer.h"
33 #include "libmesh/parsed_fem_function.h"
34 #include "libmesh/parsed_fem_function_parameter.h"
35 #include "libmesh/parsed_function.h"
36 #include "libmesh/parsed_function_parameter.h"
37 
38 
39 namespace GRINS
40 {
41 #if LIBMESH_DIM == 3
42  std::string ParameterUser::zero_vector_function = std::string("{0}{0}{0}");
43 #elif LIBMESH_DIM == 2
44  std::string ParameterUser::zero_vector_function = std::string("{0}{0}");
45 #else
46  std::string ParameterUser::zero_vector_function = std::string("{0}");
47 #endif
48 
49 
50  void ParameterUser::set_parameter( libMesh::Number & param_variable,
51  const GetPot& input,
52  const std::string & param_name,
53  libMesh::Number param_default )
54  {
55  param_variable = input(param_name, param_default);
56 
57  libmesh_assert_msg(!_my_parameters.count(param_name),
58  "ERROR: " << _my_name << " double-registered parameter " <<
59  param_name);
60 
61  _my_parameters[param_name] = &param_variable;
62  }
63 
66  const GetPot & input,
67  const std::string & func_param_name,
68  const std::string & param_default)
69  {
70  if((param_default == "DIE!") &&
71  (!input.have_variable(func_param_name)))
72  {
73  libMesh::err << "Error: Must specify parsed function for " <<
74  _my_name << std::endl
75  << " Please specify " << func_param_name << std::endl;
76  libmesh_error();
77  }
78 
79  func.reparse(input(func_param_name, param_default));
80 
81  libmesh_assert_msg(!_my_parsed_functions.count(func_param_name),
82  "ERROR: " << _my_name << " double-registered parameter " <<
83  func_param_name);
84 
85  _my_parsed_functions[func_param_name] = &func;
86  }
87 
90  const GetPot & input,
91  const std::string & func_param_name,
92  const std::string & param_default)
93  {
94  if((param_default == "DIE!") &&
95  (!input.have_variable(func_param_name)))
96  {
97  libMesh::err << "Error: Must specify parsed (fem) function for " <<
98  _my_name << std::endl
99  << " Please specify " << func_param_name << std::endl;
100  libmesh_error();
101  }
102 
103  func.reparse(input(func_param_name, param_default));
104 
105  libmesh_assert_msg(!_my_parsed_fem_functions.count(func_param_name),
106  "ERROR: " << _my_name << " double-registered parameter " <<
107  func_param_name);
108 
109  _my_parsed_fem_functions[func_param_name] = &func;
110  }
111 
113  (const libMesh::Number & old_parameter,
114  libMesh::Number & new_parameter)
115  {
116  std::map<std::string, libMesh::Number*>::iterator it =
117  _my_parameters.begin();
118  const std::map<std::string, libMesh::Number*>::iterator end =
119  _my_parameters.end();
120  for (; it != end; ++it)
121  if (it->second == &old_parameter)
122  {
123  it->second = &new_parameter;
124  break;
125  }
126  }
127 
131  {
132  std::map
133  <std::string,
135  >::iterator it = _my_parsed_functions.begin();
136  const std::map
137  <std::string,
139  >::iterator end = _my_parsed_functions.end();
140  for (; it != end; ++it)
141  if (it->second == &old_func)
142  {
143  it->second = &new_func;
144  break;
145  }
146  }
147 
151  {
152  std::map
153  <std::string,
155  >::iterator it = _my_parsed_fem_functions.begin();
156  const std::map
157  <std::string,
159  >::iterator end = _my_parsed_fem_functions.end();
160  for (; it != end; ++it)
161  if (it->second == &old_func)
162  {
163  it->second = &new_func;
164  break;
165  }
166  }
167 
168 
170  ( const std::string & param_name,
172  const
173  {
174  std::map<std::string, libMesh::Number*>::const_iterator it =
175  _my_parameters.find(param_name);
176 
177  // Make sure we don't find duplicate parameters - a Number
178  // parameter shouldn't have the same name as a ParsedFunction or
179  // ParsedFEMFunction parameter.
180 #ifndef NDEBUG
181  bool found_parameter = false;
182 #endif
183 
184  // First search for simple Number parameters
185  if (it != _my_parameters.end())
186  {
187  std::cout << _my_name << " has Number parameter " << param_name
188  << std::endl;
189  param_pointer.push_back
190  (libMesh::ParameterPointer<libMesh::Number>(it->second));
191 
192 #ifndef NDEBUG
193  found_parameter = true;
194 #else
195  return;
196 #endif
197  }
198 
199  // Next search for inline variable parameters in parsed functions
200  std::size_t last_slash_i = param_name.rfind('/');
201 
202  if (last_slash_i != std::string::npos)
203  {
204  std::string search_name = param_name.substr(0, last_slash_i);
205 
206  std::string var_name = param_name.substr(last_slash_i+1);
207 
208  std::map
209  <std::string, libMesh::ParsedFunction
210  <libMesh::Number,libMesh::Gradient>*>::const_iterator
211  pf_it = _my_parsed_functions.find(search_name);
212 
213  if (pf_it != _my_parsed_functions.end())
214  {
215  std::cout << _my_name << " has ParsedFunction for " <<
216  search_name << " / " << var_name << std::endl;
217  param_pointer.push_back
218  (libMesh::ParsedFunctionParameter<libMesh::Number>
219  (*pf_it->second, var_name));
220 
221 #ifndef NDEBUG
222  libmesh_assert(!found_parameter);
223  found_parameter = true;
224 #else
225  return;
226 #endif
227  }
228 
229  std::map
230  <std::string, libMesh::ParsedFEMFunction
231  <libMesh::Number>*>::const_iterator
232  pff_it = _my_parsed_fem_functions.find(search_name);
233 
234  if (pff_it != _my_parsed_fem_functions.end())
235  {
236  std::cout << _my_name << " has ParsedFEMFunction for " <<
237  search_name << " / " << var_name << std::endl;
238  param_pointer.push_back
239  (libMesh::ParsedFEMFunctionParameter<libMesh::Number>
240  (*pff_it->second, var_name));
241 
242 #ifndef NDEBUG
243  libmesh_assert(!found_parameter);
244 #endif
245  }
246  }
247  }
248 
249 } // namespace GRINS
virtual void set_parameter(libMesh::Number &param_variable, const GetPot &input, const std::string &param_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
static std::string zero_vector_function
A parseable function string with LIBMESH_DIM components, all 0.
GRINS namespace.
std::map< std::string, libMesh::Number * > _my_parameters
virtual void move_parameter(const libMesh::Number &old_parameter, libMesh::Number &new_parameter)
When cloning an object, we need to update parameter pointers.
virtual void register_parameter(const std::string &param_name, libMesh::ParameterMultiAccessor< libMesh::Number > &param_pointer) const
Each subclass will register its copy of an independent.

Generated on Thu Jun 2 2016 21:52:28 for GRINS-0.7.0 by  doxygen 1.8.10