Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <aspect/material_model/interface.h>
#include <aspect/simulator_access.h>
#include <aspect/newton.h>
#include <aspect/utilities.h>

namespace aspect
{
Expand Down Expand Up @@ -288,7 +289,7 @@ namespace aspect
std::vector<SymmetricTensor<2,dim>> composition_viscosities_derivatives(volume_fractions.size());
std::vector<double> composition_dviscosities_dpressure(volume_fractions.size());

const SymmetricTensor<2,dim> deviator_strain_rate = use_deviator_of_strain_rate ? deviator(in.strain_rate[i]) : in.strain_rate[i];
const SymmetricTensor<2,dim> deviator_strain_rate = use_deviator_of_strain_rate ? Utilities::Tensors::consistent_deviator(in.strain_rate[i]) : in.strain_rate[i];

for (unsigned int c=0; c < volume_fractions.size(); ++c)
{
Expand All @@ -297,7 +298,9 @@ namespace aspect
// Otherwise, calculate the square-root of the norm of the second invariant of the deviatoric-
// strain rate (often simplified as epsilondot_ii)

const double edot_ii = compute_second_invariant(deviator_strain_rate, min_strain_rate[c]);
const double edot_ii = sqrt(2.0 * std::abs(use_deviator_of_strain_rate ?
Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(deviator_strain_rate) :
second_invariant(deviator_strain_rate)));

// Find effective viscosities for each of the individual phases
// Viscosities should have same number of entries as compositional fields
Expand All @@ -316,15 +319,11 @@ namespace aspect
{
const double drucker_prager_viscosity = compute_viscosity(edot_ii,pressure,c,prefactor[c],false,min_visc[c],max_visc[c]);
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);
Copy link
Member

Choose a reason for hiding this comment

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

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.

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 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.


composition_viscosities_derivatives[c] = -regularization_adjustment *
(drucker_prager_viscosity / (edot_ii * edot_ii)) * deviator_strain_rate;

if (use_deviator_of_strain_rate == true)
composition_viscosities_derivatives[c]*deviator_tensor<dim>();

composition_dviscosities_dpressure[c] = regularization_adjustment *
((dim == 3)
?
Expand All @@ -349,9 +348,14 @@ namespace aspect
const TableIndices<2> strain_rate_indices = SymmetricTensor<2,dim>::unrolled_to_component_indices (component);

// add a small difference to one independent component of the strain-rate tensor
const SymmetricTensor<2,dim> strain_rate_difference_plus = deviator_strain_rate + std::max(edot_ii, min_strain_rate[c]*min_strain_rate[c]) * finite_difference_accuracy
* Utilities::nth_basis_for_symmetric_tensors<dim>(component);
const double second_invariant_strain_rate_difference_plus = compute_second_invariant(strain_rate_difference_plus, min_strain_rate[c]);
SymmetricTensor<2,dim> strain_rate_difference_plus = in.strain_rate[i] + std::max(edot_ii, min_strain_rate[c]*min_strain_rate[c]) * finite_difference_accuracy
* Utilities::nth_basis_for_symmetric_tensors<dim>(component);
if (use_deviator_of_strain_rate)
strain_rate_difference_plus = Utilities::Tensors::consistent_deviator(strain_rate_difference_plus);
const double second_invariant_strain_rate_difference_plus =
std::sqrt(2.0 * std::abs(use_deviator_of_strain_rate ?
Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(strain_rate_difference_plus) :
second_invariant(strain_rate_difference_plus)));
const double eta_component_plus = compute_viscosity(second_invariant_strain_rate_difference_plus,pressure,c,prefactor[c],true,min_visc[c],max_visc[c]);

// compute the difference between the viscosity with and without the strain-rate difference.
Expand Down
5 changes: 5 additions & 0 deletions doc/modules/changes/20250617_yiminjin
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

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?

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 forget why I wrote this. I deleted the second sentence in a new commit.

<br>
(Yimin Jin, 2025/06/17)
32 changes: 32 additions & 0 deletions include/aspect/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,38 @@ namespace aspect
// Declare the existence of a specialization:
template <>
const Tensor<3,3> &levi_civita<3>();

/**
* Compute the deviator of a symmetric tensor. This function is equivalent to
* dealii::deviator in 3D, while in 2D it is consistent with the plane strain assumption.
* Specifically, the deviator of the stress tensor $\mathbf\tau$ in 2D is given by
* $\text{dev}(\mathbf\tau) = \mathbf\tau - \frac{1}{3}\text{trace}(\mathbf\tau)\mathbf 1$
* under the plane strain assumption.
Copy link
Member

Choose a reason for hiding this comment

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

Add one sentence that in 3D this returns the usual definition of a deviatoric tensor.

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 comments for the two functions are revised accordingly.

*
* It should be noted that the consistent deviator of a consistently deviatoric tensor is
* not itself in 2D, which implies that it is invalid to apply this function to a symmetric
* tensor more than once.
*/
template <int dim>
SymmetricTensor<2,dim>
consistent_deviator(const SymmetricTensor<2,dim> &input);

/**
* Compute the second invariant of a deviatoric tensor of rank 2. This function is
* equivalent to dealii::second_invariant in 3D, while in 2D it is consistent with the
* plane strain assumption. Specifically, the second invariant of the deviatoric
* stress tensor $\tau_{II}$ in 2D is given by $\tau_{II} = -\frac{1}{2}(\tau_{11}^2 +
* \tau_{22}^2 + \tau_{33}^2 + 2\tau_{12}^2) = -\frac{1}{2}[\tau_{11}^2 + \tau_{22}^2 +
* (\tau_{11} + \tau_{22})^2 + 2\tau_{12}^2]$ under the plane strain assumption.
Copy link
Member

Choose a reason for hiding this comment

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

Add one sentence that in 3D this function simply returns the usual second invariant.

*
* It should be noted that this function provides the correct result in 2D only when the
* input tensor is deviatoric in the sense of plane strain, which cannot be examined
* without extra information (the trace of a plane strain deviatoric tensor is not
* zero). Thus, extra care must be taken when using this function.
*/
template <int dim>
double
consistent_second_invariant_of_deviatoric_tensor(const SymmetricTensor<2,dim> &input);
}

}
Expand Down
2 changes: 1 addition & 1 deletion source/heating_model/shear_heating.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace aspect
drucker_prager_parameters);

// Scale the stress accordingly.
const double deviatoric_stress = 2 * material_model_outputs.viscosities[q] * std::sqrt(std::fabs(second_invariant(deviatoric_strain_rate)));
const double deviatoric_stress = 2 * material_model_outputs.viscosities[q] * std::sqrt(std::fabs(Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(deviatoric_strain_rate)));
double scaling_factor = 1.0;
if (deviatoric_stress > 0.0)
scaling_factor = std::min(yield_stress / deviatoric_stress, 1.0);
Expand Down
10 changes: 5 additions & 5 deletions source/material_model/drucker_prager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace aspect
Assert(std::isfinite(in.strain_rate[i].norm()),
ExcMessage("Invalid strain_rate in the MaterialModelInputs. This is likely because it was "
"not filled by the caller."));
const SymmetricTensor<2,dim> strain_rate_deviator = deviator(in.strain_rate[i]);
const SymmetricTensor<2,dim> strain_rate_deviator = Utilities::Tensors::consistent_deviator(in.strain_rate[i]);

// For the very first time this function is called
// (the first iteration of the first timestep), this function is called
Expand All @@ -64,8 +64,8 @@ namespace aspect
// In later iterations and timesteps we calculate the second moment
// invariant of the deviatoric strain rate tensor.
// This is equal to the negative of the second principle
// invariant of the deviatoric strain rate (calculated with the function second_invariant),
// as shown in Appendix A of Zienkiewicz and Taylor (Solid Mechanics, 2000).
// invariant of the deviatoric strain rate, as shown in Appendix A of
// Zienkiewicz and Taylor (Solid Mechanics, 2000).
//
// The negative of the second principle invariant is equal to 0.5 e_dot_dev_ij e_dot_dev_ji,
// where e_dot_dev is the deviatoric strain rate tensor. The square root of this quantity
Expand All @@ -78,7 +78,7 @@ namespace aspect
// initialized. This might mean that we are
// in a unit test, or at least that we can't
// rely on any simulator information
std::fabs(second_invariant(strain_rate_deviator))
std::fabs(Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(strain_rate_deviator))
:
// simulator object is available, but we need to treat the
// first time step separately
Expand All @@ -88,7 +88,7 @@ namespace aspect
?
reference_strain_rate * reference_strain_rate
:
std::fabs(second_invariant(strain_rate_deviator))));
std::fabs(Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(strain_rate_deviator))));

const double strain_rate_effective = edot_ii_strict;

Expand Down
2 changes: 1 addition & 1 deletion source/material_model/entropy_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ namespace aspect
drucker_prager_parameters);
}

const double strain_rate_effective = std::fabs(second_invariant(deviator(in.strain_rate[i])));
const double strain_rate_effective = std::fabs(Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(Utilities::Tensors::consistent_deviator(in.strain_rate[i])));

if (std::sqrt(strain_rate_effective) >= std::numeric_limits<double>::min())
{
Expand Down
10 changes: 5 additions & 5 deletions source/material_model/grain_size.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ 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>();
const double second_strain_rate_invariant = std::sqrt(std::max(-second_invariant(shear_strain_rate), 0.));
const SymmetricTensor<2,dim> shear_strain_rate = Utilities::Tensors::consistent_deviator(strain_rate);
const double second_strain_rate_invariant = std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(shear_strain_rate), 0.));

// If the strain rate is zero, the dislocation viscosity is infinity.
if (second_strain_rate_invariant <= std::numeric_limits<double>::min())
Expand All @@ -221,7 +221,7 @@ namespace aspect
{
const SymmetricTensor<2,dim> dislocation_strain_rate = diffusion_viscosity
/ (diffusion_viscosity + dis_viscosity) * shear_strain_rate;
const double dislocation_strain_rate_invariant = std::sqrt(std::max(-second_invariant(dislocation_strain_rate), 0.));
const double dislocation_strain_rate_invariant = std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(dislocation_strain_rate), 0.));

dis_viscosity_old = dis_viscosity;
dis_viscosity = dislocation_creep_prefactor[phase_index]
Expand Down Expand Up @@ -540,8 +540,8 @@ namespace aspect
Assert(std::isfinite(in.strain_rate[i].norm()),
ExcMessage("Invalid strain_rate in the MaterialModelInputs. This is likely because it was "
"not filled by the caller."));
const SymmetricTensor<2,dim> shear_strain_rate = deviator(in.strain_rate[i]);
const double second_strain_rate_invariant = std::sqrt(std::max(-second_invariant(shear_strain_rate), 0.));
const SymmetricTensor<2,dim> shear_strain_rate = Utilities::Tensors::consistent_deviator(in.strain_rate[i]);
const double second_strain_rate_invariant = std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(shear_strain_rate), 0.));

const double adiabatic_temperature = this->get_adiabatic_conditions().is_initialized()
?
Expand Down
4 changes: 2 additions & 2 deletions source/material_model/reaction_model/grain_size_evolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ namespace aspect
std::pow(roughness_to_grain_size, m);

// grain size reduction in dislocation creep regime
const SymmetricTensor<2,dim> shear_strain_rate = in.strain_rate[i] - 1./dim * trace(in.strain_rate[i]) * unit_symmetric_tensor<dim>();
const double second_strain_rate_invariant = std::sqrt(std::max(-second_invariant(shear_strain_rate), 0.));
const SymmetricTensor<2,dim> shear_strain_rate = Utilities::Tensors::consistent_deviator(in.strain_rate[i]);
const double second_strain_rate_invariant = std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(shear_strain_rate), 0.));

const double current_diffusion_viscosity = diffusion_viscosity(in.temperature[i], adiabatic_temperature, pressures[i], grain_size, second_strain_rate_invariant, phase_indices[i]);
current_dislocation_viscosity = dislocation_viscosity(in.temperature[i], adiabatic_temperature, pressures[i], in.strain_rate[i], phase_indices[i], current_diffusion_viscosity, current_dislocation_viscosity);
Expand Down
4 changes: 2 additions & 2 deletions source/material_model/rheology/composite_visco_plastic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace aspect
// to prevent a division-by-zero, and a floating point exception.
// Otherwise, calculate the square-root of the norm of the second invariant of the deviatoric-
// strain rate (often simplified as epsilondot_ii)
const double edot_ii = std::max(std::sqrt(std::max(-second_invariant(deviator(strain_rate)), 0.)),
const double edot_ii = std::max(std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(Utilities::Tensors::consistent_deviator(strain_rate)), 0.)),
minimum_strain_rate);
const double log_edot_ii = std::log(edot_ii);

Expand Down Expand Up @@ -475,7 +475,7 @@ namespace aspect
// to prevent a division-by-zero, and a floating point exception.
// Otherwise, calculate the square-root of the norm of the second invariant of the deviatoric-
// strain rate (often simplified as epsilondot_ii)
const double edot_ii = std::max(std::sqrt(std::max(-second_invariant(deviator(strain_rate)), 0.)),
const double edot_ii = std::max(std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(Utilities::Tensors::consistent_deviator(strain_rate)), 0.)),
minimum_strain_rate);
const double log_edot_ii = std::log(edot_ii);

Expand Down
2 changes: 1 addition & 1 deletion source/material_model/rheology/diffusion_dislocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace aspect
// to prevent a division-by-zero, and a floating point exception.
// Otherwise, calculate the square-root of the norm of the second invariant of the deviatoric-
// strain rate (often simplified as epsilondot_ii)
const double edot_ii = std::max(std::sqrt(std::max(-second_invariant(deviator(strain_rate)), 0.)),
const double edot_ii = std::max(std::sqrt(std::max(-Utilities::Tensors::consistent_second_invariant_of_deviatoric_tensor(Utilities::Tensors::consistent_deviator(strain_rate)), 0.)),
min_strain_rate);
const double log_edot_ii = std::log(edot_ii);

Expand Down
Loading
Loading