LCOV - code coverage report
Current view: top level - src/materials - MaterialBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 1f9d31 Lines: 102 116 87.9 %
Date: 2025-09-02 20:01:20 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     2165365 : MaterialBase::validParams()
      22             : {
      23             : 
      24     2165365 :   InputParameters params = MooseObject::validParams();
      25     2165365 :   params += BlockRestrictable::validParams();
      26     2165365 :   params += BoundaryRestrictable::validParams();
      27     2165365 :   params += TransientInterface::validParams();
      28     2165365 :   params += RandomInterface::validParams();
      29     2165365 :   params += ADFunctorInterface::validParams();
      30             : 
      31     6496095 :   params.addParam<bool>("use_displaced_mesh",
      32     4330730 :                         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     4330730 :   params.addParam<bool>("compute",
      39     4330730 :                         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     4330730 :   params.addPrivateParam<bool>("_neighbor", false);
      46     4330730 :   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     4330730 :   params.addPrivateParam<bool>("_force_stateful_init", false);
      52             : 
      53             :   // Outputs
      54     2165365 :   params += OutputInterface::validParams();
      55     6496095 :   params.set<std::vector<OutputName>>("outputs") = {"none"};
      56     8661460 :   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     6496095 :   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     6496095 :   params.declareControllable("enable");
      69             : 
      70     8661460 :   params.addParamNamesToGroup("outputs output_properties", "Outputs");
      71     8661460 :   params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
      72     2165365 :   params.registerBase("MaterialBase");
      73     2165365 :   return params;
      74     2165365 : }
      75             : 
      76       37974 : 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      151896 :                     *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
      97       37974 :                     parameters.get<THREAD_ID>("_tid"),
      98             :                     false),
      99             :     ElementIDInterface(this),
     100             :     GeometricSearchInterface(this),
     101             :     ADFunctorInterface(this),
     102             :     SolutionInvalidInterface(this),
     103      113922 :     _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
     104      151896 :     _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
     105       37974 :     _tid(parameters.get<THREAD_ID>("_tid")),
     106       37974 :     _assembly(_subproblem.assembly(_tid, 0)),
     107       37974 :     _qp(std::numeric_limits<unsigned int>::max()),
     108       37974 :     _coord(_assembly.coordTransformation()),
     109       37974 :     _normals(_assembly.normals()),
     110       37974 :     _mesh(_subproblem.mesh()),
     111       37974 :     _coord_sys(_assembly.coordSystem()),
     112       75948 :     _compute(getParam<bool>("compute")),
     113       37974 :     _has_stateful_property(false),
     114       37974 :     _declare_suffix(getParam<MaterialPropertyName>("declare_suffix")),
     115      379740 :     _force_stateful_init(getParam<bool>("_force_stateful_init"))
     116             : {
     117       37974 : }
     118             : 
     119             : void
     120      663348 : MaterialBase::initStatefulProperties(unsigned int n_points)
     121             : {
     122     3360894 :   for (_qp = 0; _qp < n_points; ++_qp)
     123     2697546 :     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     2199234 :   for (const auto id : _supplied_prop_ids)
     130     1982940 :     if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
     131      447054 :         !_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      663348 : }
     137             : 
     138             : void
     139           0 : MaterialBase::initQpStatefulProperties()
     140             : {
     141           0 :   _overrides_init_stateful_props = false;
     142           0 : }
     143             : 
     144             : void
     145       14121 : MaterialBase::checkStatefulSanity() const
     146             : {
     147       34918 :   for (const auto & [id, min_state] : _props_to_min_states)
     148       20797 :     if (min_state > 0)
     149           0 :       mooseError("The stateful property '",
     150           0 :                  _fe_problem.getMaterialPropertyRegistry().getName(id),
     151             :                  "' is undefined");
     152       14121 : }
     153             : 
     154             : void
     155       82726 : MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
     156             : {
     157       82726 :   if (!is_get)
     158             :   {
     159       63703 :     const auto property_id = materialData().getPropertyId(prop_name);
     160             : 
     161       63703 :     _supplied_props.insert(prop_name);
     162       63703 :     _supplied_prop_ids.insert(property_id);
     163             : 
     164             :     // Store the minimum state declared
     165       63703 :     auto find_min_state = _props_to_min_states.find(property_id);
     166       63703 :     if (find_min_state == _props_to_min_states.end())
     167       63703 :       _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      132479 :     for (const auto & block_id : blockIDs())
     173       68776 :       _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
     174             : 
     175             :     // Store material properties for the boundary ids
     176      128469 :     for (const auto & boundary_id : boundaryIDs())
     177       64766 :       _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
     178             :   }
     179             : 
     180       82726 :   if (state > 0)
     181        4436 :     _has_stateful_property = true;
     182       82726 : }
     183             : 
     184             : void
     185     3043815 : MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
     186             : {
     187     3043815 :   _active_prop_ids.clear();
     188     7316371 :   for (const auto supplied_id : _supplied_prop_ids)
     189     4272556 :     if (needed_props.count(supplied_id))
     190     2054946 :       _active_prop_ids.insert(supplied_id);
     191     3043815 : }
     192             : 
     193             : std::set<OutputName>
     194       43093 : MaterialBase::getOutputs()
     195             : {
     196       86186 :   const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
     197       43093 :   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        3089 : MaterialBase::resetProperties()
     219             : {
     220       15429 :   for (_qp = 0; _qp < qRule().n_points(); ++_qp)
     221       12344 :     resetQpProperties();
     222        3085 : }
     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      135360 : MaterialBase::computePropertiesAtQp(unsigned int qp)
     237             : {
     238      135360 :   _qp = qp;
     239      135360 :   computeQpProperties();
     240      135360 : }
     241             : 
     242             : void
     243       19023 : MaterialBase::checkExecutionStage()
     244             : {
     245       19023 :   if (_fe_problem.startedInitialSetup())
     246           0 :     mooseError("Material properties must be retrieved during material object construction to "
     247             :                "ensure correct dependency resolution.");
     248       19023 : }
     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