LCOV - code coverage report
Current view: top level - src/mfem/interfaces - MFEMBoundaryRestrictable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 27 29 93.1 %
Date: 2025-08-08 20:01:16 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 "MFEMBoundaryRestrictable.h"
      13             : 
      14             : InputParameters
      15       86962 : MFEMBoundaryRestrictable::validParams()
      16             : {
      17             :   // Create InputParameters object that will be appended to the parameters for the inheriting object
      18       86962 :   InputParameters params = emptyInputParameters();
      19      260886 :   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       86962 :   return params;
      25       86962 : }
      26             : 
      27         331 : MFEMBoundaryRestrictable::MFEMBoundaryRestrictable(const InputParameters & parameters,
      28         331 :                                                    const mfem::ParMesh & mfem_mesh)
      29         331 :   : _mfem_mesh(mfem_mesh),
      30         331 :     _boundary_names(parameters.get<std::vector<BoundaryName>>("boundary")),
      31         331 :     _boundary_attributes(_boundary_names.size())
      32             : {
      33         331 :   _boundary_attributes = boundariesToAttributes(_boundary_names);
      34         331 :   if (!_boundary_attributes.IsEmpty())
      35         331 :     mfem::common::AttrToMarker(
      36         331 :         _mfem_mesh.bdr_attributes.Max(), _boundary_attributes, _boundary_markers);
      37         331 : }
      38             : 
      39             : mfem::Array<int>
      40         331 : MFEMBoundaryRestrictable::boundariesToAttributes(const std::vector<BoundaryName> & boundary_names)
      41             : {
      42         331 :   mfem::Array<int> attributes(boundary_names.size());
      43         331 :   auto & mesh = getMesh();
      44         331 :   std::transform(
      45             :       boundary_names.begin(),
      46             :       boundary_names.end(),
      47             :       attributes.begin(),
      48         427 :       [&mesh](const BoundaryName & boundary) -> int
      49             :       {
      50             :         try
      51             :         {
      52             :           // Is this a sideset ID?
      53         363 :           return std::stoi(boundary);
      54             :         }
      55          64 :         catch (...)
      56             :         {
      57             :           // It was not
      58          64 :           auto & boundary_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary);
      59          64 :           if (boundary_ids.Size() != 1)
      60           0 :             mooseError(
      61             :                 "There should be a 1-to-1 correspondence between boundary name and boundary ID");
      62          64 :           return boundary_ids[0];
      63          64 :         }
      64             :       });
      65         331 :   return attributes;
      66           0 : }
      67             : 
      68             : #endif

Generated by: LCOV version 1.14