Loading...
Searching...
No Matches
levelSetOctreeKernel.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_voloctree.hpp"
26# include "bitpit_CG.hpp"
27# include "levelSetKernel.hpp"
28# include "levelSetOctreeKernel.hpp"
29
30namespace bitpit {
31
45
46 // Initialize cache
48 if (fillIn == LevelSetFillIn::SPARSE) {
49 m_cellCentroidCacheId = cacheCollection.insert<CellSparseCacheContainer<std::array<double, 3>>>(CellCacheCollection::NULL_CACHE_ID);
50 } else if (fillIn == LevelSetFillIn::DENSE) {
52 } else {
53 m_cellCentroidCacheId = CellCacheCollection::NULL_CACHE_ID;
54 }
55
56 // Mesh information
57 VolOctree *mesh = getMesh();
58 int dimension = mesh->getDimension();
59 int maxLevel = TreeConstants::instance(dimension).maxLevel;
60
61 // Initialize bounding and tangent radii
62 m_octantTangentRadii.resize(maxLevel + 1);
63 m_octantBoundingRadii.resize(maxLevel + 1);
64 for (int level = 0; level <= maxLevel; ++level) {
65 double levelSize = mesh->getTree().levelToSize(level);
66
67 m_octantTangentRadii[level] = 0.5 * levelSize;
68 m_octantBoundingRadii[level] = 0.5 * std::sqrt(dimension) * levelSize;
69 }
70
71}
72
78 return static_cast<VolOctree *>(LevelSetKernel::getMesh()) ;
79}
80
91
92 return m_octantTangentRadii[level];
93
94}
95
106
107 return m_octantBoundingRadii[level];
108
109}
110
117std::array<double, 3> LevelSetOctreeKernel::computeCellCentroid( long id ) const {
118
119 // Try fetching the value from the cache
120 CellCacheCollection::ValueCache<std::array<double, 3>> *cache = (*m_cellCacheCollection)[m_cellCentroidCacheId].getCache<std::array<double, 3>>();
121 if (cache) {
122 typename CellCacheCollection::ValueCache<std::array<double, 3>>::Entry cacheEntry = cache->findEntry(id);
123 if (cacheEntry.isValid()) {
124 return *cacheEntry;
125 }
126 }
127
128 // Evaluate the centroid
129 std::array<double, 3> centroid = getMesh()->evalCellCentroid(id);
130
131 // Update the cache
132 if (cache) {
133 cache->insertEntry(id, centroid);
134 }
135
136 return centroid;
137
138}
139
150
151 const VolOctree *mesh = getMesh();
152 int cellLevel = mesh->getCellLevel(id);
153
154 return getOctantTangentRadius(cellLevel);
155
156}
157
168
169 const VolOctree *mesh = getMesh();
170 int cellLevel = mesh->getCellLevel(id);
171
172 return getOctantBoundingRadius(cellLevel);
173
174}
175
176}
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)
Base class for defining kernels that need to cache data.
CellCacheCollection & getCellCacheCollection()
virtual VolumeKernel * getMesh() const
double computeCellBoundingRadius(long) const override
double getOctantTangentRadius(int level) const
LevelSetOctreeKernel(VolOctree &patch, LevelSetFillIn fillIn)
std::array< double, 3 > computeCellCentroid(long) const override
double getOctantBoundingRadius(int level) const
VolOctree * getMesh() const override
double computeCellTangentRadius(long) const override
The class LevelSetCache is the base class for defining caches that store values.
double levelToSize(uint8_t level) const
The VolOctree defines a Octree patch.
Definition voloctree.hpp:37
int getCellLevel(long id) const
PabloUniform & getTree()
Gets a reference to the octree associated with the patch.
std::array< double, 3 > evalCellCentroid(long id) const override
static BITPIT_PUBLIC_API const TreeConstants & instance(uint8_t dim)
--- layout: doxygen_footer ---