https://mooseframework.inl.gov
MFEMMultiAppTransfer.h
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 #ifdef MOOSE_MFEM_ENABLED
11 
12 #pragma once
13 
14 #include "MultiAppTransfer.h"
15 #include "FEProblemBase.h"
16 
21 {
22 public:
24  MFEMMultiAppTransfer(InputParameters const & params);
26  void execute() override;
28  void checkSiblingsTransferSupported() const override {}
29 
31  const VariableName & getFromVarName(int i) const { return _from_var_names.at(i); }
33  const VariableName & getToVarName(int i) const { return _to_var_names.at(i); }
35  unsigned int numFromVar() const { return _from_var_names.size(); }
37  unsigned int numToVar() const { return _to_var_names.size(); }
38 
39 protected:
41  virtual void transferVariables(bool is_target_local) = 0;
42 
44  void setActiveFromProblem(FEProblemBase & from_problem, const unsigned int global_app_index)
45  {
46  _active_from_problem = &from_problem;
47  _active_from_global_app_index = global_app_index;
48  }
50  void setActiveToProblem(FEProblemBase & to_problem, const unsigned int global_app_index)
51  {
52  _active_to_problem = &to_problem;
53  _active_to_global_app_index = global_app_index;
54  }
62  virtual unsigned int & getActiveFromProblemGlobalAppIndex()
63  {
65  }
66 
69  {
71  }
74  {
76  }
78  libMesh::Point mapPointToActiveSourceFrame(const Point & point_in_target_frame) const
79  {
80  return getActiveFromTransform().mapBack(getActiveToTransform()(point_in_target_frame));
81  }
84  bool use_displaced) const;
85 
87  void setMFEMOutOfMeshValue(mfem::real_t mfem_out_of_mesh_value)
88  {
89  _mfem_out_of_mesh_value = mfem_out_of_mesh_value;
90  }
92  mfem::real_t getMFEMOutOfMeshValue() const { return _mfem_out_of_mesh_value; }
93 
95  template <Moose::FEBackend TO_BACKEND, Moose::FEBackend FROM_BACKEND>
97 
98 private:
100  const std::vector<VariableName> & _from_var_names;
102  const std::vector<VariableName> & _to_var_names;
112  mfem::real_t _mfem_out_of_mesh_value{std::numeric_limits<mfem::real_t>::infinity()};
113 };
114 
115 template <Moose::FEBackend TO_BACKEND, Moose::FEBackend FROM_BACKEND>
116 inline void
118 {
119  // Check if source sub-apps exist, and if so, if they are of the expected type
120  if (hasFromMultiApp())
121  {
122  for (const auto i : make_range(getFromMultiApp()->numGlobalApps()))
123  if (getFromMultiApp()->hasLocalApp(i) &&
124  getFromMultiApp()->appProblemBase(i).feBackend() != FROM_BACKEND)
125  paramError("from_multi_app", type() + " is incompatible with the source app's backend.");
126  }
127  else if (getToMultiApp()->problemBase().feBackend() != FROM_BACKEND)
128  mooseError(type() + " is incompatible with this (the source) app's backend.");
129 
130  // Check if destination sub-apps exist, and if so, if they are of the expected type
131  if (hasToMultiApp())
132  {
133  for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
134  if (getToMultiApp()->hasLocalApp(i) &&
135  getToMultiApp()->appProblemBase(i).feBackend() != TO_BACKEND)
136  paramError("to_multi_app", type() + " is incompatible with the destination app's backend.");
137  }
138  else if (getFromMultiApp()->problemBase().feBackend() != TO_BACKEND)
139  mooseError(type() + " is incompatible with this (the destination) app's backend.");
140 }
141 
142 #endif
unsigned int _active_to_global_app_index
Global app index for the active destination problem.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
Virtual base class for MultiApp transfers to and/or from MFEMProblems.
unsigned int numFromVar() const
Return the number of source variables.
libMesh::EquationSystems & getlibMeshEquationSystem(FEProblemBase &problem, bool use_displaced) const
Get libMesh EquationSystem, which may or may not be displaced.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
const std::vector< VariableName > & _from_var_names
Vector of source variable names to be transferred.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
FEProblemBase * _active_to_problem
Pointer to active destination problem variable is being transferred to.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
virtual FEProblemBase & getActiveFromProblem()
Getter for current problem containing source variables.
libMesh::Point mapBack(const libMesh::Point &point) const
Inverse transform from the reference space to our space.
unsigned int _active_from_global_app_index
Global app index for the active source problem.
bool hasFromMultiApp() const
Whether the transfer owns a non-null from_multi_app.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void setMFEMOutOfMeshValue(mfem::real_t mfem_out_of_mesh_value)
Set default value for transfers evaluated at points outside source mesh.
virtual FEProblemBase & getActiveToProblem()
Getter for current problem containing destination variables.
unsigned int numToVar() const
Return for the number of destination variables.
mfem::real_t _mfem_out_of_mesh_value
Default value to return for transfers from points outside the source mesh.
void setActiveToProblem(FEProblemBase &to_problem, const unsigned int global_app_index)
Set current problem to fetch destination variables from.
FEProblemBase * _active_from_problem
Pointer to active source problem variable is being transferred from.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
MFEMMultiAppTransfer(InputParameters const &params)
virtual unsigned int & getActiveFromProblemGlobalAppIndex()
Getter for current destination problem global app index.
const std::vector< VariableName > & _to_var_names
Vector of destination variable names to transfer to.
mfem::real_t getMFEMOutOfMeshValue() const
Getter for default value for transfers evaluated at points outside source mesh.
void setActiveFromProblem(FEProblemBase &from_problem, const unsigned int global_app_index)
Set current problem to fetch source variables from.
const VariableName & getFromVarName(int i) const
Getter for source variable name.
const MultiAppCoordTransform & getActiveFromTransform() const
Getter for the active source transform.
static InputParameters validParams()
libMesh::Point mapPointToActiveSourceFrame(const Point &point_in_target_frame) const
Map a point in the active destination app frame to the active source app frame.
Base class for all MultiAppTransfer objects.
const VariableName & getToVarName(int i) const
Getter for destination variable name.
void checkSiblingsTransferSupported() const override
Allow sibling transfers.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
IntRange< T > make_range(T beg, T end)
bool hasToMultiApp() const
Whether the transfer owns a non-null to_multi_app.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
const MultiAppCoordTransform & getActiveToTransform() const
Getter for the active destination transform.
void checkValidTransferProblemTypes()
Templated method to check source and destination problems are of the expected types.
virtual void transferVariables(bool is_target_local)=0
Transfer all variables from active source problem to active destination problem.
virtual unsigned int & getActiveToProblemGlobalAppIndex()
Getter for current destination problem global app index.
This class contains transformation information that only exists in a context in which there are multi...
void execute() override
Set active source and destination problems, and execute variable transfer.