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 200044 : MFEMBlockRestrictable::validParams() 16 : { 17 : // Create InputParameters object that will be appended to the parameters for the inheriting object 18 200044 : 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 600132 : 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 200044 : return params; 27 0 : } 28 : 29 778 : MFEMBlockRestrictable::MFEMBlockRestrictable(const InputParameters & parameters, 30 778 : const mfem::ParMesh & mfem_mesh) 31 778 : : _mfem_mesh(mfem_mesh), 32 778 : _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")), 33 778 : _subdomain_attributes(_subdomain_names.size()) 34 : { 35 778 : _subdomain_attributes = subdomainsToAttributes(_subdomain_names); 36 778 : if (!_subdomain_attributes.IsEmpty()) 37 204 : mfem::common::AttrToMarker( 38 204 : _mfem_mesh.attributes.Max(), _subdomain_attributes, _subdomain_markers); 39 778 : } 40 : 41 : mfem::Array<int> 42 930 : MFEMBlockRestrictable::subdomainsToAttributes(const std::vector<SubdomainName> & subdomain_names) 43 : { 44 930 : mfem::Array<int> attributes; 45 930 : auto & mesh = getMesh(); 46 : 47 1298 : for (const SubdomainName & subdomain_name : subdomain_names) 48 : { 49 : try 50 : { 51 : // Is this a block ID? 52 368 : const int attribute_id = std::stoi(subdomain_name); 53 124 : 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 930 : return attributes; 64 0 : } 65 : 66 : std::vector<std::string> 67 152 : MFEMBlockRestrictable::subdomainsToStrings(const std::vector<SubdomainName> & subdomain_names) 68 : { 69 152 : auto attributes = subdomainsToAttributes(subdomain_names); 70 152 : std::vector<std::string> subdomain_attr_strings(subdomain_names.size()); 71 263 : for (const auto i : index_range(subdomain_names)) 72 111 : subdomain_attr_strings[i] = std::to_string(attributes[i]); 73 304 : return subdomain_attr_strings; 74 152 : } 75 : 76 : #endif