forked from E3SM-Project/E3SM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request E3SM-Project#62 from mwarusz/mw/omega/operators
Add mesh operators
- Loading branch information
Showing
13 changed files
with
1,046 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(omega-dev-horz-operators)= | ||
|
||
# Horizontal Operators | ||
|
||
The TRiSK scheme horizontal operators are implemented in C++ as functors, which | ||
are classes that can be called with input arguments in the same way as functions | ||
can. However, in contrast to plain functions, functors can contain internal | ||
state. In the case of Omega operators they contain shallow copies of various | ||
`HorzMesh` arrays that are needed to compute the operator, but are not strictly | ||
inputs of the operator. | ||
|
||
Operators are constructed from an instance of the `HorzMesh` class, for example | ||
```c++ | ||
auto mesh = OMEGA::HorzMesh::getDefault(); | ||
DivergenceOnCell DivOnCell(mesh); | ||
``` | ||
which sets up the previously mentioned internal state. | ||
Each Omega operator provides a C++ call operator, which computes its value on a | ||
mesh element given the element index and operator-specific input arrays. | ||
Typically, operators are created outside of a parallel region and are used | ||
inside a parallel loop over mesh elements, for example | ||
```c++ | ||
auto mesh = OMEGA::HorzMesh::getDefault(); | ||
DivergenceOnCell DivOnCell(mesh); | ||
parallelFor({mesh->NCellsOwned}, KOKKOS_LAMBDA(Int ICell) { | ||
Real Div = DivOnCell(ICell, Vec); // computes divergence of Vec over cell with index ICell | ||
}); | ||
``` | ||
|
||
Currently, the following operators are implemented: | ||
- `DivergenceOnCell` | ||
- `GradientOnEdge` | ||
- `CurlOnVertex` | ||
- `TangentialReconOnEdge` | ||
|
||
Some tendency terms in the Omega PDE solver could in principle be constructed | ||
using these operators as building blocks. However, very often tendency terms | ||
require evaluation of slightly modified operators. Moreover, there is a | ||
potential performance cost of nesting operators within classes. Hence, the | ||
primary motivation for introducing these classes is to provide reference | ||
implementation of the basic TRiSK operators and for diagnostic and debugging | ||
purposes. |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(omega-user-horz-operators)= | ||
|
||
# Horizontal Operators | ||
|
||
The horizontal discretization in Omega is a staggered numerical scheme known as | ||
TRiSK. It defines discrete versions of basic differential operators (divergence, | ||
gradient, and curl) as well as other operators that are needed by the scheme, | ||
such as reconstruction of tangential velocity from its normal components. Omega | ||
provides reference implementations of these operators, each in a separate C++ | ||
class. The class name describes the operator and the mesh element associated | ||
with its result. | ||
|
||
The following operators are currently implemented: | ||
- `DivergenceOnCell` | ||
- `GradientOnEdge` | ||
- `CurlOnVertex` | ||
- `TangentialReconOnEdge` | ||
|
||
There are no user-configurable options. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "HorzOperators.h" | ||
#include "DataTypes.h" | ||
#include "HorzMesh.h" | ||
|
||
namespace OMEGA { | ||
|
||
DivergenceOnCell::DivergenceOnCell(HorzMesh const *Mesh) | ||
: NEdgesOnCell(Mesh->NEdgesOnCell), EdgesOnCell(Mesh->EdgesOnCell), | ||
DvEdge(Mesh->DvEdge), AreaCell(Mesh->AreaCell), | ||
EdgeSignOnCell(Mesh->EdgeSignOnCell) {} | ||
|
||
GradientOnEdge::GradientOnEdge(HorzMesh const *Mesh) | ||
: CellsOnEdge(Mesh->CellsOnEdge), DcEdge(Mesh->DcEdge) {} | ||
|
||
CurlOnVertex::CurlOnVertex(HorzMesh const *Mesh) | ||
: VertexDegree(Mesh->VertexDegree), EdgesOnVertex(Mesh->EdgesOnVertex), | ||
DcEdge(Mesh->DcEdge), AreaTriangle(Mesh->AreaTriangle), | ||
EdgeSignOnVertex(Mesh->EdgeSignOnVertex) {} | ||
|
||
TangentialReconOnEdge::TangentialReconOnEdge(HorzMesh const *Mesh) | ||
: NEdgesOnEdge(Mesh->NEdgesOnEdge), EdgesOnEdge(Mesh->EdgesOnEdge), | ||
WeightsOnEdge(Mesh->WeightsOnEdge) {} | ||
|
||
} // namespace OMEGA |
This file contains 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef OMEGA_HORZOPERATORS_H | ||
#define OMEGA_HORZOPERATORS_H | ||
|
||
#include "DataTypes.h" | ||
#include "HorzMesh.h" | ||
|
||
namespace OMEGA { | ||
|
||
class DivergenceOnCell { | ||
public: | ||
DivergenceOnCell(HorzMesh const *Mesh); | ||
|
||
KOKKOS_FUNCTION Real operator()(int ICell, | ||
const Array1DReal &VecEdge) const { | ||
Real DivCell = 0; | ||
for (int J = 0; J < NEdgesOnCell(ICell); ++J) { | ||
const int JEdge = EdgesOnCell(ICell, J); | ||
DivCell -= DvEdge(JEdge) * EdgeSignOnCell(ICell, J) * VecEdge(JEdge); | ||
} | ||
const Real InvAreaCell = 1. / AreaCell(ICell); | ||
DivCell *= InvAreaCell; | ||
return DivCell; | ||
} | ||
|
||
private: | ||
Array1DI4 NEdgesOnCell; | ||
Array2DI4 EdgesOnCell; | ||
Array1DR8 DvEdge; | ||
Array1DR8 AreaCell; | ||
Array2DR8 EdgeSignOnCell; | ||
}; | ||
|
||
class GradientOnEdge { | ||
public: | ||
GradientOnEdge(HorzMesh const *Mesh); | ||
|
||
KOKKOS_FUNCTION Real operator()(int IEdge, | ||
const Array1DReal &ScalarCell) const { | ||
const auto JCell0 = CellsOnEdge(IEdge, 0); | ||
const auto JCell1 = CellsOnEdge(IEdge, 1); | ||
const Real InvDcEdge = 1. / DcEdge(IEdge); | ||
const Real GradEdge = | ||
InvDcEdge * (ScalarCell(JCell1) - ScalarCell(JCell0)); | ||
return GradEdge; | ||
} | ||
|
||
private: | ||
Array2DI4 CellsOnEdge; | ||
Array1DR8 DcEdge; | ||
}; | ||
|
||
class CurlOnVertex { | ||
public: | ||
CurlOnVertex(HorzMesh const *Mesh); | ||
|
||
KOKKOS_FUNCTION Real operator()(int IVertex, | ||
const Array1DReal &VecEdge) const { | ||
Real CurlVertex = 0; | ||
for (int J = 0; J < VertexDegree; ++J) { | ||
const int JEdge = EdgesOnVertex(IVertex, J); | ||
CurlVertex += | ||
DcEdge(JEdge) * EdgeSignOnVertex(IVertex, J) * VecEdge(JEdge); | ||
} | ||
const Real InvAreaTriangle = 1. / AreaTriangle(IVertex); | ||
CurlVertex *= InvAreaTriangle; | ||
return CurlVertex; | ||
} | ||
|
||
private: | ||
I4 VertexDegree; | ||
Array2DI4 EdgesOnVertex; | ||
Array1DR8 DcEdge; | ||
Array1DR8 AreaTriangle; | ||
Array2DR8 EdgeSignOnVertex; | ||
}; | ||
|
||
class TangentialReconOnEdge { | ||
public: | ||
TangentialReconOnEdge(HorzMesh const *Mesh); | ||
|
||
KOKKOS_FUNCTION Real operator()(int IEdge, | ||
const Array1DReal &VecEdge) const { | ||
Real ReconEdge = 0; | ||
for (int J = 0; J < NEdgesOnEdge(IEdge); ++J) { | ||
const int JEdge = EdgesOnEdge(IEdge, J); | ||
ReconEdge += WeightsOnEdge(IEdge, J) * VecEdge(JEdge); | ||
} | ||
return ReconEdge; | ||
} | ||
|
||
private: | ||
Array1DI4 NEdgesOnEdge; | ||
Array2DI4 EdgesOnEdge; | ||
Array2DR8 WeightsOnEdge; | ||
}; | ||
|
||
} // namespace OMEGA | ||
#endif |
This file contains 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.