moose icon indicating copy to clipboard operation
moose copied to clipboard

getMaterialPropertyOld marks the property as regular

Open hugary1995 opened this issue 3 years ago • 7 comments

Bug Description

I have an object A that retrieves an old material property in its initialization list

_strain_old(getMaterialPropertyOldByName<RankTwoTensor>("total_strain"))

and an object B that declares an AD material property as

_total_strain(declareADProperty<RankTwoTensor>("total_strain"))

Then I get an error message like this

*** ERROR ***
Attempting to declare AD material property total_strain, but it is already retrieved/declared as a regular material property.

Steps to Reproduce

A MWE here.

Impact

This bug leads to errors that are construction order dependent.

hugary1995 avatar Oct 15 '21 03:10 hugary1995

To elaborate a bit more, if the first call involving a material property is just getting the old state, MOOSE sets up the property as non-AD. There is not much else that could be done within the current design, as the getMaterialPropertyOld calls do not distinguish between AD and non-AD.

If any of the AD/non-AD specific calls (like declareProperty/declareADProperty or getMaterialProperty/getADMaterialProperty) happen first, then MOOSE knows what flavor to set the property up as. And the successive getMaterialPropertyOld call will just fetch whatever flavor already exists.

dschwen avatar Oct 15 '21 15:10 dschwen

Ok, @simopier just ran into this issue again. We might have to update that API to include an is_ad template parameter (getGenericmaterialPropertyOld?). Or did you find a workaround?

dschwen avatar Mar 11 '24 21:03 dschwen

No, the requestor cannot possibly know whether the current state of the property needs to be AD or non-AD. Fetching an old state just cannot trigger the creation of a material property. This is going to be tough to resolve.

dschwen avatar Mar 11 '24 21:03 dschwen

No, the requestor cannot possibly know whether the current state of the property needs to be AD or non-AD. Fetching an old state just cannot trigger the creation of a material property. This is going to be tough to resolve.

It might not be appropriate all the time, but could we assume that the current state of material property is the same type (AD or non-AD) as the material properties that the requestor would create?

Meaning, using the case above, object A would assume that object B would have the same type as object A. This is basically what it currently does anyway, but only for the non-AD case.

simopier avatar Mar 11 '24 22:03 simopier

Or did you find a workaround?

I didn't find any workaround.

hugary1995 avatar Mar 11 '24 23:03 hugary1995

No, the requestor cannot possibly know whether the current state of the property needs to be AD or non-AD. Fetching an old state just cannot trigger the creation of a material property. This is going to be tough to resolve.

One design is to queue all the stateful requestors and wait to process all of them at the very end of the construction phase. That's the easiest solution I can think of at the moment.

hugary1995 avatar Mar 11 '24 23:03 hugary1995

What is this object A, a material? When using actions to add the object, developers will have control on when to add the user object but not always by MOOSE input syntax. In Griffin, we have a new task like add_aux_materials, which happens after add_materials and actions add some auxiliary materials after materials added through MOOSE syntax.

YaqiWang avatar Mar 12 '24 00:03 YaqiWang

OK, after a quick discussion with @loganharbour we came up with a way forward that I'll implement.

dschwen avatar Mar 13 '24 16:03 dschwen

I look forward to seeing it

lindsayad avatar Mar 13 '24 16:03 lindsayad