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 void resetInterfaces() override;
70
71 long getVertexCount() const override;
72 int getVertexCount(int direction) const;
73
74 long getCellCount() const override;
75 int getCellCount(int direction) const;
76
78 ElementType getCellType(long id) const override;
79
80 long getInterfaceCount() const override;
82 ElementType getInterfaceType(long id) const override;
83
84 std::array<double, 3> evalVertexCoords(long id) const;
85 std::array<double, 3> evalVertexCoords(const std::array<int, 3> &ijk) const;
86 const std::vector<double> & getVertexCoords(int direction) const;
87
88 double evalCellVolume(long id) const override;
89 double evalCellVolume(const std::array<int, 3> &ijk) const;
90 double evalCellSize(long id) const override;
91 double evalCellSize(const std::array<int, 3> &ijk) const;
92 std::array<double, 3> evalCellCentroid(long id) const override;
93 std::array<double, 3> evalCellCentroid(const std::array<int, 3> &ijk) const;
94 const std::vector<double> & getCellCentroids(int direction) const;
95
96 void evalCellBoundingBox(long id, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const override;
97
98 double evalInterfaceArea(long id) const override;
99 std::array<double, 3> evalInterfaceNormal(long id) const override;
100
101 std::array<double, 3> getSpacing() const;
102 double getSpacing(int direction) const;
103
104 void switchMemoryMode(MemoryMode mode);
105 MemoryMode getMemoryMode() const;
106
107 bool isPointInside(const std::array<double, 3> &point) const override;
108 bool isPointInside(long id, const std::array<double, 3> &point) const override;
109 long locatePoint(const std::array<double, 3> &point) const override;
110 std::array<int, 3> locatePointCartesian(const std::array<double, 3> &point) const;
111 long locateClosestVertex(std::array<double,3> const &point) const;
112 std::array<int, 3> locateClosestVertexCartesian(std::array<double,3> const &point) const;
113 long locateClosestCell(std::array<double,3> const &point) const;
114 std::array<int, 3> locateClosestCellCartesian(std::array<double,3> const &point) const;
115
116 std::vector<long> extractCellSubSet(std::array<int, 3> const &ijkMin, std::array<int, 3> const &ijkMax) const;
117 std::vector<long> extractCellSubSet(int idMin, int idMax) const;
118 std::vector<long> extractCellSubSet(std::array<double, 3> const &pointMin, std::array<double, 3> const &pointMax) const;
119 std::vector<long> extractVertexSubSet(std::array<int, 3> const &ijkMin, std::array<int, 3> const &ijkMax) const;
120 std::vector<long> extractVertexSubSet(int idMin, int idMax) const;
121 std::vector<long> extractVertexSubSet(std::array<double, 3> const &pointMin, std::array<double, 3> const &pointMax) const;
122
123 std::array<double, 3> getOrigin() const;
124 void setOrigin(const std::array<double, 3> &origin);
125 void translate(const std::array<double, 3> &translation) override;
126 void rotate(const std::array<double, 3> &n0, const std::array<double, 3> &n1, double angle) override;
127 std::array<double, 3> getLengths() const;
128 void setLengths(const std::array<double, 3> &lengths);
129 void scale(const std::array<double, 3> &scaling, const std::array<double, 3> &center) override;
130
131 std::vector<double> convertToVertexData(const std::vector<double> &cellData) const;
132 std::vector<double> convertToCellData(const std::vector<double> &vertexData) const;
133
134 int linearCellInterpolation(const std::array<double,3> &point, std::vector<int> *stencil, std::vector<double> *weights) const;
135 int linearVertexInterpolation(const std::array<double,3> &point, std::vector<int> *stencil, std::vector<double> *weights) const;
136
137 long getCellLinearId(int i, int j, int k) const;
138 long getCellLinearId(const std::array<int, 3> &ijk) const;
139 std::array<int, 3> getCellCartesianId(long id) const;
140 bool isCellCartesianIdValid(const std::array<int, 3> &ijk) const;
141 long getVertexLinearId(int i, int j, int k) const;
142 long getVertexLinearId(const std::array<int, 3> &ijk) const;
143 std::array<int, 3> getVertexCartesianId(long id) const;
144 std::array<int, 3> getVertexCartesianId(long cellId, int vertex) const;
145 std::array<int, 3> getVertexCartesianId(const std::array<int, 3> &cellIjk, int vertex) const;
146 bool isVertexCartesianIdValid(const std::array<int, 3> &ijk) const;
147
148 std::array<int, 3> getCellFaceNeighsCartesianId(long id, int face) const;
149 long getCellFaceNeighsLinearId(long id, int face) const;
150
151protected:
152 void _updateAdjacencies() override;
153
154 void _updateInterfaces() override;
155
156 int _getDumpVersion() const override;
157 void _dump(std::ostream &stream) const override;
158 void _restore(std::istream &stream) override;
159
160 void _findCellFaceNeighs(long id, int face, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
161 void _findCellEdgeNeighs(long id, int edge, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
162 void _findCellVertexNeighs(long id, int vertex, const std::vector<long> *blackList, std::vector<long> *neighs) const override;
163
164private:
165 MemoryMode m_memoryMode;
166
167 std::array<double, 3> m_cellSpacings;
168 std::array<double, 3> m_minCoords;
169 std::array<double, 3> m_maxCoords;
170
171 std::array<int, 3> m_directionOrdering;
172
173 std::array<std::vector<double>, 3> m_vertexCoords;
174 std::array<std::vector<double>, 3> m_cellCenters;
175
176 std::array<int, 3> m_nCells1D;
177 std::array<int, 3> m_nVertices1D;
178
179 long m_nVertices;
180 long m_nCells;
181 long m_nInterfaces;
182
183 double m_cellVolume;
184 double m_cellSize;
185 std::array<double, 3> m_interfaceArea;
186 std::array<std::array<double, 3>, 6> m_normals;
187
188 std::vector<std::array<int, 3>> m_vertexNeighDeltas;
189 std::vector<std::array<int, 3>> m_edgeNeighDeltas;
190 std::vector<std::array<int, 2>> m_edgeFaces;
191
192 void initialize();
193 void initializeInterfaceArea();
194 void initializeCellVolume();
195 void initializeCellSize();
196
197 void setDiscretization(const std::array<int, 3> &nCells);
198
199 void setMemoryMode(MemoryMode mode);
200
201 void addVertices();
202
203 void addCells();
204
205 double evalCellVolume() const;
206 double evalCellSize() const;
207
208};
209
210}
211
212#endif
virtual ElementType getInterfaceType(long id) const
long locatePoint(double x, double y, double z) const
virtual ElementType getCellType(long id) const
The VolCartesian defines a Cartesian patch.
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 resetInterfaces() override
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
The VolumeKernel class provides an interface for defining volume patches.
bool isPointInside(double x, double y, double z) const
--- layout: doxygen_footer ---