LCOV - code coverage report
Current view: top level - src/materials - MaterialBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 101 116 87.1 %
Date: 2025-08-08 20:01:16 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     2134968 : MaterialBase::validParams()
      22             : {
      23             : 
      24     2134968 :   InputParameters params = MooseObject::validParams();
      25     2134968 :   params += BlockRestrictable::validParams();
      26     2134968 :   params += BoundaryRestrictable::validParams();
      27     2134968 :   params += TransientInterface::validParams();
      28     2134968 :   params += RandomInterface::validParams();
      29     2134968 :   params += ADFunctorInterface::validParams();
      30             : 
      31     6404904 :   params.addParam<bool>("use_displaced_mesh",
      32     4269936 :                         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     6404904 :   params.addParam<bool>("compute",
      39     4269936 :                         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     2134968 :   params.addPrivateParam<bool>("_neighbor", false);
      46     2134968 :   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     2134968 :   params.addPrivateParam<bool>("_force_stateful_init", false);
      52             : 
      53             :   // Outputs
      54     2134968 :   params += OutputInterface::validParams();
      55     4269936 :   params.set<std::vector<OutputName>>("outputs") = {"none"};
      56     2134968 :   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     2134968 :   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     2134968 :   params.declareControllable("enable");
      69             : 
      70     2134968 :   params.addParamNamesToGroup("outputs output_properties", "Outputs");
      71     2134968 :   params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
      72     2134968 :   params.registerBase("MaterialBase");
      73     2134968 :   return params;
      74     2134968 : }
      75             : 
      76       36606 : 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       73212 :                     *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
      97       36606 :                     parameters.get<THREAD_ID>("_tid"),
      98             :                     false),
      99             :     ElementIDInterface(this),
     100             :     GeometricSearchInterface(this),
     101             :     ADFunctorInterface(this),
     102             :     SolutionInvalidInterface(this),
     103       36606 :     _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
     104       36606 :     _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
     105       36606 :     _tid(parameters.get<THREAD_ID>("_tid")),
     106       36606 :     _assembly(_subproblem.assembly(_tid, 0)),
     107       36606 :     _qp(std::numeric_limits<unsigned int>::max()),
     108       36606 :     _coord(_assembly.coordTransformation()),
     109       36606 :     _normals(_assembly.normals()),
     110       36606 :     _mesh(_subproblem.mesh()),
     111       36606 :     _coord_sys(_assembly.coordSystem()),
     112       36606 :     _compute(getParam<bool>("compute")),
     113       36606 :     _has_stateful_property(false),
     114       36606 :     _declare_suffix(getParam<MaterialPropertyName>("declare_suffix")),
     115      256242 :     _force_stateful_init(getParam<bool>("_force_stateful_init"))
     116             : {
     117       36606 : }
     118             : 
     119             : void
     120      663048 : MaterialBase::initStatefulProperties(unsigned int n_points)
     121             : {
     122     3360294 :   for (_qp = 0; _qp < n_points; ++_qp)
     123     2697246 :     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     2198634 :   for (const auto id : _supplied_prop_ids)
     130     1982340 :     if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
     131      446754 :         !_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      663048 : }
     137             : 
     138             : void
     139           0 : MaterialBase::initQpStatefulProperties()
     140             : {
     141           0 :   _overrides_init_stateful_props = false;
     142           0 : }
     143             : 
     144             : void
     145       13622 : MaterialBase::checkStatefulSanity() const
     146             : {
     147       34052 :   for (const auto & [id, min_state] : _props_to_min_states)
     148       20430 :     if (min_state > 0)
     149           0 :       mooseError("The stateful property '",
     150           0 :                  _fe_problem.getMaterialPropertyRegistry().getName(id),
     151             :                  "' is undefined");
     152       13622 : }
     153             : 
     154             : void
     155       81430 : MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
     156             : {
     157       81430 :   if (!is_get)
     158             :   {
     159       62479 :     const auto property_id = materialData().getPropertyId(prop_name);
     160             : 
     161       62479 :     _supplied_props.insert(prop_name);
     162       62479 :     _supplied_prop_ids.insert(property_id);
     163             : 
     164             :     // Store the minimum state declared
     165       62479 :     auto find_min_state = _props_to_min_states.find(property_id);
     166       62479 :     if (find_min_state == _props_to_min_states.end())
     167       62479 :       _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      129989 :     for (const auto & block_id : blockIDs())
     173       67510 :       _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
     174             : 
     175             :     // Store material properties for the boundary ids
     176      126021 :     for (const auto & boundary_id : boundaryIDs())
     177       63542 :       _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
     178             :   }
     179             : 
     180       81430 :   if (state > 0)
     181        4400 :     _has_stateful_property = true;
     182       81430 : }
     183             : 
     184             : void
     185     2465676 : MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
     186             : {
     187     2465676 :   _active_prop_ids.clear();
     188     6163798 :   for (const auto supplied_id : _supplied_prop_ids)
     189     3698122 :     if (needed_props.count(supplied_id))
     190     1785723 :       _active_prop_ids.insert(supplied_id);
     191     2465676 : }
     192             : 
     193             : std::set<OutputName>
     194       41596 : MaterialBase::getOutputs()
     195             : {
     196       41596 :   const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
     197       41596 :   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        3038 : MaterialBase::resetProperties()
     219             : {
     220       15178 :   for (_qp = 0; _qp < qRule().n_points(); ++_qp)
     221       12143 :     resetQpProperties();
     222        3035 : }
     223             : 
     224             : void
     225           3 : MaterialBase::resetQpProperties()
     226             : {
     227           3 :   if (!_compute)
     228           3 :     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           0 : }
     234             : 
     235             : void
     236      135360 : MaterialBase::computePropertiesAtQp(unsigned int qp)
     237             : {
     238      135360 :   _qp = qp;
     239      135360 :   computeQpProperties();
     240      135360 : }
     241             : 
     242             : void
     243       18951 : MaterialBase::checkExecutionStage()
     244             : {
     245       18951 :   if (_fe_problem.startedInitialSetup())
     246           0 :     mooseError("Material properties must be retrieved during material object construction to "
     247             :                "ensure correct dependency resolution.");
     248       18951 : }
     249             : 
     250             : void
     251        9522 : MaterialBase::markMatPropRequested(const std::string & name)
     252             : {
     253        9522 :   _fe_problem.markMatPropRequested(name);
     254        9522 : }
     255             : 
     256             : void
     257        9522 : MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
     258             : {
     259        9522 :   _fe_problem.storeSubdomainZeroMatProp(block_id, name);
     260        9522 : }
     261             : 
     262             : void
     263        9522 : MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
     264             : {
     265        9522 :   _fe_problem.storeBoundaryZeroMatProp(boundary_id, name);
     266        9522 : }
     267             : 
     268             : unsigned int
     269       10134 : MaterialBase::getMaxQps() const
     270             : {
     271       10134 :   return _fe_problem.getMaxQps();
     272             : }

Generated by: LCOV version 1.14