Skip to content

Commit 51c647a

Browse files
committed
Improve anisotropic viscosity code
1 parent e544695 commit 51c647a

File tree

9 files changed

+198
-152
lines changed

9 files changed

+198
-152
lines changed

cookbooks/anisotropic_viscosity/av_material.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <aspect/introspection.h>
2222
#include <aspect/material_model/interface.h>
23-
#include <aspect/plugins.h>
23+
#include <aspect/material_model/additional_outputs/anisotropic_viscosity.h>
2424
#include <aspect/simulator/assemblers/stokes_anisotropic_viscosity.h>
2525
#include <deal.II/base/parameter_handler.h>
2626
#include <deal.II/base/patterns.h>

include/aspect/heating_model/shear_heating_anisotropic_viscosity.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace aspect
3131
{
3232
/**
3333
* A class that implements a standard model for shear heating extended for an
34-
* anisotropic viscosity tensor. If the material model provides a stress-
35-
* strain director tensor, then the strain-rate is multiplied with this
34+
* anisotropic viscosity tensor. If the material model provides a stress-strain
35+
* director tensor, then the strain-rate is multiplied with this
3636
* tensor to compute the stress that is used when computing the shear heating.
3737
*
3838
* @ingroup HeatingModels
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright (C) 2025 - by the authors of the ASPECT code.
3+
4+
This file is part of ASPECT.
5+
6+
ASPECT is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 2, or (at your option)
9+
any later version.
10+
11+
ASPECT is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with ASPECT; see the file doc/COPYING. If not see
18+
<http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef _aspect_material_model_additional_outputs_anisotropic_viscosity_h
22+
#define _aspect_material_model_additional_outputs_anisotropic_viscosity_h
23+
24+
25+
#include <aspect/material_model/interface.h>
26+
27+
namespace aspect
28+
{
29+
namespace MaterialModel
30+
{
31+
/**
32+
* Additional output fields for anisotropic viscosities to be added to
33+
* the MaterialModel::MaterialModelOutputs structure and filled in the
34+
* MaterialModel::Interface::evaluate() function.
35+
*/
36+
template <int dim>
37+
class AnisotropicViscosity : public NamedAdditionalMaterialOutputs<dim>
38+
{
39+
public:
40+
AnisotropicViscosity(const unsigned int n_points);
41+
42+
std::vector<double>
43+
get_nth_output(const unsigned int idx) const override;
44+
45+
/**
46+
* Stress-strain "director" tensors at the given positions. This
47+
* variable is used to implement anisotropic viscosity.
48+
*
49+
* @note The strain rate term in equation (1) of the manual will be
50+
* multiplied by this tensor *and* the viscosity scalar ($\eta$), as
51+
* described in the manual section titled "Constitutive laws". This
52+
* variable is assigned the rank-four identity tensor by default.
53+
* This leaves the isotropic constitutive law unchanged if the material
54+
* model does not explicitly assign a value.
55+
*/
56+
std::vector<SymmetricTensor<4,dim>> stress_strain_directors;
57+
};
58+
}
59+
}
60+
61+
#endif

include/aspect/simulator/assemblers/stokes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace aspect
7878
};
7979

8080
/**
81-
* This class assembles the term that arises in the viscosity term of Stokes matrix for
81+
* This class assembles the term that arises in the viscosity term of the Stokes matrix for
8282
* compressible models, because the divergence of the velocity is not longer zero.
8383
*/
8484
template <int dim>

include/aspect/simulator/assemblers/stokes_anisotropic_viscosity.h

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -27,80 +27,11 @@
2727

2828
namespace aspect
2929
{
30-
namespace MaterialModel
31-
{
32-
/**
33-
* Additional output fields for anisotropic viscosities to be added to
34-
* the MaterialModel::MaterialModelOutputs structure and filled in the
35-
* MaterialModel::Interface::evaluate() function.
36-
*/
37-
template <int dim>
38-
class AnisotropicViscosity : public NamedAdditionalMaterialOutputs<dim>
39-
{
40-
public:
41-
AnisotropicViscosity(const unsigned int n_points);
42-
43-
std::vector<double>
44-
get_nth_output(const unsigned int idx) const override;
45-
46-
/**
47-
* Stress-strain "director" tensors at the given positions. This
48-
* variable is used to implement anisotropic viscosity.
49-
*
50-
* @note The strain rate term in equation (1) of the manual will be
51-
* multiplied by this tensor *and* the viscosity scalar ($\eta$), as
52-
* described in the manual section titled "Constitutive laws". This
53-
* variable is assigned the rank-four identity tensor by default.
54-
* This leaves the isotropic constitutive law unchanged if the material
55-
* model does not explicitly assign a value.
56-
*/
57-
std::vector<SymmetricTensor<4,dim>> stress_strain_directors;
58-
};
59-
60-
namespace
61-
{
62-
template <int dim>
63-
std::vector<std::string> make_AnisotropicViscosity_additional_outputs_names()
64-
{
65-
std::vector<std::string> names;
66-
67-
for (unsigned int i = 0; i < Tensor<4,dim>::n_independent_components ; ++i)
68-
{
69-
TableIndices<4> indices(Tensor<4,dim>::unrolled_to_component_indices(i));
70-
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]));
71-
}
72-
return names;
73-
}
74-
}
75-
76-
77-
78-
template <int dim>
79-
AnisotropicViscosity<dim>::AnisotropicViscosity (const unsigned int n_points)
80-
:
81-
NamedAdditionalMaterialOutputs<dim>(make_AnisotropicViscosity_additional_outputs_names<dim>()),
82-
stress_strain_directors(n_points, dealii::identity_tensor<dim> ())
83-
{}
84-
85-
86-
87-
template <int dim>
88-
std::vector<double>
89-
AnisotropicViscosity<dim>::get_nth_output(const unsigned int idx) const
90-
{
91-
std::vector<double> output(stress_strain_directors.size());
92-
for (unsigned int i = 0; i < stress_strain_directors.size() ; ++i)
93-
{
94-
output[i]= stress_strain_directors[i][Tensor<4,dim>::unrolled_to_component_indices(idx)];
95-
}
96-
return output;
97-
}
98-
}
99-
10030
namespace Assemblers
10131
{
10232
/**
103-
* A class containing the functions to assemble the Stokes preconditioner.
33+
* A class containing the functions to assemble the Stokes preconditioner for the
34+
* case of anisotropic viscosities.
10435
*/
10536
template <int dim>
10637
class StokesPreconditionerAnisotropicViscosity : public Assemblers::Interface<dim>,
@@ -120,7 +51,7 @@ namespace aspect
12051

12152
/**
12253
* A class containing the functions to assemble the compressible adjustment
123-
* to the Stokes preconditioner.
54+
* to the Stokes preconditioner for the case of anisotropic viscosities.
12455
*/
12556
template <int dim>
12657
class StokesCompressiblePreconditionerAnisotropicViscosity : public Assemblers::Interface<dim>,
@@ -134,7 +65,7 @@ namespace aspect
13465

13566
/**
13667
* This class assembles the terms for the matrix and right-hand-side of the incompressible
137-
* Stokes equation for the current cell.
68+
* Stokes equation for the case of anisotropic viscosities.
13869
*/
13970
template <int dim>
14071
class StokesIncompressibleTermsAnisotropicViscosity : public Assemblers::Interface<dim>,
@@ -153,8 +84,9 @@ namespace aspect
15384
};
15485

15586
/**
156-
* This class assembles the term that arises in the viscosity term of Stokes matrix for
157-
* compressible models, because the divergence of the velocity is not longer zero.
87+
* This class assembles the term that arises in the viscosity term of the Stokes matrix for
88+
* compressible models for the case of anisotropic viscosities, because the divergence
89+
* of the velocity is not longer zero.
15890
*/
15991
template <int dim>
16092
class StokesCompressibleStrainRateViscosityTermAnisotropicViscosity : public Assemblers::Interface<dim>,

source/heating_model/shear_heating_anisotropic_viscosity.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <aspect/heating_model/shear_heating_anisotropic_viscosity.h>
2222

2323
#include <aspect/material_model/interface.h>
24+
#include <aspect/material_model/additional_outputs/anisotropic_viscosity.h>
2425
#include <aspect/heating_model/shear_heating.h>
25-
#include <aspect/simulator/assemblers/stokes_anisotropic_viscosity.h>
2626

2727
#include <deal.II/base/symmetric_tensor.h>
2828
#include <deal.II/base/signaling_nan.h>
@@ -49,15 +49,15 @@ namespace aspect
4949
const std::shared_ptr<const MaterialModel::AnisotropicViscosity<dim>> anisotropic_viscosity =
5050
material_model_outputs.template get_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>();
5151

52+
Assert(anisotropic_viscosity != nullptr,
53+
ExcMessage("This heating plugin should only be used with material models that provide "
54+
"an anisotropic viscosity tensor, but none was provided."));
55+
5256
for (unsigned int q=0; q<heating_model_outputs.heating_source_terms.size(); ++q)
5357
{
5458
// If there is an anisotropic viscosity, use it to compute the correct stress
55-
const SymmetricTensor<2,dim> &directed_strain_rate = ((anisotropic_viscosity != nullptr)
56-
?
57-
anisotropic_viscosity->stress_strain_directors[q]
58-
* material_model_inputs.strain_rate[q]
59-
:
60-
material_model_inputs.strain_rate[q]);
59+
const SymmetricTensor<2,dim> &directed_strain_rate = anisotropic_viscosity->stress_strain_directors[q]
60+
* material_model_inputs.strain_rate[q];
6161

6262
const SymmetricTensor<2,dim> stress =
6363
2 * material_model_outputs.viscosities[q] *
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright (C) 2025 - by the authors of the ASPECT code.
3+
4+
This file is part of ASPECT.
5+
6+
ASPECT is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 2, or (at your option)
9+
any later version.
10+
11+
ASPECT is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with ASPECT; see the file doc/COPYING. If not see
18+
<http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include <aspect/material_model/additional_outputs/anisotropic_viscosity.h>
22+
23+
namespace aspect
24+
{
25+
namespace MaterialModel
26+
{
27+
namespace
28+
{
29+
template <int dim>
30+
std::vector<std::string> make_anisotropic_viscosity_additional_outputs_names()
31+
{
32+
std::vector<std::string> names;
33+
34+
for (unsigned int i = 0; i < Tensor<4,dim>::n_independent_components ; ++i)
35+
{
36+
TableIndices<4> indices(Tensor<4,dim>::unrolled_to_component_indices(i));
37+
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]));
38+
}
39+
return names;
40+
}
41+
}
42+
43+
44+
45+
template <int dim>
46+
AnisotropicViscosity<dim>::AnisotropicViscosity (const unsigned int n_points)
47+
:
48+
NamedAdditionalMaterialOutputs<dim>(make_anisotropic_viscosity_additional_outputs_names<dim>()),
49+
stress_strain_directors(n_points, dealii::identity_tensor<dim> ())
50+
{}
51+
52+
53+
54+
template <int dim>
55+
std::vector<double>
56+
AnisotropicViscosity<dim>::get_nth_output(const unsigned int idx) const
57+
{
58+
std::vector<double> output(stress_strain_directors.size());
59+
for (unsigned int i = 0; i < stress_strain_directors.size() ; ++i)
60+
{
61+
output[i]= stress_strain_directors[i][Tensor<4,dim>::unrolled_to_component_indices(idx)];
62+
}
63+
return output;
64+
}
65+
}
66+
}
67+
68+
// explicit instantiations
69+
namespace aspect
70+
{
71+
namespace MaterialModel
72+
{
73+
#define INSTANTIATE(dim) \
74+
template class AnisotropicViscosity<dim>;
75+
76+
ASPECT_INSTANTIATE(INSTANTIATE)
77+
78+
#undef INSTANTIATE
79+
}
80+
}

0 commit comments

Comments
 (0)