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 Darcy field convection timestep #5856

Merged

Conversation

danieldouglas92
Copy link
Contributor

Add the functionality to limit the time step based on the Darcy velocity. Currently, when the 'darcy field' advection method is used, a field is advected with the Darcy velocity but the time step is not limited by this velocity. This leads to convergence issues, since the Darcy velocity is always equal to or greater than the solid velocity. This adds the functionality to convection_time_step.cc to limit the time step based on the Darcy velocity.

The implementation I have in this PR is currently working in that it gives the proper limited time step, however the fluid parameters are currently hard-coded in because when I try to access MeltOutputs through a variable fluid_out, fluid_out is a nullptr. @jdannberg am I missing something obvious here? Once I can access the Melt variables, I think this PR is basically good to go.

This addresses one of the issues in #4748

@danieldouglas92 danieldouglas92 changed the title Add Darcy field convection step Add Darcy field convection timestep Jun 9, 2024
Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

I left some comments that should fix the issue. Nice test. Can you also add a changelog entry?

{
if (this->introspection().compositional_name_exists("porosity"))
{
const unsigned int porosity_idx = this->introspection().compositional_index_for_name("porosity");
Copy link
Member

Choose a reason for hiding this comment

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

move this to the top of the file, where you also compute consider_darcy_timestep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm misunderstanding your comments, I don't know if it's possible to not compute the porosity_idx here because you need to divide by the porosity to calculate the Darcy velocity

Copy link
Member

Choose a reason for hiding this comment

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

But you can compute the porosirty_idx above, and use it here. See my comment above.

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from c23977f to 99f42b2 Compare June 9, 2024 20:23
@danieldouglas92
Copy link
Contributor Author

Thanks for the comments @gassmoeller, I still wasn't able to get fluid_out to not be a nullptr, and I'm not sure if I followed exactly all of your comments about what to calculate when determining whether consider_darcy_timestep should be true.

Just to outline my thought process, I think that the following line:
consider_darcy_timestep = this->get_parameters().compositional_field_methods[this->introspection().compositional_index_for_name("porosity")] == Parameters<dim>::AdvectionFieldMethod::fem_darcy_field

is important because the field type could be "porosity" but not be advected with the darcy field method. I think I was able to follow all your comments, but the only confusing part to me was bringing the line:

const unsigned int porosity_idx = this->introspection().compositional_index_for_name("porosity");

up to where we calculate consider_darcy_timestep.

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

Looks much better. A few more comments.
I think your fluid_out is empty, because your material model does not actually create a MeltOutputs object in the create_additional_named_outputs function. You need to modify ReactiveFluidTransport to do that (currently it only fills the values in evaluate if the MeltOutputs exist, but they never exist, so it never fills them).

{
if (this->introspection().compositional_name_exists("porosity"))
{
const unsigned int porosity_idx = this->introspection().compositional_index_for_name("porosity");
Copy link
Member

Choose a reason for hiding this comment

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

But you can compute the porosirty_idx above, and use it here. See my comment above.

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from 99f42b2 to cbf218b Compare June 13, 2024 21:00
@danieldouglas92
Copy link
Contributor Author

Got the melt outputs working thanks @gassmoeller!

@jdannberg
Copy link
Contributor

A point on the MeltOutputs: They are not additional named outputs, they are a separate type of outputs (AdditionalMaterialOutputs). In all other places, it is the responsibility of the caller to create them, not the material model itself. None of the melt models create their own MeltOutputs in the create_additional_named_outputs function.

To be consistent with the rest of ASPECT, the melt outputs should be created in the place where you need them, with MeltHandler<dim>::create_material_model_outputs(out), before you call evaluate (see my comment on #5902).

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from cbf218b to 2a27f3d Compare June 14, 2024 16:25
@danieldouglas92
Copy link
Contributor Author

@jdannberg I had tried this actually but for whatever reason at the time it didn't work and I clearly didn't try that hard to get it working, but now it seems to work!

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch 2 times, most recently from 7cb2242 to fcf6142 Compare June 16, 2024 02:32
@danieldouglas92
Copy link
Contributor Author

danieldouglas92 commented Jun 17, 2024

@gassmoeller Unfortunately I'm running into a git issue, the test viscoplastic_melt_fraction is failing here because the .prm file asked for named additional outputs, but somehow the PR (#5799) that I got merged at the hackathon which actually allows this to be done is not here. My local main is up to date and does have all the code required for viscoplastic_melt_fraction to not fail, but when I try to rebase onto main it says that this branch (limit_timestep_by_darcy_velocity) is already up to date with main, which clearly isn't true. I'm not really sure how this is happening?

@gassmoeller
Copy link
Member

A bit hard to debug remotely, but if I check out your branch from this PR, I clearly see the commit from #5799 in the commit history. Are you sure it is functionality from #5799 that is missing for this PR to pass the tests?
Here is the test error message: https://github.com/geodynamics/aspect/actions/runs/9532699918/job/26275098979?pr=5856#step:6:2060
The error message does not mention named additional outputs.

@danieldouglas92
Copy link
Contributor Author

@gassmoeller Yes there are two tests that fail, the first is uncoupled_two_phase_tian_parameterization_kinematic_slab fails because of the changes that I'm adding here and I need to fix this test also, but the second test viscoplastic_melt_fraction fails because of the named additional outputs. But you're right, I do also see the merge in my git log but the actual code that was merged in that PR is not in this branch.

@gassmoeller
Copy link
Member

But you're right, I do also see the merge in my git log but the actual code that was merged in that PR is not in this branch.

The only way I can see that happening is if either you (in this PR) or someone else (in another PR) undid the changes. Can you check here if you maybe undid your changes accidentally?

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from fcf6142 to ca30245 Compare June 18, 2024 04:06
@danieldouglas92
Copy link
Contributor Author

@gassmoeller It never once occurred to me that I might've accidentally deleted the code and committed it! Thanks for catching that

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch 2 times, most recently from 2b99c79 to 17f388b Compare June 18, 2024 05:22
@gassmoeller
Copy link
Member

/rebuild

@gassmoeller
Copy link
Member

Is this ready for a review?

@danieldouglas92
Copy link
Contributor Author

@gassmoeller yes!

Copy link
Member

@gassmoeller gassmoeller 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, just two small comments left.
@jdannberg could you take a look at the equation for the darcy flow? I am not qualified for that.

in.reinit(fe_values, cell, this->introspection(), this->get_solution());
this->get_material_model().create_additional_named_outputs(out);
this->get_material_model().evaluate(in, out);
this->get_material_model().fill_additional_material_model_inputs(in, this->get_solution(), fe_values, this->introspection());
Copy link
Member

Choose a reason for hiding this comment

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

This line would need to happen before the call to evaluate, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried putting the line:

this->get_material_model().fill_additional_material_model_inputs(in, this->get_solution(), fe_values, this->introspection());

before evalute, after evalute, and not including at all, and it seems to give the same solution for all 3 cases so I'll remove it and see if it causes any of the other tests to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the line:

this->get_material_model().create_additional_named_outputs(out);

also doesn't seem to be required, so I'll remove this line too.

@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from 17f388b to 8559e4f Compare June 19, 2024 03:07
@danieldouglas92 danieldouglas92 force-pushed the limit_timestep_by_darcy_velocity branch from 8559e4f to d1cb2c6 Compare June 19, 2024 04:20
Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

Sorry for the dealy, looks good to go.

@gassmoeller gassmoeller merged commit b302651 into geodynamics:main Jun 23, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants