www.mooseframework.org
DumpObjectsProblem.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "DumpObjectsProblem.h"
12 #include "AuxiliarySystem.h"
13 #include <sstream>
14 
15 #include "libmesh/string_to_enum.h"
16 
18 
19 template <>
22 {
24  params.addClassDescription("Single purpose problem object that does not run the given input but "
25  "allows deconstructing actions into their series of underlying Moose "
26  "objects and variables.");
27  params.addRequiredParam<std::string>(
28  "dump_path", "Syntax path of the action of which to dump the generated syntax");
29  return params;
30 }
31 
33  : FEProblemBase(parameters), _nl_sys(std::make_shared<DumpObjectsNonlinearSystem>(*this, "nl0"))
34 {
35  _nl = _nl_sys;
36  _aux = std::make_shared<AuxiliarySystem>(*this, "aux0");
38 
39  // Create extra vectors and matrices if any
41 }
42 
43 void
44 DumpObjectsProblem::addVariable(const std::string & var_name,
45  const FEType & type,
46  Real scale_factor,
47  const std::set<SubdomainID> * const active_subdomains)
48 {
50  "Variables", var_name, type.family, type.order, scale_factor, active_subdomains);
51  FEProblemBase::addVariable(var_name, type, scale_factor, active_subdomains);
52 }
53 
54 void
55 DumpObjectsProblem::addScalarVariable(const std::string & var_name,
56  Order order,
57  Real scale_factor,
58  const std::set<SubdomainID> * const active_subdomains)
59 {
60  dumpVariableHelper("Variables", var_name, SCALAR, order, scale_factor, active_subdomains);
61  FEProblemBase::addScalarVariable(var_name, order, scale_factor, active_subdomains);
62 }
63 
64 void
65 DumpObjectsProblem::addAuxVariable(const std::string & var_name,
66  const FEType & type,
67  const std::set<SubdomainID> * const active_subdomains)
68 {
69  dumpVariableHelper("AuxVariables", var_name, type.family, type.order, 1.0, active_subdomains);
70  FEProblemBase::addAuxVariable(var_name, type, active_subdomains);
71 }
72 
73 void
74 DumpObjectsProblem::addAuxScalarVariable(const std::string & var_name,
75  Order order,
76  Real scale_factor,
77  const std::set<SubdomainID> * const active_subdomains)
78 {
79  dumpVariableHelper("AuxVariables", var_name, SCALAR, order, 1.0, active_subdomains);
80  FEProblemBase::addScalarVariable(var_name, order, scale_factor, active_subdomains);
81 }
82 
83 void
85  const std::string & name,
86  InputParameters parameters)
87 {
88  dumpObjectHelper("Functions", type, name, parameters);
90 }
91 
92 void
93 DumpObjectsProblem::addKernel(const std::string & type,
94  const std::string & name,
95  InputParameters parameters)
96 {
97  dumpObjectHelper("Kernels", type, name, parameters);
99 }
100 
101 void
103  const std::string & name,
104  InputParameters parameters)
105 {
106  dumpObjectHelper("NodalKernel", type, name, parameters);
108 }
109 
110 void
112  const std::string & name,
113  InputParameters parameters)
114 {
115  dumpObjectHelper("ScalarKernels", type, name, parameters);
117 }
118 
119 void
121  const std::string & name,
122  InputParameters parameters)
123 {
126 }
127 
128 void
130  const std::string & name,
131  InputParameters parameters)
132 {
133  dumpObjectHelper("Constraints", type, name, parameters);
135 }
136 
137 void
139  const std::string & name,
140  InputParameters parameters)
141 {
142  dumpObjectHelper("AuxKernels", type, name, parameters);
144 }
145 
146 void
148  const std::string & name,
149  InputParameters parameters)
150 {
151  dumpObjectHelper("AuxScalarKernels", type, name, parameters);
153 }
154 
155 void
157  const std::string & name,
158  InputParameters parameters)
159 {
160  dumpObjectHelper("DiracKernels", type, name, parameters);
162 }
163 
164 void
166  const std::string & name,
167  InputParameters parameters)
168 {
169  dumpObjectHelper("DGKernels", type, name, parameters);
171 }
172 
173 void
175  const std::string & name,
176  InputParameters parameters)
177 {
178  dumpObjectHelper("InterfaceKernels", type, name, parameters);
180 }
181 
182 void
184  const std::string & name,
185  InputParameters parameters)
186 {
189 }
190 
191 void
193  const std::string & name,
194  InputParameters parameters)
195 {
196  dumpObjectHelper("Materials", type, name, parameters);
198 }
199 
200 std::string
202  const InputParameters & parameters)
203 {
204  auto factory_params = stringifyParameters(_factory.getValidParams(type));
205  auto specified_params = stringifyParameters(parameters);
206 
207  std::string param_text;
208  for (auto & value_pair : specified_params)
209  {
210  // parameter name
211  const auto & param_name = value_pair.first;
212  const auto & param_value = value_pair.second;
213 
214  auto factory_it = factory_params.find(param_name);
215  if (factory_it == factory_params.end() || factory_it->second != param_value)
216  param_text += " " + param_name + " = " + param_value + '\n';
217  }
218 
219  return param_text;
220 }
221 
222 void
224  const std::string & type,
225  const std::string & name,
226  const InputParameters & parameters)
227 {
228  auto path = _app.actionWarehouse().getCurrentActionName();
229  auto param_text = deduceNecessaryParameters(type, parameters);
230 
231  // clang-format off
232  _generated_syntax[path][system] +=
233  " [./" + name + "]\n"
234  + " type = " + type + '\n'
235  + param_text
236  + " [../]\n";
237  // clang-format on
238 }
239 
240 void
242  const std::string & var_name,
243  FEFamily family,
244  Order order,
245  Real scale_factor,
246  const std::set<SubdomainID> * const active_subdomains)
247 {
248  auto path = _app.actionWarehouse().getCurrentActionName();
249  std::string param_text;
250 
251  if (active_subdomains)
252  {
253  std::string blocks;
254  for (auto & subdomain_id : *active_subdomains)
255  {
256  auto subdomain_name = _mesh.getMesh().subdomain_name(subdomain_id);
257  if (subdomain_name == "")
258  subdomain_name = std::to_string(subdomain_id);
259 
260  if (!blocks.empty())
261  blocks += ' ';
262 
263  blocks += subdomain_name;
264  }
265 
266  if (active_subdomains->size() > 1)
267  blocks = "'" + blocks + "'";
268 
269  param_text += " blocks = " + blocks + '\n';
270  }
271 
272  if (family != LAGRANGE)
273  param_text += " family = " + libMesh::Utility::enum_to_string<FEFamily>(family) + '\n';
274  if (order != FIRST)
275  param_text += " order = " + libMesh::Utility::enum_to_string<Order>(order) + '\n';
276  if (scale_factor != 1.0)
277  param_text += " scale = " + std::to_string(scale_factor);
278 
279  // clang-format off
280  _generated_syntax[path][system] +=
281  " [./" + var_name + "]\n"
282  + param_text
283  + " [../]\n";
284  // clang-format on
285 }
286 
287 void
289 {
290  dumpGeneratedSyntax(getParam<std::string>("dump_path"));
291 }
292 
293 void
295 {
296  auto pathit = _generated_syntax.find(path);
297  if (pathit == _generated_syntax.end())
298  return;
299 
300  for (const auto & system_pair : pathit->second)
301  Moose::out << '[' << system_pair.first << "]\n" << system_pair.second << "[]\n\n";
302 }
303 
304 std::map<std::string, std::string>
306 {
307  std::map<std::string, std::string> parameter_map;
308 
309  std::string syntax;
310  if (parameters.isParamValid("parser_syntax"))
311  syntax = parameters.get<std::string>("parser_syntax");
312 
313  for (auto & value_pair : parameters)
314  {
315  // parameter name
316  const auto & param_name = value_pair.first;
317 
318  if (!parameters.isPrivate(param_name) && parameters.isParamValid(param_name))
319  {
320  if (param_name == "control_tags")
321  {
322  // deal with the control tags. The current parser_syntax is automatically added to this. So
323  // we can remove the parameter if that's all there is in it
324  }
325  else
326  {
327  // special treatment for some types
328  auto param_bool = dynamic_cast<InputParameters::Parameter<bool> *>(value_pair.second);
329 
330  // parameter value
331  std::string param_value;
332  if (param_bool)
333  param_value = param_bool->get() ? "true" : "false";
334  else
335  {
336  std::stringstream ss;
337  value_pair.second->print(ss);
338  param_value = ss.str();
339  }
340 
341  // delete trailing space
342  if (param_value.back() == ' ')
343  param_value.pop_back();
344 
345  // add quotes if the parameter contains spaces
346  if (param_value.find_first_of(" ") != std::string::npos)
347  param_value = "'" + param_value + "'";
348 
349  parameter_map[param_name] = param_value;
350  }
351  }
352  }
353 
354  return parameter_map;
355 }
void addAuxKernel(const std::string &type, const std::string &name, InputParameters parameters) override
Factory & _factory
The Factory for building objects.
Definition: SubProblem.h:649
virtual void addMaterial(const std::string &kernel_name, const std::string &name, InputParameters parameters)
virtual void addScalarVariable(const std::string &var_name, Order order, Real scale_factor=1., const std::set< SubdomainID > *const active_subdomains=NULL)
std::shared_ptr< NonlinearSystemBase > _nl
std::shared_ptr< DumpObjectsNonlinearSystem > _nl_sys
virtual void addDiracKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
virtual void addAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
Specialization of SubProblem for dumping generated objects as input file syntax.
std::string getCurrentActionName() const
void addInitialCondition(const std::string &type, const std::string &name, InputParameters parameters) override
void addDGKernel(const std::string &type, const std::string &name, InputParameters parameters) override
void addScalarKernel(const std::string &type, const std::string &name, InputParameters parameters) override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
bool isPrivate(const std::string &name) const
Returns a Boolean indicating whether the specified parameter is private or not.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addFunction(std::string type, const std::string &name, InputParameters parameters) override
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
void addAuxScalarKernel(const std::string &type, const std::string &name, InputParameters parameters) override
void dumpObjectHelper(const std::string &system, const std::string &type, const std::string &name, const InputParameters &parameters)
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:53
virtual void addAuxScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
virtual void addConstraint(const std::string &c_name, const std::string &name, InputParameters parameters)
Nonlinear system for dumping objects.
void addKernel(const std::string &type, const std::string &name, InputParameters parameters) override
virtual void newAssemblyArray(NonlinearSystemBase &nl)
nl system()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
void createTagVectors()
Create extra tagged vectors and matrices.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
std::shared_ptr< AuxiliarySystem > _aux
virtual void addFunction(std::string type, const std::string &name, InputParameters parameters)
MooseMesh & _mesh
ActionWarehouse & actionWarehouse()
Definition: MooseApp.h:146
virtual void addVariable(const std::string &var_name, const FEType &type, Real scale_factor, const std::set< SubdomainID > *const active_subdomains=NULL)
std::map< std::string, std::string > stringifyParameters(const InputParameters &parameters)
create a string map form parameter names to stringified parameter values
void addDiracKernel(const std::string &type, const std::string &name, InputParameters parameters) override
void addConstraint(const std::string &type, const std::string &name, InputParameters parameters) override
InputParameters validParams< DumpObjectsProblem >()
void addAuxVariable(const std::string &var_name, const FEType &type, const std::set< SubdomainID > *const active_subdomains=NULL) override
std::map< std::string, std::map< std::string, std::string > > _generated_syntax
store input syntax to build objects generated by a specific action
MatType type
virtual void addDGKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
void addNodalKernel(const std::string &type, const std::string &name, InputParameters parameters) override
registerMooseObject("MooseApp", DumpObjectsProblem)
InputParameters validParams< FEProblemBase >()
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
void addScalarVariable(const std::string &var_name, Order order, Real scale_factor=1., const std::set< SubdomainID > *const active_subdomains=NULL) override
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters parameters)
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual void solve() override
output data in solve
void addAuxScalarVariable(const std::string &var_name, Order order, Real scale_factor=1., const std::set< SubdomainID > *const active_subdomains=NULL) override
void addMaterial(const std::string &type, const std::string &name, InputParameters parameters) override
void dumpGeneratedSyntax(const std::string path)
output input blocks for a given action path
virtual void addInterfaceKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
std::string deduceNecessaryParameters(const std::string &type, const InputParameters &parameters)
build a text snippet of the minimal set of parameters that need to be specified
void addInterfaceKernel(const std::string &type, const std::string &name, InputParameters parameters) override
void addBoundaryCondition(const std::string &type, const std::string &name, InputParameters parameters) override
virtual void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters parameters)
void addVariable(const std::string &var_name, const FEType &type, Real scale_factor, const std::set< SubdomainID > *const active_subdomains=NULL) override
virtual void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters parameters)
DumpObjectsProblem(const InputParameters &parameters)
void dumpVariableHelper(const std::string &system, const std::string &var_name, FEFamily family, Order order, Real scale_factor, const std::set< SubdomainID > *const active_subdomains)
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
virtual void addAuxVariable(const std::string &var_name, const FEType &type, const std::set< SubdomainID > *const active_subdomains=NULL)