https://mooseframework.inl.gov
CoefficientManager.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 MFEM_ENABLED
11 
12 #pragma once
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <tuple>
17 #include <utility>
18 #include <variant>
19 #include <vector>
20 
21 #include "MooseException.h"
22 
23 #include "libmesh/ignore_warnings.h"
24 #include <mfem.hpp>
25 #include "libmesh/restore_warnings.h"
26 #include "CoefficientMap.h"
27 
28 namespace Moose::MFEM
29 {
36 {
37 public:
38  CoefficientManager() = default;
39 
43  mfem::Coefficient & declareScalar(const std::string & name,
44  const std::string & existing_or_literal);
46  template <class P, class... Args>
47  P & declareScalar(const std::string & name, Args &&... args)
48  {
49  auto coef = _scalar_coeffs.make<P>(args...);
50  this->declareScalar(name, coef);
51  return *coef;
52  }
53 
61  mfem::Coefficient & declareScalarProperty(const std::string & name,
62  const std::vector<std::string> & blocks,
63  const std::string & existing_or_literal);
70  template <class P, class... Args>
71  mfem::Coefficient & declareScalarProperty(const std::string & name,
72  const std::vector<std::string> & blocks,
73  Args &&... args)
74  {
75  return this->declareScalarProperty(name, blocks, _scalar_coeffs.make<P>(args...));
76  }
77 
81  mfem::VectorCoefficient & declareVector(const std::string & name,
82  const std::string & existing_or_literal);
84  template <class P, class... Args>
85  P & declareVector(const std::string & name, Args &&... args)
86  {
87  auto coef = _vector_coeffs.make<P>(args...);
88  this->declareVector(name, coef);
89  return *coef;
90  }
91 
100  mfem::VectorCoefficient & declareVectorProperty(const std::string & name,
101  const std::vector<std::string> & blocks,
102  const std::string & existing_or_literal);
109  template <class P, class... Args>
110  mfem::VectorCoefficient & declareVectorProperty(const std::string & name,
111  const std::vector<std::string> & blocks,
112  Args &&... args)
113  {
114  return this->declareVectorProperty(name, blocks, _vector_coeffs.make<P>(args...));
115  }
116 
121  mfem::MatrixCoefficient & declareMatrix(const std::string & name,
122  const std::string & existing_coef);
124  template <class P, class... Args>
125  P & declareMatrix(const std::string & name, Args &&... args)
126  {
127  auto coef = _matrix_coeffs.make<P>(args...);
128  this->declareMatrix(name, coef);
129  return *coef;
130  }
131 
140  mfem::MatrixCoefficient & declareMatrixProperty(const std::string & name,
141  const std::vector<std::string> & blocks,
142  const std::string & existing_coef);
149  template <class P, class... Args>
150  mfem::MatrixCoefficient & declareMatrixProperty(const std::string & name,
151  const std::vector<std::string> & blocks,
152  Args &&... args)
153  {
154  return this->declareMatrixProperty(name, blocks, _matrix_coeffs.make<P>(args...));
155  }
156 
160  mfem::Coefficient & getScalarCoefficient(const std::string & name);
161 
165  mfem::VectorCoefficient & getVectorCoefficient(const std::string & name);
166 
171  mfem::MatrixCoefficient & getMatrixCoefficient(const std::string & name);
172 
173  bool scalarPropertyIsDefined(const std::string & name, const std::string & block) const;
174  bool vectorPropertyIsDefined(const std::string & name, const std::string & block) const;
175  bool matrixPropertyIsDefined(const std::string & name, const std::string & block) const;
176  void setTime(const double time);
177 
178 private:
182 
183  mfem::Coefficient & declareScalar(const std::string & name,
184  std::shared_ptr<mfem::Coefficient> coef);
185  mfem::Coefficient & declareScalarProperty(const std::string & name,
186  const std::vector<std::string> & blocks,
187  std::shared_ptr<mfem::Coefficient> coef);
188  mfem::VectorCoefficient & declareVector(const std::string & name,
189  std::shared_ptr<mfem::VectorCoefficient> coef);
190  mfem::VectorCoefficient & declareVectorProperty(const std::string & name,
191  const std::vector<std::string> & blocks,
192  std::shared_ptr<mfem::VectorCoefficient> coef);
193  mfem::MatrixCoefficient & declareMatrix(const std::string & name,
194  std::shared_ptr<mfem::MatrixCoefficient> coef);
195  mfem::MatrixCoefficient & declareMatrixProperty(const std::string & name,
196  const std::vector<std::string> & blocks,
197  std::shared_ptr<mfem::MatrixCoefficient> coef);
198  std::shared_ptr<mfem::Coefficient> getScalarCoefficientPtr(const std::string & name);
199  std::shared_ptr<mfem::VectorCoefficient> getVectorCoefficientPtr(const std::string & name);
200  std::shared_ptr<mfem::MatrixCoefficient> getMatrixCoefficientPtr(const std::string & name);
201 };
202 }
203 
204 #endif
mfem::VectorCoefficient & declareVectorProperty(const std::string &name, const std::vector< std::string > &blocks, Args &&... args)
Use a new vector coefficient, constructed from the argument pack, for a property on some blocks of th...
std::string name(const ElemQuality q)
P & declareScalar(const std::string &name, Args &&... args)
Create a new scalar coefficient, constructed from the argument pack.
mfem::Coefficient & declareScalarProperty(const std::string &name, const std::vector< std::string > &blocks, const std::string &existing_or_literal)
Use an existing scalar coefficient for a property on some blocks of the mesh.
char ** blocks
mfem::VectorCoefficient & getVectorCoefficient(const std::string &name)
Return a vector coefficient with the given name or, if that doesn&#39;t exists, try interpreting the name...
mfem::VectorCoefficient & declareVectorProperty(const std::string &name, const std::vector< std::string > &blocks, const std::string &existing_or_literal)
Use an existing vector coefficient for a property on some blocks of the mesh.
bool scalarPropertyIsDefined(const std::string &name, const std::string &block) const
mfem::MatrixCoefficient & declareMatrixProperty(const std::string &name, const std::vector< std::string > &blocks, Args &&... args)
Use a new matrix coefficient, constructed from the argument pack, for a property on some blocks of th...
Front-end class for creating and storing MFEM coefficients.
mfem::MatrixCoefficient & declareMatrixProperty(const std::string &name, const std::vector< std::string > &blocks, const std::string &existing_coef)
Use an existing matrix coefficient for a property on some blocks of the mesh.
std::shared_ptr< mfem::VectorCoefficient > getVectorCoefficientPtr(const std::string &name)
void setTime(const double time)
std::shared_ptr< mfem::MatrixCoefficient > getMatrixCoefficientPtr(const std::string &name)
mfem::MatrixCoefficient & declareMatrix(const std::string &name, const std::string &existing_coef)
Declare an alias to an existing matrix coefficient.
mfem::MatrixCoefficient & getMatrixCoefficient(const std::string &name)
Return scalar coefficient with the given name.
P & declareMatrix(const std::string &name, Args &&... args)
Create a new matrix coefficient, constructed from the argument pack.
mfem::Coefficient & declareScalar(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing scalar coefficient or, if it does not exist, try interpreting the nam...
std::shared_ptr< mfem::Coefficient > getScalarCoefficientPtr(const std::string &name)
P & declareVector(const std::string &name, Args &&... args)
Create a new vector coefficient, constructed from the argument pack.
mfem::Coefficient & declareScalarProperty(const std::string &name, const std::vector< std::string > &blocks, Args &&... args)
Use a new scalar coefficient, constructed from the argument pack, for a property on some blocks of th...
mfem::VectorCoefficient & declareVector(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing vector coefficientor or, if it does not exist, try interpreting the n...
bool vectorPropertyIsDefined(const std::string &name, const std::string &block) const
bool matrixPropertyIsDefined(const std::string &name, const std::string &block) const
mfem::Coefficient & getScalarCoefficient(const std::string &name)
Return a scalar coefficient with the given name or, if that doesn&#39;t exists, try interpreting the name...
std::shared_ptr< P > make(Args &&... args)
Make arbitrary coefficients which will be tracked by this object.