LCOV - code coverage report
Current view: top level - src/mfem/interfaces - MFEMBoundaryRestrictable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 31 33 93.9 %
Date: 2026-05-29 20:35:17 Functions: 6 6 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 "MFEMBoundaryRestrictable.h"
      13             : 
      14             : InputParameters
      15       49350 : MFEMBoundaryRestrictable::validParams()
      16             : {
      17             :   // Create InputParameters object that will be appended to the parameters for the inheriting object
      18       49350 :   InputParameters params = emptyInputParameters();
      19      197400 :   params.addParam<std::vector<BoundaryName>>(
      20             :       "boundary",
      21             :       {"-1"},
      22             :       "The list of boundaries (ids or names) from the mesh where this object applies. "
      23             :       "Defaults to all boundaries.");
      24       49350 :   return params;
      25       49350 : }
      26             : 
      27        1599 : MFEMBoundaryRestrictable::MFEMBoundaryRestrictable(const InputParameters & parameters,
      28        1599 :                                                    const mfem::ParMesh & mfem_mesh)
      29        1599 :   : _mfem_mesh(mfem_mesh),
      30        1599 :     _boundary_names(parameters.get<std::vector<BoundaryName>>("boundary")),
      31        1599 :     _boundary_attributes(boundariesToAttributes())
      32             : {
      33        1599 :   if (!_boundary_attributes.IsEmpty())
      34        1599 :     mfem::common::AttrToMarker(
      35        1599 :         _mfem_mesh.bdr_attributes.Max(), _boundary_attributes, _boundary_markers);
      36        1599 : }
      37             : 
      38             : mfem::Array<int>
      39        1599 : MFEMBoundaryRestrictable::boundariesToAttributes()
      40             : {
      41        1599 :   mfem::Array<int> attributes(_boundary_names.size());
      42        1599 :   auto & mesh = getMesh();
      43        1599 :   std::transform(
      44             :       _boundary_names.begin(),
      45             :       _boundary_names.end(),
      46             :       attributes.begin(),
      47        1673 :       [&mesh](const BoundaryName & boundary) -> int
      48             :       {
      49             :         try
      50             :         {
      51             :           // Is this a sideset ID?
      52        1673 :           return std::stoi(boundary);
      53             :         }
      54         487 :         catch (...)
      55             :         {
      56             :           // It was not
      57         487 :           auto & boundary_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary);
      58         487 :           if (boundary_ids.Size() != 1)
      59           0 :             mooseError(
      60             :                 "There should be a 1-to-1 correspondence between boundary name and boundary ID");
      61         487 :           return boundary_ids[0];
      62         487 :         }
      63             :       });
      64        1599 :   return attributes;
      65           0 : }
      66             : 
      67             : std::vector<std::string>
      68          13 : MFEMBoundaryRestrictable::boundariesToStrings()
      69             : {
      70          13 :   const auto & attrs = _boundary_attributes;
      71          13 :   std::vector<std::string> strs(attrs.Size());
      72          26 :   std::transform(attrs.begin(), attrs.end(), strs.begin(), [](int n) { return std::to_string(n); });
      73          13 :   return strs;
      74             : }
      75             : 
      76             : #endif

Generated by: LCOV version 1.14