Go to the documentation of this file.
21 #ifndef THUNDEREGG_DOMAIN_TOOLS_H
22 #define THUNDEREGG_DOMAIN_TOOLS_H
50 template<
int D,
typename T>
51 static void _SetValues(
const Domain<D>& domain,
Vector<D>& vec,
int component_index, T func)
53 SetValues(domain, vec, component_index, func);
68 template<
int D,
typename T,
typename... Args>
69 static void _SetValues(
const Domain<D>& domain,
75 SetValues(domain, vec, component_index, func);
76 _SetValues(domain, vec, component_index + 1, args...);
89 template<
int D,
typename T>
90 static void _SetValuesWithGhost(
const Domain<D>& domain,
110 template<
int D,
typename T,
typename... Args>
111 static void _SetValuesWithGhost(
const Domain<D>& domain,
118 _SetValuesWithGhost(domain, vec, component_index + 1, args...);
135 const std::array<int, D>& coord,
136 std::array<double, D>& real_coord)
139 if (coord[dir] == -1) {
140 real_coord[dir] = pinfo.
starts[dir];
141 }
else if (coord[dir] == pinfo.
ns[dir]) {
159 const std::array<int, D>& coord,
160 std::array<double, D>& real_coord)
179 const std::array<int, D - 1>& coord,
181 std::array<double, D>& real_coord)
184 if (coord[dir] == -1) {
185 real_coord[dir] = pinfo.
starts[dir];
186 }
else if (coord[dir] == pinfo.
ns[dir]) {
199 for (
size_t dir = s.
getAxisIndex() + 1; dir < D; dir++) {
200 if (coord[dir - 1] == -1) {
201 real_coord[dir] = pinfo.
starts[dir];
202 }
else if (coord[dir - 1] == pinfo.
ns[dir]) {
223 std::function<
double(
const std::array<
double, (
int)D>&)> func)
225 if (component_index >= vec.getNumComponents()) {
228 std::array<double, D> real_coord;
232 Loop::Nested<D>(ld.
getStart(), ld.
getEnd(), [&](
const std::array<int, D>& coord) {
233 GetRealCoord<D>(pinfo, coord, real_coord);
234 ld[coord] = func(real_coord);
249 std::function<
double(
double,
double,
double)> func)
251 if (component_index >= vec.getNumComponents()) {
260 for (
int zi = 0; zi < pinfo.
ns[2]; zi++) {
261 double z = pinfo.
starts[2] + 0.5 * dz + zi * dz;
262 for (
int yi = 0; yi < pinfo.
ns[1]; yi++) {
263 double y = pinfo.
starts[1] + 0.5 * dy + yi * dy;
264 for (
int xi = 0; xi < pinfo.
ns[0]; xi++) {
265 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
266 ld(xi, yi, zi) = func(x, y, z);
283 std::function<
double(
double,
double)> func)
285 if (component_index >= vec.getNumComponents()) {
293 for (
int yi = 0; yi < pinfo.
ns[1]; yi++) {
294 double y = pinfo.
starts[1] + 0.5 * dy + yi * dy;
295 for (
int xi = 0; xi < pinfo.
ns[0]; xi++) {
296 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
297 ld(xi, yi) = func(x, y);
313 std::function<
double(
double)> func)
315 if (component_index >= vec.getNumComponents()) {
322 for (
int xi = 0; xi < pinfo.
ns[0]; xi++) {
323 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
339 template<
int D,
typename... Args>
342 std::function<
double(
const std::array<double, D>&)> func,
345 _SetValues(domain, vec, 0, func, args...);
360 std::function<
double(
const std::array<
double, (
int)D>&)> func)
362 if (component_index >= vec.getNumComponents()) {
365 std::array<double, D> real_coord;
370 GetRealCoordGhost<D>(pinfo, coord, real_coord);
371 ld[coord] = func(real_coord);
386 std::function<
double(
double,
double,
double)> func)
388 if (component_index >= vec.getNumComponents()) {
398 for (
int zi = -num_ghost; zi < pinfo.
ns[2] + num_ghost; zi++) {
399 double z = pinfo.
starts[2] + 0.5 * dz + zi * dz;
400 for (
int yi = -num_ghost; yi < pinfo.
ns[1] + num_ghost; yi++) {
401 double y = pinfo.
starts[1] + 0.5 * dy + yi * dy;
402 for (
int xi = -num_ghost; xi < pinfo.
ns[0] + num_ghost; xi++) {
403 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
404 ld(xi, yi, zi) = func(x, y, z);
421 std::function<
double(
double,
double)> func)
423 if (component_index >= vec.getNumComponents()) {
432 for (
int yi = -num_ghost; yi < pinfo.
ns[1] + num_ghost; yi++) {
433 double y = pinfo.
starts[1] + 0.5 * dy + yi * dy;
434 for (
int xi = -num_ghost; xi < pinfo.
ns[0] + num_ghost; xi++) {
435 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
436 ld(xi, yi) = func(x, y);
452 std::function<
double(
double)> func)
454 if (component_index >= vec.getNumComponents()) {
462 for (
int xi = -num_ghost; xi < pinfo.
ns[0] + num_ghost; xi++) {
463 double x = pinfo.
starts[0] + 0.5 * dx + xi * dx;
480 template<
int D,
typename... Args>
483 std::function<
double(
const std::array<double, D>&)> func,
486 _SetValuesWithGhost(domain, vec, 0, func, args...);
498 template<
typename... Args>
501 std::function<
double(
double,
double,
double)> func,
504 _SetValuesWithGhost(domain, vec, 0, func, args...);
518 for (
int c = 0; c < u.getNumComponents(); c++) {
521 double patch_sum = 0;
522 Loop::Nested<D>(u_data.
getStart(), u_data.
getEnd(), [&](std::array<int, D> coord) {
523 patch_sum += u_data[coord];
526 for (
size_t i = 0; i < D; i++) {
527 patch_sum *= pinfo.spacings[i];
533 MPI_Allreduce(&sum, &retval, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
ComponentView< double, D > getComponentView(int component_index, int patch_local_index)
Get the ComponentView for the specified patch and component.
Definition: Vector.h:336
auto getAxisIndex() const -> typename std::enable_if< D<=3 &&D >=1 &&M==D - 1 &&N==N, size_t >::type
Get the axis index of this side.
Definition: Face.h:458
static void Unroll(T lambda)
Unroll a fixed-length loop.
Definition: Loops.h:72
static void SetValuesWithGhost(const Domain< 3 > &domain, Vector< 3 > &vec, int component_index, std::function< double(double, double, double)> func)
Set the values (including ghost values) for a vector with the given function.
Definition: DomainTools.h:383
const std::array< int, D > & getGhostStart() const
Get the coordinate of the first ghost cell element.
Definition: View.h:215
static void SetValuesWithGhost(const Domain< D > &domain, Vector< D > &vec, int component_index, std::function< double(const std::array< double,(int) D > &)> func)
Set the values (including ghost values) for a vector with the given function.
Definition: DomainTools.h:357
std::array< int, D > ns
The number of cells in each direction.
Definition: PatchInfo.h:117
Uses a collection of PatchInfo objects to represent the domain of the problem.
Definition: Domain.h:50
static void SetValuesWithGhost(const Domain< 2 > &domain, Vector< 2 > &vec, int component_index, std::function< double(double, double)> func)
Set the values (including ghost values) for a vector with the given function.
Definition: DomainTools.h:418
auto isLowerOnAxis() const -> typename std::enable_if< D<=3 &&D >=1 &&M==D - 1 &&N==N, bool >::type
Return if this side is lower on it's axis.
Definition: Face.h:468
static void GetRealCoordGhost(const PatchInfo< D > &pinfo, const std::array< int, D > &coord, std::array< double, D > &real_coord)
Given a path info object, get the coordinate from a given index into the patch.
Definition: DomainTools.h:158
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
static void SetValues(const Domain< D > &domain, Vector< D > &vec, std::function< double(const std::array< double, D > &)> func, Args... args)
Set the values for a vector with the given functions.
Definition: DomainTools.h:340
const std::array< int, D > & getEnd() const
Get the coordinate of the last element.
Definition: View.h:211
Contains metadata for a patch.
Definition: PatchInfo.h:51
static void GetRealCoord(const PatchInfo< D > &pinfo, const std::array< int, D > &coord, std::array< double, D > &real_coord)
Given a path info object, get the coordinate from a given index into the patch.
Definition: DomainTools.h:134
Various tools for filling in values in a domain.
Definition: DomainTools.h:36
static void SetValues(const Domain< 3 > &domain, Vector< 3 > &vec, int component_index, std::function< double(double, double, double)> func)
Set the values for a vector with the given function.
Definition: DomainTools.h:246
static void SetValues(const Domain< D > &domain, Vector< D > &vec, int component_index, std::function< double(const std::array< double,(int) D > &)> func)
Set the values for a vector with the given function.
Definition: DomainTools.h:220
std::array< double, D > spacings
The cell spacings in each direction.
Definition: PatchInfo.h:125
std::array< double, D > starts
The lower-left-bottom index of the patch.
Definition: PatchInfo.h:121
int num_ghost_cells
Number of ghost cells on each side of the patch.
Definition: PatchInfo.h:103
static void SetValues(const Domain< 1 > &domain, Vector< 1 > &vec, int component_index, std::function< double(double)> func)
Set the values for a vector with the given function.
Definition: DomainTools.h:310
Vector class for use in thunderegg.
Definition: Vector.h:42
const std::vector< PatchInfo< D > > & getPatchInfoVector() const
Get a vector of PatchInfo pointers where index in the vector corresponds to the patch's local index.
Definition: Domain.h:259
Enum-style class for the faces of an n-dimensional cube.
Definition: Face.h:41
static void SetValuesWithGhost(const Domain< 1 > &domain, Vector< 1 > &vec, int component_index, std::function< double(double)> func)
Set the values (including ghost values) for a vector with the given function.
Definition: DomainTools.h:449
static void GetRealCoordBound(const PatchInfo< D > &pinfo, const std::array< int, D - 1 > &coord, Side< D > s, std::array< double, D > &real_coord)
Given a path info object and a side of the patch, get the coordinate from a given index into the inte...
Definition: DomainTools.h:178
int getNumLocalPatches() const
Get the number of local patches.
Definition: Vector.h:316
static double Integrate(const Domain< D > &domain, const Vector< D > &u)
Integrate a vector over the domain.
Definition: DomainTools.h:513
static void SetValuesWithGhost(const Domain< 3 > &domain, Vector< 3 > &vec, std::function< double(double, double, double)> func, Args... args)
Set the values (including ghost values) for a vector with the given functions.
Definition: DomainTools.h:499
const std::array< int, D > & getGhostEnd() const
Get the coordinate of the last ghost cell element.
Definition: View.h:219
const std::array< int, D > & getStart() const
Get the coordinate of the first element.
Definition: View.h:207
ThunderEgg runtime exception.
Definition: RuntimeError.h:36
static void SetValues(const Domain< 2 > &domain, Vector< 2 > &vec, int component_index, std::function< double(double, double)> func)
Set the values for a vector with the given function.
Definition: DomainTools.h:280
static void SetValuesWithGhost(const Domain< D > &domain, Vector< D > &vec, std::function< double(const std::array< double, D > &)> func, Args... args)
Set the values (including ghost values) for a vector with the given functions.
Definition: DomainTools.h:481