https://mooseframework.inl.gov
ParsedNodeTransformGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
11 #include "CastUniquePointer.h"
12 
13 #include <libmesh/int_range.h>
14 
16 
17 const std::string ParsedNodeTransformGenerator::_func_name[] = {
18  "x_function", "y_function", "z_function"};
19 
22 {
25 
26  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
27  params.addClassDescription("Applies a transform to a the x,y,z coordinates of a Mesh");
28  params.addParam<ParsedFunctionExpression>(
29  _func_name[0], "x", "Function for the updated x component of the node");
30  params.addParam<ParsedFunctionExpression>(
31  _func_name[1], "y", "Function for the updated y component of the node");
32  params.addParam<ParsedFunctionExpression>(
33  _func_name[2], "z", "Function for the updated z component of the node");
34 
35  params.addParam<std::vector<std::string>>(
36  "constant_names", {}, "Vector of constants used in the parsed function");
37  params.addParam<std::vector<std::string>>(
38  "constant_expressions",
39  {},
40  "Vector of values for the constants in constant_names (can be an FParser expression)");
41 
42  return params;
43 }
44 
46  : MeshGenerator(parameters), FunctionParserUtils<false>(parameters), _input(getMesh("input"))
47 {
48  for (const auto i : index_range(_functions))
49  {
50  // Create parsed function
51  _functions[i] = std::make_shared<SymFunction>();
53  getParam<ParsedFunctionExpression>(_func_name[i]),
54  "x,y,z",
55  getParam<std::vector<std::string>>("constant_names"),
56  getParam<std::vector<std::string>>("constant_expressions"),
57  comm());
58  }
59 
60  _func_params.resize(3);
61 }
62 
63 std::unique_ptr<MeshBase>
65 {
66  std::unique_ptr<MeshBase> mesh = std::move(_input);
67 
68  for (auto & node : mesh->node_ptr_range())
69  {
70  for (const auto i : make_range(3))
71  _func_params[i] = (*node)(i);
72 
73  for (const auto i : make_range(3))
74  (*node)(i) = evaluate(_functions[i], _func_name[i]);
75  }
76 
77  return mesh;
78 }
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::unique_ptr< MeshBase > & _input
the input mesh
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & comm() const
ParsedNodeTransformGenerator(const InputParameters &parameters)
registerMooseObject("MooseApp", ParsedNodeTransformGenerator)
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...
static const std::string _func_name[]
names of each component function parameter
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
Performs setup steps on a SymFunction.
static InputParameters validParams()
Definition: MeshGenerator.C:23
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
IntRange< T > make_range(T beg, T end)
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...
static InputParameters validParams()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::array< SymFunctionPtr, 3 > _functions
the node position functions
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
auto index_range(const T &sizable)