Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function in material base class to check whether a property is active #26696

Merged
merged 6 commits into from
Feb 7, 2024

Conversation

YaqiWang
Copy link
Contributor

@YaqiWang YaqiWang commented Jan 30, 2024

Closes #26675.

@YaqiWang YaqiWang force-pushed the mat_prop_active_26675 branch 2 times, most recently from c6878db to cc46c1d Compare January 30, 2024 23:57
@YaqiWang
Copy link
Contributor Author

I think this is ready for review. @lindsayad and @NamjaeChoi

@moosebuild
Copy link
Contributor

moosebuild commented Jan 31, 2024

Job Documentation on 4246721 wanted to post the following:

View the site here

This comment will be updated on new commits.

@moosebuild
Copy link
Contributor

moosebuild commented Jan 31, 2024

Job Coverage on 4246721 wanted to post the following:

Framework coverage

519d81 #26696 424672
Total Total +/- New
Rate 85.21% 85.21% +0.00% 100.00%
Hits 99626 99628 +2 28
Misses 17292 17286 -6 0

Diff coverage report

Full coverage report

Modules coverage

Ray tracing

519d81 #26696 424672
Total Total +/- New
Rate 95.29% 95.29% -0.00% 100.00%
Hits 4327 4326 -1 1
Misses 214 214 - 0

Diff coverage report

Full coverage report

Full coverage reports

Reports

This comment will be updated on new commits.

Copy link
Contributor

@GiudGiud GiudGiud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you set the status, but you dont use it. Didnt you mean to try to skip material property evaluations for inactive properties?

framework/include/materials/MaterialData.h Outdated Show resolved Hide resolved
framework/include/materials/MaterialData.h Outdated Show resolved Hide resolved
framework/src/problems/FEProblemBase.C Outdated Show resolved Hide resolved
framework/src/problems/FEProblemBase.C Show resolved Hide resolved
@GiudGiud GiudGiud self-assigned this Jan 31, 2024
@YaqiWang
Copy link
Contributor Author

YaqiWang commented Jan 31, 2024

you set the status, but you dont use it. Didnt you mean to try to skip material property evaluations for inactive properties?

Yes. I only tested the function but I did not create a material use the function to skip evaluations. Actually I can make the derived test material I added in this PR do the skip.

@YaqiWang
Copy link
Contributor Author

I also added more protection when calling isPropertyActive with mooseAssert. Because isPropertyActive is called in element loop and only developer will be interacting with this function, I did not make those protection as mooseError.

@YaqiWang
Copy link
Contributor Author

@NamjaeChoi can you test this out with your PR in Griffin?

@YaqiWang YaqiWang force-pushed the mat_prop_active_26675 branch 2 times, most recently from 52d97e7 to 212304d Compare January 31, 2024 16:07
@YaqiWang
Copy link
Contributor Author

Added some documentation.

Copy link
Contributor

@GiudGiud GiudGiud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lindsayad should we have a meeting on this?
Seems like we should figure out how to turn this extra work of keeping track which properties are active into some sort of optimization in moose not just in derived apps

@YaqiWang
Copy link
Contributor Author

@lindsayad should we have a meeting on this? Seems like we should figure out how to turn this extra work of keeping track which properties are active into some sort of optimization in moose not just in derived apps

I think this has to be in computeQpProperties of individual materials. Moose has had the capability of whether call computeQpProperties of materials, right?

@YaqiWang
Copy link
Contributor Author

Wait a moment... looks like MOOSE will call computeQpProperties even all properties of a material are inactive. This can be seen by adding another dummy material in the test input.

@lindsayad
Copy link
Member

@YaqiWang see what you think of 96a61d2. It's an optimization changing the broader active properties to an unordered_set

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Feb 2, 2024

Looks good! Thanks Alex.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Feb 2, 2024

The last commit will need patches for apps due to the interface change. I think having efficient MaterialBase::isPropertyActive is good enough.

@lindsayad
Copy link
Member

Nothing a little c++ can't handle

@lindsayad
Copy link
Member

The more I think about this the more I think we should just query the problem for whether a material property ID is active as opposed to doing these mat->setActiveProperties calls. If std::unordered_set::count is constant complexity on average, then it seems a little silly to me to essentially duplicate the active material property storage in FEProblemBase and in the material classes. If somehow a profile showed heavy cpu in std::unordered_set::count then that would motivate me more to consider local storage on the Material

@lindsayad lindsayad force-pushed the mat_prop_active_26675 branch 2 times, most recently from 63f34b2 to e6c98ae Compare February 2, 2024 05:30
@YaqiWang
Copy link
Contributor Author

YaqiWang commented Feb 2, 2024

The more I think about this the more I think we should just query the problem for whether a material property ID is active as opposed to doing these mat->setActiveProperties calls. If std::unordered_set::count is constant complexity on average, then it seems a little silly to me to essentially duplicate the active material property storage in FEProblemBase and in the material classes. If somehow a profile showed heavy cpu in std::unordered_set::count then that would motivate me more to consider local storage on the Material

There is one thing in Material::subdomainChange might change your mind.

@lindsayad
Copy link
Member

There is one thing in Material::subdomainChange might change your mind.

Ok you can see my follow-on commits in this PR that consolidates the active material property storage onto the materials. To keep CI clean this should be a two-stage process. Stage 1 will be to get #26720 merged. I then have a Griffin patch ready to go that will switch to the new prepareMaterials API as well as change the MatSetType to an unordered_set instead of the decltype involving getActiveMaterialProperties. Then once those two patches are merged, then this PR should test cleanly

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Feb 5, 2024

@lindsayad your change in Griffin has been merged into Griffin master.

@lindsayad
Copy link
Member

👍 I'll fixup this PR momentarily

YaqiWang and others added 5 commits February 5, 2024 16:50
This allows for O(1) insertion of individual elements as opposed
to O(log(N)). Similarly when marking active material properties in
a given material this allows us to do a O(N) loop over the likely <= size of
the supplied properties and do a O(1) search in the `needed_mat_props`
@lindsayad
Copy link
Member

This should be ready for further review. Forward compatible relap-7 patch is here. Hopefully will get merged early tomorrow and then we can invalidate the failing targets here

Copy link
Contributor

@GiudGiud GiudGiud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

it would be good to have some numbers to justify the optimization at some point @YaqiWang but no rush, this can come just for reporting in the TA report. thanks!

framework/include/materials/MaterialBase.h Outdated Show resolved Hide resolved
framework/include/materials/MaterialBase.h Show resolved Hide resolved
framework/src/problems/FEProblemBase.C Outdated Show resolved Hide resolved
Co-authored-by: Guillaume Giudicelli <guillaume.giudicelli@gmail.com>
@lindsayad lindsayad merged commit bb2a44c into idaholab:next Feb 7, 2024
47 checks passed
@lindsayad
Copy link
Member

thanks for the review!

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Feb 7, 2024

Really appreciate the helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants