www.mooseframework.org
Axisymmetric2D3DSolutionFunction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "MooseError.h"
17 #include "SolutionUserObject.h"
18 
19 template <>
22 {
23  // Get the Function input parameters
25 
26  // Add parameters specific to this object
27  params.addRequiredParam<UserObjectName>("solution",
28  "The SolutionUserObject to extract data from.");
29  params.addParam<std::vector<std::string>>(
30  "from_variables",
31  "The names of the variables in the file that are to be extracted, in x, y "
32  "order if they are vector components");
33 
34  params.addParam<Real>(
35  "scale_factor",
36  1.0,
37  "Scale factor (a) to be applied to the solution (x): ax+b, where b is the 'add_factor'");
38  params.addParam<Real>(
39  "add_factor",
40  0.0,
41  "Add this value (b) to the solution (x): ax+b, where a is the 'scale_factor'");
42  params.addParam<Real>("axial_dimension_ratio",
43  1.0,
44  "Ratio of the axial dimension in the 3d model to that in the 2d model. "
45  "Optinally permits the 3d model to be larger than the 2d model in that "
46  "dimension, and scales vector solutions in that direction by this factor.");
47 
48  params.addParam<RealVectorValue>("2d_axis_point1",
49  RealVectorValue(0, 0, 0),
50  "Start point for axis of symmetry for the 2d model");
51  params.addParam<RealVectorValue>("2d_axis_point2",
52  RealVectorValue(0, 1, 0),
53  "End point for axis of symmetry for the 2d model");
54  params.addParam<RealVectorValue>("3d_axis_point1",
55  RealVectorValue(0, 0, 0),
56  "Start point for axis of symmetry for the 3d model");
57  params.addParam<RealVectorValue>("3d_axis_point2",
58  RealVectorValue(0, 1, 0),
59  "End point for axis of symmetry for the 3d model");
60 
61  params.addParam<unsigned int>("component",
62  "Component of the variable to be computed if it is a vector");
63 
64  params.addClassDescription("Function for reading a 2D axisymmetric solution from file and "
65  "mapping it to a 3D Cartesian model");
66 
67  return params;
68 }
69 
71  const InputParameters & parameters)
72  : Function(parameters),
73  _solution_object_ptr(NULL),
74  _scale_factor(getParam<Real>("scale_factor")),
75  _add_factor(getParam<Real>("add_factor")),
76  _axial_dim_ratio(getParam<Real>("axial_dimension_ratio")),
77  _2d_axis_point1(getParam<RealVectorValue>("2d_axis_point1")),
78  _2d_axis_point2(getParam<RealVectorValue>("2d_axis_point2")),
79  _3d_axis_point1(getParam<RealVectorValue>("3d_axis_point1")),
80  _3d_axis_point2(getParam<RealVectorValue>("3d_axis_point2")),
81  _has_component(isParamValid("component")),
82  _component(_has_component ? getParam<unsigned int>("component") : 99999),
83  _var_names(getParam<std::vector<std::string>>("from_variables"))
84 {
85  if (_has_component && _var_names.size() != 2)
86  mooseError("Must supply names of 2 variables in 'from_variables' if 'component' is specified");
87  else if (!_has_component && _var_names.size() == 2)
88  mooseError("Must supply 'component' if 2 variables specified in 'from_variables'");
89  else if (_var_names.size() > 2)
90  mooseError("If 'from_variables' is specified, it must have either 1 (scalar) or 2 (vector "
91  "components) variables");
92 
93  Point zero;
94  Point unit_vec_y;
95  unit_vec_y(1) = 1;
96  if (_2d_axis_point1 == zero && _2d_axis_point2 == unit_vec_y && _3d_axis_point1 == zero &&
97  _3d_axis_point2 == unit_vec_y)
98  _default_axes = true;
99  else
100  _default_axes = false;
101 
102  if (_3d_axis_point1.relative_fuzzy_equals(_3d_axis_point2))
103  mooseError("3d_axis_point1 and 3d_axis_point2 must be different points");
104  if (_2d_axis_point1.relative_fuzzy_equals(_2d_axis_point2))
105  mooseError("2d_axis_point1 and 2d_axis_point2 must be different points");
106 }
107 
108 void
110 {
111  // Get a pointer to the SolutionUserObject. A pointer is used because the UserObject is not
112  // available during the
113  // construction of the function
114  _solution_object_ptr = &getUserObject<SolutionUserObject>("solution");
115 
116  // If 'from_variable' is not specified, get the value from the SolutionUserObject
117  if (_var_names.size() == 0)
118  {
119  // Get all the variables from the SolutionUserObject
120  const std::vector<std::string> & vars = _solution_object_ptr->variableNames();
121 
122  // If there are more than one, throw an error
123  if (vars.size() > 1)
124  mooseError("If the SolutionUserObject contains multiple variables, the variable name must be "
125  "specified in the input file with 'from_variables'");
126 
127  // Define the variable
128  _var_names.push_back(vars[0]);
129  }
130  if (_2d_axis_point1(2) != 0)
131  mooseError("3rd component of 2d_axis_point1 must be zero");
132  if (_2d_axis_point2(2) != 0)
133  mooseError("3rd component of 2d_axis_point2 must be zero");
134 
136  for (unsigned int i = 0; i < _var_names.size(); ++i)
138 }
139 
140 Real
142 {
143  Point xypoint;
144  Point r_dir_2d;
145  Point z_dir_2d;
146  Point r_dir_3d;
147  Point z_dir_3d;
148  bool r_gt_zero = false;
149 
150  if (_default_axes)
151  {
152  r_dir_2d(0) = 1;
153  z_dir_2d(1) = 1;
154  r_dir_3d = p;
155  r_dir_3d(1) = 0;
156  Real r = r_dir_3d.norm();
158  {
159  r_gt_zero = true;
160  r_dir_3d /= r;
161  }
162  z_dir_3d(1) = 1;
163  xypoint(0) = std::sqrt(p(0) * p(0) + p(2) * p(2));
164  xypoint(1) = p(1) / _axial_dim_ratio;
165  }
166  else
167  {
168  // Find the r, z coordinates of the point in the 3D model relative to the 3D axis
169  z_dir_3d = _3d_axis_point2 - _3d_axis_point1;
170  z_dir_3d /= z_dir_3d.norm();
171  Point v3dp1p(p - _3d_axis_point1);
172  Real z = z_dir_3d * v3dp1p;
173  Point axis_proj = _3d_axis_point1 + z * z_dir_3d; // projection of point onto axis
174  Point axis_proj_to_p = p - axis_proj;
175  Real r = axis_proj_to_p.norm();
177  {
178  r_gt_zero = true;
179  r_dir_3d = axis_proj_to_p / r;
180  }
181 
182  // Convert point in r, z coordinates into x, y coordinates
183  z_dir_2d = _2d_axis_point2 - _2d_axis_point1;
184  z_dir_2d /= z_dir_2d.norm();
185  Point out_of_plane_vec(0, 0, 1);
186  r_dir_2d = z_dir_2d.cross(out_of_plane_vec);
187  r_dir_2d /= r_dir_2d.norm(); // size should be 1, maybe this isn't necessary
188  xypoint = _2d_axis_point1 + z / _axial_dim_ratio * z_dir_2d + r * r_dir_2d;
189  }
190 
191  Real val;
192  if (_has_component)
193  {
194  Real val_x = _solution_object_ptr->pointValue(t, xypoint, _solution_object_var_indices[0]);
195  Real val_y = _solution_object_ptr->pointValue(t, xypoint, _solution_object_var_indices[1]);
196 
197  // val_vec_rz contains the value vector converted from x,y to r,z coordinates
198  Point val_vec_rz;
199  val_vec_rz(0) = r_dir_2d(0) * val_x + r_dir_2d(1) * val_y;
200  val_vec_rz(1) = z_dir_2d(0) * val_x + z_dir_2d(1) * val_y;
201  if (!r_gt_zero && !MooseUtils::absoluteFuzzyEqual(val_vec_rz(0), 0.0))
202  mooseError("In Axisymmetric2D3DSolutionFunction r=0 and r component of value vector != 0");
203  Point val_vec_3d = val_vec_rz(0) * r_dir_3d + val_vec_rz(1) * z_dir_3d;
204 
205  val = val_vec_3d(_component);
206  }
207  else
209 
210  return _scale_factor * val + _add_factor;
211 }
const Real _add_factor
Factor to add to the solution (default = 0)
Base class for function objects.
Definition: Function.h:46
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
std::vector< unsigned int > _solution_object_var_indices
The local SolutionUserObject indices for the variables extracted from the file.
Axisymmetric2D3DSolutionFunction(const InputParameters &parameters)
Constructor.
const unsigned int _component
The index of the component.
const RealVectorValue _2d_axis_point1
Two points that define the axis of rotation for the 2d model.
virtual Real value(Real t, const Point &p) override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const RealVectorValue _3d_axis_point1
Two points that define the axis of rotation for the 3d model.
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...
Real pointValue(Real t, const Point &p, const unsigned int local_var_index) const
Returns a value at a specific location and variable (see SolutionFunction)
InputParameters validParams< Axisymmetric2D3DSolutionFunction >()
bool _default_axes
Are the default axes of rotation being used?
std::vector< std::string > _var_names
The variable names to extract from the file.
const SolutionUserObject * _solution_object_ptr
Pointer to SolutionUserObject containing the solution of interest.
const Real _axial_dim_ratio
Ratio of axial dimension of 3d model to its counterpart in the 2d model.
virtual void initialSetup() override
Setup the function for use Gathers a pointer to the SolutionUserObject containing the solution that w...
bool absoluteFuzzyGreaterThan(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< Function >()
Definition: Function.C:19
unsigned int getLocalVarIndex(const std::string &var_name) const
Returns the local index for a given variable name.
const std::vector< std::string > & variableNames() const
const bool _has_component
If the solution field is a vector, the desired component must be specified Has the component been spe...
const Real _scale_factor
Factor to scale the solution by (default = 1)