Skip to content

Commit

Permalink
Add test for differing states
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Jan 29, 2024
1 parent 797524b commit 5c13109
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
16 changes: 4 additions & 12 deletions framework/src/materials/MaterialPropertyStorage.C
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ MaterialPropertyStorage::initProps(const THREAD_ID tid,
void
dataStore(std::ostream & stream, MaterialPropertyStorage & storage, void * context)
{
const auto num_states = storage.numStates();
dataStore(stream, num_states, nullptr);

// Store the material property ID -> name map for mapping back
const auto & registry = storage.getMaterialPropertyRegistry();
std::vector<std::string> ids_to_names(registry.idsToNamesBegin(), registry.idsToNamesEnd());
Expand Down Expand Up @@ -514,15 +511,6 @@ dataLoad(std::istream & stream, MaterialPropertyStorage & storage, void * contex

const auto & registry = storage.getMaterialPropertyRegistry();

decltype(storage.numStates()) num_states;
dataLoad(stream, num_states, nullptr);
if (num_states != storage.numStates())
mooseError("Stateful material properties up to state ",
num_states,
" were stored in checkpoint/backup,\nbut state ",
storage.numStates(),
" is now the maximum state requested.\n\nThis mismatch is not currently supported.");

std::vector<std::string> from_prop_ids_to_names;
dataLoad(stream, from_prop_ids_to_names, nullptr);

Expand Down Expand Up @@ -649,6 +637,10 @@ dataLoad(std::istream & stream, MaterialPropertyStorage & storage, void * contex
mooseError("The type for the restarted stateful material property '",
name,
"' in does not match");

// I'm not sure if we need to enforce this one, but I don't want to think
// about it deeply so we'll just make it an error until someone complains
// we have time to think
if (from_record.state != to_record.state)
mooseError("The number of states for the restarted stateful material property '",
name,
Expand Down
6 changes: 5 additions & 1 deletion test/src/materials/RestartStatefulMaterial.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ RestartStatefulMaterial::validParams()
params.addParam<std::vector<Real>>(
"real_values", {}, "The values to set for the real properties");
params.addParam<std::vector<std::string>>(
"real_stateful_names", {}, "The name of the real properties to request as stateful");
"real_stateful_names", {}, "The name of the real properties to request as old");
params.addParam<std::vector<std::string>>(
"real_older_stateful_names", {}, "The name of the real properties to request as older");
params.addParam<std::vector<std::string>>(
"int_names", {}, "The name of the int properties to declare");
return params;
Expand All @@ -37,6 +39,8 @@ RestartStatefulMaterial::RestartStatefulMaterial(const InputParameters & paramet
declareProperty<Real>(name);
for (const auto & name : getParam<std::vector<std::string>>("real_stateful_names"))
getMaterialPropertyOld<Real>(name);
for (const auto & name : getParam<std::vector<std::string>>("real_older_stateful_names"))
getMaterialPropertyOlder<Real>(name);
for (const auto & name : getParam<std::vector<std::string>>("int_names"))
{
declareProperty<int>(name);
Expand Down
8 changes: 8 additions & 0 deletions test/tests/restart/advanced_stateful_material/tests
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@
prereq = checkpoint
detail = 'the type of a restored stateful property has changed'
[]
[different_state]
type = RunException
input = 'advanced_stateful_material_restart.i'
cli_args = "Materials/test/real_older_stateful_names='a'"
expect_err = 'The number of states for the restarted stateful material property \'a\' do not match.'
prereq = checkpoint
detail = 'the requested state of a restored stateful property has changed'
[]
[]
[]

0 comments on commit 5c13109

Please sign in to comment.