LCOV - code coverage report
Current view: top level - src/mfem/interfaces - MFEMBlockRestrictable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 33 36 91.7 %
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 "MFEMBlockRestrictable.h"
      13             : 
      14             : InputParameters
      15      147170 : MFEMBlockRestrictable::validParams()
      16             : {
      17             :   // Create InputParameters object that will be appended to the parameters for the inheriting object
      18      147170 :   InputParameters params = emptyInputParameters();
      19             :   // Create user-facing 'boundary' input for restricting inheriting object to boundaries
      20             :   // MFEM uses the boundary -1 to signify every sideset
      21      147170 :   params.addParam<std::vector<SubdomainName>>("block",
      22             :                                               {},
      23             :                                               "The list of subdomains (names or ids) that this "
      24             :                                               "object will be restricted to. Leave empty to apply "
      25             :                                               "to all subdomains.");
      26      147170 :   return params;
      27           0 : }
      28             : 
      29         231 : MFEMBlockRestrictable::MFEMBlockRestrictable(const InputParameters & parameters,
      30         231 :                                              const mfem::ParMesh & mfem_mesh)
      31         231 :   : _mfem_mesh(mfem_mesh),
      32         231 :     _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")),
      33         231 :     _subdomain_attributes(_subdomain_names.size())
      34             : {
      35         231 :   _subdomain_attributes = subdomainsToAttributes(_subdomain_names);
      36         231 :   if (!_subdomain_attributes.IsEmpty())
      37          55 :     mfem::common::AttrToMarker(
      38          55 :         _mfem_mesh.attributes.Max(), _subdomain_attributes, _subdomain_markers);
      39         231 : }
      40             : 
      41             : mfem::Array<int>
      42         308 : MFEMBlockRestrictable::subdomainsToAttributes(const std::vector<SubdomainName> & subdomain_names)
      43             : {
      44         308 :   mfem::Array<int> attributes(subdomain_names.size());
      45         308 :   auto & mesh = getMesh();
      46         308 :   std::transform(
      47             :       subdomain_names.begin(),
      48             :       subdomain_names.end(),
      49             :       attributes.begin(),
      50         169 :       [&mesh](const SubdomainName & subdomain) -> int
      51             :       {
      52             :         try
      53             :         {
      54             :           // Is this a block ID?
      55         133 :           return std::stoi(subdomain);
      56             :         }
      57          36 :         catch (...)
      58             :         {
      59             :           // It was not
      60          36 :           auto & subdomain_ids = mesh.attribute_sets.GetAttributeSet(subdomain);
      61          36 :           if (subdomain_ids.Size() != 1)
      62           0 :             mooseError(
      63             :                 "There should be a 1-to-1 correspondence between subdomain name and subdomain ID");
      64          36 :           return subdomain_ids[0];
      65          36 :         }
      66             :       });
      67         308 :   return attributes;
      68           0 : }
      69             : 
      70             : std::vector<std::string>
      71          77 : MFEMBlockRestrictable::subdomainsToStrings(const std::vector<SubdomainName> & subdomain_names)
      72             : {
      73          77 :   auto attributes = subdomainsToAttributes(subdomain_names);
      74          77 :   std::vector<std::string> subdomain_attr_strings(subdomain_names.size());
      75         153 :   for (const auto i : index_range(subdomain_names))
      76          76 :     subdomain_attr_strings[i] = std::to_string(attributes[i]);
      77         154 :   return subdomain_attr_strings;
      78          77 : }
      79             : 
      80             : #endif

Generated by: LCOV version 1.14