MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
structuredgrid.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef STRUCTUREDGRID_H
8#define STRUCTUREDGRID_H
9
10#include <vector>
11#include "COMM/mpioverride.h"
12#include "FV/fvstructuredcell.h"
13#include "FV/fvstructuredcomm.h"
16
25 MFloat** coordinates = nullptr;
26 MFloat** variables = nullptr;
32};
33
41template <MInt nDim>
43 public:
44 StructuredGrid(const MInt, const MPI_Comm);
46
50 void readGrid();
51 void prepareReadGrid();
56 void setCells(StructuredCell* cells) { m_cells = cells; };
57
58 void exchangePoints(std::vector<std::unique_ptr<StructuredComm<nDim>>>&,
59 std::vector<std::unique_ptr<StructuredComm<nDim>>>&,
61 void gatherPoints(std::vector<std::unique_ptr<StructuredComm<nDim>>>&, StructuredCommType);
62 void sendPoints(std::vector<std::unique_ptr<StructuredComm<nDim>>>&, StructuredCommType, std::vector<MPI_Request>&);
63 void
64 receivePoints(std::vector<std::unique_ptr<StructuredComm<nDim>>>&, StructuredCommType, std::vector<MPI_Request>&);
65 void scatterPoints(std::vector<std::unique_ptr<StructuredComm<nDim>>>&, StructuredCommType);
66 void periodicPointsChange(MFloat&, const MInt, const MInt);
67
69
70 void saveGrid();
71 void saveCellJacobian();
73 void computeMetrics();
74 void computeJacobian();
85
87
89 std::unique_ptr<StructuredDecomposition<nDim>> m_partition;
90
91 // Singularities
92 // class SingularInformation;
95
97 MString m_gridInputFileName; // is copy of m_gridInputFileName in the structuredBlck
100
101 MInt* m_nPoints = nullptr; // stores the maximum dimension of the partition with ghost points
102 MInt* m_nActivePoints = nullptr; // stores the maximum dimension of the partition without ghost points
103 MInt* m_nCells = nullptr; // cell array dimension with ghost layer
104 MInt* m_nActiveCells = nullptr; // cell array dimension without ghost layer
107 MInt* m_nBlockCells = nullptr;
111 MFloat** m_velocity = nullptr;
113
115 MInt m_noGhostLayers; // is a copy of m_noGhostLayers in the structuredBlck
120
121 MInt m_hasConnectionInfo; // not used yet, but can replace m_hasConnectionInfo in
122 // fvstructuredsolverwindowinfo
124
130 MInt getBlockId(MInt domainId_) { return m_partition->getBlockIdFromPartition(domainId_); };
131
136 MInt getMyBlockId() { return m_partition->getBlockIdFromPartition(domainId()); };
137
143 MInt getMyOffset(MInt dim) { return m_partition->getPartitionOffset(domainId(), dim); };
144
151 MInt getOffset(MInt domainId_, MInt dim) { return m_partition->getPartitionOffset(domainId_, dim); };
152
158 MInt getMyActivePoints(MInt dim) { return m_partition->getPartitionSize(domainId(), dim); };
159
166 MInt getActivePoints(MInt domainId_, MInt dim) { return m_partition->getPartitionSize(domainId_, dim); };
167
174 MInt getBlockNoCells(MInt blockId_, MInt dim) { return m_partition->getBlockSize(blockId_, dim); }
175
182 MInt getBlockNoPoints(MInt blockId_, MInt dim) { return (m_partition->getBlockSize(blockId_, dim) + 1); }
183
189 MInt getMyBlockNoCells(MInt dim) { return m_partition->getBlockSize(getMyBlockId(), dim); }
190
196 MInt getMyBlockNoPoints(MInt dim) { return m_partition->getBlockSize(getMyBlockId(), dim) + 1; }
197
203
207 constexpr MPI_Comm mpiComm() const { return m_mpiComm; }
208
212 constexpr MInt solverId() const { return m_solverId; }
213
217 MInt noDomains() const { return m_noDomains; }
218
222 MInt domainId() const { return m_domainId; }
223
224 protected:
231 inline void crossProduct(MFloat* result, MFloat* vec1, MFloat* vec2) {
232 result[xsd] = vec1[ysd] * vec2[zsd] - vec1[zsd] * vec2[ysd];
233 result[ysd] = vec1[zsd] * vec2[xsd] - vec1[xsd] * vec2[zsd];
234 result[zsd] = vec1[xsd] * vec2[ysd] - vec1[ysd] * vec2[xsd];
235 }
236
243 inline MFloat crossProduct(MFloat vec1[2], MFloat vec2[2]) {
244 MFloat result = vec1[xsd] * vec2[ysd] - vec1[ysd] * vec2[xsd];
245 return result;
246 }
247
256 inline MInt getPointIdFromPoint(const MInt origin, const MInt incI, const MInt incJ, const MInt incK) {
257 return origin + incI + incJ * m_nPoints[2] + incK * m_nPoints[2] * m_nPoints[1];
258 }
259
267 inline MInt getPointIdFromPoint(const MInt origin, const MInt incI, const MInt incJ) {
268 return origin + incI + incJ * m_nPoints[1];
269 }
270
279 inline MInt getCellIdFromCell(const MInt origin, const MInt incI, const MInt incJ, const MInt incK) {
280 return origin + incI + incJ * m_nCells[2] + incK * m_nCells[2] * m_nCells[1];
281 }
282
290 inline MInt getCellIdFromCell(MInt origin, MInt incI, MInt incJ) { return origin + incI + incJ * m_nCells[1]; }
291
299 inline MInt getPointIdFromCell(const MInt i, const MInt j, const MInt k) {
300 return i + (k * (m_nCells[1] + 1) + j) * (m_nCells[2] + 1);
301 }
302
309 inline MInt getPointIdFromCell(const MInt i, const MInt j) { return i + (j * (m_nCells[1] + 1)); }
310
318 inline MInt cellIndex(const MInt i, const MInt j, const MInt k) { return i + (j + k * m_nCells[1]) * m_nCells[2]; }
319
326 inline MInt cellIndex(const MInt i, const MInt j) { return i + (j * m_nCells[1]); }
327
335 inline MInt pointIndex(const MInt i, const MInt j, const MInt k) { return i + (j + k * m_nPoints[1]) * m_nPoints[2]; }
336
343 inline MInt pointIndex(const MInt i, const MInt j) { return i + (j * m_nPoints[1]); }
344
345 inline MInt surfId(const MInt point, const MInt isd, const MInt dim) { return point + (isd + 3 * dim) * 9; }
346
347 static const MInt xsd = 0;
348 static const MInt ysd = 1;
349 static const MInt zsd = 2;
350
351 private:
353 const MPI_Comm m_mpiComm;
356
359
360 // repartitionFile
362
363
364 inline std::array<MInt, nDim> pointBegin(const MInt plus) {
365 std::array<MInt, nDim> result{};
366 std::fill_n(result.begin(), nDim, plus);
367 return result;
368 }
369
370 inline std::array<MInt, nDim> cellBegin(const MInt plus) {
371 std::array<MInt, nDim> result{};
372 std::fill_n(result.begin(), nDim, plus);
373 return result;
374 }
375
376 inline std::array<MInt, nDim> cellEnd(const MInt minus) {
377 std::array<MInt, nDim> result{};
378 for(MInt i = 0; i < nDim; ++i) {
379 result[i] = m_nCells[nDim - 1 - i] - minus;
380 }
381 return result;
382 }
383
384 inline std::array<MInt, nDim> pointEnd(const MInt minus) {
385 std::array<MInt, nDim> result{};
386 for(MInt i = 0; i < nDim; ++i) {
387 result[i] = m_nPoints[nDim - 1 - i] - minus;
388 }
389 return result;
390 }
391};
392
393
394#endif
Structured grid class.
static const MInt xsd
MBool m_readDecompositionFromFile
MBool isMovingGrid()
MInt noDomains() const
Return the total number of domains (total number of ranks in current MPI communicator)
void setCells(StructuredCell *cells)
void gridDecomposition(MBool)
Create decomposition of the grid into partitions for MPI parallelization.
void computeCellJacobian()
void computeMetrics()
Computes all metrics by calling the functions for each type of metric computation (cell,...
void extrapolateGhostPointCoordinates()
std::array< MInt, nDim > cellEnd(const MInt minus)
MFloat ** m_oldCoordinates
SingularInformation * m_singularity
void saveCellJacobian()
Copies the current state of the cell Jacobians to m_cells->oldCellJacobian.
MInt domainId() const
Return the domainId (rank)
MInt pointIndex(const MInt i, const MInt j, const MInt k)
Compute point ID for given (i,j,k)
void periodicPointsChange(MFloat &, const MInt, const MInt)
Displaces the points on periodic boundaries by the distance between the two periodic boundaries.
MInt getPointIdFromCell(const MInt i, const MInt j)
Compute the lower point id for cell (i,j)
std::unique_ptr< StructuredDecomposition< nDim > > m_partition
MInt getPointIdFromPoint(const MInt origin, const MInt incI, const MInt incJ, const MInt incK)
Compute the point id of the point that has the offset (incI, inJ, incK) to the given point origin.
void exchangePoints(std::vector< std::unique_ptr< StructuredComm< nDim > > > &, std::vector< std::unique_ptr< StructuredComm< nDim > > > &, StructuredCommType)
Exchanges the boundary grid points between MPI partitions.
MFloat ** m_initCoordinates
constexpr MInt solverId() const
Return the solver id to which this grid belongs.
const MPI_Comm m_mpiComm
void writeGrid(MString, MString)
Writes the current grid (including deformations for moving grids) to a file.
MInt getMyBlockNoPoints(MInt dim)
Returns the number of total block points in the given dimension for the own block.
MFloat ** m_velocity
MInt cellIndex(const MInt i, const MInt j)
Compute cell ID for given (i,j)
void computeCornerMetrics()
void computeModCornerJacobian()
void computeCornerJacobian()
void computeCellMetrics()
MInt getPointIdFromPoint(const MInt origin, const MInt incI, const MInt incJ)
Compute the point id of the point that has the offset (incI, inJ) to the given point origin.
MInt getBlockId(MInt domainId_)
Returns the block id of the block in which the given domain is located.
std::array< MInt, nDim > pointBegin(const MInt plus)
MFloat ** m_coordinates
MInt surfId(const MInt point, const MInt isd, const MInt dim)
~StructuredGrid()
Destructor of the structured grid class.
void readGrid()
Reads in the coordinates (x,y,z) from the grid file.
MInt getCellIdFromCell(MInt origin, MInt incI, MInt incJ)
Compute the cell id of the cell that has the offset (incI, inJ) to the given cell origin.
MInt getActivePoints(MInt domainId_, MInt dim)
Returns the number of active points in the given dimension (without ghost-cells) of the given domain ...
void computeJacobian()
Computes the Jacobians by calling the functions for each type of Jacobian computation (corner,...
StructuredCell * m_cells
const MInt m_solverId
MInt getMyBlockId()
Returns the block id of the block in which the own domain.
MInt getMyBlockNoCells(MInt dim)
Returns the number of total block cells in the given dimension for the own block.
MInt pointIndex(const MInt i, const MInt j)
Compute point ID for given (i,j)
void sendPoints(std::vector< std::unique_ptr< StructuredComm< nDim > > > &, StructuredCommType, std::vector< MPI_Request > &)
Send the coordinates between partitions to other partitions.
MInt getMyOffset(MInt dim)
Returns the offset in the given dimension of the own domain inside the block.
static const MInt ysd
MInt getPointIdFromCell(const MInt i, const MInt j, const MInt k)
Compute the lower point id for cell (i,j,k)
static const MInt zsd
void computeDxt(MFloat, MFloat *, MInt)
void computeModCornerMetrics()
MFloat * m_periodicDisplacements
void computeSurfaceJacobian()
void setCellReference(StructuredCell *)
Sets the reference to the cell object.
MFloat ** m_acceleration
void writePartitionedGrid()
Saves coordinates for partitioned grid with ghost points. Useful for debugging.
MInt getMyActivePoints(MInt dim)
Returns the number of active points in the given dimension (without ghost-cells) of the own domain.
MInt getBlockNoPoints(MInt blockId_, MInt dim)
Returns the number of total block points in the given dimension for the given block id.
std::array< MInt, nDim > pointEnd(const MInt minus)
void computeSurfaceMetricsSingularity()
Computes the surface metrics for the cell surfaces at the surface centroids (2D) Special version for ...
MString m_gridInputFileName
void computeCellCenterCoordinates()
void scatterPoints(std::vector< std::unique_ptr< StructuredComm< nDim > > > &, StructuredCommType)
Distributes the exchanged points from the receiving buffers to the actual coordinates of the grid.
MInt * m_nOffsetPoints
void gatherPoints(std::vector< std::unique_ptr< StructuredComm< nDim > > > &, StructuredCommType)
Gathers the coordinates of the points for all given sending maps and copies them to a sending buffer.
MInt getNoBlocks()
Returns the total number of blocks.
void prepareReadGrid()
Prepares the arrays containing the size of the grid (points/cells) before the grid coordinates are ac...
MInt getBlockNoCells(MInt blockId_, MInt dim)
Returns the number of total block cells in the given dimension for the given block id.
MInt getOffset(MInt domainId_, MInt dim)
Returns the offset in the given dimension inside the block of the own domain.
constexpr MPI_Comm mpiComm() const
Return the MPI communicator used by this grid.
void allocateMetricsAndJacobians()
Allocates memory for the metrics and the Jacobians.
std::array< MInt, nDim > cellBegin(const MInt plus)
MInt * m_nActivePoints
MInt getCellIdFromCell(const MInt origin, const MInt incI, const MInt incJ, const MInt incK)
Compute the cell id of the cell that has the offset (incI, inJ, incK) to the given cell origin.
void crossProduct(MFloat *result, MFloat *vec1, MFloat *vec2)
Computes the 3D cross product.
MInt cellIndex(const MInt i, const MInt j, const MInt k)
Compute cell ID for given (i,j,k)
void receivePoints(std::vector< std::unique_ptr< StructuredComm< nDim > > > &, StructuredCommType, std::vector< MPI_Request > &)
Receives the coordinates between partitions to other partitions.
void moveCellPoints()
MFloat crossProduct(MFloat vec1[2], MFloat vec2[2])
Computes the 2D cross product.
void computeSurfaceMetrics()
MInt getGridMovingMethod()
StructuredCommType
Definition: enums.h:343
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
MFloat ** ReconstructionConstants
MInt displacement[5][3]