Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cookbooks/anisotropic_viscosity/AV_Rayleigh_Taylor.prm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ subsection Initial composition model

subsection Function
set Variable names = x,z
set Function constants = pi=3.1415926;
set Function constants = pi=3.1415926
Copy link
Contributor

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

Copy link
Member Author

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.

ERROR: FunctionParser failed to parse
	'Initial composition model.Function'
with expression
	'0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02)); (0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02))) > 0.8 ? sin(45*pi/180) : 0.0; (0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02))) > 0.8 ? cos(45*pi/180) : 0.0;'
More information about the cause of the parse error 
is shown below.
---------------------------------------------------------
TimerOutput objects finalize timed values printed to the
screen by communicating over MPI in their destructors.
Since an exception is currently uncaught, this
synchronization (and subsequent output) will be skipped
to avoid a possible deadlock.
---------------------------------------------------------


----------------------------------------------------
Exception 'ExcMessage("Can't convert <" + s + "> to a double.")' on rank 0 on processing: 

--------------------------------------------------------
An error occurred in line <678> of file </home/rene/software/deal.II-9.5.2/tmp/unpack/deal.II-v9.7.0-rc1/source/base/utilities.cc> in function
    double dealii::Utilities::string_to_double(const std::string&)
Additional information: 
    Can't convert <3.1415926;> to a double.

Stacktrace:
-----------
#0  /home/rene/software/deal.II-9.5.2/deal.II-v9.7.0-rc1/lib/libdeal_II.g.so.9.7.0-rc1: dealii::Utilities::string_to_double(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
#1  /home/rene/software/deal.II-9.5.2/deal.II-v9.7.0-rc1/lib/libdeal_II.g.so.9.7.0-rc1: dealii::Functions::ParsedFunction<2>::parse_parameters(dealii::ParameterHandler&)
#2  ./aspect: aspect::InitialComposition::Function<2>::parse_parameters(dealii::ParameterHandler&)
#3  ./aspect: aspect::InitialComposition::Manager<2>::parse_parameters(dealii::ParameterHandler&)
#4  ./aspect: aspect::Simulator<2>::Simulator(ompi_communicator_t*, dealii::ParameterHandler&)
#5  ./aspect: 
#6  ./aspect: main
--------------------------------------------------------

Aborting!
----------------------------------------------------
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------

Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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 :-)

set Function expression = 0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02)); \
(0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02))) > 0.8 ? sin(45*pi/180) : 0.0; \
(0.5*(1+tanh((z-0.85-0.02*cos(2*pi*x/2))/0.02))) > 0.8 ? cos(45*pi/180) : 0.0;
Expand Down
438 changes: 2 additions & 436 deletions cookbooks/anisotropic_viscosity/av_material.cc

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions include/aspect/heating_model/shear_heating_anisotropic_viscosity.h
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
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
2 changes: 1 addition & 1 deletion include/aspect/simulator/assemblers/stokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace aspect
};

/**
* 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
* compressible models, because the divergence of the velocity is not longer zero.
*/
template <int dim>
Expand Down
104 changes: 104 additions & 0 deletions include/aspect/simulator/assemblers/stokes_anisotropic_viscosity.h
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 source/heating_model/shear_heating_anisotropic_viscosity.cc
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.")
}
}
Loading