Skip to content

Commit

Permalink
Fix initStatefulProps() to only run on stateful materials that aren't…
Browse files Browse the repository at this point in the history
… restarted

refs idaholab#25840
  • Loading branch information
loganharbour committed Feb 28, 2024
1 parent aabcc3d commit ffd9f3d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 128 deletions.
42 changes: 16 additions & 26 deletions framework/include/materials/MaterialPropertyStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ class MaterialPropertyStorage
*/
struct PropRecord
{
/// Whether or not this property is stateful
bool stateful() const { return state > 0; }
std::variant<const MaterialBase *, std::pair<std::string, std::string>> declarer;
/// The material names that have declared this property; used in restart when pointers are unavailable
std::set<std::pair<std::string, std::string>> declarer_type_and_names;
/// The type of this property
std::string type;
/// The stateful id in _stroage used for this property, if any
unsigned int stateful_id = invalid_uint;
/// The max state requrested for this property (0 = current, 1 = old, ...)
unsigned int state = 0;
};

Expand Down Expand Up @@ -277,11 +283,6 @@ class MaterialPropertyStorage
*/
std::optional<std::string> queryStatefulPropName(const unsigned int id) const;

/**
* @returns Whether or not the property \prop_name is stateful
*/
bool isStatefulProp(const std::string & prop_name) const;

/**
* Remove the property storage and element pointer from internal data structures
* Use this when elements are deleted so we don't end up with invalid elem pointers (for e.g.
Expand Down Expand Up @@ -340,6 +341,11 @@ class MaterialPropertyStorage
*/
void setRestartInPlace();

/**
* Get the property record associated with the material with id \p id
*/
const PropRecord & getPropRecord(const unsigned int id) const;

protected:
/// The actual storage
std::array<PropsType, MaterialData::max_state + 1> _storage;
Expand Down Expand Up @@ -407,30 +413,14 @@ class MaterialPropertyStorage
/// The threaded material data
std::vector<MaterialData> _material_data;

/**
* Helper struct for all of the data needed to load stateful property data for a
* [state, elem, side, stateful_id] combination later in time in initStatefulProps()
*
* This is needed beacuse restartable data is loaded in FEProblemBase::initialSetup()
* so early. At the point it is loaded, we have yet to call initProps() on any properties
* to setup the entries in _storage. As this data is dynamically typed, there's no way
* we know its type this early on
*/
struct RestartableEntry
{
unsigned int stateful_id;
unsigned int state;
std::size_t num_q_points;
std::stringstream data;
};

typedef std::unordered_map<std::pair<const Elem *, unsigned int>, std::vector<RestartableEntry>>
typedef std::unordered_map<std::pair<const Elem *, unsigned int>,
std::map<unsigned int, std::vector<std::stringstream>>>
RestartableMapType;

/// The restartable data to be loaded in initStatefulProps() later; see RestartableEntry
/// The restartable data to be loaded in initStatefulProps() later
RestartableMapType _restartable_map;

/// Whether or not we want to restart stateful properties in place; see RestartableEntry
/// Whether or not we want to restart stateful properties in place
bool _restart_in_place;
/// Whether or not we're recovering; enforces a one-to-one mapping of stateful properties
bool _recovering;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/materials/MaterialBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ MaterialBase::initStatefulProperties(unsigned int n_points)
// because owned props might have been promoted to stateful by calls to
// getMaterialProperty[Old/Older] from other objects. In these cases, this
// object won't otherwise know that it owns stateful properties.
for (auto & prop : _supplied_props)
if (materialData().getMaterialPropertyStorage().isStatefulProp(prop) &&
for (const auto id : _supplied_prop_ids)
if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
!_overrides_init_stateful_props)
mooseWarning(std::string("Material \"") + name() +
"\" provides one or more stateful "
Expand Down

0 comments on commit ffd9f3d

Please sign in to comment.