Loading...
Searching...
No Matches
volcartesian.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_VOLCARTESIAN_HPP__
26#define __BITPIT_VOLCARTESIAN_HPP__
27
28#include <array>
29#include <cstddef>
30#include <memory>
31#include <vector>
32
33#include "bitpit_patchkernel.hpp"
34
35namespace bitpit {
36
37class VolCartesian : public VolumeKernel {
38
39public:
44
45 enum MemoryMode {
46 MEMORY_NORMAL,
47 MEMORY_LIGHT
48 };
49
51 VolCartesian(int dimension, const std::array<double, 3> &origin,
52 const std::array<double, 3> &lengths, const std::array<int, 3> &nCells);
53 VolCartesian(int id, int dimension, const std::array<double, 3> &origin,
54 const std::array<double, 3> &lengths, const std::array<int, 3> &nCells);
55 VolCartesian(int dimension, const std::array<double, 3> &origin,
56 double length, int nCells1D);
57 VolCartesian(int id, int dimension, const std::array<double, 3> &origin,
58 double length, int nCells1D);
59 VolCartesian(int dimension, const std::array<double, 3> &origin,
60 double length, double dh);
61 VolCartesian(int id, int dimension, const std::array<double, 3> &origin,
62 double length, double dh);
63 VolCartesian(std::istream &stream);
64
65 std::unique_ptr<PatchKernel> clone() const override;
66
67 void reset() override;
68
69 long getVertexCount() const override;
70 int getVertexCount(int direction) const;
71
72 long getCellCount() const override;
73 int getCellCount(int direction) const;
74
76 ElementType getCellType(long id) const override;
77
78 long getInterfaceCount() const override;
80 ElementType getInterfaceType(long id) const override;
81
82 std::array<double, 3> evalVertexCoords(long id) const;
83 std::array<double, 3> evalVertexCoords(const std::array<int, 3> &ijk) const;
84 const std::vector<double> & getVertexCoords(int direction) const;
85
86 double evalCellVolume(long id) const override;
87 double evalCellVolume(const std::array<int, 3> &ijk) const;
88 double evalCellSize(long id) const override;
89 double evalCellSize(const std::array<int, 3> &ijk) const;
90 std::array<double, 3> evalCellCentroid(long id) const override;
91 std::array<double, 3> evalCellCentroid(const std::array<int, 3> &ijk) const;
92 const std::vector<double> & getCellCentroids(int direction) const;
93
94 void evalCellBoundingBox(long id, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const override;
95
96 double evalInterfaceArea(long id) const override;
97 std::array<double, 3> evalInterfaceNormal(long id) const override;
98
99 std::array<double, 3> getSpacing() const;
100 double getSpacing(int direction) const;
101
102 void switchMemoryMode(MemoryMode mode);
103 MemoryMode getMemoryMode() const;
104
105 bool isPointInside(const std::array<double, 3> &point) const override;
106 bool isPointInside(long id, const std::array<double, 3> &point) const override;
107 long locatePoint(const std::array<double, 3> &point) const override;
108 std::array<int, 3> locatePointCartesian(const std::array<double, 3> &point) const;
109 long locateClosestVertex(std::array<double,3> const &point) const;
110 std::array<int, 3> locateClosestVertexCartesian(std::array<double,3> const &point) const;
111 long locateClosestCell(std::array<double,3> const &point) const;
112 std::array<int, 3> locateClosestCellCartesian(std::array<double,3> const &point) const;
113
114 std::vector<long> extractCellSubSet(std::array<int, 3> const &ijkMin, std::array<int, 3> const &ijkMax) const;
115 std::vector<long> extractCellSubSet(int idMin, int idMax) const;
116 std::vector<long> extractCellSubSet(std::array<double, 3> const &pointMin, std::array<double, 3> const &pointMax) const;
117 std::vector<long> extractVertexSubSet(std::array<int, 3> const &ijkMin, std::array<int, 3> const &ijkMax) const;
118 std::vector<long> extractVertexSubSet(int idMin, int idMax) const;
119 std::vector<long> extractVertexSubSet(std::array<double, 3> const &pointMin, std::array<double, 3> const &pointMax) const;
120
121 std::array<double, 3> getOrigin() const;
122 void setOrigin(const std::array<double, 3> &origin);
123 void translate(const std::array<double, 3> &translation) override;
124 void rotate(const std::array<double, 3> &n0, const std::array<double, 3> &n1, double angle) override;
125 std::array<double, 3> getLengths() const;
126 void setLengths(const std::array<double, 3> &lengths);
127 void scale(const std::array<double, 3> &scaling, const std::array<double, 3> &center) override;
128
129 std::vector<double> convertToVertexData(const std::vector<double> &cellData) const;
130 std::vector<double> convertToCellData(const std::vector<double> &vertexData) const;
131
132 int linearCellInterpolation(const std::array<double,3> &point, std::vector<int> *stencil, std::vector<double> *weights) const;
133 int linearVertexInterpolation(const std::array<double,3> &point, std::vector<int> *stencil, std::vector<double> *weights) const;
134
135 long getCellLinearId(int i, int j, int k) const;
136 long getCellLinearId(const std::array<int, 3> &ijk) const;
137 std::array<int, 3> getCellCartesianId(long id) const;
138 bool isCellCartesianIdValid(const std::array<int, 3> &ijk) const;
139 long getVertexLinearId(int i, int j, int k) const;
140 long getVertexLinearId(const std::array<int, 3> &ijk) const;
141 std::array<int, 3> getVertexCartesianId(long id) const;
142 std::array<int, 3> getVertexCartesianId(long cellId, int vertex) const;
143 std::array<int, 3> getVertexCartesianId(const std::array<int, 3> &cellIjk, int vertex) const;
144 bool isVertexCartesianIdValid(const std::array<int, 3> &ijk) const;
145
146 std::array<int, 3> getCellFaceNeighsCartesianId(long id, int face) const;
147 long getCellFaceNeighsLinearId(long id, int face) const;
148
149protected:
150 void _updateAdjacencies() override;
151
152 void _updateInterfaces() override;
153
154 int _getDumpVersion() const override;
155 void _dump(std::ostream &stream) const override;
156 void _restore(std::istream &stream) override;
157
158 void _findCellFaceNeighs(long id, int face, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
159 void _findCellEdgeNeighs(long id, int edge, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
160 void _findCellVertexNeighs(long id, int vertex, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
161
162private:
163 MemoryMode m_memoryMode;
164
165 std::array<double, 3> m_cellSpacings;
166 std::array<double, 3> m_minCoords;
167 std::array<double, 3> m_maxCoords;
168
169 std::array<int, 3> m_directionOrdering;
170
171 std::array<std::vector<double>, 3> m_vertexCoords;
172 std::array<std::vector<double>, 3> m_cellCenters;
173
174 std::array<int, 3> m_nCells1D;
175 std::array<int, 3> m_nVertices1D;
176
177 long m_nVertices;
178 long m_nCells;
179 long m_nInterfaces;
180
181 double m_cellVolume;
182 double m_cellSize;
183 std::array<double, 3> m_interfaceArea;
184 std::array<std::array<double, 3>, 6> m_normals;
185
186 std::vector<std::array<int, 3>> m_vertexNeighDeltas;
187 std::vector<std::array<int, 3>> m_edgeNeighDeltas;
188 std::vector<std::array<int, 2>> m_edgeFaces;
189
190 void initialize();
191 void initializeInterfaceArea();
192 void initializeCellVolume();
193 void initializeCellSize();
194
195 void setDiscretization(const std::array<int, 3> &nCells);
196
197 void setMemoryMode(MemoryMode mode);
198
199 void addVertices();
200
201 void addCells();
202
203 double evalCellVolume() const;
204 double evalCellSize() const;
205
206};
207
208}
209
210#endif
virtual ElementType getInterfaceType(long id) const
long locatePoint(double x, double y, double z) const
virtual ElementType getCellType(long id) const
void _findCellVertexNeighs(long id, int vertex, const std::vector< long > *blackList, std::vector< long > *neighs) const override
std::array< double, 3 > getLengths() const
std::array< int, 3 > getCellFaceNeighsCartesianId(long id, int face) const
long getCellLinearId(int i, int j, int k) const
double evalCellSize(long id) const override
std::array< double, 3 > evalInterfaceNormal(long id) const override
void reset() override
long getCellFaceNeighsLinearId(long id, int face) const
long getInterfaceCount() const override
void setLengths(const std::array< double, 3 > &lengths)
void setOrigin(const std::array< double, 3 > &origin)
bool isPointInside(const std::array< double, 3 > &point) const override
void evalCellBoundingBox(long id, std::array< double, 3 > *minPoint, std::array< double, 3 > *maxPoint) const override
std::vector< long > extractVertexSubSet(std::array< int, 3 > const &ijkMin, std::array< int, 3 > const &ijkMax) const
long locateClosestCell(std::array< double, 3 > const &point) const
std::vector< long > extractCellSubSet(std::array< int, 3 > const &ijkMin, std::array< int, 3 > const &ijkMax) const
std::array< int, 3 > locatePointCartesian(const std::array< double, 3 > &point) const
std::array< int, 3 > locateClosestVertexCartesian(std::array< double, 3 > const &point) const
long locateClosestVertex(std::array< double, 3 > const &point) const
long getCellCount() const override
std::unique_ptr< PatchKernel > clone() const override
std::array< double, 3 > getOrigin() const
void rotate(const std::array< double, 3 > &n0, const std::array< double, 3 > &n1, double angle) override
double evalCellVolume(long id) const override
void _updateAdjacencies() override
std::array< int, 3 > locateClosestCellCartesian(std::array< double, 3 > const &point) const
ElementType getCellType() const
std::array< double, 3 > evalCellCentroid(long id) const override
int _getDumpVersion() const override
bool isVertexCartesianIdValid(const std::array< int, 3 > &ijk) const
std::array< int, 3 > getVertexCartesianId(long id) const
ElementType getInterfaceType() const
long locatePoint(const std::array< double, 3 > &point) const override
const std::vector< double > & getVertexCoords(int direction) const
long getVertexCount() const override
std::vector< double > convertToCellData(const std::vector< double > &vertexData) const
double evalInterfaceArea(long id) const override
void _findCellFaceNeighs(long id, int face, const std::vector< long > *blackList, std::vector< long > *neighs) const override
std::array< int, 3 > getCellCartesianId(long id) const
std::vector< double > convertToVertexData(const std::vector< double > &cellData) const
bool isCellCartesianIdValid(const std::array< int, 3 > &ijk) const
void switchMemoryMode(MemoryMode mode)
int linearCellInterpolation(const std::array< double, 3 > &point, std::vector< int > *stencil, std::vector< double > *weights) const
void _updateInterfaces() override
void _findCellEdgeNeighs(long id, int edge, const std::vector< long > *blackList, std::vector< long > *neighs) const override
int linearVertexInterpolation(const std::array< double, 3 > &point, std::vector< int > *stencil, std::vector< double > *weights) const
long getVertexLinearId(int i, int j, int k) const
void translate(const std::array< double, 3 > &translation) override
const std::vector< double > & getCellCentroids(int direction) const
std::array< double, 3 > evalVertexCoords(long id) const
std::array< double, 3 > getSpacing() const
void _dump(std::ostream &stream) const override
void _restore(std::istream &stream) override
void scale(const std::array< double, 3 > &scaling, const std::array< double, 3 > &center) override
MemoryMode getMemoryMode() const
bool isPointInside(double x, double y, double z) const
VolumeKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode)