www.mooseframework.org
FunctionPeriodicBoundary.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 // MOOSE includes
12 #include "FEProblem.h"
13 #include "Function.h"
14 #include "MooseMesh.h"
15 
16 // A mutex we can acquire to prevent simultaneous ParsedFunction
17 // evaluation on multiple threads. ParsedFunction evaluation is
18 // currently not thread-safe.
19 Threads::spin_mutex parsed_function_mutex;
20 
22  std::vector<std::string> fn_names)
23  : _dim(fn_names.size()),
24  _tr_x(&feproblem.getFunction(fn_names[0])),
25  _tr_y(_dim > 1 ? &feproblem.getFunction(fn_names[1]) : NULL),
26  _tr_z(_dim > 2 ? &feproblem.getFunction(fn_names[2]) : NULL)
27 {
28 
29  // Make certain the the dimensions agree
30  if (_dim != feproblem.mesh().dimension())
31  mooseError("Transform function has to have the same dimension as the problem being solved.");
32 
33  // Initialize the functions (i.e., call thier initialSetup methods)
34  init();
35 }
36 
38  : PeriodicBoundaryBase(o), _dim(o._dim), _tr_x(o._tr_x), _tr_y(o._tr_y), _tr_z(o._tr_z)
39 {
40  // Initialize the functions (i.e., call thier initialSetup methods)
41  init();
42 }
43 
44 Point
46 {
47  // Force thread-safe evaluation of what could be ParsedFunctions.
48  Threads::spin_mutex::scoped_lock lock(parsed_function_mutex);
49 
50  Real t = 0.;
51  Point p;
52  switch (_dim)
53  {
54  case 1:
55  return Point(_tr_x->value(t, pt));
56 
57  case 2:
58  mooseAssert(_tr_y, "Must provide a function to map y in 2D.");
59  return Point(_tr_x->value(t, pt), _tr_y->value(t, pt));
60 
61  case 3:
62  mooseAssert(_tr_y, "Must provide a function to map y in 2D.");
63  mooseAssert(_tr_z, "Must provide a function to map z in 3D.");
64  return Point(_tr_x->value(t, pt), _tr_y->value(t, pt), _tr_z->value(t, pt));
65 
66  default:
67  mooseError("Unsupported dimension");
68  break;
69  }
70 
71  return pt;
72 }
73 
74 std::unique_ptr<PeriodicBoundaryBase>
75 FunctionPeriodicBoundary::clone(TransformationType t) const
76 {
77  if (t == INVERSE)
78  mooseError("No way to automatically clone() an inverse FunctionPeriodicBoundary object");
79 
80  return libmesh_make_unique<FunctionPeriodicBoundary>(*this);
81 }
82 
83 void
85 {
86  switch (_dim)
87  {
88  case 1:
90  break;
91  case 2:
94  break;
95  case 3:
99  break;
100  default:
101  mooseError("Unsupported dimension");
102  break;
103  }
104 }
virtual Real value(Real t, const Point &p)
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
Definition: Function.C:38
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
Periodic boundary for calculation periodic BC on domains where the translation is given by functions...
Function * _tr_y
Pointer to Function for y-component of the boundary.
Function * _tr_z
Pointer to Function for z-component of the boundary.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Function * _tr_x
Pointer to Function for x-component of the boundary.
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimsension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh m...
Definition: MooseMesh.C:2133
virtual Point get_corresponding_pos(const Point &pt) const override
Get the translation based on point &#39;pt&#39;.
virtual std::unique_ptr< PeriodicBoundaryBase > clone(TransformationType t) const override
Required interface, this class must be able to clone itself.
void init()
An initialization method to make certain that initialSetup() of a function prior to value() ...
Threads::spin_mutex parsed_function_mutex
virtual MooseMesh & mesh() override
virtual void initialSetup()
Gets called at the beginning of the simulation before this object is asked to do its job...
FunctionPeriodicBoundary(FEProblemBase &subproblem, std::vector< std::string > fn_names)
Initialize the periodic boundary with three functions.