-
Notifications
You must be signed in to change notification settings - Fork 18
Use meshFields parametric coordinates for dof coordinate construction #368
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
Open
Sichao25
wants to merge
2
commits into
SCOREC:develop
Choose a base branch
from
Sichao25:evaluation-library
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| #include "pcms/utility/inclusive_scan.h" | ||
| #include "pcms/utility/profile.h" | ||
| #include <Omega_h_for.hpp> | ||
| #include <MeshField.hpp> | ||
| #include <memory> | ||
|
|
||
| namespace pcms | ||
|
|
@@ -36,59 +37,133 @@ Omega_h::Write<Omega_h::GO> GetGidsHelper(LO total_ents, | |
| return owned_gids; | ||
| } | ||
|
|
||
| // this is a workaround to specify the parametric coordinates for MeshFields to | ||
| // be replaced when https://github.com/SCOREC/meshFields/issues/70 is resolved | ||
| struct ComputeVertexCoordsFunctor | ||
| namespace | ||
| { | ||
| Kokkos::View<Real**> dof_holder_coords_; | ||
| Omega_h::Reals coords_; | ||
| size_t offset_; | ||
|
|
||
| ComputeVertexCoordsFunctor(Kokkos::View<Real**> dof_holder_coords, | ||
| Omega_h::Reals coords, size_t offset) | ||
| : dof_holder_coords_(dof_holder_coords), coords_(coords), offset_(offset) | ||
| { | ||
| // Maps a meshFields topology to the dimension. | ||
| KOKKOS_INLINE_FUNCTION int TopologyToDim(MeshField::Mesh_Topology topo) | ||
| { | ||
| switch (topo) { | ||
| case MeshField::Vertex: return 0; | ||
| case MeshField::Edge: return 1; | ||
| case MeshField::Triangle: return 2; | ||
| case MeshField::Tetrahedron: return 3; | ||
| default: return -1; | ||
| } | ||
| } | ||
|
|
||
| KOKKOS_INLINE_FUNCTION | ||
| void operator()(LO i) const | ||
| { | ||
| dof_holder_coords_(offset_ + i, 0) = coords_[2 * i + 0]; | ||
| dof_holder_coords_(offset_ + i, 1) = coords_[2 * i + 1]; | ||
| // Gets the appropriate MeshField element | ||
| template <int Dim, int Order> | ||
| auto GetMeshFieldElement(Omega_h::Mesh& mesh) | ||
|
Collaborator
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. I suspect you want these sort of helpers to take dim/oder as a runtime argument. That will let you have a limited number of places in the source code where you have to deal with the static to dynamic mapping. |
||
| { | ||
| if constexpr (Dim == 2) { | ||
| return MeshField::Omegah::getTriangleElement<Order>(mesh); | ||
| } else { | ||
| return MeshField::Omegah::getTetrahedronElement<Order>(mesh); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| // this is a workaround to specify the parametric coordinates for MeshFields to | ||
| // be replaced when https://github.com/SCOREC/meshFields/issues/70 is resolved | ||
| struct ComputeEdgeCoordsFunctor | ||
| template <int Dim, int Order> | ||
| void BuildDofHolderCoordsFromMeshFieldImpl( | ||
| Omega_h::Mesh& mesh, Kokkos::View<Real**> holder_coords, | ||
| const std::array<int, 4>& nodes_per_dim) | ||
| { | ||
| Kokkos::View<Real**> dof_holder_coords_; | ||
| Omega_h::Reals coords_; | ||
| Omega_h::LOs edge_verts_; | ||
| size_t offset_; | ||
| const auto elem = GetMeshFieldElement<Dim, Order>(mesh); | ||
|
|
||
| ComputeEdgeCoordsFunctor(Kokkos::View<Real**> dof_holder_coords, | ||
| Omega_h::Reals coords, Omega_h::LOs edge_verts, | ||
| size_t offset) | ||
| : dof_holder_coords_(dof_holder_coords), | ||
| coords_(coords), | ||
| edge_verts_(edge_verts), | ||
| offset_(offset) | ||
| using ShapeT = std::decay_t<decltype(elem.shp)>; | ||
| constexpr size_t numNodes = ShapeT::numNodes; | ||
| constexpr size_t meshDim = ShapeT::meshEntDim; | ||
| constexpr MeshField::Mesh_Topology elemTopo = | ||
| (Dim == 2) ? MeshField::Triangle : MeshField::Tetrahedron; | ||
| const auto map = elem.map; | ||
|
|
||
| // Compute the starting offset of DOF holders for each entity dimension. | ||
| Kokkos::Array<LO, 4> dof_holder_offset; | ||
| { | ||
| LO cur_offset = 0; | ||
| for (int d = 0; d < 4; ++d) { | ||
| dof_holder_offset[d] = cur_offset; | ||
| if (d <= mesh.dim() && nodes_per_dim[d] != 0) | ||
| cur_offset += mesh.nents(d); | ||
| } | ||
| } | ||
|
|
||
| KOKKOS_INLINE_FUNCTION | ||
| void operator()(LO i) const | ||
| { | ||
| auto verts = Omega_h::gather_verts<2>(edge_verts_, i); | ||
| Real x0 = coords_[2 * verts[0] + 0]; | ||
| Real y0 = coords_[2 * verts[0] + 1]; | ||
| Real x1 = coords_[2 * verts[1] + 0]; | ||
| Real y1 = coords_[2 * verts[1] + 1]; | ||
| dof_holder_coords_(offset_ + i, 0) = (x0 + x1) / 2; | ||
| dof_holder_coords_(offset_ + i, 1) = (y0 + y1) / 2; | ||
| const LO nelems = mesh.nelems(); | ||
| const auto vtx_coords = mesh.coords(); | ||
| const auto param_coords = elem.shp.getNodeParametricCoords(); | ||
|
|
||
| Kokkos::parallel_for( | ||
| "MeshFieldsDofHolderCoords", | ||
| Kokkos::RangePolicy<DeviceMemorySpace::execution_space>(0, nelems), | ||
| KOKKOS_LAMBDA(const LO e) { | ||
| constexpr size_t NVerts = Dim + 1; | ||
|
|
||
| Real Xv[NVerts * Dim]; | ||
| for (size_t b = 0; b < NVerts; ++b) { | ||
| const auto hv = map(static_cast<MeshField::LO>(b), 0, e, elemTopo); | ||
| const LO v = hv.entity; | ||
| for (size_t d = 0; d < Dim; ++d) | ||
| Xv[b * Dim + d] = vtx_coords[static_cast<size_t>(v) * Dim + d]; | ||
| } | ||
|
|
||
| for (size_t n = 0; n < numNodes; ++n) { | ||
| const auto h = map(static_cast<MeshField::LO>(n), 0, e, elemTopo); | ||
|
|
||
| // Compute the barycentric coordinates L[b] at the node's parametric | ||
| // coordinates. | ||
| Real L[NVerts]; | ||
| L[0] = 1; | ||
| for (size_t d = 0; d < Dim; ++d) { | ||
| const Real xi_d = param_coords[n * Dim + d]; | ||
| L[d + 1] = xi_d; | ||
| L[0] -= xi_d; | ||
| } | ||
|
|
||
| Real X[Dim] = {0}; | ||
| for (size_t b = 0; b < NVerts; ++b) | ||
| for (size_t d = 0; d < Dim; ++d) | ||
| X[d] += L[b] * Xv[b * Dim + d]; | ||
|
|
||
| const int dim_of_holder = TopologyToDim(h.topo); | ||
| const LO row = dof_holder_offset[dim_of_holder] + h.entity; | ||
| for (size_t d = 0; d < Dim; ++d) | ||
| holder_coords(row, d) = X[d]; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void BuildDofHolderCoordsFromMeshField(Omega_h::Mesh& mesh, | ||
| Kokkos::View<Real**> holder_coords, | ||
| const std::array<int, 4>& nodes_per_dim) | ||
| { | ||
| int dim = mesh.dim(); | ||
| int order = 0; | ||
| for (int i = 0; i <= dim; ++i) { | ||
| if (nodes_per_dim[i] == 1) | ||
| ++order; | ||
| else if (nodes_per_dim[i] != 0) { | ||
| std::cerr << "Unsupported" << std::endl; | ||
| std::abort(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| if (dim == 2 && order == 1) | ||
| BuildDofHolderCoordsFromMeshFieldImpl<2, 1>(mesh, holder_coords, | ||
| nodes_per_dim); | ||
| else if (dim == 2 && order == 2) | ||
| BuildDofHolderCoordsFromMeshFieldImpl<2, 2>(mesh, holder_coords, | ||
| nodes_per_dim); | ||
| else if (dim == 3 && order == 1) | ||
| BuildDofHolderCoordsFromMeshFieldImpl<3, 1>(mesh, holder_coords, | ||
| nodes_per_dim); | ||
| else if (dim == 3 && order == 2) | ||
| BuildDofHolderCoordsFromMeshFieldImpl<3, 2>(mesh, holder_coords, | ||
| nodes_per_dim); | ||
| else { | ||
| std::cerr << "Unsupported element/order combination" << std::endl; | ||
| std::abort(); | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| struct CopyClassInfoFunctor | ||
| { | ||
|
|
@@ -152,32 +227,9 @@ MeshFieldsAdapterLayout::MeshFieldsAdapterLayout( | |
| std::abort(); | ||
| } | ||
|
|
||
| auto coords = mesh_.coords(); | ||
| BuildDofHolderCoordsFromMeshField(mesh_, dof_holder_coords_, nodes_per_dim); | ||
|
|
||
| size_t offset = 0; | ||
| for (int i = 0; i <= mesh_.dim(); ++i) { | ||
| if (nodes_per_dim[i] == 1) { | ||
| if (i == 0) { | ||
| ComputeVertexCoordsFunctor functor(dof_holder_coords_, coords, offset); | ||
| Kokkos::parallel_for(mesh_.nents(0), functor); | ||
| } else if (i == 1) { | ||
| auto edge_verts = mesh_.ask_verts_of(1); | ||
| ComputeEdgeCoordsFunctor functor(dof_holder_coords_, coords, edge_verts, | ||
| offset); | ||
| Kokkos::parallel_for(mesh_.nents(1), functor); | ||
| } else { | ||
| std::cerr << "Unsupported" << std::endl; | ||
| std::abort(); | ||
| } | ||
| } else if (nodes_per_dim[i] != 0) { | ||
| std::cerr << "Unsupported" << std::endl; | ||
| std::abort(); | ||
| } | ||
|
|
||
| offset += mesh.nents(i); | ||
| } | ||
|
|
||
| offset = 0; | ||
| for (int i = 0; i <= mesh_.dim(); ++i) { | ||
| if (nodes_per_dim_[i]) { | ||
| auto ids = mesh_.get_array<Omega_h::ClassId>(i, "class_id"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 use
meshEntDimwhich is defined in all the shapes?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 feel like the mapping here is for the DOFs, while the shape function entity dimensions are for the element itself. If my understanding is correct, then they should be different mapping.