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 "MFEMBoundaryRestrictable.h" 13 : 14 : InputParameters 15 78046 : MFEMBoundaryRestrictable::validParams() 16 : { 17 : // Create InputParameters object that will be appended to the parameters for the inheriting object 18 78046 : InputParameters params = emptyInputParameters(); 19 234138 : 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 78046 : return params; 25 78046 : } 26 : 27 188 : MFEMBoundaryRestrictable::MFEMBoundaryRestrictable(const InputParameters & parameters, 28 188 : const mfem::ParMesh & mfem_mesh) 29 188 : : _mfem_mesh(mfem_mesh), 30 188 : _boundary_names(parameters.get<std::vector<BoundaryName>>("boundary")), 31 188 : _boundary_attributes(_boundary_names.size()) 32 : { 33 188 : _boundary_attributes = boundariesToAttributes(_boundary_names); 34 188 : if (!_boundary_attributes.IsEmpty()) 35 188 : mfem::common::AttrToMarker( 36 188 : _mfem_mesh.bdr_attributes.Max(), _boundary_attributes, _boundary_markers); 37 188 : } 38 : 39 : mfem::Array<int> 40 188 : MFEMBoundaryRestrictable::boundariesToAttributes(const std::vector<BoundaryName> & boundary_names) 41 : { 42 188 : mfem::Array<int> attributes(boundary_names.size()); 43 188 : auto & mesh = getMesh(); 44 188 : std::transform( 45 : boundary_names.begin(), 46 : boundary_names.end(), 47 : attributes.begin(), 48 240 : [&mesh](const BoundaryName & boundary) -> int 49 : { 50 : try 51 : { 52 : // Is this a sideset ID? 53 204 : return std::stoi(boundary); 54 : } 55 36 : catch (...) 56 : { 57 : // It was not 58 36 : auto & boundary_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary); 59 36 : if (boundary_ids.Size() != 1) 60 0 : mooseError( 61 : "There should be a 1-to-1 correspondence between boundary name and boundary ID"); 62 36 : return boundary_ids[0]; 63 36 : } 64 : }); 65 188 : return attributes; 66 0 : } 67 : 68 : #endif