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 204694 : MFEMBlockRestrictable::validParams() 16 : { 17 : // Create InputParameters object that will be appended to the parameters for the inheriting object 18 204694 : 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 614082 : 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 204694 : return params; 27 0 : } 28 : 29 797 : MFEMBlockRestrictable::MFEMBlockRestrictable(const InputParameters & parameters, 30 797 : const mfem::ParMesh & mfem_mesh) 31 797 : : _mfem_mesh(mfem_mesh), 32 797 : _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")), 33 797 : _subdomain_attributes(_subdomain_names.size()) 34 : { 35 797 : _subdomain_attributes = subdomainsToAttributes(_subdomain_names); 36 797 : if (!_subdomain_attributes.IsEmpty()) 37 209 : mfem::common::AttrToMarker( 38 209 : _mfem_mesh.attributes.Max(), _subdomain_attributes, _subdomain_markers); 39 797 : } 40 : 41 : mfem::Array<int> 42 968 : MFEMBlockRestrictable::subdomainsToAttributes(const std::vector<SubdomainName> & subdomain_names) 43 : { 44 968 : mfem::Array<int> attributes; 45 968 : auto & mesh = getMesh(); 46 : 47 1352 : for (const SubdomainName & subdomain_name : subdomain_names) 48 : { 49 : try 50 : { 51 : // Is this a block ID? 52 384 : const int attribute_id = std::stoi(subdomain_name); 53 140 : attributes.Append(attribute_id); 54 : } 55 244 : catch (...) 56 : { 57 : // It was not 58 244 : auto & subdomain_ids = mesh.attribute_sets.GetAttributeSet(subdomain_name); 59 550 : for (const auto & subdomain_id : subdomain_ids) 60 306 : attributes.Append(subdomain_id); 61 244 : } 62 : } 63 968 : return attributes; 64 0 : } 65 : 66 : std::vector<std::string> 67 171 : MFEMBlockRestrictable::subdomainsToStrings(const std::vector<SubdomainName> & subdomain_names) 68 : { 69 171 : auto attributes = subdomainsToAttributes(subdomain_names); 70 171 : std::vector<std::string> subdomain_attr_strings(subdomain_names.size()); 71 293 : for (const auto i : index_range(subdomain_names)) 72 122 : subdomain_attr_strings[i] = std::to_string(attributes[i]); 73 342 : return subdomain_attr_strings; 74 171 : } 75 : 76 : #endif