-
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
Changes from 5 commits
5ed666d
c5f2883
8034727
6b74606
e544695
51c647a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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 | ||||||||||
|
||||||||||
| * anisotropic viscosity tensor. If the material model provides a stress- | |
| * strain director tensor, then the strain-rate is multiplied with this | |
| * anisotropic viscosity tensor. If the material model provides a stress-strain | |
| * director tensor, then the strain-rate is multiplied with this |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,172 @@ | ||||||||||
| /* | ||||||||||
| 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 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; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| namespace | ||||||||||
| { | ||||||||||
| template <int dim> | ||||||||||
| std::vector<std::string> make_AnisotropicViscosity_additional_outputs_names() | ||||||||||
| { | ||||||||||
| std::vector<std::string> names; | ||||||||||
|
|
||||||||||
| for (unsigned int i = 0; i < Tensor<4,dim>::n_independent_components ; ++i) | ||||||||||
| { | ||||||||||
| TableIndices<4> indices(Tensor<4,dim>::unrolled_to_component_indices(i)); | ||||||||||
| names.push_back("anisotropic_viscosity"+std::to_string(indices[0])+std::to_string(indices[1])+std::to_string(indices[2])+std::to_string(indices[3])); | ||||||||||
| } | ||||||||||
| return names; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| template <int dim> | ||||||||||
| AnisotropicViscosity<dim>::AnisotropicViscosity (const unsigned int n_points) | ||||||||||
| : | ||||||||||
| NamedAdditionalMaterialOutputs<dim>(make_AnisotropicViscosity_additional_outputs_names<dim>()), | ||||||||||
|
||||||||||
| stress_strain_directors(n_points, dealii::identity_tensor<dim> ()) | ||||||||||
| {} | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| template <int dim> | ||||||||||
| std::vector<double> | ||||||||||
| AnisotropicViscosity<dim>::get_nth_output(const unsigned int idx) const | ||||||||||
| { | ||||||||||
| std::vector<double> output(stress_strain_directors.size()); | ||||||||||
| for (unsigned int i = 0; i < stress_strain_directors.size() ; ++i) | ||||||||||
| { | ||||||||||
| output[i]= stress_strain_directors[i][Tensor<4,dim>::unrolled_to_component_indices(idx)]; | ||||||||||
| } | ||||||||||
| return output; | ||||||||||
| } | ||||||||||
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| namespace Assemblers | ||||||||||
| { | ||||||||||
| /** | ||||||||||
| * A class containing the functions to assemble the Stokes preconditioner. | ||||||||||
|
||||||||||
| * A class containing the functions to assemble the Stokes preconditioner. | |
| * A class containing the functions to assemble the Stokes preconditioner for the case of anisotropic viscosities. |
Outdated
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 class containing the functions to assemble the compressible adjustment | |
| * to the Stokes preconditioner. | |
| * A class containing the functions to assemble the compressible adjustment | |
| * to the Stokes preconditioner for the case of anisotropic viscosities. |
Outdated
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.
same here, and perhaps also below
Outdated
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.
| * This class assembles the term that arises in the viscosity term of Stokes matrix for | |
| * This class assembles the term that arises in the viscosity term of the Stokes matrix for |
This is a copy-paste mistake -- the grammatically wrong code is already in line include/aspect/simulator/assemblers/stokes.h:81.
| 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/heating_model/shear_heating.h> | ||
| #include <aspect/simulator/assemblers/stokes_anisotropic_viscosity.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>>(); | ||
|
|
||
| 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 != nullptr) | ||
| ? | ||
| anisotropic_viscosity->stress_strain_directors[q] | ||
| * material_model_inputs.strain_rate[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.") | ||
| } | ||
| } | ||
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 :-)