Loading...
Searching...
No Matches
levelSetComplementObject.tpp
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 <cassert>
26
27# include "bitpit_IO.hpp"
28# include "bitpit_common.hpp"
29
30# include "levelSetObject.hpp"
31# include "levelSetProxyObject.hpp"
32# include "levelSetComplementObject.hpp"
33
34namespace bitpit {
35
49template<typename SourceLevelSetObject>
51 : LevelSetProxyObject<SourceLevelSetObject, SourceLevelSetObject>(id),
52 m_sourceObject(source)
53{
61template<typename SourceLevelSetObject>
64 return m_sourceObject->empty();
73template<typename SourceLevelSetObject>
74void LevelSetComplementBaseObject<SourceLevelSetObject>::replaceSourceObject(const SourceLevelSetObject *current, const SourceLevelSetObject *updated)
75{
76 if (current != m_sourceObject) {
77 throw std::runtime_error("Unable to find the source that should be replaced.");
78 }
79
80 m_sourceObject = updated;
81}
82
86template<typename SourceLevelSetObject>
88{
89 // Early return if propagated sign cannot be copied from the source object
90 LevelSetBulkEvaluationMode sourceBulkEvaluationMode = m_sourceObject->getCellBulkEvaluationMode();
91
92 bool useSourceSign = false;
93 if (sourceBulkEvaluationMode == LevelSetBulkEvaluationMode::SIGN_PROPAGATION) {
94 useSourceSign = true;
95 } else if (sourceBulkEvaluationMode == LevelSetBulkEvaluationMode::EXACT) {
96 LevelSetCacheMode sourceSignCacheMode = m_sourceObject->getFieldCellCacheMode(LevelSetField::SIGN);
97 if (sourceSignCacheMode == LevelSetCacheMode::FULL) {
98 useSourceSign = true;
99 } else {
100 LevelSetCacheMode sourceValueCacheMode = m_sourceObject->getFieldCellCacheMode(LevelSetField::VALUE);
101 if (sourceValueCacheMode == LevelSetCacheMode::FULL) {
102 useSourceSign = true;
103 }
104 }
105 }
106
107 if (!useSourceSign) {
108 SourceLevelSetObject::fillCellPropagatedSignCache();
109 return;
110 }
111
112 // Mesh information
113 const VolumeKernel &mesh = *(this->getKernel()->getMesh()) ;
116
117 // Get cache for sign propagation
118 typedef typename SourceLevelSetObject::CellCacheCollection::template ValueCache<char> ZoneCache;
119 ZoneCache *propagatedSignCache = this->template getCellCache<char>(this->m_cellPropagatedSignCacheId);
120
121 // Get propagated sign from source object
122 for (VolumeKernel::CellConstIterator cellItr = cellBegin; cellItr != cellEnd; ++cellItr) {
123 long cellId = cellItr.getId();
124 short cellSign = - m_sourceObject->evalCellSign(cellId);
125
126 propagatedSignCache->insertEntry(cellId, static_cast<char>(cellSign));
127 }
128}
129
136template<typename SourceLevelSetObject>
138{
139 return (-1 * m_sourceObject->evalCellSign(id));
140}
141
149template<typename SourceLevelSetObject>
151{
152 double value = m_sourceObject->evalCellValue(id, signedLevelSet);
153 if (signedLevelSet) {
154 value *= -1.;
155 }
156
157 return value;
158}
159
167template<typename SourceLevelSetObject>
168std::array<double,3> LevelSetComplementBaseObject<SourceLevelSetObject>::_evalCellGradient(long id, bool signedLevelSet) const
169{
170 std::array<double,3> gradient = m_sourceObject->evalCellGradient(id, signedLevelSet);
171 if (signedLevelSet) {
172 gradient *= -1.;
173 }
174
175 return gradient;
176}
177
184template<typename SourceLevelSetObject>
185short LevelSetComplementBaseObject<SourceLevelSetObject>::_evalSign(const std::array<double,3> &point) const
186{
187 return (-1 * m_sourceObject->evalSign(point));
188}
189
197template<typename SourceLevelSetObject>
198double LevelSetComplementBaseObject<SourceLevelSetObject>::_evalValue(const std::array<double,3> &point, bool signedLevelSet) const
199{
200 double value = m_sourceObject->evalValue(point, signedLevelSet);
201 if (signedLevelSet) {
202 value *= -1.;
203 }
204
205 return value;
206}
207
215template<typename SourceLevelSetObject>
216std::array<double,3> LevelSetComplementBaseObject<SourceLevelSetObject>::_evalGradient(const std::array<double,3> &point, bool signedLevelSet) const
217{
218 std::array<double,3> gradient = m_sourceObject->evalGradient(point, signedLevelSet);
219 if (signedLevelSet) {
220 gradient *= -1.;
221 }
222
223 return gradient;
224}
225
233template<typename SourceLevelSetObject>
235{
236 BITPIT_UNUSED(id);
237
238 return m_sourceObject;
239}
240
248template<typename SourceLevelSetObject>
249const SourceLevelSetObject * LevelSetComplementBaseObject<SourceLevelSetObject>::getReferenceObject(const std::array<double, 3> &point) const
250{
251 BITPIT_UNUSED(point);
252
253 return m_sourceObject;
254}
255
262template<typename SourceLevelSetObject>
264{
265 return m_sourceObject;
266}
267
274template<typename SourceLevelSetObject>
275std::vector<const SourceLevelSetObject *> LevelSetComplementBaseObject<SourceLevelSetObject>::getSourceObjects() const
276{
277 return std::vector<const SourceLevelSetObject *>(1, m_sourceObject);
278}
279
280}
std::array< double, 3 > _evalGradient(const std::array< double, 3 > &point, bool signedLevelSet) const override
const SourceLevelSetObject * getReferenceObject(const std::array< double, 3 > &point) const override
double _evalValue(const std::array< double, 3 > &point, bool signedLevelSet) const override
const SourceLevelSetObject * getCellReferenceObject(long id) const override
std::array< double, 3 > _evalCellGradient(long id, bool signedLevelSet) const override
virtual const SourceLevelSetObject * getSourceObject() const
double _evalCellValue(long id, bool signedLevelSet) const override
void replaceSourceObject(const SourceLevelSetObject *current, const SourceLevelSetObject *updated) override
LevelSetComplementBaseObject(int id, const SourceLevelSetObject *source)
short _evalSign(const std::array< double, 3 > &point) const override
std::vector< const SourceLevelSetObject * > getSourceObjects() const override
Interface class for all objects, which depend on other LevelSetObjects.
CellConstIterator cellConstBegin() const
CellConstIterator cellConstEnd() const
Iterator for the class PiercedStorage.
The VolumeKernel class provides an interface for defining volume patches.
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
@ FULL
Data are cached in the whole domain.
@ SIGN_PROPAGATION
Sign is propagated from the narrow band, no other data will be evaluated.
@ EXACT
Exact data is evaluated.
--- layout: doxygen_footer ---