LCOV - code coverage report
Current view: top level - src/mfem/functormaterials - MFEMGenericFunctorVectorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 39 44 88.6 %
Date: 2025-07-17 01:28:37 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 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          12 : processLiteralVectors(const std::vector<MFEMVectorCoefficientName> & input)
      20             : {
      21          12 :   std::vector<MFEMVectorCoefficientName> result;
      22          12 :   bool in_literal = false;
      23          12 :   MFEMVectorCoefficientName literal;
      24          55 :   for (const auto & item : input)
      25             :   {
      26          43 :     if (in_literal)
      27             :     {
      28          24 :       if (item.front() == '{')
      29           0 :         mooseError("Nested numeric vector values are not permitted in "
      30             :                    "MFEMGenericFunctorVectoMaterial prop_values.");
      31          24 :       else if (item.back() == '}')
      32             :       {
      33          12 :         in_literal = false;
      34          12 :         literal += " " + item.substr(0, item.size() - 1);
      35          12 :         result.push_back(literal);
      36             :       }
      37             :       else
      38          12 :         literal += " " + item;
      39             :     }
      40          19 :     else if (item.front() == '{')
      41             :     {
      42          13 :       if (item.back() == '}')
      43           1 :         result.push_back(item.substr(1, item.size() - 2));
      44             :       else
      45             :       {
      46          12 :         in_literal = true;
      47          12 :         literal = item.substr(1);
      48             :       }
      49             :     }
      50             :     else
      51           6 :       result.push_back(item);
      52             :   }
      53          12 :   if (in_literal)
      54           0 :     mooseError("No closing curly brace for vector value in "
      55           0 :                "MFEMGenericFunctorVectorMaterial prop_values: '{" +
      56           0 :                literal + "'");
      57          24 :   return result;
      58          12 : }
      59             : 
      60             : InputParameters
      61        8653 : MFEMGenericFunctorVectorMaterial::validParams()
      62             : {
      63        8653 :   InputParameters params = MFEMFunctorMaterial::validParams();
      64        8653 :   params.addClassDescription("Declares material vector properties based on names and coefficients "
      65             :                              "prescribed by input parameters.");
      66        8653 :   params.addRequiredParam<std::vector<std::string>>(
      67             :       "prop_names", "The names of the properties this material will have");
      68        8653 :   params.addRequiredParam<std::vector<MFEMVectorCoefficientName>>(
      69             :       "prop_values",
      70             :       "The corresponding names of coefficients associated with the named properties");
      71             : 
      72        8653 :   return params;
      73           0 : }
      74             : 
      75          12 : MFEMGenericFunctorVectorMaterial::MFEMGenericFunctorVectorMaterial(
      76          12 :     const InputParameters & parameters)
      77             :   : MFEMFunctorMaterial(parameters),
      78          12 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      79          12 :     _prop_values(
      80          12 :         processLiteralVectors(getParam<std::vector<MFEMVectorCoefficientName>>("prop_values")))
      81             : {
      82          12 :   if (_prop_names.size() != _prop_values.size())
      83           3 :     paramError("prop_names", "Must match the size of prop_values");
      84             : 
      85          29 :   for (const auto i : index_range(_prop_names))
      86          18 :     _properties.declareVectorProperty(
      87          36 :         _prop_names[i], subdomainsToStrings(_subdomain_names), _prop_values[i]);
      88          13 : }
      89             : 
      90          22 : MFEMGenericFunctorVectorMaterial::~MFEMGenericFunctorVectorMaterial() {}
      91             : 
      92             : #endif

Generated by: LCOV version 1.14