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

Implement general 2D forest meshes #1047

Open
wants to merge 78 commits into
base: lroberts36/refactor-mesh-constructors
Choose a base branch
from

Conversation

lroberts36
Copy link
Collaborator

@lroberts36 lroberts36 commented Apr 11, 2024

PR Summary

This PR implements the minimum necessary technology for defining meshes based on generally connected forests of octrees. I have left details of coordinates to a future PR, so for now each tree must cover a hyper-rectangular domain defined by $\vec{x}_\text{min}$ and $\Delta \vec{x}$. Some rough notes about my implementation are in ForestOfOctreesNotes.pdf

The four major things this PR accomplishes:

  • Add forest::Node, forest::Edge, and forest::Face for defining the forest mesh topology. forest::Face contains routines for finding neighbors and then calculating the correct logical coordinate transformations to those neighbors. For now, I have stuck to defining 2D forests but the mechanisms used here should generalize to 3D relatively easily in a future PR.
  • Add forest::Forest::Make2D that builds a Forest from a forest::ForestDefinition. ForestDefinition contains a set of Faces, boundary conditions defined on forest::Edges, RegionSizes associated with each block, and a set of initial LogicalLocations to refine.
  • Add Mesh constructor as well as ParthenonManager::ParthenonInitPackagesAndMesh that takes a forest::ForestDefinition and constructs a mesh based on a general 2D forest.
  • Thread logical coordinate transformations through boundary communication routines so that neighbor blocks that are non-simply oriented can communicate boundaries.

Smaller things also included in the PR:

  • Rename RelativeOrientation -> LogicalLocationCoordinateTransformation for clarity.
  • Move MeshBndryFnctn to Mesh::forest::trees instead of Mesh and add appropriate registration routines.
  • Adds an example and associated regression test that communicates gids and other information through boundaries to ensure that neighbor communication is occurring correctly. The gold file has just been verified by hand.
  • Adds a unit test that performs refinement on non-simply connected forests.

Things this PR does not do (but maybe a future PR should):

  • Deal with physical coordinates on trees beyond the simplest choice.
  • Implement periodic boundary conditions for general forests.
  • Allow for 3D meshes.
  • Allow for 6+ valent points in the macro-mesh.
  • Deal with corner communication for 5-valent corners or generally store information about valence of corners and edges in MeshBlock.
  • Make a better interface for users to define general forests.

Some examples of properly nested refinement near singular mesh points (this mesh configuration is tested in the newly added unit test):
Screen Shot 2024-04-30 at 9 41 34 AM

Boundaries filled with neighbor gids in a 2x2 forest where the lower left tree coordinates are rotated by 90 degrees relative to the other trees (results of the boundary communication regression test):
Screenshot 2024-05-07 at 1 10 27 PM

PR Checklist

@lroberts36 lroberts36 changed the title WIP: Thread relative block orientation through communication routines WIP: Include relative block orientation transformations in communication routines Apr 11, 2024
@lroberts36 lroberts36 changed the base branch from lroberts36/add-forest-block-orientation to lroberts36/refactor-mesh-constructors April 17, 2024 19:26
@lroberts36 lroberts36 changed the title WIP: Include relative block orientation transformations in communication routines WIP: Implement general 2D forest meshes May 7, 2024
@lroberts36 lroberts36 changed the title WIP: Implement general 2D forest meshes Implement general 2D forest meshes May 14, 2024
@lroberts36
Copy link
Collaborator Author

Passes riot and parthenon-mhd tests.

@lroberts36
Copy link
Collaborator Author

Agrees with old athenapk blast wave results to 1.e-13.

Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

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

This is really cool. And I think I understood most of what's going on here. But this is pretty complicated and introduces a lot of new concepts to parthenon that are hard to visualize and reason about. I feel pretty strongly that this MR needs documentation associated with it.

Comment on lines +55 to +64
std::unordered_map<uint64_t, std::shared_ptr<parthenon::forest::Node>> nodes;
nodes[0] = parthenon::forest::Node::create(0, {0.0, 0.0});
nodes[1] = parthenon::forest::Node::create(1, {1.0, 0.0});
nodes[2] = parthenon::forest::Node::create(2, {1.0, 1.0});
nodes[3] = parthenon::forest::Node::create(3, {0.0, 1.0});
nodes[4] = parthenon::forest::Node::create(4, {2.0, 0.0});
nodes[5] = parthenon::forest::Node::create(5, {2.0, 1.0});
nodes[6] = parthenon::forest::Node::create(6, {0.0, 2.0});
nodes[7] = parthenon::forest::Node::create(7, {1.0, 2.0});
nodes[8] = parthenon::forest::Node::create(8, {2.0, 2.0});
Copy link
Collaborator

Choose a reason for hiding this comment

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

how should I interpret this initialization? These are coordinates, but of what?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would probably be nice to have some automated machinery for common useful topologies to save users from having to manually define mesh structures.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now, nodes store a position in the x-y plane. This was convenient for making plots like the refinement plot shown above but the positions are unused otherwise. Probably in the future we don't actually want to associate nodes with positions since they are just there for specifying the topology of the mesh.

Comment on lines +21 to +35
nx1 = 8
x1min = 0.0
x1max = 1.0
ix1_bc = outflow
ox1_bc = outflow

nx2 = 8
x2min = 0.0
x2max = 1.0
ix2_bc = outflow
ox2_bc = outflow

nx3 = 1
x3min = -0.5
x3max = 0.5
Copy link
Collaborator

Choose a reason for hiding this comment

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

In a forest setting, how are nx1, nx2, nx3 interpreted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are ignored. These should probably be removed from this input deck.

Comment on lines +46 to +53
<parthenon/static_refinement0>
level = 1 # refinement level
x1min = 0.0 # refinement region inner boundary, X1-dir
x1max = 0.5 # refinement region outer boundary, X1-dir
x2min = 0.0 # refinement region inner boundary, X2-dir
x2max = 0.5 # refinement region outer boundary, X2-dir
x3min = -1.0 # refinement region inner boundary, X3-dir
x3max = 1.0 # refinement region outer boundary, X3-dir
Copy link
Collaborator

Choose a reason for hiding this comment

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

same Q as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Static refinement of a region is not currently supported for general forests, so this will be ignored. Currently, to statically refine a general forest you just have to initially tell it the the LogicalLocations that you want to be refined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this (and above) would probably be good to explain. And the extraneous lines removed from the input deck.

src/mesh/forest/forest.cpp Show resolved Hide resolved
src/mesh/forest/forest.hpp Show resolved Hide resolved
src/mesh/forest/forest.hpp Show resolved Hide resolved
src/utils/cell_center_offsets.hpp Show resolved Hide resolved
src/mesh/forest/tree.cpp Show resolved Hide resolved
@lroberts36
Copy link
Collaborator Author

This is really cool. And I think I understood most of what's going on here. But this is pretty complicated and introduces a lot of new concepts to parthenon that are hard to visualize and reason about. I feel pretty strongly that this MR needs documentation associated with it.

Are you satisfied with the latex document that is linked in the PR description or do you think it needs more detail? I don't really want to write this up in Sphinx, since I don't know how to deal with tikz and equations there. Do we have a way of including latex documentation in the repo?

@lroberts36 lroberts36 mentioned this pull request May 15, 2024
13 tasks
@Yurlungur
Copy link
Collaborator

Are you satisfied with the latex document that is linked in the PR description or do you think it needs more detail?

I think it works well as a description of your design and implementation. I don't think it suffices as a user-level explanation of how to actually build a forest or use it. Ideally what I would like to see is a link to your latex writeup in the docs folder---and maybe the tex source under version control in the repo---as well as some user-focused references for how to actually build a tree.

I don't really want to write this up in Sphinx, since I don't know how to deal with tikz and equations there. Do we have a way of including latex documentation in the repo?

There seems to be some way to do this... but a cursory skim doesn't provide a clean answer. It does support latex syntax for equations, but your doc has quite a bit of inline math.

@lroberts36
Copy link
Collaborator Author

I think it works well as a description of your design and implementation. I don't think it suffices as a user-level explanation of how to actually build a forest or use it. Ideally what I would like to see is a link to your latex writeup in the docs folder---and maybe the tex source under version control in the repo---as well as some user-focused references for how to actually build a tree.

I think that a lot of the practical interface with forests is going to change in near future PRs. For instance, the simplest way to specify forests would be to have blocks for each face in the parameter input that contain a list of the nodes defining the face and some information about the coordinates of the face (although this would become unwieldy for forests with lots of trees). I also haven't completely figured out how to deal with singular valence points, more general coordinates, and visualization. As a result, I don't think it makes sense to write up detailed documentation of how to use forests in this PR, since it is really focused on under the hood changes (plus the minimum necessary interface to write some tests).

There seems to be some way to do this... but a cursory skim doesn't provide a clean answer. It does support latex syntax for equations, but your doc has quite a bit of inline math.

Also tikz needs to work for the diagrams (which I think are key to understanding what is going on).

@Yurlungur
Copy link
Collaborator

I think that a lot of the practical interface with forests is going to change in near future PRs. For instance, the simplest way to specify forests would be to have blocks for each face in the parameter input that contain a list of the nodes defining the face and some information about the coordinates of the face (although this would become unwieldy for forests with lots of trees). I also haven't completely figured out how to deal with singular valence points, more general coordinates, and visualization. As a result, I don't think it makes sense to write up detailed documentation of how to use forests in this PR, since it is really focused on under the hood changes (plus the minimum necessary interface to write some tests).

Fair enough. Can we at least stick the tex source file in the repo under version control and link to the pdf in the docs?

Also tikz needs to work for the diagrams (which I think are key to understanding what is going on).

I think there's some way to just use a tex file but I couldn't figure it out from the docs... And yes tikz is life.

@lroberts36
Copy link
Collaborator Author

lroberts36 commented May 15, 2024

I think there's some way to just use a tex file but I couldn't figure it out from the docs... And yes tikz is life.

Yeah, Sphinx is extremely frustrating. Stack Overflow suggests you can't include a latex file directly, but the comment is pretty old.

@Yurlungur
Copy link
Collaborator

ah that's frustrating

@lroberts36 lroberts36 mentioned this pull request May 24, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants