You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hasMaterialProperty depends on order in the input file #13890
When hasMaterialProperty is used in the InputParameters in a material, the ordering of the input file on whether the material will be found or not. Strangely, getDefaultMaterialProperty from DerivativeMaterialInterface does not have a problem with the ordering, I think because it uses haveMaterialProperty instead of hasMaterialProperty. getDefaultMaterialProperty seems like a useful function and should maybe be in MaterialPropertyInterface so it can be more readily used (e.g. #13876). But really, hasMaterialProperty shouldn't be dependent on input file ordering.
Steps to Reproduce
See associated PR with test code that reproduces this issue.
Impact
This prevents robust checking for material properties.
Your description is mostly accurate but not entirely. It's not a fundamental issue with that method but more a function of how Materials work (e.g. Materials declare the material properties that they are going to provide in the constructor of the Material). There's no knowledge of what material properties are going to be available until the Material is constructed. So now when you look at the input file and see a list of Materials, how would we know which ones to construct first? Keep in mind that we don't require material properties to be published as InputParameters. So there's no real solution to this issue without overhauling the design of the Material system. We'd have to do something like make each Material publish their properties in a validParams type function to resolve this issue robustly.
So, knowing the limitations of the system, what we've done in cases like this is to move the various querying functions to initialSetup() instead. This will get you past the input file ordering issue. hasMaterialProperty is reliable when used after all materials have been constructed.
Thanks for the clarification @permcody. I get that this is a native limitation of the way things are built, it just seems like a dangerously easy mistake to make. What I don't get is how getDefaultMaterialProperty gets around this issue, maybe I'll try and dig into the codebase a bit more.
getDefaultMaterialProperty does not use hasMaterialPropery! It creates a material property that is set to the default value (if the property doesn't already exist). However it allows other materials to capture that property and claim it as their own (to fill it with computed values).
This makes it independent of construction order.
We do have flags to check if we are done with construction. I think I added this to throw an error if getMaterialProperty is used after the construction phase. We could also use it to throw an error if hasMaterialProperty is used during (or before) the construction phase.
Activity
Test showing ordering problem for hasMaterialProperty idaholab#13890
permcody commentedon Aug 14, 2019
Your description is mostly accurate but not entirely. It's not a fundamental issue with that method but more a function of how Materials work (e.g. Materials declare the material properties that they are going to provide in the constructor of the Material). There's no knowledge of what material properties are going to be available until the Material is constructed. So now when you look at the input file and see a list of Materials, how would we know which ones to construct first? Keep in mind that we don't require material properties to be published as InputParameters. So there's no real solution to this issue without overhauling the design of the Material system. We'd have to do something like make each Material publish their properties in a validParams type function to resolve this issue robustly.
So, knowing the limitations of the system, what we've done in cases like this is to move the various querying functions to
initialSetup()instead. This will get you past the input file ordering issue.hasMaterialPropertyis reliable when used after all materials have been constructed.tophmatthews commentedon Aug 15, 2019
Thanks for the clarification @permcody. I get that this is a native limitation of the way things are built, it just seems like a dangerously easy mistake to make. What I don't get is how
getDefaultMaterialPropertygets around this issue, maybe I'll try and dig into the codebase a bit more.dschwen commentedon Aug 15, 2019
✨magic✨
dschwen commentedon Aug 15, 2019
getDefaultMaterialPropertydoes not usehasMaterialPropery! It creates a material property that is set to the default value (if the property doesn't already exist). However it allows other materials to capture that property and claim it as their own (to fill it with computed values).This makes it independent of construction order.
tophmatthews commentedon Aug 15, 2019
Yup, so magic?
tophmatthews commentedon Aug 15, 2019
How about moving it to MaterialInterface?
ADStressUpdateBasedoesn't have access to it (StressUpdateBasedoes though)dschwen commentedon Aug 15, 2019
We do have flags to check if we are done with construction. I think I added this to throw an error if
getMaterialPropertyis used after the construction phase. We could also use it to throw an error ifhasMaterialPropertyis used during (or before) the construction phase.permcody commentedon Aug 15, 2019
OK all this is true if one of you guys is interested in expanding the error messages. That is reasonable. I'm not closing the issue.