-
Notifications
You must be signed in to change notification settings - Fork 274
Add viscosity additional outputs #6974
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Added: additional named outputs for diffusion and dislocation viscosities in the visco-plastic material model, including rheology-specific handling of inactive flow laws and visualization support through the additional material output system. | ||
| <br> | ||
| (Haoyuan Li, 2026/05/12) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,32 @@ namespace aspect | |
|
|
||
| }; | ||
|
|
||
| /** | ||
| * Additional output fields for diffusion and dislocation viscosities. | ||
| */ | ||
| template <int dim> | ||
| class ViscosityAdditionalOutputs : public NamedAdditionalMaterialOutputs<dim> | ||
| { | ||
| public: | ||
| /** | ||
| * Constructor. | ||
| */ | ||
| ViscosityAdditionalOutputs(const unsigned int n_points); | ||
|
|
||
| std::vector<double> | ||
| get_nth_output(const unsigned int idx) const override; | ||
|
|
||
| /** | ||
| * Diffusion viscosities. | ||
| */ | ||
| std::vector<double> diffusion_viscosities; | ||
|
|
||
| /** | ||
| * Dislocation viscosities. | ||
| */ | ||
|
Comment on lines
+107
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| std::vector<double> dislocation_viscosities; | ||
| }; | ||
|
|
||
| /** | ||
| * A data structure with the output of calculate_isostrain_viscosities. | ||
| */ | ||
|
|
@@ -117,6 +143,16 @@ namespace aspect | |
| * MaterialModel::PrescribedDilation::dilation_rhs_term. | ||
| */ | ||
| std::vector<double> dilation_rhs_terms; | ||
|
|
||
| /** | ||
| * Diffusion viscosities for each composition. | ||
| */ | ||
| std::vector<double> diffusion_viscosities; | ||
|
|
||
| /** | ||
| * Dislocation viscosities for each composition. | ||
| */ | ||
| std::vector<double> dislocation_viscosities; | ||
| }; | ||
|
|
||
| namespace Rheology | ||
|
|
@@ -209,6 +245,21 @@ namespace aspect | |
| const MaterialModel::MaterialModelInputs<dim> &in, | ||
| MaterialModel::MaterialModelOutputs<dim> &out, | ||
| const IsostrainViscosities &isostrain_viscosities) const; | ||
| /** | ||
| * Create additional outputs for diffusion and dislocation viscosities. | ||
| */ | ||
| void | ||
| create_viscosity_outputs(MaterialModel::MaterialModelOutputs<dim> &out) const; | ||
|
|
||
|
|
||
| /** | ||
| * Fill additional outputs for diffusion and dislocation viscosities, | ||
| * if viscosity additional output object is created. | ||
| */ | ||
|
lhy11009 marked this conversation as resolved.
|
||
| void fill_viscosity_outputs(const unsigned int point_index, | ||
| const std::vector<double> &volume_fractions, | ||
| MaterialModel::MaterialModelOutputs<dim> &out, | ||
| const IsostrainViscosities &isostrain_viscosities) const; | ||
|
|
||
| /** | ||
| * Minimum strain rate used to stabilize the strain rate dependent rheology. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,42 @@ namespace aspect | |
|
|
||
|
|
||
|
|
||
| namespace | ||
| { | ||
| std::vector<std::string> make_viscosity_additional_outputs_names() | ||
| { | ||
| std::vector<std::string> names; | ||
| names.emplace_back("diffusion_viscosity"); | ||
| names.emplace_back("dislocation_viscosity"); | ||
| return names; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| ViscosityAdditionalOutputs<dim>::ViscosityAdditionalOutputs(const unsigned int n_points) | ||
| : NamedAdditionalMaterialOutputs<dim>(make_viscosity_additional_outputs_names()), | ||
| diffusion_viscosities(n_points, numbers::signaling_nan<double>()), | ||
| dislocation_viscosities(n_points, numbers::signaling_nan<double>()) | ||
| {} | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| std::vector<double> | ||
| ViscosityAdditionalOutputs<dim>::get_nth_output(const unsigned int idx) const | ||
| { | ||
| AssertIndexRange(idx, 2); | ||
|
|
||
| if (idx == 0) | ||
| return diffusion_viscosities; | ||
| else | ||
| return dislocation_viscosities; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| namespace Rheology | ||
| { | ||
|
|
||
|
|
@@ -110,6 +146,8 @@ namespace aspect | |
| output_parameters.drucker_prager_parameters.resize(volume_fractions.size()); | ||
| output_parameters.dilation_lhs_terms.resize(volume_fractions.size(), numbers::signaling_nan<double>()); | ||
| output_parameters.dilation_rhs_terms.resize(volume_fractions.size(), numbers::signaling_nan<double>()); | ||
| output_parameters.diffusion_viscosities.resize(volume_fractions.size(), numbers::signaling_nan<double>()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, in the calculation step, it seems the nan value won't trigger issue, as indicated by the examples of other variables. |
||
| output_parameters.dislocation_viscosities.resize(volume_fractions.size(), numbers::signaling_nan<double>()); | ||
|
|
||
| // Assemble current and old stress tensor if elastic behavior is enabled | ||
| SymmetricTensor<2, dim> stress_0_advected = numbers::signaling_nan<SymmetricTensor<2, dim>>(); | ||
|
|
@@ -220,12 +258,14 @@ namespace aspect | |
| { | ||
| non_yielding_viscosity = compositional_viscosity_prefactors.compute_viscosity(in, viscosity_diffusion, j, i, | ||
| CompositionalViscosityPrefactors<dim>::ModifiedFlowLaws::diffusion); | ||
| output_parameters.diffusion_viscosities[j] = non_yielding_viscosity; | ||
| break; | ||
| } | ||
| case dislocation: | ||
| { | ||
| non_yielding_viscosity = compositional_viscosity_prefactors.compute_viscosity(in, viscosity_dislocation, j, i, | ||
| CompositionalViscosityPrefactors<dim>::ModifiedFlowLaws::dislocation); | ||
| output_parameters.dislocation_viscosities[j] = non_yielding_viscosity; | ||
| break; | ||
| } | ||
| case frank_kamenetskii: | ||
|
|
@@ -244,6 +284,9 @@ namespace aspect | |
| CompositionalViscosityPrefactors<dim>::ModifiedFlowLaws::dislocation); | ||
| non_yielding_viscosity = (scaled_viscosity_diffusion * scaled_viscosity_dislocation)/ | ||
| (scaled_viscosity_diffusion + scaled_viscosity_dislocation); | ||
|
|
||
| output_parameters.diffusion_viscosities[j] = scaled_viscosity_diffusion; | ||
| output_parameters.dislocation_viscosities[j] = scaled_viscosity_dislocation; | ||
| break; | ||
| } | ||
| case minimum_diffusion_dislocation: | ||
|
|
@@ -253,6 +296,9 @@ namespace aspect | |
| const double scaled_viscosity_dislocation = compositional_viscosity_prefactors.compute_viscosity(in, viscosity_dislocation, j, i, | ||
| CompositionalViscosityPrefactors<dim>::ModifiedFlowLaws::dislocation); | ||
| non_yielding_viscosity = std::min(scaled_viscosity_diffusion, scaled_viscosity_dislocation); | ||
|
|
||
| output_parameters.diffusion_viscosities[j] = scaled_viscosity_diffusion; | ||
| output_parameters.dislocation_viscosities[j] = scaled_viscosity_dislocation; | ||
| break; | ||
| } | ||
| default: | ||
|
|
@@ -984,6 +1030,95 @@ namespace aspect | |
| } | ||
| } | ||
|
|
||
| template <int dim> | ||
| void | ||
| Rheology::ViscoPlastic<dim>::create_viscosity_outputs (MaterialModel::MaterialModelOutputs<dim> &out) const | ||
| { | ||
| if (out.template has_additional_output_object<ViscosityAdditionalOutputs<dim>>() == false) | ||
| { | ||
| const unsigned int n_points = out.n_evaluation_points(); | ||
|
|
||
| out.additional_outputs.push_back( | ||
| std::make_unique<ViscosityAdditionalOutputs<dim>>(n_points)); | ||
| } | ||
| } | ||
|
|
||
| template <int dim> | ||
| void | ||
| Rheology::ViscoPlastic<dim>::fill_viscosity_outputs( | ||
| const unsigned int i, | ||
| const std::vector<double> &volume_fractions, | ||
| MaterialModel::MaterialModelOutputs<dim> &out, | ||
| const IsostrainViscosities &isostrain_viscosities) const | ||
| { | ||
| if (const std::shared_ptr<ViscosityAdditionalOutputs<dim>> | ||
| viscosity_out = out.template get_additional_output_object<ViscosityAdditionalOutputs<dim>>()) | ||
| { | ||
| switch (viscous_flow_law) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are doing almost the same operation in the each case, you could replace ln 1057-1114 by initializing the viscosities using a default value (std::max in your case) and a flag to decide whether to output diffusion viscosities or/and dislocation viscosities. and similarly for the |
||
| { | ||
| case diffusion: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, I assign the value to max limit, if the viscosity is not computed by the viscous flow law (e.g. the dislocation creep would not be calculated if the flow law is diffusion). I'm not entirely sure this is the best approach. I have tested that assigning values to nan doesn't work and will trigger error in the post-processor. The values will be written as "inf" in outputs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I see. Does the issue persist after #6973 was merged?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this and 6973 are separated. |
||
| { | ||
| viscosity_out->diffusion_viscosities[i] | ||
| = MaterialUtilities::average_value( | ||
| volume_fractions, | ||
| isostrain_viscosities.diffusion_viscosities, | ||
| viscosity_averaging); | ||
|
|
||
| viscosity_out->dislocation_viscosities[i] | ||
| = std::numeric_limits<double>::max(); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case dislocation: | ||
| { | ||
| viscosity_out->diffusion_viscosities[i] | ||
| = std::numeric_limits<double>::max(); | ||
|
|
||
| viscosity_out->dislocation_viscosities[i] | ||
| = MaterialUtilities::average_value( | ||
| volume_fractions, | ||
| isostrain_viscosities.dislocation_viscosities, | ||
| viscosity_averaging); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case composite: | ||
| case minimum_diffusion_dislocation: | ||
| { | ||
| viscosity_out->diffusion_viscosities[i] | ||
| = MaterialUtilities::average_value( | ||
| volume_fractions, | ||
| isostrain_viscosities.diffusion_viscosities, | ||
| viscosity_averaging); | ||
|
|
||
| viscosity_out->dislocation_viscosities[i] | ||
| = MaterialUtilities::average_value( | ||
| volume_fractions, | ||
| isostrain_viscosities.dislocation_viscosities, | ||
| viscosity_averaging); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case frank_kamenetskii: | ||
| { | ||
| viscosity_out->diffusion_viscosities[i] | ||
| = std::numeric_limits<double>::max(); | ||
|
|
||
| viscosity_out->dislocation_viscosities[i] | ||
| = std::numeric_limits<double>::max(); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| default: | ||
| AssertThrow(false, ExcInternalError()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
@@ -995,6 +1130,7 @@ namespace aspect | |
| { | ||
| #define INSTANTIATE(dim) \ | ||
| template class PlasticAdditionalOutputs<dim>; \ | ||
| template class ViscosityAdditionalOutputs<dim>; \ | ||
| \ | ||
| namespace Rheology \ | ||
| { \ | ||
|
|
||
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.
Here, it would be helpful to add the details. As I understand, these are the diffusion viscosities that are computed in Rheology::DiffusionCreep::compute_viscosity() function before yielding. The values are only relevant when diffusion creep is present, i.e., viscous flow law is either diffusion or composite.
Or something along these lines.