Loading...
Searching...
No Matches
line_kernel.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_CG.hpp"
26#include "line_kernel.hpp"
27
28namespace bitpit {
29
30
31#if BITPIT_ENABLE_MPI==1
48LineKernel::LineKernel(MPI_Comm communicator, std::size_t haloSize,
49 AdaptionMode adaptionMode, PartitioningMode partitioningMode)
50 : PatchKernel(communicator, haloSize, adaptionMode, partitioningMode)
51#else
58 : PatchKernel(adaptionMode)
59#endif
60{
61 initialize();
62}
63
64#if BITPIT_ENABLE_MPI==1
82LineKernel::LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
83 AdaptionMode adaptionMode, PartitioningMode partitioningMode)
84 : PatchKernel(dimension, communicator, haloSize, adaptionMode, partitioningMode)
85#else
92LineKernel::LineKernel(int dimension, AdaptionMode adaptionMode)
93 : PatchKernel(dimension, adaptionMode)
94#endif
95{
96 initialize();
97}
98
99#if BITPIT_ENABLE_MPI==1
118LineKernel::LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
119 AdaptionMode adaptionMode, PartitioningMode partitioningMode)
120 : PatchKernel(id, dimension, communicator, haloSize, adaptionMode, partitioningMode)
121#else
129LineKernel::LineKernel(int id, int dimension, AdaptionMode adaptionMode)
130 : PatchKernel(id, dimension, adaptionMode)
131#endif
132{
133}
134
138void LineKernel::initialize()
139{
140 // Nothing to do
141}
142
149{
150 return 2;
151}
152
159{
160 return 1;
161}
162
169{
170 return 0;
171}
172
179{
180 return -1;
181}
182
192{
194}
195
202double LineKernel::evalCellSize(long id) const
203{
204 return evalCellLength(id);
205}
206
215double LineKernel::evalCellLength(long id) const
216{
217 const Cell &cell = m_cells[id];
218 switch (cell.getType()) {
219
220 case ElementType::LINE:
221 {
222 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
223 const Vertex &vertex_0 = getVertex(cellVertexIds[0]);
224 const Vertex &vertex_1 = getVertex(cellVertexIds[1]);
225 double length = norm2(vertex_1.getCoords() - vertex_0.getCoords());
226
227 return length;
228 }
229
230 default:
231 {
232 return 0.;
233 }
234
235 }
236}
237
250std::array<double, 3> LineKernel::evalCellNormal(long id, const std::array<double, 3> &orientation) const
251{
252 const Cell &cell = m_cells[id];
253 switch (cell.getType()) {
254
255 case ElementType::LINE:
256 {
257 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
258 const Vertex &vertex_0 = getVertex(cellVertexIds[0]);
259 const Vertex &vertex_1 = getVertex(cellVertexIds[1]);
260
261 std::array<double, 3> normal = vertex_1.getCoords() - vertex_0.getCoords();
262 normal = crossProduct(normal, orientation);
263 normal = normal / norm2(normal);
264
265 return normal;
266 }
267
268 default:
269 {
270 return {{0., 0., 0.}};
271 }
272
273 }
274}
275
286void LineKernel::evalBarycentricCoordinates(long id, const std::array<double, 3> &point, double *lambda) const
287{
288
289 // ====================================================================== //
290 // VARIABLES DECLARATION //
291 // ====================================================================== //
292
293 // Local variables
294 const Cell *cell_ = &m_cells[id];
295
296 // Counters
297 // none
298
299 // ====================================================================== //
300 // COMPUTE BARYCENTRIC COORDINATES
301 // ====================================================================== //
302 switch (cell_->getType()) {
303
304 case ElementType::LINE:
305 {
306 ConstProxyVector<long> vertexIds = cell_->getVertexIds();
307
308 std::array<double,3> point0 = getVertexCoords(vertexIds[0]);
309 std::array<double,3> point1 = getVertexCoords(vertexIds[1]);
310
311 std::array<double, 3> projectionPoint = CGElem::projectPointSegment(point, point0, point1, lambda);
312 BITPIT_UNUSED(projectionPoint);
313 return;
314 }
315
316 default:
317 {
318 int nVertices = cell_->getVertexCount();
319 for (int i = 0; i < nVertices; ++i) {
320 lambda[i] = 0.0;
321 }
322 return;
323 }
324
325 }
326}
327
328}
The Cell class defines the cells.
Definition cell.hpp:42
ElementType getType() const
Definition element.cpp:551
static ConstProxyVector< long > getVertexIds(ElementType type, const long *connectivity)
Definition element.cpp:1193
int getVertexCount() const
Definition element.cpp:1152
int getVolumeCodimension() const override
int getPointCodimension() const override
void evalBarycentricCoordinates(long id, const std::array< double, 3 > &point, double *lambda) const
virtual double evalCellLength(long id) const
double evalCellSize(long id) const override
int getLineCodimension() const override
LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode)
void extractEnvelope(PointKernel &envelope) const
virtual std::array< double, 3 > evalCellNormal(long id, const std::array< double, 3 > &orientation={{0., 0., 1.}}) const
int getSurfaceCodimension() const override
The PatchKernel class provides an interface for defining patches.
Vertex & getVertex(long id)
const std::array< double, 3 > & getVertexCoords(long id) const
void extractEnvelope(PatchKernel &envelope) const
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
The Vertex class defines the vertexs.
Definition vertex.hpp:42
std::array< double, 3 > & getCoords()
Definition vertex.cpp:246
array3D projectPointSegment(array3D const &, array3D const &, array3D const &)
Definition CG_elem.cpp:996
std::array< T, 3 > crossProduct(const std::array< T, 3 > &x, const std::array< T, 3 > &y)
double norm2(const std::array< T, d > &x)
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
--- layout: doxygen_footer ---