Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 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 : #include "KokkosMaterialBase.h" 11 : 12 : #include "FEProblemBase.h" 13 : 14 : namespace Moose::Kokkos 15 : { 16 : 17 : InputParameters 18 39308 : MaterialBase::validParams() 19 : { 20 39308 : InputParameters params = ::MaterialBase::validParams(); 21 : 22 157232 : MooseEnum constant_option("NONE=0 ELEMENT=1 SUBDOMAIN=2", "NONE"); 23 157232 : params.addParam<MooseEnum>( 24 : "constant_on", 25 : constant_option, 26 : "When ELEMENT or SUBDOMAIN, computeQpProperties() will be only called once for each " 27 : "element/face or subdomain, respectively. Material properties will be only stored for each " 28 : "element/face or subdomain accordingly. The 'qp' argument wlll be ignored."); 29 : 30 78616 : params.suppressParameter<bool>("use_displaced_mesh"); 31 78616 : params.suppressParameter<bool>("compute"); 32 78616 : params.suppressParameter<std::vector<OutputName>>("outputs"); 33 39308 : params.suppressParameter<std::vector<std::string>>("output_properties"); 34 : 35 39308 : params.addPrivateParam<bool>(MooseBase::kokkos_object_param, true); 36 78616 : params.addPrivateParam<bool>("_kokkos_material", true); 37 : 38 78616 : return params; 39 39308 : } 40 : 41 5172 : MaterialBase::MaterialBase(const InputParameters & parameters) 42 : : ::MaterialBase(parameters), 43 1566 : MeshHolder(*_fe_problem.mesh().getKokkosMesh()), 44 1566 : AssemblyHolder(_fe_problem.kokkosAssembly()), 45 1566 : SystemHolder(_fe_problem.getKokkosSystems()), 46 3132 : _constant_option(getParam<MooseEnum>("constant_on").getEnum<PropertyConstantOption>()), 47 1566 : _t(TransientInterface::_t), 48 1566 : _t_old(TransientInterface::_t_old), 49 1566 : _t_step(TransientInterface::_t_step), 50 1566 : _dt(TransientInterface::_dt), 51 4698 : _dt_old(TransientInterface::_dt_old) 52 : { 53 2768 : _fe_problem.addKokkosMeshInitializationHook( 54 1566 : std::bind(&MaterialBase::initializeMaterialRestrictable, this)); 55 2768 : } 56 : 57 87859 : MaterialBase::MaterialBase(const MaterialBase & object) 58 : : ::MaterialBase(object, {}), 59 : MeshHolder(object), 60 : AssemblyHolder(object), 61 : SystemHolder(object), 62 49327 : _constant_option(object._constant_option), 63 49327 : _t(object._t), 64 49327 : _t_old(object._t_old), 65 49327 : _t_step(object._t_step), 66 49327 : _dt(object._dt), 67 98654 : _dt_old(object._dt_old) 68 : { 69 87859 : _element_ids = object._element_ids; 70 87859 : _element_side_ids = object._element_side_ids; 71 87859 : } 72 : 73 : void 74 2744 : MaterialBase::initializeMaterialRestrictable() 75 : { 76 2744 : if (_constant_option == PropertyConstantOption::SUBDOMAIN) 77 : { 78 102 : auto & restricted_blocks = boundaryRestricted() ? meshBlockIDs() : blockIDs(); 79 : 80 102 : std::set<ContiguousElementID> element_ids; 81 : 82 408 : for (auto block : restricted_blocks) 83 : { 84 306 : auto first_elem = *_mesh.getKokkosMesh()->getSubdomainContiguousElementIDRange(block).begin(); 85 306 : if (first_elem != libMesh::DofObject::invalid_id) 86 252 : element_ids.insert(first_elem); 87 : } 88 : 89 102 : _element_ids = element_ids; 90 102 : } 91 2642 : else if (materialDataType() == Moose::BLOCK_MATERIAL_DATA) 92 : { 93 875 : std::set<ContiguousElementID> element_ids; 94 : 95 2124 : for (auto block : blockIDs()) 96 1249 : element_ids.insert(_mesh.getKokkosMesh()->getSubdomainContiguousElementIDRange(block).begin(), 97 1414 : _mesh.getKokkosMesh()->getSubdomainContiguousElementIDRange(block).end()); 98 : 99 875 : _element_ids = element_ids; 100 875 : } 101 : else 102 : { 103 1767 : auto & restricted_blocks = boundaryRestricted() ? meshBlockIDs() : blockIDs(); 104 1767 : auto & restricted_boundaries = boundaryRestricted() ? boundaryIDs() : meshBoundaryIDs(); 105 1767 : auto & material_boundaries = kokkosAssembly().getMaterialBoundaries(); 106 : 107 1767 : std::vector<BoundaryID> boundaries; 108 : 109 1767 : std::set_intersection(restricted_boundaries.begin(), 110 : restricted_boundaries.end(), 111 : material_boundaries.begin(), 112 : material_boundaries.end(), 113 : std::back_inserter(boundaries)); 114 : 115 1767 : std::set<Pair<ContiguousElementID, unsigned int>> element_side_ids; 116 : 117 2024 : for (auto boundary : boundaries) 118 2727 : for (auto elem_id : _mesh.getBoundaryActiveSemiLocalElemIds(boundary)) 119 : { 120 2470 : const auto elem = _mesh.elemPtr(elem_id); 121 : 122 3740 : if (elem->processor_id() == processor_id() && 123 2722 : restricted_blocks.find(elem->subdomain_id()) != restricted_blocks.end()) 124 3400 : element_side_ids.insert({_mesh.getKokkosMesh()->getContiguousElementID(elem), 125 1270 : _mesh.sideWithBoundaryID(elem, boundary)}); 126 257 : } 127 : 128 1767 : _element_side_ids = element_side_ids; 129 1767 : } 130 2744 : } 131 : 132 : } // namespace Moose::Kokkos