Skip to content

hasMaterialProperty depends on order in the input file #13890

Open

Description

@tophmatthews

Bug Description

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.

Activity

  1. added
    T: defectAn anomaly, which is anything that deviates from expectations.
    on Aug 10, 2019
  2. permcody commented on Aug 14, 2019

    @permcody
    Member

    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.

  3. tophmatthews commented on Aug 15, 2019

    @tophmatthews
    CollaboratorAuthor

    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.

  4. dschwen commented on Aug 15, 2019

    @dschwen
    Member

    ✨magic✨

  5. dschwen commented on Aug 15, 2019

    @dschwen
    Member

    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.

  6. tophmatthews commented on Aug 15, 2019

    @tophmatthews
    CollaboratorAuthor

    Yup, so magic?

  7. tophmatthews commented on Aug 15, 2019

    @tophmatthews
    CollaboratorAuthor

    How about moving it to MaterialInterface? ADStressUpdateBase doesn't have access to it (StressUpdateBase does though)

  8. dschwen commented on Aug 15, 2019

    @dschwen
    Member

    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.

  9. removed
    T: defectAn anomaly, which is anything that deviates from expectations.
    on Aug 15, 2019
  10. permcody commented on Aug 15, 2019

    @permcody
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions