10 #ifdef MOOSE_MFEM_ENABLED 14 #include "libmesh/mesh_function.h" 15 #include "libmesh/parallel_algebra.h" 23 params.
addClassDescription(
"Transfers variable values from a libMesh based application to an " 24 "MFEM application, using shape function evaluations.");
32 checkValidTransferProblemTypes<Moose::FEBackend::MFEM, Moose::FEBackend::LibMesh>();
48 std::map<processor_id_type, std::vector<Point>> outgoing_points;
49 mfem::Vector interp_vals;
53 mfem::ParGridFunction & to_gf =
55 mfem::ParFiniteElementSpace & to_pfespace = *to_gf.ParFESpace();
56 if (to_gf.VectorDim() > 1)
57 mooseError(
"MultiApplibMeshToMFEMShapeEvaluationTransfer does not support transfers of " 58 "vector variables from libMesh to MFEM-based subapps");
60 mfem::Ordering::Type point_ordering;
65 const int dim = to_pfespace.GetParMesh()->Dimension();
66 const int nnodes = vxyz.Size() /
dim;
71 point_in_target_frame(d) = vxyz[i + d * nnodes];
75 outgoing_points[i_proc].push_back(point_in_source_frame);
77 interp_vals.SetSize(nnodes);
86 mfem::ParGridFunction & to_gf =
88 mfem::Ordering::Type libmesh_interp_ordering(mfem::Ordering::Type::byNODES);
97 const unsigned int var_index,
98 mfem::Vector & interp_vals)
105 System & from_sys = from_var.
sys().
system();
110 *from_sys.current_local_solution,
111 from_sys.get_dof_map(),
113 local_meshfuns.
init();
117 auto gather_functor =
119 const std::vector<Point> & incoming_points,
120 std::vector<std::pair<mfem::real_t, unsigned>> & vals_for_incoming_points)
122 vals_for_incoming_points.assign(incoming_points.size(), {0., 0});
124 for (
const auto i_pt :
index_range(incoming_points))
126 const auto map = local_meshfuns.discontinuous_value(incoming_points[i_pt]);
127 for (
const auto & [elem, val] : map)
128 if (elem && elem->processor_id() == this->
processor_id())
130 vals_for_incoming_points[i_pt].first += val;
131 vals_for_incoming_points[i_pt].second++;
137 std::vector<unsigned> neighbor_elems(interp_vals.Size(), 0);
139 auto action_functor =
141 const std::vector<Point> & ,
142 const std::vector<std::pair<mfem::real_t, unsigned>> & vals_for_outgoing_points)
144 for (
const auto i :
make_range(interp_vals.Size()))
146 const auto val = vals_for_outgoing_points[i].first;
147 const auto elems = vals_for_outgoing_points[i].second;
151 interp_vals(i) = val / (neighbor_elems[i] += elems);
153 interp_vals(i) = (interp_vals(i) * neighbor_elems[i] + val) / (neighbor_elems[i] += elems);
160 std::pair<mfem::real_t, unsigned> * dummy =
nullptr;
161 libMesh::Parallel::pull_parallel_vector_data(
162 comm(), outgoing_points, gather_functor, action_functor, dummy);
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
Virtual base class for MultiApp transfers to and/or from MFEMProblems.
void projectNodalValues(const mfem::Vector &nodal_vals, const mfem::Ordering::Type &nodal_val_ordering, mfem::ParGridFunction &gridfunction)
Project a vector of values provided at projection points (nodes) to set GridFunction DoFs...
libMesh::EquationSystems & getlibMeshEquationSystem(FEProblemBase &problem, bool use_displaced) const
Get libMesh EquationSystem, which may or may not be displaced.
registerMooseObject("MooseApp", MultiApplibMeshToMFEMShapeEvaluationTransfer)
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
const Parallel::Communicator & comm() const
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual FEProblemBase & getActiveFromProblem()
Getter for current problem containing source variables.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
unsigned int variable_number(std::string_view var) const
uint8_t processor_id_type
virtual FEProblemBase & getActiveToProblem()
Getter for current problem containing destination variables.
processor_id_type n_processors() const
unsigned int numToVar() const
Return for the number of destination variables.
virtual void init() override
MFEMNodalProjector _mfem_projector
Object to extract node positions and perform projections on MFEM GridFunctions.
void extractNodePositions(const mfem::ParFiniteElementSpace &fespace, mfem::Vector &node_positions, mfem::Ordering::Type &node_ordering)
Extract node positions from MFEM FESpace at which projection will take place.
mfem::real_t getMFEMOutOfMeshValue() const
Getter for default value for transfers evaluated at points outside source mesh.
const VariableName & getFromVarName(int i) const
Getter for source variable name.
MultiApplibMeshToMFEMShapeEvaluationTransfer(InputParameters const ¶ms)
static InputParameters validParams()
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.
virtual MFEMProblem & getActiveToProblem() override
Set current MFEM problem to fetch destination variables from.
void interpolatelibMeshVariable(std::map< processor_id_type, std::vector< Point >> &outgoing_points, const unsigned int var_index, mfem::Vector &interp_vals)
Interpolate libMesh variable corresponding to var_index at target points for DoF evaluation.
const VariableName & getToVarName(int i) const
Getter for destination variable name.
IntRange< T > make_range(T beg, T end)
bool _displaced_source_mesh
True if displaced mesh is used for the source mesh, otherwise false.
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...
virtual void transferVariables(bool is_target_local) override
Transfer all variables from active source problem to active destination problem.
processor_id_type processor_id() const
SystemBase & sys()
Get the system this variable is part of.
auto index_range(const T &sizable)
MultiApp transfer from libMesh to MFEM variables, performed via evaluation of shape functions...