Support 180 degree phi-periodic 2d spherical shells#6957
Conversation
|
I know this is just a draft for now, I just wanted to mention a few concerns I have about this PR. The periodicity of a 3D spherical shell is fundamentally different from what we have implemented at the moment for 2D. In a 2D spherical shell the periodic boundaries are not physically at the same location, there is no location where the periodic faces that are connected across the periodic boundary connect to each other. In a 3D 180 degree spherical shell this is different, the two periodic faces (the two half cuts across the sphere that form a plane) are essentially just one face that you split into two periodic faces. This has a few consequences:
I think what I am saying is mostly, this could be an interesting contribution, but it will need:
|
|
Adding only 180° in 2D for the moment |
|
I updated this PR to keep only the 2D 180 degree phi-periodic spherical shell support. The 3D 180 degree case has been removed from the scope of this PR, because I agree that it needs separate benchmarks, documentation, and checks for the periodicity direction and rotational nullspace behavior. So the current PR is intentionally limited to the simpler 2D case, analogous to the existing 90 degree periodic shell tests, with added 180 degree periodic shell and particle advection tests. Would this reduced 2D-only scope be acceptable for review/merge, while leaving the 3D 180 degree case for a separate future contribution? |
gassmoeller
left a comment
There was a problem hiding this comment.
This should work in principle, but I have some comments that I would like to see addressed before merging this.
Also: Thanks for adding the test. Did you check if particles are crossing the periodic boundary correctly, i.e. did you see a particle with a certain ID leave the domain on one side and enter it on the other? I am just asking because from the setup I cannot tell if this actually happens in your test model.
| template <int dim> | ||
| unsigned int | ||
| phi_periodicity_direction(const double phi) | ||
| { | ||
| Assert(phi == 90 || phi == 180, ExcInternalError()); | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
I dont think this function adds anything to the code for the 2D version (maybe there was a use in 3D). Please remove.
|
|
||
| GridTools::collect_periodic_faces(coarse_grid, /*b_id1*/ 2, /*b_id2*/ 3, | ||
| /*direction*/ 1, matched_pairs, | ||
| phi_periodicity_direction<dim>(phi), matched_pairs, |
There was a problem hiding this comment.
Like I mentioned above, I think the previous code was clearer here. Please revert this line.
| if (periodic) | ||
| { | ||
| Tensor<2, dim> align_with_phi_range; | ||
| align_with_phi_range[0][1] = -1.; | ||
| align_with_phi_range[1][0] = 1.; | ||
|
|
||
| GridTools::transform( | ||
| [&](const Point<dim> &p) -> Point<dim> | ||
| { | ||
| const Tensor<1, dim> rotated_point = align_with_phi_range * p; | ||
| Point<dim> transformed_point; | ||
| for (unsigned int d=0; d<dim; ++d) | ||
| transformed_point[d] = rotated_point[d]; | ||
|
|
||
| return transformed_point; | ||
| }, | ||
| coarse_grid); |
There was a problem hiding this comment.
I dont understand this piece of code. It looks like you are rotating the whole grid by 90 degrees. Is this necessary or a preference? It should definitely get a comment explaining the reasoning behind it. But this also creates practical problems. Consider a model that you first run and evaluate without periodic boundaries. Then you switch the boundary condition and suddenly your model geometry changes. This is unexpected from a user perspective and may break workflows that assume they can rely on the geometry of the 180 degree 2D spherical shell. Does the periodic boundary work without rotating the grid?
| if (position[1] >= 0.) | ||
| return; |
There was a problem hiding this comment.
So this part relies on the geometry modification you did above. But couldnt this be formulated no matter how the geometry is rotated?
Also I would recommend to keep the structure in a way that there is only one early return statement, i.e. the meaning of this condition should be:
if (phi == 180 && coordinate suggests the position needs to be rotated)
set rotation matrix
else if (phi == 90 && coordinate suggests the position needs to be rotated)
set rotation matrix
else
// nothing to do, return early
// now do the rotation
There was a problem hiding this comment.
This code now looks odd, because you introduced the function phi_periodicity_rotation_tensor above, which should already give the rotation matrix. Instead you could write the following to make the intent more clear:
| else if (position[0] < 0.) | |
| { | |
| // if the position crossed the west boundary there | |
| // is nothing to do, use the rotation matrix as is | |
| // to rotate the position clock-wise | |
| } | |
| else if (position[1] < 0.) | |
| { | |
| // rotate the opposite direction (anti clock-wise) | |
| // if the position crossed the east boundary | |
| rotation_matrix *= -1; | |
| } | |
| else |
|
|
||
| return rotation_matrix; | ||
| } | ||
|
|
There was a problem hiding this comment.
It is unfortunate that GridTools::collect_periodic_faces requires a FullMatrix as input, while we want to use a Tensor<2,dim elsewhere, but the solution is not to duplicate this code. Please check if there is a deal.II function to convert a dimxdim matrix into a Tensor<2,dim>, and if not, then we can easily write our own:
template <int dim>
FullMatrix<double>
phi_periodicity_rotation_matrix(const double phi)
{
FullMatrix<double> rotation_matrix(dim);
const Tensor<2,dim> rotation_tensor = phi_periodicity_rotation_tensor(phi);
// loop to convert rotation tensor into rotation matrix
...
This avoids the code duplication.
|
Also please add a changelog entry. |
Hi, for my simulations cases (LLSVPs simulations, so thermochemical simulations where i give a field for LLSVPs and a field for the mantle) LLSVPs cross the boundary perfectly like in the 90° cases without any problem, I was also thinking that these 180° implementation was "good enough" to "replicate" the behaviour of the 360° sims. I'm gonna address also your comment and make clearer tests |
|
Hi @gassmoeller, I went through your comments and cleaned up the patch. What I changed:
The relevant local tests for 2d spherical-shell periodicity and particles pass. I also did a larger manual sanity test with a Steinberger-style 180 degree shell and particles. I first ran it without phi periodicity to 100 Myr. The 100 Myr non-periodic output had 43,425 particles. Then I restarted from that run with The particle count is not expected to stay constant in this setup, because the model uses the To make the restart behavior easier to check, I also made a side-by-side movie from the original output files. The left panel shows the particles colored by temperature, the right panel shows the full temperature field, and the frame around 100 Myr is marked with The zipped movie is available here: |
gassmoeller
left a comment
There was a problem hiding this comment.
Very nice, just two minor comments left. Thanks for checking, I just couldnt tell from your previous comments if you had actually observed particles crossing the boundary.
After addressing the comments and updating the test results this should be ready.
| * <li> New: The 2d spherical shell geometry model now supports | ||
| * 180 degree phi-periodic shells, including particle advection across | ||
| * the periodic boundary. | ||
| * <br> | ||
| * (Francesco Radica, 2026/05/20) | ||
| * |
There was a problem hiding this comment.
Sorry, this file is reserved for changes that happened before 3.0.0. Please put this changelog entry into a new file in /doc/modules/changes. We will combine all changelog entries into a new file for the release 3.1 later. (see here for instructions).
| end | ||
|
|
||
| subsection Mesh refinement | ||
| set Initial global refinement = 5 |
There was a problem hiding this comment.
The two particle tests run with a global resolution of 4, which makes the tests run in less than 10 seconds, which saves some compute time. Since you have to update the test results anyway (the tester failed), can you also reduce the resolution here to 4?
instructions on updating test results: https://aspect-documentation.readthedocs.io/en/latest/user/extending/testing/writing-tests.html#updating-test-results-for-pull-requests
|
@gassmoeller done |
gassmoeller
left a comment
There was a problem hiding this comment.
Thanks, then this is ready when the testers are done.
|
/rebuild |
|
One of our testers has connection issues, but it is almost a duplicate of one of the other test setups, so I think this is fine to merge now. |
Summary
Phi periodicparameter documentation to list only the supported 2d opening angles.This addresses the 2d spherical-shell part of #6926.
Testing
git diff --checkcmake --build build-debug --target aspect -j20cmake --build build-debug --target setup_tests -j20ctest -N -R 'periodic_half_shell_3d'->Total Tests: 0ctest -R '^(periodic_half_shell|particle_periodic_half_shell|particle_periodic_half_shell_2|periodic_quarter_shell|particle_periodic_quarter_shell|particle_periodic_quarter_shell_2)$' --output-on-failure100% tests passed, 0 tests failed out of 6withnumdiffenabled for numerical comparisons.