LCOV - code coverage report
Current view: top level - src/mfem/interfaces - MFEMBlockRestrictable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: d8769b Lines: 33 35 94.3 %
Date: 2025-11-07 20:01:30 Functions: 4 4 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      207456 : MFEMBlockRestrictable::validParams()
      16             : {
      17             :   // Create InputParameters object that will be appended to the parameters for the inheriting object
      18      207456 :   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      622368 :   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      207456 :   return params;
      27           0 : }
      28             : 
      29         858 : MFEMBlockRestrictable::MFEMBlockRestrictable(const InputParameters & parameters,
      30         858 :                                              const mfem::ParMesh & mfem_mesh)
      31         858 :   : _mfem_mesh(mfem_mesh),
      32         858 :     _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")),
      33         858 :     _subdomain_attributes(_subdomain_names.size())
      34             : {
      35         858 :   _subdomain_attributes = subdomainsToAttributes(_subdomain_names);
      36         858 :   if (!_subdomain_attributes.IsEmpty())
      37         217 :     mfem::common::AttrToMarker(
      38         217 :         _mfem_mesh.attributes.Max(), _subdomain_attributes, _subdomain_markers);
      39         858 : }
      40             : 
      41             : mfem::Array<int>
      42        1037 : MFEMBlockRestrictable::subdomainsToAttributes(const std::vector<SubdomainName> & subdomain_names)
      43             : {
      44        1037 :   mfem::Array<int> attributes;
      45        1037 :   auto & mesh = getMesh();
      46             : 
      47        1429 :   for (const SubdomainName & subdomain_name : subdomain_names)
      48             :   {
      49             :     try
      50             :     {
      51             :       // Is this a block ID?
      52         392 :       const int attribute_id = std::stoi(subdomain_name);
      53         140 :       attributes.Append(attribute_id);
      54             :     }
      55         252 :     catch (...)
      56             :     {
      57             :       // It was not
      58         252 :       auto & subdomain_ids = mesh.attribute_sets.GetAttributeSet(subdomain_name);
      59         566 :       for (const auto & subdomain_id : subdomain_ids)
      60         314 :         attributes.Append(subdomain_id);
      61         252 :     }
      62             :   }
      63        1037 :   return attributes;
      64           0 : }
      65             : 
      66             : std::vector<std::string>
      67         179 : MFEMBlockRestrictable::subdomainsToStrings(const std::vector<SubdomainName> & subdomain_names)
      68             : {
      69         179 :   auto attributes = subdomainsToAttributes(subdomain_names);
      70         179 :   std::vector<std::string> subdomain_attr_strings(subdomain_names.size());
      71         301 :   for (const auto i : index_range(subdomain_names))
      72         122 :     subdomain_attr_strings[i] = std::to_string(attributes[i]);
      73         358 :   return subdomain_attr_strings;
      74         179 : }
      75             : 
      76             : #endif

Generated by: LCOV version 1.14