Loading...
Searching...
No Matches
levelSetUnstructuredKernel.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2022 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 "levelSetUnstructuredKernel.hpp"
26
27# include "bitpit_CG.hpp"
28
29namespace bitpit {
30
44
46 if (fillIn == LevelSetFillIn::SPARSE) {
47 m_cellCentroidCacheId = cacheCollection.insert<CellSparseCacheContainer<std::array<double, 3>>>(CellCacheCollection::NULL_CACHE_ID);
48 m_cellTangentRadiusCacheId = cacheCollection.insert<CellSparseCacheContainer<double>>(CellCacheCollection::NULL_CACHE_ID);
49 m_cellBoundingRadiusCacheId = cacheCollection.insert<CellSparseCacheContainer<double>>(CellCacheCollection::NULL_CACHE_ID);
50 } else if (fillIn == LevelSetFillIn::DENSE) {
52 m_cellTangentRadiusCacheId = cacheCollection.insert<CellDenseCacheContainer<double>>(CellCacheCollection::NULL_CACHE_ID);
53 m_cellBoundingRadiusCacheId = cacheCollection.insert<CellDenseCacheContainer<double>>(CellCacheCollection::NULL_CACHE_ID);
54 } else {
55 m_cellCentroidCacheId = CellCacheCollection::NULL_CACHE_ID;
56 m_cellTangentRadiusCacheId = CellCacheCollection::NULL_CACHE_ID;
57 m_cellBoundingRadiusCacheId = CellCacheCollection::NULL_CACHE_ID;
58 }
59}
60
68
75std::array<double, 3> LevelSetUnstructuredKernel::computeCellCentroid( long id ) const {
76
77 // Try fetching the value from the cache
78 CellCacheCollection::ValueCache<std::array<double, 3>> *cache = (*m_cellCacheCollection)[m_cellCentroidCacheId].getCache<std::array<double, 3>>();
79 if (cache) {
80 typename CellCacheCollection::ValueCache<std::array<double, 3>>::Entry cacheEntry = cache->findEntry(id);
81 if (cacheEntry.isValid()) {
82 return *cacheEntry;
83 }
84 }
85
86 // Evaluate the centroid
87 std::array<double, 3> centroid = getMesh()->evalCellCentroid(id);
88
89 // Update the cache
90 if (cache) {
91 cache->insertEntry(id, centroid);
92 }
93
94 return centroid;
95
96}
97
108
109 // Try fetching the value from the cache
110 CellCacheCollection::ValueCache<double> *cache = (*m_cellCacheCollection)[m_cellTangentRadiusCacheId].getCache<double>();
111 if (cache) {
112 typename CellCacheCollection::ValueCache<double>::Entry cacheEntry = cache->findEntry(id);
113 if (cacheEntry.isValid()) {
114 return *cacheEntry;
115 }
116 }
117
118 // Get mesh information
119 const VolUnstructured &unstructuredPatch = *(this->getMesh()) ;
120
121 // Cell information
122 const Cell &cell = unstructuredPatch.getCell(id);
123 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
124 int nCellVertices = cellVertexIds.size();
125 std::array<double, 3> centroid = computeCellCentroid(id);
126
127 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nCellVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
128 unstructuredPatch.getVertexCoords(nCellVertices, cellVertexIds.data(), vertexCoordinates);
129
130 // Evaluate the radius of the tangent sphere
131 //
132 // Since the center of the tangent sphere is the cell centroid, its
133 // radius can be evaluated as distance between the cell centroid and
134 // the cell.
135 double tangentRadius = cell.evalPointDistance(centroid, vertexCoordinates);
136
137 // Update the cache
138 if (cache) {
139 cache->insertEntry(id, tangentRadius);
140 }
141
142 return tangentRadius;
143
144}
145
156
157 // Try fetching the value from the cache
158 CellCacheCollection::ValueCache<double> *cache = (*m_cellCacheCollection)[m_cellBoundingRadiusCacheId].getCache<double>();
159 if (cache) {
160 typename CellCacheCollection::ValueCache<double>::Entry cacheEntry = cache->findEntry(id);
161 if (cacheEntry.isValid()) {
162 return *cacheEntry;
163 }
164 }
165
166 // Get mesh information
167 const VolUnstructured &unstructuredPatch = *(this->getMesh()) ;
168
169 // Cell information
170 const Cell &cell = unstructuredPatch.getCell(id);
171 ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
172 int nCellVertices = cellVertexIds.size();
173 std::array<double, 3> centroid = computeCellCentroid(id);
174
175 BITPIT_CREATE_WORKSPACE(vertexCoordinates, std::array<double BITPIT_COMMA 3>, nCellVertices, ReferenceElementInfo::MAX_ELEM_VERTICES);
176 unstructuredPatch.getVertexCoords(nCellVertices, cellVertexIds.data(), vertexCoordinates);
177
178 // Evaluate the radius of the bounding sphere
179 //
180 // Since the center of the bounding sphere is the cell centroid, its
181 // radius can be evaluated as distance between the cell centroid and
182 // the farthest vertex.
183 double boundingRadius = 0.;
184 for (int k = 0; k < nCellVertices; ++k) {
185 double vertexDistance = 0.;
186 for (int d = 0; d < 3; ++d) {
187 vertexDistance += uipow(centroid[d] - vertexCoordinates[k][d], 2);
188 }
189
190 boundingRadius = std::max(vertexDistance, boundingRadius);
191 }
192 boundingRadius = std::sqrt(boundingRadius);
193
194 // Update the cache
195 if (cache) {
196 cache->insertEntry(id, boundingRadius);
197 }
198
199 return boundingRadius;
200
201}
202
203}
The Cell class defines the cells.
Definition cell.hpp:42
The class ElementCacheCollection allows to store a collection of caches for the elements of a mesh.
std::size_t insert(std::size_t index, Args &&... args)
static ConstProxyVector< long > getVertexIds(ElementType type, const long *connectivity)
Definition element.cpp:1193
double evalPointDistance(const std::array< double, 3 > &point, const std::array< double, 3 > *coordinates) const
Definition element.cpp:1828
Base class for defining kernels that need to cache data.
CellCacheCollection & getCellCacheCollection()
virtual VolumeKernel * getMesh() const
std::array< double, 3 > computeCellCentroid(long) const override
double computeCellBoundingRadius(long) const override
double computeCellTangentRadius(long) const override
LevelSetUnstructuredKernel(VolUnstructured &patch, LevelSetFillIn fillIn)
VolUnstructured * getMesh() const override
The class LevelSetCache is the base class for defining caches that store values.
Cell & getCell(long id)
const std::array< double, 3 > & getVertexCoords(long id) const
virtual std::array< double, 3 > evalCellCentroid(long id) const
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.
T uipow(const T &, unsigned int)
Definition Operators.tpp:55
#define BITPIT_CREATE_WORKSPACE(workspace, item_type, size, stack_size)
--- layout: doxygen_footer ---