LCOV - code coverage report
Current view: top level - src/mfem/functormaterials - MFEMGenericFunctorVectorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 39 44 88.6 %
Date: 2025-08-08 20:01:16 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "MFEMGenericFunctorVectorMaterial.h"
      13             : #include "MFEMProblem.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMGenericFunctorVectorMaterial);
      16             : 
      17             : /// Handle any numerical vector values, which should be enclosed in curly braces
      18             : std::vector<MFEMVectorCoefficientName>
      19          14 : processLiteralVectors(const std::vector<MFEMVectorCoefficientName> & input)
      20             : {
      21          14 :   std::vector<MFEMVectorCoefficientName> result;
      22          14 :   bool in_literal = false;
      23          14 :   MFEMVectorCoefficientName literal;
      24          63 :   for (const auto & item : input)
      25             :   {
      26          49 :     if (in_literal)
      27             :     {
      28          28 :       if (item.front() == '{')
      29           0 :         mooseError("Nested numeric vector values are not permitted in "
      30             :                    "MFEMGenericFunctorVectoMaterial prop_values.");
      31          28 :       else if (item.back() == '}')
      32             :       {
      33          14 :         in_literal = false;
      34          14 :         literal += " " + item.substr(0, item.size() - 1);
      35          14 :         result.push_back(literal);
      36             :       }
      37             :       else
      38          14 :         literal += " " + item;
      39             :     }
      40          21 :     else if (item.front() == '{')
      41             :     {
      42          15 :       if (item.back() == '}')
      43           1 :         result.push_back(item.substr(1, item.size() - 2));
      44             :       else
      45             :       {
      46          14 :         in_literal = true;
      47          14 :         literal = item.substr(1);
      48             :       }
      49             :     }
      50             :     else
      51           6 :       result.push_back(item);
      52             :   }
      53          14 :   if (in_literal)
      54           0 :     mooseError("No closing curly brace for vector value in "
      55           0 :                "MFEMGenericFunctorVectorMaterial prop_values: '{" +
      56           0 :                literal + "'");
      57          28 :   return result;
      58          14 : }
      59             : 
      60             : InputParameters
      61        8657 : MFEMGenericFunctorVectorMaterial::validParams()
      62             : {
      63        8657 :   InputParameters params = MFEMFunctorMaterial::validParams();
      64        8657 :   params.addClassDescription("Declares material vector properties based on names and coefficients "
      65             :                              "prescribed by input parameters.");
      66        8657 :   params.addRequiredParam<std::vector<std::string>>(
      67             :       "prop_names", "The names of the properties this material will have");
      68        8657 :   params.addRequiredParam<std::vector<MFEMVectorCoefficientName>>(
      69             :       "prop_values",
      70             :       "The corresponding names of coefficients associated with the named properties");
      71             : 
      72        8657 :   return params;
      73           0 : }
      74             : 
      75          14 : MFEMGenericFunctorVectorMaterial::MFEMGenericFunctorVectorMaterial(
      76          14 :     const InputParameters & parameters)
      77             :   : MFEMFunctorMaterial(parameters),
      78          14 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      79          14 :     _prop_values(
      80          14 :         processLiteralVectors(getParam<std::vector<MFEMVectorCoefficientName>>("prop_values")))
      81             : {
      82          14 :   if (_prop_names.size() != _prop_values.size())
      83           3 :     paramError("prop_names", "Must match the size of prop_values");
      84             : 
      85          33 :   for (const auto i : index_range(_prop_names))
      86          20 :     _properties.declareVectorProperty(
      87          40 :         _prop_names[i], subdomainsToStrings(_subdomain_names), _prop_values[i]);
      88          15 : }
      89             : 
      90          26 : MFEMGenericFunctorVectorMaterial::~MFEMGenericFunctorVectorMaterial() {}
      91             : 
      92             : #endif

Generated by: LCOV version 1.14