https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
22public:
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
39protected:
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
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
98private:
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
115template <Moose::FEBackend TO_BACKEND, Moose::FEBackend FROM_BACKEND>
116inline 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
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Virtual base class for MultiApp transfers to and/or from MFEMProblems.
void setActiveFromProblem(FEProblemBase &from_problem, const unsigned int global_app_index)
Set current problem to fetch source variables from.
const std::vector< VariableName > & _from_var_names
Vector of source variable names to be transferred.
FEProblemBase * _active_to_problem
Pointer to active destination problem variable is being transferred to.
void setActiveToProblem(FEProblemBase &to_problem, const unsigned int global_app_index)
Set current problem to fetch destination variables from.
const VariableName & getToVarName(int i) const
Getter for destination variable name.
unsigned int numToVar() const
Return for the number of destination variables.
static InputParameters validParams()
const MultiAppCoordTransform & getActiveToTransform() const
Getter for the active destination transform.
const VariableName & getFromVarName(int i) const
Getter for source variable name.
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.
const std::vector< VariableName > & _to_var_names
Vector of destination variable names to transfer to.
void checkSiblingsTransferSupported() const override
Allow sibling transfers.
mfem::real_t _mfem_out_of_mesh_value
Default value to return for transfers from points outside the source mesh.
libMesh::EquationSystems & getlibMeshEquationSystem(FEProblemBase &problem, bool use_displaced) const
Get libMesh EquationSystem, which may or may not be displaced.
virtual unsigned int & getActiveFromProblemGlobalAppIndex()
Getter for current destination problem global app index.
void checkValidTransferProblemTypes()
Templated method to check source and destination problems are of the expected types.
void execute() override
Set active source and destination problems, and execute variable transfer.
virtual FEProblemBase & getActiveToProblem()
Getter for current problem containing destination variables.
mfem::real_t getMFEMOutOfMeshValue() const
Getter for default value for transfers evaluated at points outside source mesh.
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.
unsigned int _active_from_global_app_index
Global app index for the active source problem.
virtual FEProblemBase & getActiveFromProblem()
Getter for current problem containing source variables.
unsigned int numFromVar() const
Return the number of source variables.
FEProblemBase * _active_from_problem
Pointer to active source problem variable is being transferred from.
unsigned int _active_to_global_app_index
Global app index for the active destination problem.
void setMFEMOutOfMeshValue(mfem::real_t mfem_out_of_mesh_value)
Set default value for transfers evaluated at points outside source mesh.
const MultiAppCoordTransform & getActiveFromTransform() const
Getter for the active source transform.
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
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:457
This class contains transformation information that only exists in a context in which there are multi...
libMesh::Point mapBack(const libMesh::Point &point) const
Inverse transform from the reference space to our space.
Base class for all MultiAppTransfer objects.
bool hasToMultiApp() const
Whether the transfer owns a non-null to_multi_app.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
bool hasFromMultiApp() const
Whether the transfer owns a non-null from_multi_app.