LCOV - code coverage report
Current view: top level - src/mfem/interfaces - MFEMBlockRestrictable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 30 32 93.8 %
Date: 2026-05-29 20:35:17 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 "MFEMBlockRestrictable.h"
      13             : 
      14             : InputParameters
      15       57072 : MFEMBlockRestrictable::validParams()
      16             : {
      17             :   // Create InputParameters object that will be appended to the parameters for the inheriting object
      18       57072 :   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      171216 :   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       57072 :   return params;
      27           0 : }
      28             : 
      29        2313 : MFEMBlockRestrictable::MFEMBlockRestrictable(const InputParameters & parameters,
      30        2313 :                                              const mfem::ParMesh & mfem_mesh)
      31        2313 :   : _mfem_mesh(mfem_mesh),
      32        2313 :     _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")),
      33        2313 :     _subdomain_attributes(subdomainsToAttributes())
      34             : {
      35        2313 :   if (!_subdomain_attributes.IsEmpty())
      36         447 :     mfem::common::AttrToMarker(
      37         447 :         _mfem_mesh.attributes.Max(), _subdomain_attributes, _subdomain_markers);
      38        2313 : }
      39             : 
      40             : mfem::Array<int>
      41        2313 : MFEMBlockRestrictable::subdomainsToAttributes()
      42             : {
      43        2313 :   mfem::Array<int> attributes;
      44        2313 :   auto & mesh = getMesh();
      45             : 
      46        2896 :   for (const SubdomainName & subdomain_name : _subdomain_names)
      47             :   {
      48             :     try
      49             :     {
      50             :       // Is this a block ID?
      51         583 :       const int attribute_id = std::stoi(subdomain_name);
      52          82 :       attributes.Append(attribute_id);
      53             :     }
      54         501 :     catch (...)
      55             :     {
      56             :       // It was not
      57         501 :       auto & subdomain_ids = mesh.attribute_sets.GetAttributeSet(subdomain_name);
      58        1204 :       for (const auto & subdomain_id : subdomain_ids)
      59         703 :         attributes.Append(subdomain_id);
      60         501 :     }
      61             :   }
      62        2313 :   return attributes;
      63           0 : }
      64             : 
      65             : std::vector<std::string>
      66         316 : MFEMBlockRestrictable::subdomainsToStrings()
      67             : {
      68         316 :   const auto & attrs = _subdomain_attributes;
      69         316 :   std::vector<std::string> strs(attrs.Size());
      70         565 :   std::transform(attrs.begin(), attrs.end(), strs.begin(), [](int n) { return std::to_string(n); });
      71         316 :   return strs;
      72             : }
      73             : 
      74             : #endif

Generated by: LCOV version 1.14