https://mooseframework.inl.gov
FunctionPeriodicBoundary.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 
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.
20 
22  const std::vector<std::string> & fn_names,
23  const std::vector<std::string> & inv_fn_names)
24  : libMesh::PeriodicBoundaryBase(),
25  _dim(fn_names.size()),
26  _tr(getFunctions(feproblem, fn_names)),
27  _inv_tr(getFunctions(feproblem, inv_fn_names))
28 {
29  mooseAssert(fn_names.size() == inv_fn_names.size(), "Size mismatch");
30 
31  // Make certain the the dimensions agree
32  if (_dim != feproblem.mesh().dimension())
33  mooseError("Transform function has to have the same dimension as the problem being solved.");
34 }
35 
37  TransformationType t /* = FORWARD */)
38  : libMesh::PeriodicBoundaryBase(o),
39  _dim(o._dim),
40  _tr(t == INVERSE ? o._inv_tr : o._tr),
41  _inv_tr(t == INVERSE ? o._tr : o._inv_tr)
42 {
43  if (t == INVERSE)
45 }
46 
47 Point
49 {
50  // Force thread-safe evaluation of what could be ParsedFunctions.
51  Threads::spin_mutex::scoped_lock lock(parsed_function_mutex);
52 
53  Point p;
54  for (const auto i : make_range(_dim))
55  {
56  mooseAssert(_tr[i], "Function not provided");
57  p(i) = _tr[i]->value(0.0, pt);
58  }
59  return p;
60 }
61 
62 std::unique_ptr<libMesh::PeriodicBoundaryBase>
64 {
65  return std::make_unique<FunctionPeriodicBoundary>(*this, t);
66 }
67 
68 std::array<const Function *, 3>
70  const std::vector<std::string> & names)
71 {
72  std::array<const Function *, 3> functions;
73  for (const auto i : index_range(functions))
74  if (names.size() > i)
75  {
76  functions[i] = &problem.getFunction(names[i]);
77  const_cast<Function *>(functions[i])->initialSetup();
78  }
79  return functions;
80 }
Base class for function objects.
Definition: Function.h:29
virtual std::unique_ptr< libMesh::PeriodicBoundaryBase > clone(TransformationType t) const override
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
const std::array< const Function *, 3 > _tr
Pointers to translation functions in each dimension.
void swap(std::vector< T > &data, const std::size_t idx0, const std::size_t idx1, const libMesh::Parallel::Communicator &comm)
Swap function for serial or distributed vector of data.
Definition: Shuffle.h:495
Periodic boundary for calculation periodic BC on domains where the translation is given by Function o...
boundary_id_type pairedboundary
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const unsigned int _dim
The dimension of the problem (says which of _tr and _inv_tr are active)
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MooseMesh.C:3012
Threads::spin_mutex parsed_function_mutex
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
static std::array< const Function *, 3 > getFunctions(FEProblemBase &problem, const std::vector< std::string > &names)
virtual libMesh::Point get_corresponding_pos(const libMesh::Point &pt) const override
Get the translation based on point &#39;pt&#39;.
FunctionPeriodicBoundary(FEProblemBase &subproblem, const std::vector< std::string > &fn_names, const std::vector< std::string > &inv_fn_names)
Initialize the periodic with the functions and inverse functions, one for each dimension needed...
auto index_range(const T &sizable)