-
Notifications
You must be signed in to change notification settings - Fork 240
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
Add cpo elastic tensor decomposition plugin #5116
Conversation
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. |
{ | ||
|
||
/** | ||
* Computes the elastic tensor $C_{ijkl} based on the cpo in both olivine |
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.
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. |
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.
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 |
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.
* 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 |
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.
* 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. |
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
const ArrayView<double> &data) const | ||
{ | ||
SymmetricTensor<2,6,double> Sav; | ||
const SymmetricTensor<2,6> *stiffness_matrix = &stiffness_matrix_olivine; |
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.
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; |
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.
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 |
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.
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); |
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.
Please use the std namespace for sin, cos and similar math functions.
0dd656d
to
f88113a
Compare
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.
@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. |
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.
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 |
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.
Why do you expect it to be 6x6?
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
f88113a
to
f8a4bcd
Compare
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.
First batch of comments. I can take another look after you moved the matrices.
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
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 |
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.
this first sentence doesnt really make sense. please rework.
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.
I hope this is more clear.
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.
Thanks for your review and sorry that it took so long to get around to this. I have addressed all your comments.
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.; |
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.
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 |
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.
I hope this is more clear.
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
e946b52
to
9fd6dc1
Compare
@gassmoeller Could you have another look at this? |
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.
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 | ||
{ | ||
|
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.
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.
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
include/aspect/particle/property/elastic_tensor_decomposition.h
Outdated
Show resolved
Hide resolved
// 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; |
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.
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; |
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.
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 &) |
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.
if declare_parameters
and parse_parameters
are empty remove them
"elastic tensor decomposition", | ||
"A plugin in which decomposes the elastic tensor " | ||
"into different approximations and provides the " | ||
"eigenvectors of the tensor.") |
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.
Is it worth describing in a bit more details what the different approximations are?
b0e31f6
to
55be865
Compare
@gassmoeller I addressed all your comments, except for adding a test. I will do that next, but the rest is ready for review again. |
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? |
Co-authored-by: Bob Myhill <[email protected]>
Co-authored-by: Rene Gassmoeller <[email protected]>
55be865
to
7368f89
Compare
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. |
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.
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?
/rebuild |
Thanks for all the reviewing, it is really appreciated and made the code a whole lot better! 🎉 |
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.