Make deviator() and second_invariant() consistent with plane strain assumption in 2D#6471
Conversation
|
Others know this area much better than me, but in any case, this deserves a changelog entry. |
gassmoeller
left a comment
There was a problem hiding this comment.
Thank you for tackling these questions. I left a few comments. I think this is the right approach, but there are still some places that compute the deviatoric strain rate as strain rate - 1/dim * trace, please fix those as well.
In light of the discussion in #6434 I think this is the right path forward, but like Wolfgang commented, please add a changelog entry. And we will likely have to update a lot of test results.
source/material_model/grain_size.cc
Outdated
| @@ -199,7 +199,7 @@ namespace aspect | |||
|
|
|||
| const double strain_rate_dependence = (1.0 - dislocation_creep_exponent[phase_index]) / dislocation_creep_exponent[phase_index]; | |||
| const SymmetricTensor<2,dim> shear_strain_rate = strain_rate - 1./dim * trace(strain_rate) * unit_symmetric_tensor<dim>(); | |||
There was a problem hiding this comment.
here we still compute the shear strain rate as strain_rate -1./dim *trace. Does this need to be changed as well? If so, there are several places in the code base where we compute the shear strain rate in this way. Please search for /dim in ASPECT's directories and check which places need fixes.
There was a problem hiding this comment.
Thank you for pointing this out. I found two more 1/dim * trace expressions in material models, and they are all replaced by Utilities::Tensors::deviator(). Also, a changelog is added for these modifications.
| compute_second_invariant(const SymmetricTensor<2,dim> strain_rate, const double min_strain_rate) const | ||
| compute_Utilities::Tensors::deviatoric_tensor_inv2(const SymmetricTensor<2,dim> strain_rate, const double min_strain_rate) const | ||
| { | ||
| const double edot_ii_strict = std::sqrt(strain_rate*strain_rate); |
There was a problem hiding this comment.
why do we have a different way to compute the second invariant here? This way of computing the invariant also appears in the spiegelman benchmark cases. We should figure out in which way this is identical or different to the previous form.
There was a problem hiding this comment.
It's worth mentioning that @cedrict and I looked into this at some point in the past and found that people have all sorts of incompatible definitions of the second invariant. Sometimes it included a factor of 2, sometime it didn't, and similar shenanigans. I would suggest sticking closely to the definition we had previously used, and only change 1/dim to 1/3.
There was a problem hiding this comment.
Sorry, this is my miss.
tests/spiegelman_fail_test.cc
Outdated
| { | ||
| public: | ||
| double compute_second_invariant(const SymmetricTensor<2,dim> strain_rate, const double min_strain_rate) const; | ||
| double compute_Utilities::Tensors::deviatoric_tensor_inv2(const SymmetricTensor<2,dim> strain_rate, const double min_strain_rate) const; |
There was a problem hiding this comment.
you probably didnt mean to rename this function, right?
There was a problem hiding this comment.
No, it is my mistake. I just used a script to replace the string second_invariant by Utilities::Tensors::deviatoric_tensor_inv2 in all the files.
Do you think the second invariant of strain rate tensor should be changed here? I do not know if Spiegelman use a special function here (the function calculates the norm of the strain rate tensor).
gassmoeller
left a comment
There was a problem hiding this comment.
Just a few more thoughts I had after the review.
include/aspect/utilities.h
Outdated
| */ | ||
| template <int dim> | ||
| double | ||
| deviatoric_tensor_inv2(const SymmetricTensor<2,dim> &input); |
There was a problem hiding this comment.
I am unsure about this name, maybe second_invariant_plane_strain would explain better what the purpose of this function is?
There was a problem hiding this comment.
I do not know. I agree that plane_strain should be added to the name, but deviatoric should also be added, because the function returns the correct result only when the input tensor is deviatoric. Yet, we are not able to check if the input tensor is deviatoric, for the deviator of 2D plane strain tensor is not "deviatoric" in the common sense...
|
Completion of this PR is harder than expected. Currently there are two major problems:
|
gassmoeller
left a comment
There was a problem hiding this comment.
Just a few small comments I saw while reading through the PR.
|
|
||
| const SymmetricTensor<2, dim> | ||
| edot_deviator = deviator(strain_rate) + 0.5 * stress_0_advected / elastic_viscosity | ||
| edot_deviator = strain_rate + 0.5 * stress_0_advected / elastic_viscosity |
There was a problem hiding this comment.
was this the place where you removed the deviator on purpose?
There was a problem hiding this comment.
Yes. I think we need to be more careful when using consistent_deviator(), since we cannot apply it more than once to a symmetric tensor. I move the deviator here to the place where it is called --- MaterialModel::Rheology::ViscoPlastic::compute_isostrain_viscosities (`source/material_model/rheology/visco_plastic.cc, line 310). But I need to think this over, because under this change the Newton assembler gets the full strain rate instead of deviatoric strain rate.
There was a problem hiding this comment.
By the way, is the name of the variable now wrong?
There was a problem hiding this comment.
So instead of strain_rate it should be something like consistent_deviator_of_strain_rate or just deviatoric_strain_rate?
There was a problem hiding this comment.
I think this comment is not addressed yet. The name of the variable is edot_deviator, but it now uses the full strain rate. Does that name of the variable have to be changed?
|
|
||
| if (enable_elasticity) | ||
| data.local_rhs(i) += ( deviator(elastic_out->elastic_force[q]) | ||
| data.local_rhs(i) += ( elastic_out->elastic_force[q] |
There was a problem hiding this comment.
why is this no longer the deviatoric force?
There was a problem hiding this comment.
Actually I do not know. But the Stokes also uses the full elastic force, and the deviatoric elastic force does not produce sharp shear bands in the strip footing test. I need some time to figure out why.
There was a problem hiding this comment.
Did you have the time to look into this? In fact, I'm surprised we ever had the deviator here. We multiply the right hand side by the test function, not the deviator of anything related to the test function. I see no real good reason to take the deviator here.
There was a problem hiding this comment.
I am sorry for having forgotten this comment. I do not remember the experiments I carried out last year. Anyway, since there have been a lot more modifications after that, the experiments are no longer reliable. Now I think we can reason out why there should not be a deviator here:
- The elastic force is calculated by
MaterialModel::Rheology::Elasticity::fill_elastic_output. The corresponding codes are:
elastic_out->elastic_force[i] = -1. * (viscosity_ratio * stress_0_advected
+ (1. - timestep_ratio) * (1. - viscosity_ratio) * stress_old);
- The symmetric tensor
stress_0_advectedcomes from
const SymmetricTensor<2,dim> stress_0_advected (Utilities::Tensors::to_symmetric_tensor<dim>(&in.composition[i][stress_start_index],
&in.composition[i][stress_start_index]+n_independent_components));
where stress_start_index is defined as
const unsigned int stress_start_index = this->introspection().compositional_index_for_name("ve_stress_xx");
- In function
MaterialModel::Rheology::Elasticity::fill_reaction_rates, the stress tensor is calculated by
const SymmetricTensor<2, dim> stress_update = (stress_t - stress_0_t) / dtc;
Utilities::Tensors::unroll_symmetric_tensor_into_array(stress_update,
&reaction_rate_out->reaction_rates[i][stress_start_index],
&reaction_rate_out->reaction_rates[i][stress_start_index]+n_independent_components);
where
const SymmetricTensor<2, dim> stress_0_t (Utilities::Tensors::to_symmetric_tensor<dim>(&in.composition[i][stress_start_index],
&in.composition[i][stress_start_index]+n_independent_components));
and
const SymmetricTensor<2, dim>
stress_t = 2. * effective_creep_viscosity * Utilities::Tensors::consistent_deviator(in.strain_rate[i])
+ effective_creep_viscosity / elastic_viscosity * stress_0_t
+ (1. - timestep_ratio) * (1. - effective_creep_viscosity / elastic_viscosity) * stress_old;
Note that consistent_deviator has been applied to stress_t, and also to stress_0_t at the previous time step. Therefore, since consistent_deviator can only be applied once, there should not be a deviator in the assembler.
Do you agree @gassmoeller @MFraters @bangerth ?
|
A plan forward for this PR that I just discussed with @YiminJin:
We want to make sure this PR is tested and merged before the next release, since it fixes an important bug in the current implementation. |
|
@gassmoeller The reasons for removing the
I know it contradicts my modifications on the Newton assembler last year, but I cannot remember why I use deviatoric strain rate at that time...
The comments above are only simple analyses. I think our final choice should depend on experiments. I am working on it. |
|
Sorry, I was wrong again: |
|
You already found out that Moreover, we have Both lines of the argument indicate that the system matrix is symmetric. |
|
I am trying out the benchmark in Spiegelman et al. (2016) with the modifications in this PR and #6546 . As a first step, I use the visco plastic model and the same material parameters as in |
|
hmm, that means they have been broken somewhere along the way. Just checking, have you tried running the original files and material model here: https://github.com/geodynamics/aspect/tree/main/benchmarks/newton_solver_benchmark_set/spiegelman_et_al_2016? |
Yes. I only changed the refinement level from 4 to 6. |
adbca51 to
79e2084
Compare
|
I derived the analytical expression of the system Jacobian under plane-strain assumption for DP rheology, and I think I have found the reason for the different convergence behaviors with and without stabilization shown in #6160 . The derivation is provided in the following document: In one word, the reason for the better performance of using deviatoric strain rate when SPD stabilization is turned on is that: when using the full strain rate, the Jacobian matrix is not semi-positive-definite, and we need a smaller scaling factor to restore the positive-definiteness. However, I think we should use the full strain rate even if it slows down the convergence rate, because it is correct (if we use the deviatoric strain rate, it would be equivalent to modifying the rheological model). I made some modifications in The shear bands are still not as sharp as those in the original paper of Fraters et al. (2019), but are similar to those in Spiegelman et al. (2016). Surprisingly, the nonlinear solver converges to I also plotted the convergence curves with low-resolution models: What is your opinion about my modifications @gassmoeller @MFraters ? If they are acceptable, I think it is time to apply the differences in test results and prepare for the final merge. |
|
Corrections:
The curves are almost the same as those plotted in #6160 (this time we use full strain rate when assembling the system Jacobian).
It converges to about 3e-6. The strain rate field now is very similar to Fig. 3 in the original paper. |
MFraters
left a comment
There was a problem hiding this comment.
Thanks for doing all this work! That is great.
Do I understand it correctly that the convergence plot you show should be the same as the bottom left one in figure 5?
The stabilization definitely looks better, even though, looking at the Picard iteration the problems is more difficult, since that one is not converging.
Do you have the same plots for the more difficult cases? It would be interesting to see how it behaves there.
source/utilities.cc
Outdated
| double consistent_second_invariant_of_deviatoric_tensor(const SymmetricTensor<2,dim> &t) | ||
| { | ||
| if (dim == 2) | ||
| return -( Utilities::fixed_power<2,double>(t[0][0]) // t11^2 |
There was a problem hiding this comment.
why not simply t[0][0]*t[0][0]?
Same in other places.
There was a problem hiding this comment.
I thought fixed_power() saves an addition operation for
But I think you are right. I read the source codes of fixed_power() and now I think it may cost more (there are if-else statements, and I am not sure if it will be optimized by the compiler). So I changed to the simpler form, as you suggested.
|
@MFraters The convergence behaviors for more difficult cases are shown below: It can be seen that the convergence behavior of the current code is better indeed: the unstabilized Newton solver converges for the difficult cases with second-order rate. However, without stabilization the linear solver takes more iterations to converge, and in the most difficult case (Vel = 12.5 mm/y) the cheap iterations are even exhausted. So it is still worth using the stabilization in larger models. |
|
Supplement to my comments on my derivation of the analytical formula of system Jacobian: The derivation is under plane-strain assumption, but the conclusion also applies to the original 2D formulation. In the original 2D formulation, we have |
|
Eq. (9) in my derivation is calculated with the help of Sympy. The python codes are shown below: The outputs are: It is easy to see that the expressions with and without plane-strain are equal to |
MFraters
left a comment
There was a problem hiding this comment.
Generally looks good to me. A few small comments to clear things up.
I don't see a significant difference in the unstabilized convergence when it converges (maybe I am missing something), but the stabilized one is definitely better.
Can you fix the tests? Than we can also see what difference it makes there.
@bangerth, can you have a look at the derivations?
| const double regularization_adjustment = (ref_visc * ref_visc) | ||
| / (ref_visc * ref_visc + 2.0 * ref_visc * drucker_prager_viscosity | ||
| + drucker_prager_viscosity * drucker_prager_viscosity); | ||
| / Utilities::fixed_power<2,double>(ref_visc + drucker_prager_viscosity); |
There was a problem hiding this comment.
I am personally not really a fan of using functions like this for something so simple. You are basically inlining the following code here: https://github.com/dealii/dealii/blob/93160909dbf3bbfe986ad5320b675737f89d6e00/include/deal.II/base/utilities.h#L944-L961
Since it is an inline constexpr, and with compiler optimizations, it is probably almost as fast, or as fast as writing it out yourself. You can argue both ways about which one is more clear to read, so it is fine to keep it, but I did want to mention it.
There was a problem hiding this comment.
I did not read the source code of Utilities::fixed_power() when I made the change. Now I think you are right: using the function may not be faster. I have changed it to explicit form in a new commit.
| @@ -0,0 +1,5 @@ | |||
| Changed: The deviator and second invariant of symmetric tensors are modified to | |||
| be consistent with the plane strain assumption in 2D. It changes the outputs of | |||
| compressible material models that are dependent on the deviatoric strain rate. | |||
There was a problem hiding this comment.
I don't think I fully understand this. Currently the Newton solver is only stabilized for the incompressible case. Did you mean incompressible or do you say it is now also stabilized for the compressible case?
There was a problem hiding this comment.
I forget why I wrote this. I deleted the second sentence in a new commit.
|
|
||
| const SymmetricTensor<2, dim> | ||
| edot_deviator = deviator(strain_rate) + 0.5 * stress_0_advected / elastic_viscosity | ||
| edot_deviator = strain_rate + 0.5 * stress_0_advected / elastic_viscosity |
There was a problem hiding this comment.
So instead of strain_rate it should be something like consistent_deviator_of_strain_rate or just deviatoric_strain_rate?
|
|
||
| if (enable_elasticity) | ||
| data.local_rhs(i) += ( deviator(elastic_out->elastic_force[q]) | ||
| data.local_rhs(i) += ( elastic_out->elastic_force[q] |
|
I tried the default model runs (using
a. Always use full strain rate (FSR): b. Use full strain rate when not stabilized, and use deviatoric strain rate (DSR) when stabilized: The figures correspond to Fig. 2 in the original paper: The results can be summarized as follows:
b. Use FSR when not stabilized, and use DSR when stabilized: The figures correspond to Fig. 4 in the original paper:
The results show that:
I have not figured out why using deviatoric strain rate results in slower convergence in the channel flow benchmark. But, according to the results and the mathematical work, using full strain rate seems to be the right choice. That is also the reason I changed deviatoric strain rate to full strain the in elastic rheology. There is an issue to be noticed: when using 2D tensor, one can use What do you think about the results @MFraters @bangerth @gassmoeller ? Do I need to carry out experiments with elastic rheology? (I have tested the full strain rate version with associated-plastic-flow tests (strip-footing, pure shear), but not the deviatoric strain rate version). |
|
Sorry, I made a big mistake in the last comment: I forgot that the 2D tensors in the channel flow benchmark have not been changed to plane-strain tensors. When I tried to do the modification, I found something that looks weird: line 183 and line 189 of |
|
I also made a mistake when computing the deviatoric strain rates in system Jacobian: I forgot to change @gassmoeller Do you remember how we came to the conclusion that using deviatoric strain rate when stabilized is faster than using full strain rate? |
|
I have tried to test the VEP rheology with plastic dilation, and I found some problems in
I also found that the Newton Stokes assembler uses After fixing all the problems, and adding a And, from the compressible case, I confirmed the argument that we should use full strain rate in |
|
@bangerth @gassmoeller I shall apologize for being absent for a long time. I thought I could come back to this after finishing my own tasks during Christmas, but I felt so exhausted that I took a few days' break. @bangerth Thank you for going through this PR. I have fixed the space-allocating problem in a new commit (there is a small problem. Please take a look at my reply to your comment). About the format problems: I have fixed the problems you pointed out, but I believe there are more problems (like extra white spaces) that cannot pass the format check. However, if I use astyle to reformat the file, there would be some annoying changes. For example, line 89-90 in After reformatting, it becomes I think it is because |
You could use |
|
@tjhei Thanks for the suggestion. It circumvents the astyle problem, but I searched all the source files in ASPECT and cannot find a single case of "> >" (other places with ">>" passed the format check, I do not know why). So I downloaded the "changes-astyle.diff" file and made modifications manually. |
|
That's not how this works. 😀 The diff file is provided for you to make your formatting match the official formatting given by astyle. I would suggest you accept the fact that one line of code is not formatted exactly the way you would want it to be. After all, the functionality is what counts, not the looks. 😉 |
No need to apologize, we all have a lot of other things to do, and we understand if someone needs to focus on other things (work or vacation) for a while. I just wanted to check if we can plan with this PR for the release or not. It looks like we are almost ready. Like Timo said, dont worry about the indentation for now. Our indentation rule at the moment is: we use whatever astyle 2.04 produces. This looks awkward in a few places, but we just leave it as is for now. Could you:
Then we just need to check with @bangerth if his comments were addressed. |
|
I have applied the .diff files and now I can see in the summary that .diff files are still there but empty. But there are still failing checks. Why is that? |
|
I located the problem under the help of @alarshi : the nonlinear channel flow test failed. Its top-left block has a negative eigenvalue even if the SPD stabilization is applied. So it comes back to the problem in the channel flow test: I cannot understand its material model. The problem is that: line 183 and line 189 of |
|
hmm, that does seem inconsistent. I don't remember why that 2.0 is there, or should be there. It could very well be a mistake. That would then also give a discrepancy between the computed analytical derivative and the real derivative, which could explain why the matrix is not SPD. Does it work if you remove the 2, and is the convergence still good, better or worse if you remove the 2? |
b102a0b to
8a05351
Compare
3daf1ef to
b86215d
Compare
|
I have fixed most of the problems in this PR and cleaned up the commit history (only 4 commits are left). The failed test seems to be related to the problem inside the master branch of dealii (it runs on my machine, with dealii-9.6). There might be some hidden bugs left (for example, there might be some plugins in cookbook or benchmark that still use the inconsistent 2D deviator), but I think they won't harm the performance of the software, and we can let them be discovered by some sharp-eyed fellow (like the problem hidden in the nonlinear channel flow benchmark). Do you think this PR is prepared to be merged?@gassmoeller @bangerth @MFraters ? |
MFraters
left a comment
There was a problem hiding this comment.
Thanks for all the work and testing you did on this!
Meanwhile, the robustness is hurt: the danger of divergence increases if line search is turned off.
I guess line search should just always be on (which it is by default). It doesn't hurt too much when it is not needed, and it helps a lot when it is.
Generally I think this looks good to me to merge, but I am not able to check the compressible and matrix free parts of the code. There are still a few unresolved comments though. Could you go through https://github.com/geodynamics/aspect/pull/6471/changes and make sure to check all of the currently unresolved comments to make sure they are answered?
|
@MFraters Thank you for reminding me about the unresolved comments. However, I did not find a way to filer out the unresolved comments in the "changed files" page (I tried the |
gassmoeller
left a comment
There was a problem hiding this comment.
I think it is time to close this chapter and merge the PR. Thanks again @YiminJin for this massive amount of work, I think this significantly improves our material model consistency and the Newton solver performance! We appreciate the work you do!
As Wolfgang already mentioned: For the future please try to separate fixes into individual PRs. This PR could have been much less work for us and for you if we could have handled the material model change and the change to the Newton solver in two separate PRs. I know how tempting it is to include each fix you find into the current branch, but it complicates things during review.
Just to be sure I will restart the deal.II development tester, it should be fixed by now, and I just want to avoid to introduce the next problem into it. When all testers are done, this is ready to merge.
|
|
||
| if (enable_elasticity) | ||
| data.local_rhs(i) += ( deviator(elastic_out->elastic_force[q]) | ||
| data.local_rhs(i) += ( elastic_out->elastic_force[q] |
|
/rebuild |
|
@gassmoeller Thanks for your efforts in reviewing. And yes, I will try to separate different modifications into different PRs in the future. I was too hasty to see "good" results in this PR. |
gassmoeller
left a comment
There was a problem hiding this comment.
Ok, sorry I found one more thing that needs to be fixed (the test change files should not be committed in this PR).
And I would like to get confirmation on one more benchmark, because we so far only discussed the plasticity benchmarks and this PR also modifies the elasticity terms. Someone would need to check the viscoelastic bending beam benchmark and compare the main branch with this PR. (I will see if I can get to that soon, but if someone else want to take the lead, feel free to).
changes-test-results-9.6.diff
Outdated
There was a problem hiding this comment.
I just noticed: this file should not be part of the pull request. Please remove it. And since it is quite large: Please also rebase your pull request and squash all commits into one. This will delete this file from the commit history (if it is added in one commit and deleted in the next, it will still increase the size of the repository).
changes-test-results-9.6.diff.zip
Outdated
There was a problem hiding this comment.
Here as well, this file was accidentally committed and should be deleted.
For the future: I find it is most useful to always add changes to commits with git add -u ..., this will only add changesets to the commit that concern files which are already tracked by git (this also works for folders, e.g. git add -u tests will only add changes in files already tracked). This way any new file (like these diff files) will be ignored. Only in the (rare) case where you want to add a new file you have to run simple git add ....
|
|
||
|
|
||
| Postprocessing: | ||
| Compositions min/max/mass: -1.9e+07/1.798e+07/-8.533e+11 // -1.798e+07/1.9e+07/8.533e+11 // -4.452e+06/1.536e+06/-4.011e+12 // -1.9e+07/1.799e+07/-8.462e+11 // -1.799e+07/1.9e+07/8.462e+11 // -4.427e+06/1.53e+06/-4.012e+12 // 0/1/2.278e+06 | ||
| Number of advected particles: 4466 | ||
| Compositions min/max/mass: -2.795e+07/2.647e+07/-1.285e+12 // -1.066e+07/1.119e+07/3.981e+11 // -4.623e+06/1.591e+06/-4.07e+12 // -2.795e+07/2.649e+07/-1.278e+12 // -1.067e+07/1.119e+07/3.913e+11 // -4.6e+06/1.589e+06/-4.071e+12 // 0/1/2.278e+06 |
There was a problem hiding this comment.
I noticed that the bending beam benchmarks are some of the tests that change most with this PR. This seems reasonable given the code changes to the elastic force for the Newton solver, but I would like to get @anne-glerum's take on this. The new code is reasonable in that the Newton solver and the Picard solver now both use the same full elastic force term (before the Newton solver used the deviatoric elastic force, and the Picard solver the full term), but I also know we benchmarked the current implementation and it seemed correct.
Sorry for throwing one more wrinkle in this, but I just want to make sure the new form still gives a correct solution for the viscoelastic bending beam.
b86215d to
ec71935
Compare
|
@gassmoeller Thank you for finding the mistake! I will try to be more careful. As for the elastic bending beam benchmark, I agree that it is very sensitive to changes in parameters (and of coarse in the formulation). Actually, I do not understand why it uses Newton solver in the particle case (in the field case it uses Picard solver), for the nonlinear part (the rotation of stress) is on the right-hand side, not in the matrix. I will take a closer look at it too. |


















This PR modifies the functions
deviator()andsecond_invariant()to make them consistent with the plane strain assumption in 2D. The modified functions are placed in namespaceUtilities::Tensors. For details of the mathematics, please refer to #6434 and #6459. A direct impact of this modification is that it sharpen the shear bands in plastic models with nonzero dilation angle.This PR is a follow-up of #6373, but it will affect other material models. Also, we need several test problems to show the plane strain functions work well (or to find out if we can do better), which have not been implemented. Please make comments if you have suggestions or questions about this PR.