-
Notifications
You must be signed in to change notification settings - Fork 258
Unify anisotropic viscosity Stokes assemblers / Fix anisotropic viscosity cookbook #6728
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
Merged
bangerth
merged 6 commits into
geodynamics:main
from
gassmoeller:unify_anisotropic_viscosity_code
Nov 12, 2025
+937
−1,040
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ed666d
Move anisotropic viscosity assemblers into main code
gassmoeller c5f2883
Add test for anisotropic viscosity cookbook
gassmoeller 8034727
fix anisotropic viscosity parameter file
gassmoeller 6b74606
Remove duplicated assembler from cookbook
gassmoeller e544695
Add shear heating plugin
gassmoeller 51c647a
Improve anisotropic viscosity code
gassmoeller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
include/aspect/heating_model/shear_heating_anisotropic_viscosity.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| Copyright (C) 2025 by the authors of the ASPECT code. | ||
| This file is part of ASPECT. | ||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file LICENSE. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef _aspect_heating_model_shear_heating_anisotropic_viscosity_h | ||
| #define _aspect_heating_model_shear_heating_anisotropic_viscosity_h | ||
|
|
||
| #include <aspect/heating_model/interface.h> | ||
|
|
||
| #include <aspect/simulator_access.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace HeatingModel | ||
| { | ||
| /** | ||
| * A class that implements a standard model for shear heating extended for an | ||
| * anisotropic viscosity tensor. If the material model provides a stress-strain | ||
| * director tensor, then the strain-rate is multiplied with this | ||
| * tensor to compute the stress that is used when computing the shear heating. | ||
| * | ||
| * @ingroup HeatingModels | ||
| */ | ||
| template <int dim> | ||
| class ShearHeatingAnisotropicViscosity : public Interface<dim>, public ::aspect::SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| /** | ||
| * Compute the heating model outputs for this class. | ||
| */ | ||
| void | ||
| evaluate (const MaterialModel::MaterialModelInputs<dim> &material_model_inputs, | ||
| const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs, | ||
| HeatingModel::HeatingModelOutputs &heating_model_outputs) const override; | ||
|
|
||
| /** | ||
| * Allow the heating model to attach additional material model outputs. | ||
| */ | ||
| void | ||
| create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &material_model_outputs) const override; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| #endif |
61 changes: 61 additions & 0 deletions
61
include/aspect/material_model/additional_outputs/anisotropic_viscosity.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| Copyright (C) 2025 - by the authors of the ASPECT code. | ||
|
|
||
| This file is part of ASPECT. | ||
|
|
||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
|
|
||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file doc/COPYING. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef _aspect_material_model_additional_outputs_anisotropic_viscosity_h | ||
| #define _aspect_material_model_additional_outputs_anisotropic_viscosity_h | ||
|
|
||
|
|
||
| #include <aspect/material_model/interface.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace MaterialModel | ||
| { | ||
| /** | ||
| * Additional output fields for anisotropic viscosities to be added to | ||
| * the MaterialModel::MaterialModelOutputs structure and filled in the | ||
| * MaterialModel::Interface::evaluate() function. | ||
| */ | ||
| template <int dim> | ||
| class AnisotropicViscosity : public NamedAdditionalMaterialOutputs<dim> | ||
| { | ||
| public: | ||
| AnisotropicViscosity(const unsigned int n_points); | ||
|
|
||
| std::vector<double> | ||
| get_nth_output(const unsigned int idx) const override; | ||
|
|
||
| /** | ||
| * Stress-strain "director" tensors at the given positions. This | ||
| * variable is used to implement anisotropic viscosity. | ||
| * | ||
| * @note The strain rate term in equation (1) of the manual will be | ||
| * multiplied by this tensor *and* the viscosity scalar ($\eta$), as | ||
| * described in the manual section titled "Constitutive laws". This | ||
| * variable is assigned the rank-four identity tensor by default. | ||
| * This leaves the isotropic constitutive law unchanged if the material | ||
| * model does not explicitly assign a value. | ||
| */ | ||
| std::vector<SymmetricTensor<4,dim>> stress_strain_directors; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
include/aspect/simulator/assemblers/stokes_anisotropic_viscosity.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| Copyright (C) 2025 - by the authors of the ASPECT code. | ||
|
|
||
| This file is part of ASPECT. | ||
|
|
||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
|
|
||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file doc/COPYING. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef _aspect_simulator_assemblers_stokes_anisotropic_viscosity_h | ||
| #define _aspect_simulator_assemblers_stokes_anisotropic_viscosity_h | ||
|
|
||
|
|
||
| #include <aspect/simulator/assemblers/interface.h> | ||
| #include <aspect/simulator_access.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace Assemblers | ||
| { | ||
| /** | ||
| * A class containing the functions to assemble the Stokes preconditioner for the | ||
| * case of anisotropic viscosities. | ||
| */ | ||
| template <int dim> | ||
| class StokesPreconditionerAnisotropicViscosity : public Assemblers::Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| void | ||
| execute(internal::Assembly::Scratch::ScratchBase<dim> &scratch, | ||
| internal::Assembly::CopyData::CopyDataBase<dim> &data) const override; | ||
|
|
||
| /** | ||
| * Create AnisotropicViscosities. | ||
| */ | ||
| void | ||
| create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &outputs) const override; | ||
| }; | ||
|
|
||
| /** | ||
| * A class containing the functions to assemble the compressible adjustment | ||
| * to the Stokes preconditioner for the case of anisotropic viscosities. | ||
| */ | ||
| template <int dim> | ||
| class StokesCompressiblePreconditionerAnisotropicViscosity : public Assemblers::Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| void | ||
| execute(internal::Assembly::Scratch::ScratchBase<dim> &scratch, | ||
| internal::Assembly::CopyData::CopyDataBase<dim> &data) const override; | ||
| }; | ||
|
|
||
| /** | ||
| * This class assembles the terms for the matrix and right-hand-side of the incompressible | ||
| * Stokes equation for the case of anisotropic viscosities. | ||
| */ | ||
| template <int dim> | ||
| class StokesIncompressibleTermsAnisotropicViscosity : public Assemblers::Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| void | ||
| execute(internal::Assembly::Scratch::ScratchBase<dim> &scratch, | ||
| internal::Assembly::CopyData::CopyDataBase<dim> &data) const override; | ||
|
|
||
| /** | ||
| * Create AdditionalMaterialOutputsStokesRHS if we need to do so. | ||
| */ | ||
| void | ||
| create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &outputs) const override; | ||
| }; | ||
|
|
||
| /** | ||
| * This class assembles the term that arises in the viscosity term of the Stokes matrix for | ||
| * compressible models for the case of anisotropic viscosities, because the divergence | ||
| * of the velocity is not longer zero. | ||
| */ | ||
| template <int dim> | ||
| class StokesCompressibleStrainRateViscosityTermAnisotropicViscosity : public Assemblers::Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| void | ||
| execute(internal::Assembly::Scratch::ScratchBase<dim> &scratch, | ||
| internal::Assembly::CopyData::CopyDataBase<dim> &data) const override; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| #endif |
123 changes: 123 additions & 0 deletions
123
source/heating_model/shear_heating_anisotropic_viscosity.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| Copyright (C) 2015 - 2023 by the authors of the ASPECT code. | ||
|
|
||
| This file is part of ASPECT. | ||
|
|
||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
|
|
||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file LICENSE. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <aspect/heating_model/shear_heating_anisotropic_viscosity.h> | ||
|
|
||
| #include <aspect/material_model/interface.h> | ||
| #include <aspect/material_model/additional_outputs/anisotropic_viscosity.h> | ||
| #include <aspect/heating_model/shear_heating.h> | ||
|
|
||
| #include <deal.II/base/symmetric_tensor.h> | ||
| #include <deal.II/base/signaling_nan.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace HeatingModel | ||
| { | ||
| template <int dim> | ||
| void | ||
| ShearHeatingAnisotropicViscosity<dim>:: | ||
| evaluate (const MaterialModel::MaterialModelInputs<dim> &material_model_inputs, | ||
| const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs, | ||
| HeatingModel::HeatingModelOutputs &heating_model_outputs) const | ||
| { | ||
| Assert(heating_model_outputs.heating_source_terms.size() == material_model_inputs.position.size(), | ||
| ExcMessage ("Heating outputs need to have the same number of entries as the material model inputs.")); | ||
|
|
||
| // Some material models provide dislocation viscosities and boundary area work fractions | ||
| // as additional material outputs. If they are attached, use them. | ||
| const std::shared_ptr<const ShearHeatingOutputs<dim>> shear_heating_out = | ||
| material_model_outputs.template get_additional_output_object<ShearHeatingOutputs<dim>>(); | ||
|
|
||
| const std::shared_ptr<const MaterialModel::AnisotropicViscosity<dim>> anisotropic_viscosity = | ||
| material_model_outputs.template get_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>(); | ||
|
|
||
| Assert(anisotropic_viscosity != nullptr, | ||
| ExcMessage("This heating plugin should only be used with material models that provide " | ||
| "an anisotropic viscosity tensor, but none was provided.")); | ||
|
|
||
| for (unsigned int q=0; q<heating_model_outputs.heating_source_terms.size(); ++q) | ||
| { | ||
| // If there is an anisotropic viscosity, use it to compute the correct stress | ||
| const SymmetricTensor<2,dim> &directed_strain_rate = anisotropic_viscosity->stress_strain_directors[q] | ||
| * material_model_inputs.strain_rate[q]; | ||
|
|
||
| const SymmetricTensor<2,dim> stress = | ||
| 2 * material_model_outputs.viscosities[q] * | ||
| (this->get_material_model().is_compressible() | ||
| ? | ||
| directed_strain_rate - 1./3. * trace(directed_strain_rate) * unit_symmetric_tensor<dim>() | ||
| : | ||
| directed_strain_rate); | ||
|
|
||
| const SymmetricTensor<2,dim> deviatoric_strain_rate = | ||
| (this->get_material_model().is_compressible() | ||
| ? | ||
| material_model_inputs.strain_rate[q] | ||
| - 1./3. * trace(material_model_inputs.strain_rate[q]) * unit_symmetric_tensor<dim>() | ||
| : | ||
| material_model_inputs.strain_rate[q]); | ||
|
|
||
| heating_model_outputs.heating_source_terms[q] = stress * deviatoric_strain_rate; | ||
|
|
||
| // If shear heating work fractions are provided, reduce the | ||
| // overall heating by this amount (which is assumed to be converted into other forms of energy) | ||
| if (shear_heating_out != nullptr) | ||
| heating_model_outputs.heating_source_terms[q] *= shear_heating_out->shear_heating_work_fractions[q]; | ||
|
|
||
| heating_model_outputs.lhs_latent_heat_terms[q] = 0.0; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| ShearHeatingAnisotropicViscosity<dim>:: | ||
| create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &material_model_outputs) const | ||
| { | ||
| const unsigned int n_points = material_model_outputs.viscosities.size(); | ||
|
|
||
| if (material_model_outputs.template has_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>() == false) | ||
| { | ||
| material_model_outputs.additional_outputs.push_back( | ||
| std::make_unique<MaterialModel::AnisotropicViscosity<dim>> (n_points)); | ||
| } | ||
|
|
||
| this->get_material_model().create_additional_named_outputs(material_model_outputs); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // explicit instantiations | ||
| namespace aspect | ||
| { | ||
| namespace HeatingModel | ||
| { | ||
| ASPECT_REGISTER_HEATING_MODEL(ShearHeatingAnisotropicViscosity, | ||
| "anisotropic shear heating", | ||
| "Implementation of a standard model for shear heating extended for an " | ||
| "anisotropic viscosity tensor. If the material model provides a stress-" | ||
| "strain director tensor, then the strain-rate is multiplied with this " | ||
| "tensor to compute the stress that is used when computing the shear heating.") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that yield an error? If not, our parsing is not robust enough...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the semicolon yields the following error (with deal.II v9.7.0-rc1). I guess that it worked with an older deal.II version when the cookbook was created (but have not tested specific versions yet). It is also interesting that the first error complains about the function expression, but the actual problem is inside the function constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A long time ago, we parsed numbers by calling a function that just tried to read a number from a string. That succeeds with
3.141;, it just doesn't eat the whole string. We only fixed that a couple of years ago.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See dealii/dealii#19003. I now realize the problem is that the semicolon is not the correct separator for function constants (it should be a comma). I still think this probably used to work at some point, but does not anymore. Not sure if we want to do something about it, or leave it at the current behavior (since the documentation clearly states constants are separated by comma).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least that's a separate issue. I am happy with the current state, but we're equals and you can propose a different outcome :-)