LCOV - code coverage report
Current view: top level - src/materials - MaterialPropertyInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 1f9d31 Lines: 111 122 91.0 %
Date: 2025-09-02 20:01:20 Functions: 17 20 85.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             : // MOOSE includes
      11             : #include "MaterialPropertyInterface.h"
      12             : #include "MooseApp.h"
      13             : #include "MaterialBase.h"
      14             : #include "FEProblemBase.h"
      15             : 
      16             : const std::string MaterialPropertyInterface::_interpolated_old = "_interpolated_old";
      17             : const std::string MaterialPropertyInterface::_interpolated_older = "_interpolated_older";
      18             : 
      19             : InputParameters
      20    15731135 : MaterialPropertyInterface::validParams()
      21             : {
      22    15731135 :   InputParameters params = emptyInputParameters();
      23    31462270 :   params.addPrivateParam<Moose::MaterialDataType>(
      24             :       "_material_data_type"); // optionally force the type of MaterialData to utilize
      25    62924540 :   params.addParam<MaterialPropertyName>("prop_getter_suffix",
      26             :                                         "",
      27             :                                         "An optional suffix parameter that can be appended to any "
      28             :                                         "attempt to retrieve/get material properties. The suffix "
      29             :                                         "will be prepended with a '_' character.");
      30    47193405 :   params.addParam<bool>(
      31             :       "use_interpolated_state",
      32    31462270 :       false,
      33             :       "For the old and older state use projected material properties interpolated at the "
      34             :       "quadrature points. To set up projection use the ProjectedStatefulMaterialStorageAction.");
      35    47193405 :   params.addParamNamesToGroup("use_interpolated_state prop_getter_suffix",
      36             :                               "Material property retrieval");
      37             : 
      38    15731135 :   return params;
      39           0 : }
      40             : 
      41             : namespace moose
      42             : {
      43             : namespace internal
      44             : {
      45             : bool
      46      643917 : boundaryRestricted(const std::set<BoundaryID> & boundary_ids)
      47             : {
      48      643917 :   return !boundary_ids.empty() && BoundaryRestrictable::restricted(boundary_ids);
      49             : }
      50             : }
      51             : }
      52             : 
      53      345065 : MaterialPropertyInterface::MaterialPropertyInterface(const MooseObject * moose_object,
      54             :                                                      const std::set<SubdomainID> & block_ids,
      55      345065 :                                                      const std::set<BoundaryID> & boundary_ids)
      56      345065 :   : _mi_moose_object(*moose_object),
      57      690130 :     _mi_params(_mi_moose_object.parameters()),
      58      345065 :     _mi_name(moose_object->name()),
      59      690130 :     _mi_moose_object_name(_mi_moose_object.getBase(), _mi_name, "::"),
      60     1380260 :     _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
      61     1380260 :     _mi_subproblem(*_mi_params.getCheckedPointerParam<SubProblem *>("_subproblem")),
      62      345065 :     _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
      63      345065 :     _material_data_type(getMaterialDataType(boundary_ids)),
      64      345065 :     _material_data(_mi_feproblem.getMaterialData(_material_data_type, _mi_tid)),
      65      345065 :     _stateful_allowed(true),
      66      345065 :     _get_material_property_called(false),
      67      345065 :     _get_suffix(_mi_params.get<MaterialPropertyName>("prop_getter_suffix")),
      68      345065 :     _use_interpolated_state(_mi_params.get<bool>("use_interpolated_state")),
      69      345065 :     _mi_boundary_restricted(moose::internal::boundaryRestricted(boundary_ids)),
      70      345065 :     _mi_block_ids(block_ids),
      71     1035195 :     _mi_boundary_ids(boundary_ids)
      72             : {
      73      345065 :   moose_object->getMooseApp().registerInterfaceObject(*this);
      74      345065 : }
      75             : 
      76             : MaterialPropertyName
      77       82626 : MaterialPropertyInterface::getMaterialPropertyName(const std::string & name) const
      78             : {
      79       82626 :   if (_mi_params.have_parameter<MaterialPropertyName>(name) && _mi_params.isParamValid(name))
      80       65238 :     return _mi_params.get<MaterialPropertyName>(name);
      81       17388 :   return name;
      82             : }
      83             : 
      84             : std::set<SubdomainID>
      85           0 : MaterialPropertyInterface::getMaterialPropertyBlocks(const std::string & name)
      86             : {
      87           0 :   return _mi_feproblem.getMaterialPropertyBlocks(name);
      88             : }
      89             : 
      90             : std::vector<SubdomainName>
      91           8 : MaterialPropertyInterface::getMaterialPropertyBlockNames(const std::string & name)
      92             : {
      93           8 :   return _mi_feproblem.getMaterialPropertyBlockNames(name);
      94             : }
      95             : 
      96             : std::set<BoundaryID>
      97           0 : MaterialPropertyInterface::getMaterialPropertyBoundaryIDs(const std::string & name)
      98             : {
      99           0 :   return _mi_feproblem.getMaterialPropertyBoundaryIDs(name);
     100             : }
     101             : 
     102             : std::vector<BoundaryName>
     103           8 : MaterialPropertyInterface::getMaterialPropertyBoundaryNames(const std::string & name)
     104             : {
     105           8 :   return _mi_feproblem.getMaterialPropertyBoundaryNames(name);
     106             : }
     107             : 
     108             : unsigned int
     109        2077 : MaterialPropertyInterface::getMaxQps() const
     110             : {
     111        2077 :   return _mi_feproblem.getMaxQps();
     112             : }
     113             : 
     114             : void
     115       50608 : MaterialPropertyInterface::addConsumedPropertyName(const MooseObjectName & obj_name,
     116             :                                                    const std::string & prop_name)
     117             : {
     118       50608 :   return _mi_feproblem.addConsumedPropertyName(obj_name, prop_name);
     119             : }
     120             : 
     121             : void
     122       49954 : MaterialPropertyInterface::checkMaterialProperty(const std::string & name, const unsigned int state)
     123             : {
     124       49954 :   if (state == 0)
     125             :   {
     126             :     // If the material property is boundary restrictable, add to the list of materials to check
     127       47684 :     if (_mi_boundary_restricted)
     128       10090 :       for (const auto & bnd_id : _mi_boundary_ids)
     129        6267 :         _mi_feproblem.storeBoundaryDelayedCheckMatProp(_mi_name, bnd_id, name);
     130             : 
     131             :     // The default is to assume block restrictions
     132             :     else
     133       89856 :       for (const auto & blk_ids : _mi_block_ids)
     134       45995 :         _mi_feproblem.storeSubdomainDelayedCheckMatProp(_mi_name, blk_ids, name);
     135             :   }
     136       49954 : }
     137             : 
     138             : void
     139       55308 : MaterialPropertyInterface::markMatPropRequested(const std::string & name)
     140             : {
     141       55308 :   _mi_feproblem.markMatPropRequested(name);
     142       55308 : }
     143             : 
     144             : void
     145        1998 : MaterialPropertyInterface::statefulPropertiesAllowed(bool stateful_allowed)
     146             : {
     147        1998 :   _stateful_allowed = stateful_allowed;
     148        1998 : }
     149             : 
     150             : void
     151         268 : MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
     152             :     std::shared_ptr<MaterialBase> discrete)
     153             : {
     154             :   // Check block compatibility
     155         268 :   if (!discrete->hasBlocks(_mi_block_ids))
     156             :   {
     157           4 :     std::ostringstream oss;
     158           4 :     oss << "Incompatible material and object blocks:";
     159             : 
     160          12 :     oss << "\n    " << discrete->parameters().paramLocationPrefix("block")
     161           8 :         << " material defined on blocks ";
     162           8 :     for (const auto & sbd_id : discrete->blockIDs())
     163           4 :       oss << sbd_id << ", ";
     164             : 
     165           8 :     oss << "\n    " << _mi_params.paramLocationPrefix("block")
     166           8 :         << " object needs material on blocks ";
     167          12 :     for (const auto & block_id : _mi_block_ids)
     168           8 :       oss << block_id << ", ";
     169             : 
     170           4 :     mooseError(oss.str());
     171           0 :   }
     172             : 
     173             :   // Check boundary compatibility
     174         264 :   if (!discrete->hasBoundary(_mi_boundary_ids))
     175             :   {
     176           4 :     std::ostringstream oss;
     177           4 :     oss << "Incompatible material and object boundaries:";
     178             : 
     179          12 :     oss << "\n    " << discrete->parameters().paramLocationPrefix("boundary")
     180           8 :         << " material defined on boundaries ";
     181           8 :     for (const auto & bnd_id : discrete->boundaryIDs())
     182           4 :       oss << bnd_id << ", ";
     183             : 
     184           8 :     oss << "\n    " << _mi_params.paramLocationPrefix("boundary")
     185           8 :         << " object needs material on boundaries ";
     186          12 :     for (const auto & bnd_id : _mi_boundary_ids)
     187           8 :       oss << bnd_id << ", ";
     188             : 
     189           4 :     mooseError(oss.str());
     190           0 :   }
     191         260 : }
     192             : 
     193             : MaterialBase &
     194           0 : MaterialPropertyInterface::getMaterial(const std::string & name)
     195             : {
     196           0 :   return getMaterialByName(_mi_params.get<MaterialName>(name));
     197             : }
     198             : 
     199             : MaterialBase &
     200         276 : MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
     201             : {
     202             :   std::shared_ptr<MaterialBase> discrete =
     203         276 :       _mi_feproblem.getMaterial(name, _material_data_type, _mi_tid, no_warn);
     204             : 
     205         268 :   checkBlockAndBoundaryCompatibility(discrete);
     206         520 :   return *discrete;
     207         260 : }
     208             : 
     209             : std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
     210        2688 : MaterialPropertyInterface::buildRequiredMaterials(bool allow_stateful)
     211             : {
     212        2688 :   std::unordered_map<SubdomainID, std::vector<MaterialBase *>> required_mats;
     213        2688 :   const auto & mwh = _mi_feproblem.getMaterialWarehouse();
     214        5376 :   for (const auto id : _mi_block_ids)
     215             :   {
     216        2688 :     const auto & mats = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
     217        2688 :     std::array<const MaterialPropertyInterface *, 1> consumers = {{this}};
     218             :     const auto block_required =
     219        2688 :         MaterialBase::buildRequiredMaterials(consumers, mats, allow_stateful);
     220        5376 :     required_mats[id].insert(
     221        2688 :         required_mats[id].begin(), block_required.begin(), block_required.end());
     222        2688 :   }
     223        2688 :   return required_mats;
     224           0 : }
     225             : 
     226             : void
     227       55308 : MaterialPropertyInterface::checkExecutionStage()
     228             : {
     229       55308 :   if (_mi_feproblem.startedInitialSetup())
     230           0 :     mooseError("Material properties must be retrieved during object construction. This is a code "
     231             :                "problem.");
     232       55308 : }
     233             : 
     234             : void
     235      304488 : MaterialPropertyInterface::resolveOptionalProperties()
     236             : {
     237      305472 :   for (auto & proxy : _optional_property_proxies)
     238         984 :     proxy->resolve(*this);
     239      304488 : }
     240             : 
     241             : Moose::MaterialDataType
     242      345065 : MaterialPropertyInterface::getMaterialDataType(const std::set<BoundaryID> & boundary_ids) const
     243             : {
     244     1035195 :   if (_mi_params.isParamValid("_material_data_type"))
     245       46213 :     return _mi_params.get<Moose::MaterialDataType>("_material_data_type");
     246      298852 :   if (moose::internal::boundaryRestricted(boundary_ids))
     247       21441 :     return Moose::BOUNDARY_MATERIAL_DATA;
     248      277411 :   return Moose::BLOCK_MATERIAL_DATA;
     249             : }

Generated by: LCOV version 1.14