Skip to content
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

Add cpo elastic tensor decomposition plugin #5116

Conversation

MFraters
Copy link
Member

Last major part of #3885. Adds a property plugin which can use the elastic tensor computed in #4987 to compute actual useful values from it. It requires that plugin to be present, so it is currently rebased on that.

Since this is the last major component of the CPO plugin set, I am happy to include the integration tests within this pull request, or do that in a follow up pull request. I will include the changelog entry in the pull request where the integration tests are added, so if that is here, that will be here as well.

This pull request is ready for review, but can't be merged until #4987 is merged.

@bobmyhill
Copy link
Member

bobmyhill commented Jul 8, 2023

Hi @MFraters, mostly typos here, but I do wonder whether the vast majority of this shouldn't be in an TensorConversion namespace in utilities rather than a separate plugin. Most of the functions are quite general, and they would probably be useful for anisotropic viscosity too, which also describes a linear relationship between two symmetric second order tensors.

You should extend the docstring(s) introducing the conversions, the symmetries behind them, and citing the equations from a relevant study for each (probably Mainprice). Expecially for the conversions to and from the 1x21 vector, which I don't believe is a standard form.

P.S.: Most of my comments here mirror @gassmoeller's from #4987. Good to double check his comments as well as mine to make sure you've covered everything.

include/aspect/particle/property/cpo_elastic_tensor.h Outdated Show resolved Hide resolved
{

/**
* Computes the elastic tensor $C_{ijkl} based on the cpo in both olivine
Copy link
Member

Choose a reason for hiding this comment

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

This is documentation for a class, not a function. Can you reword the docstring to clarify the purpose of the class?

* grain size, $N_s$ is the number of grains and $C_{ijkl}$ is the elastic
* tensor. This elastic tensor is computed by the equation above in
* Mainprice (1990): $C_{ijkl} = R_{ip} R_{jg} R_{kr} R_{is} C_{pgrs}$, where
* R_{ij} is the cpo orientation matrix.
Copy link
Member

Choose a reason for hiding this comment

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

Can you mention that you return the Voigt form?

SymmetricTensor<2,6> &elastic_tensor);

/**
* Rotate a 3D 4th order tensor with an other 3D 4th
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Rotate a 3D 4th order tensor with an other 3D 4th
* Rotate a 3x3x3x3 elastic tensor with a 3x3 tensor



/**
* Rotate a 6x6 voigt matrix with an other 3D 4th
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Rotate a 6x6 voigt matrix with an other 3D 4th
* Rotate a 4th order elastic tensor in Voigt form (6x6) with a 3x3 rotation tensor.

const ArrayView<double> &data) const
{
SymmetricTensor<2,6,double> Sav;
const SymmetricTensor<2,6> *stiffness_matrix = &stiffness_matrix_olivine;
Copy link
Member

Choose a reason for hiding this comment

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

there's an odd mix of hard coding here and generality in the next line

template <int dim>
CpoElasticTensor<dim>::CpoElasticTensor ()
{
permutation_operator_3d[0][1][2] = 1;
Copy link
Member

Choose a reason for hiding this comment

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

This is the Levi-Civita tensor and is already used in cpo_bingham_average. Better to move somewhere more general.

input[0][0], // 0 // 1
input[1][1], // 1 // 2
input[2][2], // 2 // 3
sqrt(2)*input[1][2], // 3 // 4
Copy link
Member

Choose a reason for hiding this comment

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

Please use the std namespace for sqrt and similar math functions.

double alpha = radians;
double beta = radians;
double gamma = radians;
rotation_tensor[0][0] = cos(alpha) * cos(beta);
Copy link
Member

Choose a reason for hiding this comment

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

Please use the std namespace for sin, cos and similar math functions.

@MFraters MFraters mentioned this pull request Jul 13, 2023
@MFraters MFraters force-pushed the add_cpo_elastic_tensor_decomposition_plugin branch 3 times, most recently from 0dd656d to f88113a Compare August 4, 2023 19:12
Copy link
Member Author

@MFraters MFraters left a comment

Choose a reason for hiding this comment

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

@bobmyhill Thanks for your review! I have addressed your comments related to the files for this pull request.


/**
* Return which data has to be provided to update the property.
* The integrated strains needs the gradients of the velocity.
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the function, since it just uses the default

indexed_even_permutation(const unsigned short int index);

/**
* Computes the voigt stiffness tensor from the elastic tensor
Copy link
Member Author

Choose a reason for hiding this comment

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

Why do you expect it to be 6x6?

@MFraters MFraters force-pushed the add_cpo_elastic_tensor_decomposition_plugin branch from f88113a to f8a4bcd Compare August 12, 2023 19:31
Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

First batch of comments. I can take another look after you moved the matrices.

if (std::abs(dv_dot_product) >= 1.0)
dv_dot_product = std::copysign(1.0,dv_dot_product);
// compute the angle bewteen the vectors and account for that vectors in the oposit
// direction are the same. So limit them between 0 and 90 degrees such that it
Copy link
Member

Choose a reason for hiding this comment

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

this first sentence doesnt really make sense. please rework.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope this is more clear.

source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
Copy link
Member Author

@MFraters MFraters left a comment

Choose a reason for hiding this comment

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

Thanks for your review and sorry that it took so long to get around to this. I have addressed all your comments.

Comment on lines 43 to 151
projection_matrix_tric_to_mono[7][7] = 1.0;
projection_matrix_tric_to_mono[8][8] = 1.0;
projection_matrix_tric_to_mono[11][11] = 1.0;
projection_matrix_tric_to_mono[14][14] = 1.0;
projection_matrix_tric_to_mono[17][17] = 1.0;
projection_matrix_tric_to_mono[20][20] = 1.0;


// projection_matrix_mono_to_ortho;
projection_matrix_mono_to_ortho[0][0] = 1.0;
projection_matrix_mono_to_ortho[1][1] = 1.0;
projection_matrix_mono_to_ortho[2][2] = 1.0;
projection_matrix_mono_to_ortho[3][3] = 1.0;
projection_matrix_mono_to_ortho[4][4] = 1.0;
projection_matrix_mono_to_ortho[5][5] = 1.0;
projection_matrix_mono_to_ortho[6][6] = 1.0;
projection_matrix_mono_to_ortho[7][7] = 1.0;
projection_matrix_mono_to_ortho[8][8] = 1.0;

// projection_matrix_ortho_to_tetra;
projection_matrix_ortho_to_tetra[0][0] = 0.5;
projection_matrix_ortho_to_tetra[0][1] = 0.5;
projection_matrix_ortho_to_tetra[1][1] = 0.5;
projection_matrix_ortho_to_tetra[2][2] = 1.0;
projection_matrix_ortho_to_tetra[3][3] = 0.5;
projection_matrix_ortho_to_tetra[3][4] = 0.5;
projection_matrix_ortho_to_tetra[4][4] = 0.5;
projection_matrix_ortho_to_tetra[5][5] = 1.0;
projection_matrix_ortho_to_tetra[6][6] = 0.5;
projection_matrix_ortho_to_tetra[6][7] = 0.5;
projection_matrix_ortho_to_tetra[7][7] = 0.5;
projection_matrix_ortho_to_tetra[8][8] = 1.0;

// projection_matrix_tetra_to_hexa;
projection_matrix_tetra_to_hexa[0][0] = 3./8.;
projection_matrix_tetra_to_hexa[0][1] = 3./8.;
projection_matrix_tetra_to_hexa[1][1] = 3./8.;
projection_matrix_tetra_to_hexa[2][2] = 1.0;
projection_matrix_tetra_to_hexa[3][3] = 0.5;
projection_matrix_tetra_to_hexa[3][4] = 0.5;
projection_matrix_tetra_to_hexa[4][4] = 0.5;
projection_matrix_tetra_to_hexa[5][5] = 3./4.;
projection_matrix_tetra_to_hexa[6][6] = 0.5;
projection_matrix_tetra_to_hexa[6][7] = 0.5;
projection_matrix_tetra_to_hexa[7][7] = 0.5;
projection_matrix_tetra_to_hexa[8][8] = 0.5;
projection_matrix_tetra_to_hexa[5][0] = 1./(4.*std::sqrt(2.0));
projection_matrix_tetra_to_hexa[5][1] = 1./(4.*std::sqrt(2.0));
projection_matrix_tetra_to_hexa[8][0] = 0.25;
projection_matrix_tetra_to_hexa[8][1] = 0.25;
projection_matrix_tetra_to_hexa[8][5] = -1/(2*std::sqrt(2.0));


// projection_matrix_hexa_to_iso;
projection_matrix_hexa_to_iso[0][0] = 3./15.;
projection_matrix_hexa_to_iso[0][1] = 3./15.;
projection_matrix_hexa_to_iso[0][2] = 3./15.;
projection_matrix_hexa_to_iso[1][1] = 3./15.;
projection_matrix_hexa_to_iso[1][2] = 3./15.;
projection_matrix_hexa_to_iso[2][2] = 3./15.;
projection_matrix_hexa_to_iso[3][3] = 4./15.;
projection_matrix_hexa_to_iso[3][4] = 4./15.;
projection_matrix_hexa_to_iso[3][5] = 4./15.;
projection_matrix_hexa_to_iso[4][4] = 4./15.;
projection_matrix_hexa_to_iso[4][5] = 4./15.;
projection_matrix_hexa_to_iso[5][5] = 4./15.;
projection_matrix_hexa_to_iso[6][6] = 1./5.;
projection_matrix_hexa_to_iso[6][7] = 1./5.;
projection_matrix_hexa_to_iso[6][8] = 1./5.;
projection_matrix_hexa_to_iso[7][7] = 1./5.;
projection_matrix_hexa_to_iso[7][8] = 1./5.;
projection_matrix_hexa_to_iso[8][8] = 1./5.;

projection_matrix_hexa_to_iso[0][3] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[0][4] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[0][5] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[1][3] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[1][4] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[1][5] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[2][3] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[2][4] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[2][5] = std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[0][6] = 2./15.;
projection_matrix_hexa_to_iso[0][7] = 2./15.;
projection_matrix_hexa_to_iso[0][8] = 2./15.;
projection_matrix_hexa_to_iso[1][6] = 2./15.;
projection_matrix_hexa_to_iso[1][7] = 2./15.;
projection_matrix_hexa_to_iso[1][8] = 2./15.;
projection_matrix_hexa_to_iso[2][6] = 2./15.;
projection_matrix_hexa_to_iso[2][7] = 2./15.;
projection_matrix_hexa_to_iso[2][8] = 2./15.;
projection_matrix_hexa_to_iso[3][6] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[3][7] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[3][8] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[4][6] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[4][7] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[4][8] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[5][6] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[5][7] = -std::sqrt(2.0)/15.;
projection_matrix_hexa_to_iso[5][8] = -std::sqrt(2.0)/15.;
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't make them constexpr, but I can make them const, so that is what I did. Feel free to see if you can make it work for constexpr, but I wasn't able to

if (std::abs(dv_dot_product) >= 1.0)
dv_dot_product = std::copysign(1.0,dv_dot_product);
// compute the angle bewteen the vectors and account for that vectors in the oposit
// direction are the same. So limit them between 0 and 90 degrees such that it
Copy link
Member Author

Choose a reason for hiding this comment

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

I hope this is more clear.

source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
@MFraters MFraters force-pushed the add_cpo_elastic_tensor_decomposition_plugin branch from e946b52 to 9fd6dc1 Compare March 16, 2024 04:13
@MFraters MFraters changed the title [ready for review, do no merge] Add cpo elastic tensor decomposition plugin Add cpo elastic tensor decomposition plugin Mar 16, 2024
@gassmoeller gassmoeller self-assigned this Apr 11, 2024
@MFraters
Copy link
Member Author

@gassmoeller Could you have another look at this?

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

The structure looks good now, I only have a bunch of small comments and requests for better documentation. Can you also add a changelog entry?

Also: We dont have many tests in the tests/ directory for the rest of CPO implementation. I vaguely remember that you said you need this PR to be able to write tests. Can you start adding tests to this PR? Otherwise we will forget about it in the future.


namespace Utility
{

Copy link
Member

Choose a reason for hiding this comment

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

Have a look and be consistent about the number of empty lines when opening namespaces. I would suggest no empty lines in line 39, and only one in line 32-33.

// The following line would do the same as the lines below, but it is slow. It has therefore been
// replaced by the lines below.
//auto ortho_and_higher_vector = projection_matrix_mono_to_ortho*mono_and_higher_vector;
dealii::Tensor<1,9> mono_and_higher_vector_cropped;
Copy link
Member

Choose a reason for hiding this comment

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

What does cropped mean?

ortho_and_higher_vector[6] = mono_and_higher_vector[6];
ortho_and_higher_vector[7] = mono_and_higher_vector[7];
ortho_and_higher_vector[8] = mono_and_higher_vector[8];
auto mono_vector = mono_and_higher_vector_cropped-ortho_and_higher_vector;
Copy link
Member

Choose a reason for hiding this comment

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

can you change the variable names to always contain the full name of the crystal system? mono is a very ambiguous name, monoclinal is much more specific.


template <int dim>
void
ElasticTensorDecomposition<dim>::declare_parameters (ParameterHandler &)
Copy link
Member

Choose a reason for hiding this comment

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

if declare_parameters and parse_parameters are empty remove them

source/particle/property/elastic_tensor_decomposition.cc Outdated Show resolved Hide resolved
"elastic tensor decomposition",
"A plugin in which decomposes the elastic tensor "
"into different approximations and provides the "
"eigenvectors of the tensor.")
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth describing in a bit more details what the different approximations are?

@MFraters MFraters force-pushed the add_cpo_elastic_tensor_decomposition_plugin branch 2 times, most recently from b0e31f6 to 55be865 Compare June 4, 2024 20:57
@MFraters
Copy link
Member Author

MFraters commented Jun 4, 2024

@gassmoeller I addressed all your comments, except for adding a test. I will do that next, but the rest is ready for review again.

@gassmoeller
Copy link
Member

There are a number of my comments that are marked as resolved, but have not been fixed in the code (it is a bad habit of Github to mark comments as resolved if you rebase and push, I think this is why they dont show up). Can you check https://github.com/geodynamics/aspect/pull/5116/files and check all resolved comments if they have been addressed?

@MFraters MFraters force-pushed the add_cpo_elastic_tensor_decomposition_plugin branch from 55be865 to 7368f89 Compare June 4, 2024 22:27
@MFraters
Copy link
Member Author

MFraters commented Jun 4, 2024

Sorry, I think I forgot to pull after applying your comments and before I added the changes locally and then force pushed. I fixed it now manually.

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

Alright, I think this is ready to be included. Last major part of the CPO implementation done. Thanks again @MFraters for undertaking this massive project! Looking forward to seeing more applications using CPO. 🎉

As a follow-up PR: Think about removing the warnings that CPO is experimental. Add more integration tests, and a changelog entry?

@gassmoeller
Copy link
Member

/rebuild

@gassmoeller gassmoeller merged commit 3c22a3a into geodynamics:main Jun 5, 2024
8 checks passed
@MFraters
Copy link
Member Author

MFraters commented Jun 5, 2024

Thanks for all the reviewing, it is really appreciated and made the code a whole lot better! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants