Loading...
Searching...
No Matches
levelSetObject.hpp
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# ifndef __BITPIT_LEVELSET_OBJECT_HPP__
26# define __BITPIT_LEVELSET_OBJECT_HPP__
27
28// Standard Template Library
29# include <iostream>
30# include <array>
31# include <vector>
32# include <unordered_map>
33# include <unordered_set>
34
35# include "bitpit_IO.hpp"
36# if BITPIT_ENABLE_MPI
37# include "bitpit_communications.hpp"
38# endif
39# include "bitpit_containers.hpp"
40# include "levelSetCommon.hpp"
41# include "levelSetCache.hpp"
42# include "levelSetKernel.hpp"
43# include "levelSetCartesianKernel.hpp"
44# include "levelSetOctreeKernel.hpp"
45# include "levelSetUnstructuredKernel.hpp"
46
47namespace bitpit{
48
49namespace adaption{
50 struct Info;
51}
52class SendBuffer;
53class RecvBuffer;
54
56
57friend class LevelSet;
58
59template<typename SourceLevelSetObject, typename BaseLevelSetObject>
60friend class LevelSetProxyObject;
61
62public:
63 typedef LevelSetCachedKernel::CellCacheCollection CellCacheCollection;
64
65 virtual ~LevelSetObject();
66
67 virtual LevelSetObject* clone() const =0;
68
69 virtual const LevelSetKernel * getKernel() const;
70
71 virtual LevelSetFieldset getSupportedFields() const;
72
73 int getId() const ;
74 virtual bool isPrimary() const ;
75
76 virtual bool empty() const = 0;
77
78 std::size_t getReferenceCount() const ;
79
80 void update(const std::vector<adaption::Info> &adaptionData);
81
84
88
89 double getNarrowBandSize() const;
90 virtual bool isCellInNarrowBand(long id) const;
91 virtual bool isInNarrowBand(const std::array<double,3> &point) const;
92
95 LevelSetIntersectionStatus isInterfaceIntersected(long id, bool invert, std::array<std::array<double, 3>, 2> *intersection, std::vector<std::array<double, 3>> *polygon) const;
97
98 virtual short evalCellSign(long id) const;
99 virtual double evalCellValue(long id, bool signedLevelSet) const;
100 virtual std::array<double,3> evalCellGradient(long id, bool signedLevelSet) const;
101 virtual std::array<double,3> evalCellProjectionPoint(long id) const;
102
103 virtual short evalSign(const std::array<double,3> &point) const;
104 virtual double evalValue(const std::array<double,3> &point, bool signedLevelSet) const;
105 virtual std::array<double,3> evalGradient(const std::array<double,3> &point, bool signedLevelSet) const;
106 virtual std::array<double,3> evalProjectionPoint(const std::array<double,3> &point) const;
107
108 void enableVTKOutput(const LevelSetFieldset &fieldset, bool enable=true);
109 void enableVTKOutput(const LevelSetFieldset &fieldset, const std::string &objectName, bool enable=true);
110 void enableVTKOutput(LevelSetField field, bool enable=true);
111 void enableVTKOutput(LevelSetField field, const std::string &objectName, bool enable=true);
112 void enableVTKOutput(LevelSetWriteField field, bool enable=true);
113 void enableVTKOutput(LevelSetWriteField fieldset, const std::string &objectName, bool enable=true);
114 void flushData(std::fstream &, const std::string &, VTKFormat) override;
115
116 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeProjectionPoint(long cellId) const);
117 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeVertexProjectionPoint(long vertexId) const);
118
119 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeProjectionPoint(const std::array<double,3> &point) const);
120
121 BITPIT_DEPRECATED_FOR(short getSign(long cellId) const, short evalCellSign(long id) const);
122 BITPIT_DEPRECATED_FOR(double getValue(long cellId) const, double evalCellValue(long id, bool signedLevelSet) const);
123 BITPIT_DEPRECATED_FOR(std::array<double BITPIT_COMMA 3> getGradient(long cellId) const, std::array<double BITPIT_COMMA 3> evalCellGradient(long id, bool signedLevelSet) const);
124
126 BITPIT_DEPRECATED(double getLS(long cellId) const);
127
128 BITPIT_DEPRECATED(double getSizeNarrowBand() const);
129
130protected:
131 template<typename data_t>
132 using CellCacheEntry = typename CellCacheCollection::ValueCache<data_t>::Entry;
133
134 static const bool CELL_CACHE_IS_SIGNED;
136
138
139 bool m_defaultSignedLevelSet;
140
141 LevelSetFieldMap<std::string> m_enabledOutputFields;
142
144
147
148 LevelSetObject(int);
149 LevelSetObject(const LevelSetObject &other);
151
152 void setDefaultLevelSetSigndness(bool signedLevelSet);
153
154 virtual void setKernel(LevelSetKernel *);
155 virtual LevelSetKernel * getKernel();
156
157 void evaluate();
158 void update();
159
160 LevelSetZone getCellZone(long id) const;
162
163 void setNarrowBandSize(double size);
165 void updateCellNarrowBandData(const std::vector<adaption::Info> &adaptionData);
167
168 virtual void fillCellLocationCache();
169 virtual void fillCellLocationCache(const std::vector<adaption::Info> &adaptionData);
171 virtual std::size_t createCellLocationCache(std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
173
175 void updateCellBulkData(const std::vector<adaption::Info> &adaptionData);
176 void destroyCellBulkData();
177
178 virtual void fillCellPropagatedSignCache();
179 virtual std::size_t createCellPropagatedSignCache(std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
181
182 virtual void dump(std::ostream &);
183 virtual void restore(std::istream &);
184
186 virtual LevelSetIntersectionStatus _isInterfaceIntersected(long id, bool positivePart, std::array<std::array<double, 3>, 2> *intersection, std::vector<std::array<double, 3>> *polygon) const;
187
188 virtual short _evalCellSign(long id) const = 0;
189 virtual double _evalCellValue(long id, bool signedLevelSet) const = 0;
190 virtual std::array<double,3> _evalCellGradient(long id, bool signedLevelSet) const = 0;
191
192 virtual short _evalSign(const std::array<double,3> &point) const;
193 virtual double _evalValue(const std::array<double,3> &point, bool signedLevelSet) const = 0;
194 virtual std::array<double,3> _evalGradient(const std::array<double,3> &point, bool signedLevelSet) const = 0;
195
196 short evalValueSign(double value) const;
197
198# if BITPIT_ENABLE_MPI
199 void startCellCacheExchange( const std::unordered_map<int,std::vector<long>> &recvCellIds, std::size_t cacheIds, DataCommunicator * ) const;
200 void startCellCachesExchange( const std::unordered_map<int,std::vector<long>> &recvCellIds, const std::vector<std::size_t> &cacheIds, DataCommunicator * ) const;
201 void completeCellCacheExchange( const std::unordered_map<int,std::vector<long>> &sendCellIds, std::size_t cacheIds, DataCommunicator * );
202 void completeCellCachesExchange( const std::unordered_map<int,std::vector<long>> &sendCellIds, const std::vector<std::size_t> &cacheIds, DataCommunicator * );
203# endif
204
205 void adaptCellCaches(const std::vector<adaption::Info> &adaptionData);
206
207 void clearCellCache(std::size_t cacheId, bool release);
208 void pruneCellCache(std::size_t cacheId, const std::vector<long> &cellIds);
209
210 std::vector<long> evalCellCacheFillIds(LevelSetZone zone, LevelSetCacheMode cacheMode) const;
211 std::vector<long> evalCellCacheFillIds(LevelSetZone zone, LevelSetCacheMode cacheMode, const std::vector<adaption::Info> &adaptionData) const;
212 std::vector<long> evalCellOnDemandCacheFillIds(LevelSetZone zone) const;
213 std::vector<long> evalCellOnDemandCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
214 std::vector<long> evalCellNarrowBandCacheFillIds(LevelSetZone zone) const;
215 std::vector<long> evalCellNarrowBandCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
216 std::vector<long> evalCellFullCacheFillIds(LevelSetZone zone) const;
217 std::vector<long> evalCellFullCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
218
219 std::vector<long> evalCellCacheStaleIds(const std::vector<adaption::Info> &adaptionData) const;
220
221 template<typename value_t, typename evaluator_t, typename fallback_t>
222 value_t evalCellFieldCached(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const;
223 template<typename value_t, typename evaluator_t, typename fallback_t>
224 value_t evalCellField(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const;
225
226 void fillFieldCellCaches(LevelSetZone zone, const std::vector<LevelSetField> &fields);
227 void fillFieldCellCaches(LevelSetZone zone, const std::vector<LevelSetField> &fields, const std::vector<adaption::Info> &adaptionData);
228 void fillFieldCellCache(LevelSetField field, const std::vector<long> &cellIds);
229 virtual void fillFieldCellCache(LevelSetField field, long id);
230 template<typename value_t>
231 void fillFieldCellCache(LevelSetField field, long id, const value_t &value) const;
232
233 template<typename value_t>
234 CellCacheCollection::ValueCache<value_t> * getFieldCellCache(LevelSetField field) const;
235 CellCacheCollection::Cache * getFieldCellCache(LevelSetField field) const;
236 std::size_t getFieldCellCacheId(LevelSetField field) const;
237 virtual std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
238 template<typename value_t>
239 std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
240 virtual void destroyFieldCellCache(LevelSetField field);
241
242
243
244 template<typename value_t>
245 CellCacheCollection::ValueCache<value_t> * getCellCache(std::size_t cacheId) const;
246 CellCacheCollection::Cache * getCellCache(std::size_t cacheId) const;
247 template<typename value_t>
248 std::size_t createCellCache(LevelSetFillIn expectedFillIn, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
249 void destroyCellCache(std::size_t cacheId);
250
251 bool hasVTKOutputData(LevelSetField field, const std::string &objectName) const;
252 void removeVTKOutputData(LevelSetField field, const std::string &objectName);
253 virtual void addVTKOutputData(LevelSetField field, const std::string &objectName);
254 std::string getVTKOutputDataName(LevelSetField field, const std::string &objectName) const;
255 virtual std::string getVTKOutputFieldName(LevelSetField field) const;
256 virtual void flushVTKOutputData(std::fstream &stream, VTKFormat format,
257 LevelSetField field) const;
258 template<typename value_t, typename evaluator_t, typename fallback_t>
259 void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field,
260 const evaluator_t evluator, const fallback_t fallback) const;
261
263
264private:
265 int m_id;
266
267 std::size_t m_nReferences;
268
269 LevelSetBulkEvaluationMode m_cellBulkEvaluationMode;
270
271 mutable std::unique_ptr<CellCacheCollection> m_cellCacheCollection;
272
273 std::vector<LevelSetCacheMode> m_cellFieldCacheModes;
274 std::vector<std::size_t> m_cellFieldCacheIds;
275
276 void setId(int id);
277
278 std::size_t incrementReferenceCount();
279 std::size_t decrementReferenceCount();
280
281};
282
283}
284
285// Include template implementations
286#include "levelSetObject.tpp"
287
288#endif
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
Mesh specific implementation to calculate the levelset function.
double getLS(long cellId) const
std::vector< long > evalCellCacheStaleIds(const std::vector< adaption::Info > &adaptionData) const
void clearCellCache(std::size_t cacheId, bool release)
void flushData(std::fstream &, const std::string &, VTKFormat) override
LevelSetInfo getLevelSetInfo(long cellId) const
virtual void destroyFieldCellCache(LevelSetField field)
CellCacheCollection::ValueCache< value_t > * getCellCache(std::size_t cacheId) const
static const LevelSetIntersectionMode CELL_LOCATION_INTERSECTION_MODE
void destroyCellCache(std::size_t cacheId)
LevelSetBulkEvaluationMode getCellBulkEvaluationMode() const
void pruneCellCache(std::size_t cacheId, const std::vector< long > &cellIds)
void updateCellNarrowBandData(const std::vector< adaption::Info > &adaptionData)
void completeCellCachesExchange(const std::unordered_map< int, std::vector< long > > &sendCellIds, const std::vector< std::size_t > &cacheIds, DataCommunicator *)
void startCellCachesExchange(const std::unordered_map< int, std::vector< long > > &recvCellIds, const std::vector< std::size_t > &cacheIds, DataCommunicator *) const
std::vector< long > evalCellCacheFillIds(LevelSetZone zone, LevelSetCacheMode cacheMode) const
void fillFieldCellCache(LevelSetField field, const std::vector< long > &cellIds)
void setDefaultLevelSetSigndness(bool signedLevelSet)
short evalValueSign(double value) const
virtual double evalValue(const std::array< double, 3 > &point, bool signedLevelSet) const
LevelSetKernel * m_kernel
virtual std::array< double, 3 > evalCellProjectionPoint(long id) const
void removeVTKOutputData(LevelSetField field, const std::string &objectName)
std::size_t createCellCache(LevelSetFillIn expectedFillIn, std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID)
void completeCellCacheExchange(const std::unordered_map< int, std::vector< long > > &sendCellIds, std::size_t cacheIds, DataCommunicator *)
void enableFieldCellCache(LevelSetField field, LevelSetCacheMode cacheMode)
std::array< double BITPIT_COMMA 3 > computeVertexProjectionPoint(long vertexId) const
virtual const LevelSetKernel * getKernel() const
std::size_t getFieldCellCacheId(LevelSetField field) const
CellCacheCollection::ValueCache< value_t > * getFieldCellCache(LevelSetField field) const
virtual std::size_t createCellLocationCache(std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID)
void updateCellBulkData(const std::vector< adaption::Info > &adaptionData)
LevelSetIntersectionStatus isCellIntersected(long id, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) const
void setCellBulkEvaluationMode(LevelSetBulkEvaluationMode evaluationMode)
virtual void addVTKOutputData(LevelSetField field, const std::string &objectName)
static const bool CELL_CACHE_IS_SIGNED
double m_narrowBandSize
Size of narrow band.
virtual std::string getVTKOutputFieldName(LevelSetField field) const
virtual bool isPrimary() const
virtual std::size_t createCellPropagatedSignCache(std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID)
virtual void fillCellPropagatedSignCache()
virtual short evalSign(const std::array< double, 3 > &point) const
virtual std::array< double, 3 > evalProjectionPoint(const std::array< double, 3 > &point) const
LevelSetCacheMode getFieldCellCacheMode(LevelSetField field) const
virtual short _evalSign(const std::array< double, 3 > &point) const
std::vector< long > evalCellNarrowBandCacheFillIds(LevelSetZone zone) const
virtual std::array< double, 3 > evalCellGradient(long id, bool signedLevelSet) const
void disableFieldCellCache(LevelSetField field)
virtual double evalCellValue(long id, bool signedLevelSet) const
virtual std::array< double, 3 > evalGradient(const std::array< double, 3 > &point, bool signedLevelSet) const
virtual LevelSetIntersectionStatus _isInterfaceIntersected(long id, bool positivePart, std::array< std::array< double, 3 >, 2 > *intersection, std::vector< std::array< double, 3 > > *polygon) const
virtual LevelSetFieldset getSupportedFields() const
virtual void dump(std::ostream &)
bool hasVTKOutputData(LevelSetField field, const std::string &objectName) const
virtual void fillCellLocationCache()
virtual short evalCellSign(long id) const
LevelSetCellLocation getCellLocation(long id) const
LevelSetZone getCellZone(long id) const
LevelSetIntersectionStatus intersectSurface(long id, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) const
void adaptCellCaches(const std::vector< adaption::Info > &adaptionData)
virtual bool isCellInNarrowBand(long id) const
std::vector< long > evalCellOnDemandCacheFillIds(LevelSetZone zone) const
value_t evalCellFieldCached(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const
void setNarrowBandSize(double size)
LevelSetIntersectionStatus isInterfaceIntersected(long id, bool invert, std::array< std::array< double, 3 >, 2 > *intersection, std::vector< std::array< double, 3 > > *polygon) const
std::size_t m_cellLocationCacheId
Id of the cache that will keep track if cell zones.
double getNarrowBandSize() const
double getSizeNarrowBand() const
std::array< double BITPIT_COMMA 3 > computeProjectionPoint(long cellId) const
virtual LevelSetCellLocation fillCellGeometricNarrowBandLocationCache(long id)
void enableVTKOutput(const LevelSetFieldset &fieldset, bool enable=true)
std::size_t m_cellPropagatedSignCacheId
Id of the cache that will keep track if cell propagated sign.
void fillFieldCellCaches(LevelSetZone zone, const std::vector< LevelSetField > &fields)
virtual void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field) const
value_t evalCellField(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const
virtual void setKernel(LevelSetKernel *)
virtual LevelSetIntersectionStatus _isCellIntersected(long, double distance, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) const
virtual void restore(std::istream &)
std::size_t getReferenceCount() const
std::vector< long > evalCellFullCacheFillIds(LevelSetZone zone) const
virtual std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID)
std::string getVTKOutputDataName(LevelSetField field, const std::string &objectName) const
virtual bool isInNarrowBand(const std::array< double, 3 > &point) const
void update(const std::vector< adaption::Info > &adaptionData)
void startCellCacheExchange(const std::unordered_map< int, std::vector< long > > &recvCellIds, std::size_t cacheIds, DataCommunicator *) const
Buffer to be used for receive communications.
Buffer to be used for send communications.
The base class to be used to derive VTK streamers form.
Definition VTK.hpp:209
VTKFormat
Definition VTK.hpp:92
#define BITPIT_DEPRECATED(func)
Definition compiler.hpp:87
The namespace 'adaption' contains the routines and the data structures for handling patch adaption.
Definition adaption.cpp:38
A public container which includes all information provided by LevelSet.
The Info struct defines the infomation associated to an adaption.
Definition adaption.hpp:63