Loading...
Searching...
No Matches
volunstructured.cpp
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#include "bitpit_common.hpp"
26
27#include "volunstructured.hpp"
28
29namespace bitpit {
30
42#if BITPIT_ENABLE_MPI==1
56VolUnstructured::VolUnstructured(MPI_Comm communicator, std::size_t haloSize)
57 : VolumeKernel(communicator, haloSize, ADAPTION_MANUAL, PARTITIONING_ENABLED)
58#else
63 : VolumeKernel(ADAPTION_MANUAL)
64#endif
65{
66}
67
68#if BITPIT_ENABLE_MPI==1
83VolUnstructured::VolUnstructured(int dimension, MPI_Comm communicator, std::size_t haloSize)
84 : VolUnstructured(PatchManager::AUTOMATIC_ID, dimension, communicator, haloSize)
85#else
91VolUnstructured::VolUnstructured(int dimension)
92 : VolUnstructured(PatchManager::AUTOMATIC_ID, dimension)
93#endif
94{
95}
96
97#if BITPIT_ENABLE_MPI==1
113VolUnstructured::VolUnstructured(int id, int dimension, MPI_Comm communicator, std::size_t haloSize)
114 : VolumeKernel(id, dimension, communicator, haloSize, ADAPTION_MANUAL, PARTITIONING_ENABLED)
115#else
122VolUnstructured::VolUnstructured(int id, int dimension)
123 : VolumeKernel(id, dimension, ADAPTION_MANUAL)
124#endif
125{
126}
127
133std::unique_ptr<PatchKernel> VolUnstructured::clone() const
134{
135 return std::unique_ptr<VolUnstructured>(new VolUnstructured(*this));
136}
137
145{
146 const Cell &cell = getCell(id);
147
148 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
149 std::size_t nCellVertices = cellVertexIds.size();
150 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nCellVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
151 getVertexCoords(nCellVertices, cellVertexIds.data(), vertexCoordinates);
152
153 if (isThreeDimensional()) {
154 return cell.evalVolume(vertexCoordinates);
155 } else {
156 return cell.evalArea(vertexCoordinates);
157 }
158}
159
166double VolUnstructured::evalCellSize(long id) const
167{
168 const Cell &cell = getCell(id);
169
170 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
171 std::size_t nCellVertices = cellVertexIds.size();
172 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nCellVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
173 getVertexCoords(nCellVertices, cellVertexIds.data(), vertexCoordinates);
174
175 return cell.evalSize(vertexCoordinates);
176}
177
185{
186 const Interface &interface = getInterface(id);
187
188 ConstProxyVector<long> interfaceVertexIds = interface.getVertexIds();
189 std::size_t nInterfaceVertices = interfaceVertexIds.size();
190 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nInterfaceVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
191 getVertexCoords(nInterfaceVertices, interfaceVertexIds.data(), vertexCoordinates);
192
193 if (isThreeDimensional()) {
194 return interface.evalArea(vertexCoordinates);
195 } else {
196 return interface.evalLength(vertexCoordinates);
197 }
198}
199
206std::array<double, 3> VolUnstructured::evalInterfaceNormal(long id) const
207{
208 const Interface &interface = getInterface(id);
209
210 ConstProxyVector<long> interfaceVertexIds = interface.getVertexIds();
211 std::size_t nInterfaceVertices = interfaceVertexIds.size();
212 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nInterfaceVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
213 getVertexCoords(nInterfaceVertices, interfaceVertexIds.data(), vertexCoordinates);
214
215 std::array<double, 3> orientation = {{0., 0., 0.}};
216 if (!isThreeDimensional()) {
217 long ownerId = interface.getOwner();
218 const Cell &owner = getCell(ownerId);
219
220 ConstProxyVector<long> ownerVertexIds = owner.getVertexIds();
221 const int nOwnerVertices = ownerVertexIds.size();
222
223 const std::array<double, 3> &V_A = getVertex(ownerVertexIds[0]).getCoords();
224 const std::array<double, 3> &V_B = getVertex(ownerVertexIds[1]).getCoords();
225 const std::array<double, 3> &V_Z = getVertex(ownerVertexIds[nOwnerVertices - 1]).getCoords();
226
227 orientation = crossProduct(V_B - V_A, V_Z - V_A);
228 }
229
230 return interface.evalNormal(vertexCoordinates, orientation);
231}
232
239{
240 const int DUMP_VERSION = 2;
241
242 return DUMP_VERSION;
243}
244
250void VolUnstructured::_dump(std::ostream &stream) const
251{
252 // Dump certices
253 dumpVertices(stream);
254
255 // Dump cells
256 dumpCells(stream);
257
258 // Dump cells
259 dumpInterfaces(stream);
260}
261
267void VolUnstructured::_restore(std::istream &stream)
268{
269 // Restore certices
270 restoreVertices(stream);
271
272 // Restore cells
273 restoreCells(stream);
274
275 // Restore cells
276 restoreInterfaces(stream);
277}
278
285bool VolUnstructured::isPointInside(const std::array<double, 3> &point) const
286{
287 BITPIT_UNUSED(point);
288
289 throw std::runtime_error ("The function 'isPointInside' is not implemented yet");
290
291 return false;
292}
293
301bool VolUnstructured::isPointInside(long id, const std::array<double, 3> &point) const
302{
303 BITPIT_UNUSED(id);
304 BITPIT_UNUSED(point);
305
306 throw std::runtime_error ("The function 'isPointInside' is not implemented yet");
307
308 return false;
309}
310
322long VolUnstructured::locatePoint(const std::array<double, 3> &point) const
323{
324 BITPIT_UNUSED(point);
325
326 throw std::runtime_error ("The function 'locatePoint' is not implemented yet");
327
328 return Cell::NULL_ID;
329}
330
331#if BITPIT_ENABLE_MPI==1
340{
341 return std::numeric_limits<uint32_t>::max();
342}
343#endif
344
345}
The Cell class defines the cells.
Definition cell.hpp:42
double evalVolume(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1646
double evalArea(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1685
double evalSize(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1549
static ConstProxyVector< long > getVertexIds(ElementType type, const long *connectivity)
Definition element.cpp:1193
The Interface class defines the interfaces among cells.
Definition interface.hpp:37
void dumpInterfaces(std::ostream &stream) const
void dumpVertices(std::ostream &stream) const
void dumpCells(std::ostream &stream) const
void restoreCells(std::istream &stream)
Cell & getCell(long id)
void restoreVertices(std::istream &stream)
void restoreInterfaces(std::istream &stream)
const std::array< double, 3 > & getVertexCoords(long id) const
bool isThreeDimensional() const
The PatchManager oversee the handling of the patches.
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
std::size_t size() const
__PXV_POINTER__ data() noexcept
The VolUnstructured class defines a dummy unstructured volume patch.
std::array< double, 3 > evalInterfaceNormal(long id) const override
std::unique_ptr< PatchKernel > clone() const override
double evalInterfaceArea(long id) const override
std::size_t _getMaxHaloSize() override
double evalCellSize(long id) const override
bool isPointInside(const std::array< double, 3 > &point) const override
double evalCellVolume(long id) const override
void _dump(std::ostream &stream) const override
void _restore(std::istream &stream) override
VolUnstructured(MPI_Comm communicator, std::size_t haloSize=1)
long locatePoint(const std::array< double, 3 > &point) const override
int _getDumpVersion() const override
The VolumeKernel class provides an interface for defining volume patches.
std::array< T, 3 > crossProduct(const std::array< T, 3 > &x, const std::array< T, 3 > &y)
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
#define BITPIT_CREATE_WORKSPACE(workspace, item_type, size, stack_size)
--- layout: doxygen_footer ---