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