https://mooseframework.inl.gov
MFEMGenericFunctorVectorMaterial.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 
13 #include "MFEMProblem.h"
14 
16 
18 std::vector<MFEMVectorCoefficientName>
19 processLiteralVectors(const std::vector<MFEMVectorCoefficientName> & input)
20 {
21  std::vector<MFEMVectorCoefficientName> result;
22  bool in_literal = false;
23  MFEMVectorCoefficientName literal;
24  for (const auto & item : input)
25  {
26  if (in_literal)
27  {
28  if (item.front() == '{')
29  mooseError("Nested numeric vector values are not permitted in "
30  "MFEMGenericFunctorVectoMaterial prop_values.");
31  else if (item.back() == '}')
32  {
33  in_literal = false;
34  literal += " " + item.substr(0, item.size() - 1);
35  result.push_back(literal);
36  }
37  else
38  literal += " " + item;
39  }
40  else if (item.front() == '{')
41  {
42  if (item.back() == '}')
43  result.push_back(item.substr(1, item.size() - 2));
44  else
45  {
46  in_literal = true;
47  literal = item.substr(1);
48  }
49  }
50  else
51  result.push_back(item);
52  }
53  if (in_literal)
54  mooseError("No closing curly brace for vector value in "
55  "MFEMGenericFunctorVectorMaterial prop_values: '{" +
56  literal + "'");
57  return result;
58 }
59 
62 {
64  params.addClassDescription("Declares material vector properties based on names and coefficients "
65  "prescribed by input parameters.");
66  params.addRequiredParam<std::vector<std::string>>(
67  "prop_names", "The names of the properties this material will have");
68  params.addRequiredParam<std::vector<MFEMVectorCoefficientName>>(
69  "prop_values",
70  "The corresponding names of coefficients associated with the named properties");
71 
72  return params;
73 }
74 
76  const InputParameters & parameters)
77  : MFEMFunctorMaterial(parameters),
78  _prop_names(getParam<std::vector<std::string>>("prop_names")),
79  _prop_values(
80  processLiteralVectors(getParam<std::vector<MFEMVectorCoefficientName>>("prop_values")))
81 {
82  if (_prop_names.size() != _prop_values.size())
83  paramError("prop_names", "Must match the size of prop_values");
84 
85  for (const auto i : index_range(_prop_names))
88 }
89 
91 
92 #endif
Moose::MFEM::CoefficientManager & _properties
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Declares material properties based on names and functions prescribed by input parameters.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::vector< std::string > & _prop_names
registerMooseObject("MooseApp", MFEMGenericFunctorVectorMaterial)
std::vector< MFEMVectorCoefficientName > processLiteralVectors(const std::vector< MFEMVectorCoefficientName > &input)
Handle any numerical vector values, which should be enclosed in curly braces.
std::vector< std::string > subdomainsToStrings(const std::vector< SubdomainName > &subdomain_names)
std::vector< SubdomainName > _subdomain_names
Stores the names of the subdomains.
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 ...
MFEMGenericFunctorVectorMaterial(const InputParameters &parameters)
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...
auto index_range(const T &sizable)
static InputParameters validParams()
const std::vector< MFEMVectorCoefficientName > _prop_values