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:
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
94
95 virtual short evalCellSign(long id) const;
96 virtual double evalCellValue(long id, bool signedLevelSet) const;
97 virtual std::array<double,3> evalCellGradient(long id, bool signedLevelSet) const;
98 virtual std::array<double,3> evalCellProjectionPoint(long id) const;
99
100 virtual short evalSign(const std::array<double,3> &point) const;
101 virtual double evalValue(const std::array<double,3> &point, bool signedLevelSet) const;
102 virtual std::array<double,3> evalGradient(const std::array<double,3> &point, bool signedLevelSet) const;
103 virtual std::array<double,3> evalProjectionPoint(const std::array<double,3> &point) const;
104
105 void enableVTKOutput(const LevelSetFieldset &fieldset, bool enable=true);
106 void enableVTKOutput(const LevelSetFieldset &fieldset, const std::string &objectName, bool enable=true);
107 void enableVTKOutput(LevelSetField field, bool enable=true);
108 void enableVTKOutput(LevelSetField field, const std::string &objectName, bool enable=true);
109 void enableVTKOutput(LevelSetWriteField field, bool enable=true);
110 void enableVTKOutput(LevelSetWriteField fieldset, const std::string &objectName, bool enable=true);
111 void flushData(std::fstream &, const std::string &, VTKFormat) override;
112
113 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeProjectionPoint(long cellId) const);
114 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeVertexProjectionPoint(long vertexId) const);
115
116 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> computeProjectionPoint(const std::array<double,3> &point) const);
117
118 BITPIT_DEPRECATED_FOR(short getSign(long cellId) const, short evalCellSign(long id) const);
119 BITPIT_DEPRECATED_FOR(double getValue(long cellId) const, double evalCellValue(long id, bool signedLevelSet) const);
120 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);
121
123 BITPIT_DEPRECATED(double getLS(long cellId) const);
124
125 BITPIT_DEPRECATED(double getSizeNarrowBand() const);
126
127protected:
128 template<typename data_t>
129 using CellCacheEntry = typename CellCacheCollection::ValueCache<data_t>::Entry;
130
131 static const bool CELL_CACHE_IS_SIGNED;
133
136 bool m_defaultSignedLevelSet;
137
138 LevelSetFieldMap<std::string> m_enabledOutputFields;
139
141
144
145 LevelSetObject(int);
146 LevelSetObject(const LevelSetObject &other);
148
149 void setDefaultLevelSetSigndness(bool signedLevelSet);
150
151 virtual void setKernel(LevelSetKernel *);
152 virtual LevelSetKernel * getKernel();
153
154 void evaluate();
155 void update();
156
157 LevelSetZone getCellZone(long id) const;
159
160 void setNarrowBandSize(double size);
162 void updateCellNarrowBandData(const std::vector<adaption::Info> &adaptionData);
164
165 virtual void fillCellLocationCache();
166 virtual void fillCellLocationCache(const std::vector<adaption::Info> &adaptionData);
168 virtual std::size_t createCellLocationCache(std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
170
172 void updateCellBulkData(const std::vector<adaption::Info> &adaptionData);
173 void destroyCellBulkData();
174
175 virtual void fillCellPropagatedSignCache();
176 virtual std::size_t createCellPropagatedSignCache(std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
178
179 virtual void dump(std::ostream &);
180 virtual void restore(std::istream &);
181
183
184 virtual short _evalCellSign(long id) const = 0;
185 virtual double _evalCellValue(long id, bool signedLevelSet) const = 0;
186 virtual std::array<double,3> _evalCellGradient(long id, bool signedLevelSet) const = 0;
187
188 virtual short _evalSign(const std::array<double,3> &point) const;
189 virtual double _evalValue(const std::array<double,3> &point, bool signedLevelSet) const = 0;
190 virtual std::array<double,3> _evalGradient(const std::array<double,3> &point, bool signedLevelSet) const = 0;
191
192 short evalValueSign(double value) const;
193
194# if BITPIT_ENABLE_MPI
195 void startCellCacheExchange( const std::unordered_map<int,std::vector<long>> &recvCellIds, std::size_t cacheIds, DataCommunicator * ) const;
196 void startCellCachesExchange( const std::unordered_map<int,std::vector<long>> &recvCellIds, const std::vector<std::size_t> &cacheIds, DataCommunicator * ) const;
197 void completeCellCacheExchange( const std::unordered_map<int,std::vector<long>> &sendCellIds, std::size_t cacheIds, DataCommunicator * );
198 void completeCellCachesExchange( const std::unordered_map<int,std::vector<long>> &sendCellIds, const std::vector<std::size_t> &cacheIds, DataCommunicator * );
199# endif
200
201 void adaptCellCaches(const std::vector<adaption::Info> &adaptionData);
202
203 void clearCellCache(std::size_t cacheId, bool release);
204 void pruneCellCache(std::size_t cacheId, const std::vector<long> &cellIds);
205
206 std::vector<long> evalCellCacheFillIds(LevelSetZone zone, LevelSetCacheMode cacheMode) const;
207 std::vector<long> evalCellCacheFillIds(LevelSetZone zone, LevelSetCacheMode cacheMode, const std::vector<adaption::Info> &adaptionData) const;
208 std::vector<long> evalCellOnDemandCacheFillIds(LevelSetZone zone) const;
209 std::vector<long> evalCellOnDemandCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
210 std::vector<long> evalCellNarrowBandCacheFillIds(LevelSetZone zone) const;
211 std::vector<long> evalCellNarrowBandCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
212 std::vector<long> evalCellFullCacheFillIds(LevelSetZone zone) const;
213 std::vector<long> evalCellFullCacheFillIds(LevelSetZone zone, const std::vector<adaption::Info> &adaptionData) const;
214
215 std::vector<long> evalCellCacheStaleIds(const std::vector<adaption::Info> &adaptionData) const;
216
217 template<typename value_t, typename evaluator_t, typename fallback_t>
218 value_t evalCellFieldCached(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const;
219 template<typename value_t, typename evaluator_t, typename fallback_t>
220 value_t evalCellField(LevelSetField field, long id, const evaluator_t &evaluator, const fallback_t &fallback) const;
221
222 void fillFieldCellCaches(LevelSetZone zone, const std::vector<LevelSetField> &fields);
223 void fillFieldCellCaches(LevelSetZone zone, const std::vector<LevelSetField> &fields, const std::vector<adaption::Info> &adaptionData);
224 void fillFieldCellCache(LevelSetField field, const std::vector<long> &cellIds);
225 virtual void fillFieldCellCache(LevelSetField field, long id);
226 template<typename value_t>
227 void fillFieldCellCache(LevelSetField field, long id, const value_t &value) const;
228
229 template<typename value_t>
232 std::size_t getFieldCellCacheId(LevelSetField field) const;
233 virtual std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
234 template<typename value_t>
235 std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
236 virtual void destroyFieldCellCache(LevelSetField field);
237
238
239
240 template<typename value_t>
241 CellCacheCollection::ValueCache<value_t> * getCellCache(std::size_t cacheId) const;
242 CellCacheCollection::Cache * getCellCache(std::size_t cacheId) const;
243 template<typename value_t>
244 std::size_t createCellCache(LevelSetFillIn expectedFillIn, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID);
245 void destroyCellCache(std::size_t cacheId);
246
247 bool hasVTKOutputData(LevelSetField field, const std::string &objectName) const;
248 void removeVTKOutputData(LevelSetField field, const std::string &objectName);
249 virtual void addVTKOutputData(LevelSetField field, const std::string &objectName);
250 std::string getVTKOutputDataName(LevelSetField field, const std::string &objectName) const;
251 virtual std::string getVTKOutputFieldName(LevelSetField field) const;
252 virtual void flushVTKOutputData(std::fstream &stream, VTKFormat format,
253 LevelSetField field) const;
254 template<typename value_t, typename evaluator_t, typename fallback_t>
255 void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field,
256 const evaluator_t evluator, const fallback_t fallback) const;
257
259
260private:
261 int m_id;
263 std::size_t m_nReferences;
264
265 LevelSetBulkEvaluationMode m_cellBulkEvaluationMode;
266
267 mutable std::unique_ptr<CellCacheCollection> m_cellCacheCollection;
268
269 std::vector<LevelSetCacheMode> m_cellFieldCacheModes;
270 std::vector<std::size_t> m_cellFieldCacheIds;
271
272 void setId(int id);
273
274 std::size_t incrementReferenceCount();
275 std::size_t decrementReferenceCount();
276
277};
278
279}
280
281// Include template implementations
282#include "levelSetObject.tpp"
283
284#endif
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
The class ElementCacheCollection allows to store a collection of caches for the elements of a mesh.
The class LevelSetCache is the base class for defining caches.
Mesh specific implementation to calculate the levelset function.
Interface class for all objects with respect to whom the levelset function may be computed.
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)
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
LevelSetIntersectionStatus intersectSurface(long, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) 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 LevelSetIntersectionStatus _intersectSurface(long, double distance, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) 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 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
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)
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 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
Interface class for all objects, which depend on other LevelSetObjects.
The class LevelSetCache is the base class for defining caches that store values.
Level Set driver class.
Definition levelSet.hpp:51
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
A public container which includes all information provided by LevelSet.
--- layout: doxygen_footer ---