LCOV - code coverage report
Current view: top level - src/materials - MaterialBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 102 116 87.9 %
Date: 2025-07-17 01:28:37 Functions: 15 19 78.9 %
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 "MaterialBase.h"
      12             : #include "MaterialPropertyStorage.h"
      13             : #include "FEProblemBase.h"
      14             : #include "Assembly.h"
      15             : #include "Executioner.h"
      16             : #include "Transient.h"
      17             : 
      18             : #include "libmesh/quadrature.h"
      19             : 
      20             : InputParameters
      21     2131702 : MaterialBase::validParams()
      22             : {
      23             : 
      24     2131702 :   InputParameters params = MooseObject::validParams();
      25     2131702 :   params += BlockRestrictable::validParams();
      26     2131702 :   params += BoundaryRestrictable::validParams();
      27     2131702 :   params += TransientInterface::validParams();
      28     2131702 :   params += RandomInterface::validParams();
      29     2131702 :   params += ADFunctorInterface::validParams();
      30             : 
      31     6395106 :   params.addParam<bool>("use_displaced_mesh",
      32     4263404 :                         false,
      33             :                         "Whether or not this object should use the "
      34             :                         "displaced mesh for computation.  Note that "
      35             :                         "in the case this is true but no "
      36             :                         "displacements are provided in the Mesh block "
      37             :                         "the undisplaced mesh will still be used.");
      38     6395106 :   params.addParam<bool>("compute",
      39     4263404 :                         true,
      40             :                         "When false, MOOSE will not call compute methods on this material. "
      41             :                         "The user must call computeProperties() after retrieving the MaterialBase "
      42             :                         "via MaterialBasePropertyInterface::getMaterialBase(). "
      43             :                         "Non-computed MaterialBases are not sorted for dependencies.");
      44             : 
      45     2131702 :   params.addPrivateParam<bool>("_neighbor", false);
      46     2131702 :   params.addPrivateParam<bool>("_interface", false);
      47             : 
      48             :   // Forces the calling of initStatefulProperties() even when this material
      49             :   // does not declare any properties that are stateful. Right now,
      50             :   // this is only used for porous_flow... pretty please keep it that way?
      51     2131702 :   params.addPrivateParam<bool>("_force_stateful_init", false);
      52             : 
      53             :   // Outputs
      54     2131702 :   params += OutputInterface::validParams();
      55     4263404 :   params.set<std::vector<OutputName>>("outputs") = {"none"};
      56     2131702 :   params.addParam<std::vector<std::string>>(
      57             :       "output_properties",
      58             :       {},
      59             :       "List of material properties, from this material, to output (outputs "
      60             :       "must also be defined to an output type)");
      61     2131702 :   params.addParam<MaterialPropertyName>(
      62             :       "declare_suffix",
      63             :       "",
      64             :       "An optional suffix parameter that can be appended to any declared properties. The suffix "
      65             :       "will be prepended with a '_' character.");
      66             : 
      67             :   // Allow Material objects to be enabled/disabled by Control objects
      68     2131702 :   params.declareControllable("enable");
      69             : 
      70     2131702 :   params.addParamNamesToGroup("outputs output_properties", "Outputs");
      71     2131702 :   params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
      72     2131702 :   params.registerBase("MaterialBase");
      73     2131702 :   return params;
      74     2131702 : }
      75             : 
      76       34344 : MaterialBase::MaterialBase(const InputParameters & parameters)
      77             :   : MooseObject(parameters),
      78             :     BlockRestrictable(this),
      79             :     BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
      80             :     SetupInterface(this),
      81             :     MooseVariableDependencyInterface(this),
      82             :     ScalarCoupleable(this),
      83             :     FunctionInterface(this),
      84             :     DistributionInterface(this),
      85             :     UserObjectInterface(this),
      86             :     TransientInterface(this),
      87             :     PostprocessorInterface(this),
      88             :     VectorPostprocessorInterface(this),
      89             :     DependencyResolverInterface(),
      90             :     Restartable(this, "MaterialBases"),
      91             :     MeshChangedInterface(parameters),
      92             :     // The false flag disables the automatic call buildOutputVariableHideList;
      93             :     // for MaterialBase objects the hide lists are handled by MaterialBaseOutputAction
      94             :     OutputInterface(parameters, false),
      95             :     RandomInterface(parameters,
      96       68688 :                     *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
      97       34344 :                     parameters.get<THREAD_ID>("_tid"),
      98             :                     false),
      99             :     ElementIDInterface(this),
     100             :     GeometricSearchInterface(this),
     101             :     ADFunctorInterface(this),
     102             :     SolutionInvalidInterface(this),
     103       34344 :     _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
     104       34344 :     _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
     105       34344 :     _tid(parameters.get<THREAD_ID>("_tid")),
     106       34344 :     _assembly(_subproblem.assembly(_tid, 0)),
     107       34344 :     _qp(std::numeric_limits<unsigned int>::max()),
     108       34344 :     _coord(_assembly.coordTransformation()),
     109       34344 :     _normals(_assembly.normals()),
     110       34344 :     _mesh(_subproblem.mesh()),
     111       34344 :     _coord_sys(_assembly.coordSystem()),
     112       34344 :     _compute(getParam<bool>("compute")),
     113       34344 :     _has_stateful_property(false),
     114       34344 :     _declare_suffix(getParam<MaterialPropertyName>("declare_suffix")),
     115      240408 :     _force_stateful_init(getParam<bool>("_force_stateful_init"))
     116             : {
     117       34344 : }
     118             : 
     119             : void
     120      589548 : MaterialBase::initStatefulProperties(unsigned int n_points)
     121             : {
     122     2987456 :   for (_qp = 0; _qp < n_points; ++_qp)
     123     2397908 :     initQpStatefulProperties();
     124             : 
     125             :   // checking for statefulness of properties via this loop is necessary
     126             :   // because owned props might have been promoted to stateful by calls to
     127             :   // getMaterialProperty[Old/Older] from other objects.  In these cases, this
     128             :   // object won't otherwise know that it owns stateful properties.
     129     1954632 :   for (const auto id : _supplied_prop_ids)
     130     1762360 :     if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
     131      397276 :         !_overrides_init_stateful_props)
     132           0 :       mooseWarning(std::string("Material \"") + name() +
     133             :                    "\" provides one or more stateful "
     134             :                    "properties but initQpStatefulProperties() "
     135             :                    "was not overridden in the derived class.");
     136      589548 : }
     137             : 
     138             : void
     139           0 : MaterialBase::initQpStatefulProperties()
     140             : {
     141           0 :   _overrides_init_stateful_props = false;
     142           0 : }
     143             : 
     144             : void
     145       12621 : MaterialBase::checkStatefulSanity() const
     146             : {
     147       31632 :   for (const auto & [id, min_state] : _props_to_min_states)
     148       19011 :     if (min_state > 0)
     149           0 :       mooseError("The stateful property '",
     150           0 :                  _fe_problem.getMaterialPropertyRegistry().getName(id),
     151             :                  "' is undefined");
     152       12621 : }
     153             : 
     154             : void
     155       76276 : MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
     156             : {
     157       76276 :   if (!is_get)
     158             :   {
     159       58673 :     const auto property_id = materialData().getPropertyId(prop_name);
     160             : 
     161       58673 :     _supplied_props.insert(prop_name);
     162       58673 :     _supplied_prop_ids.insert(property_id);
     163             : 
     164             :     // Store the minimum state declared
     165       58673 :     auto find_min_state = _props_to_min_states.find(property_id);
     166       58673 :     if (find_min_state == _props_to_min_states.end())
     167       58673 :       _props_to_min_states.emplace(property_id, state);
     168             :     else
     169           0 :       find_min_state->second = std::min(find_min_state->second, state);
     170             : 
     171             :     // Store material properties for block ids
     172      122061 :     for (const auto & block_id : blockIDs())
     173       63388 :       _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
     174             : 
     175             :     // Store material properties for the boundary ids
     176      118340 :     for (const auto & boundary_id : boundaryIDs())
     177       59667 :       _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
     178             :   }
     179             : 
     180       76276 :   if (state > 0)
     181        4104 :     _has_stateful_property = true;
     182       76276 : }
     183             : 
     184             : void
     185     2305887 : MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
     186             : {
     187     2305887 :   _active_prop_ids.clear();
     188     5752718 :   for (const auto supplied_id : _supplied_prop_ids)
     189     3446831 :     if (needed_props.count(supplied_id))
     190     1687563 :       _active_prop_ids.insert(supplied_id);
     191     2305887 : }
     192             : 
     193             : std::set<OutputName>
     194       38591 : MaterialBase::getOutputs()
     195             : {
     196       38591 :   const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
     197       38591 :   return std::set<OutputName>(out.begin(), out.end());
     198             : }
     199             : 
     200             : void
     201           0 : MaterialBase::subdomainSetup()
     202             : {
     203           0 :   mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
     204             : }
     205             : 
     206             : void
     207           0 : MaterialBase::computeProperties()
     208             : {
     209           0 :   mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
     210             : }
     211             : 
     212             : void
     213           0 : MaterialBase::computeQpProperties()
     214             : {
     215           0 : }
     216             : 
     217             : void
     218        2749 : MaterialBase::resetProperties()
     219             : {
     220       13729 :   for (_qp = 0; _qp < qRule().n_points(); ++_qp)
     221       10984 :     resetQpProperties();
     222        2745 : }
     223             : 
     224             : void
     225         204 : MaterialBase::resetQpProperties()
     226             : {
     227         204 :   if (!_compute)
     228         204 :     mooseDoOnce(mooseWarning("You disabled the computation of this (",
     229             :                              name(),
     230             :                              ") material by MOOSE, but have not overridden the 'resetQpProperties' "
     231             :                              "method, this can lead to unintended values being set for material "
     232             :                              "property values."));
     233         200 : }
     234             : 
     235             : void
     236      120240 : MaterialBase::computePropertiesAtQp(unsigned int qp)
     237             : {
     238      120240 :   _qp = qp;
     239      120240 :   computeQpProperties();
     240      120240 : }
     241             : 
     242             : void
     243       17603 : MaterialBase::checkExecutionStage()
     244             : {
     245       17603 :   if (_fe_problem.startedInitialSetup())
     246           0 :     mooseError("Material properties must be retrieved during material object construction to "
     247             :                "ensure correct dependency resolution.");
     248       17603 : }
     249             : 
     250             : void
     251        8799 : MaterialBase::markMatPropRequested(const std::string & name)
     252             : {
     253        8799 :   _fe_problem.markMatPropRequested(name);
     254        8799 : }
     255             : 
     256             : void
     257        8799 : MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
     258             : {
     259        8799 :   _fe_problem.storeSubdomainZeroMatProp(block_id, name);
     260        8799 : }
     261             : 
     262             : void
     263        8799 : MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
     264             : {
     265        8799 :   _fe_problem.storeBoundaryZeroMatProp(boundary_id, name);
     266        8799 : }
     267             : 
     268             : unsigned int
     269        9375 : MaterialBase::getMaxQps() const
     270             : {
     271        9375 :   return _fe_problem.getMaxQps();
     272             : }

Generated by: LCOV version 1.14