https://mooseframework.inl.gov
MFEMSumAux.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 #ifdef MOOSE_MFEM_ENABLED
11 
12 #include "MFEMSumAux.h"
13 #include "MFEMProblem.h"
14 
15 registerMooseObject("MooseApp", MFEMSumAux);
16 
19 {
21  params.addClassDescription(
22  "Calculates the sum of an arbitrary number of variables sharing an FE space, each "
23  "optionally scaled by a real constant, and stores the result in an auxiliary variable.");
24  MFEMExecutedObject::addRequiredDependencyParam<std::vector<VariableName>>(
25  params, "source_variables", "The names of the MFEM variables to sum");
26  params.addParam<std::vector<mfem::real_t>>(
27  "scale_factors", "The factors to scale each MFEM variable by during summation");
28  return params;
29 }
30 
32  : MFEMAuxKernel(parameters),
33  _var_names(getParam<std::vector<VariableName>>("source_variables")),
34  _scale_factors(parameters.isParamValid("scale_factors")
35  ? getParam<std::vector<mfem::real_t>>("scale_factors")
36  : std::vector<mfem::real_t>(_var_names.size(), 1.0))
37 {
38  if (_var_names.size() != _scale_factors.size())
39  paramError("scale_factors",
40  "Number of MFEM variables to sum over is different from the number of provided "
41  "scale factors.");
42  for (const auto & var_name : _var_names)
43  {
44  const mfem::ParGridFunction * gf = getMFEMProblem().getGridFunction(var_name).get();
45  if (gf->ParFESpace() == _result_var.ParFESpace())
46  _summed_vars.push_back(gf);
47  else
48  paramError("source_variables",
49  "The MFEM variable ",
50  var_name,
51  " being summed has a different FESpace from ",
53  }
54 }
55 
56 void
58 {
59  // result = sum_i (_scale_factor_i * _summed_var_i)
60  _result_var = 0.0;
61  for (const auto i : index_range(_summed_vars))
63 }
64 
65 #endif
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
Definition: MFEMProblem.h:323
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
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
const std::vector< VariableName > & _var_names
Definition: MFEMSumAux.h:36
const AuxVariableName _result_var_name
Name of auxvariable to store the result of the auxkernel in.
Definition: MFEMAuxKernel.h:35
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", MFEMSumAux)
MFEMSumAux(const InputParameters &parameters)
Definition: MFEMSumAux.C:31
virtual void execute() override
Perform the main work for this object.
Definition: MFEMSumAux.C:57
mfem::ParGridFunction & _result_var
Reference to result gridfunction.
Definition: MFEMAuxKernel.h:38
std::vector< const mfem::ParGridFunction * > _summed_vars
Pointers to input variable gridfunctions.
Definition: MFEMSumAux.h:40
Class to construct an auxiliary solver used to update a real auxvariable.
Definition: MFEMAuxKernel.h:20
static InputParameters validParams()
Definition: MFEMAuxKernel.C:16
const std::vector< mfem::real_t > _scale_factors
Definition: MFEMSumAux.h:38
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
static InputParameters validParams()
Definition: MFEMSumAux.C:18
auto index_range(const T &sizable)