GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmDiscontinuity.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2023 by Carlos Augusto Teixeira Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_DISCONTINUITY_H_
25#define _GEMA_DISCONTINUITY_H_
26
27#include "gmLog.h"
28#include "gmPODVector.h"
29
31class GmCellMesh;
32
38{
39public:
41 virtual ~GmDiscontinuity() {}
42
44 int index() const { return _index; }
45
47 QString id() const { return _id; }
48
53 int cellGroupIndex() const { return _groupIndex; }
54
55 void setCellGroupIndex(int group) { _groupIndex = group; }
56
65 virtual int propertyIndex(int propertySet) const { return _psIndex[propertySet]; }
66
73 virtual int numElements() const = 0;
74
78 virtual int numPoints() const = 0;
79
84 virtual int numIntersections() const = 0;
85
90 virtual bool extendGeometry(GmCellMesh* sMesh, double size, const GmLogCategory& logger) = 0;
91
93 virtual void clearGeometry() = 0;
94
96 virtual void printGeometry(const GmLogCategory& logger, GmLogLevel level) const = 0;
97
104 virtual size_t usedGeometryMemory() const = 0;
105
107 virtual bool findIntersections(const GmLogCategory& logger) { Q_UNUSED(logger); return true; }
108
110 virtual void printIntersections(const GmLogCategory& logger, GmLogLevel level) const { Q_UNUSED(logger); Q_UNUSED(level); }
111
113 virtual size_t usedIntersectionMemory() const { return 0; }
114
115private:
116 Q_DISABLE_COPY(GmDiscontinuity);
117
118protected:
120 GmDiscontinuity(const GmDiscontinuitySet* ds, int index, QString id, int groupIndex, const QVector<int>& psIndex)
121 : _ds(ds), _index(index), _id(id), _groupIndex(groupIndex), _psIndex(psIndex) {}
122
124 virtual void setGeometry(double* dvec, int nd, int* ivec, int ni) = 0;
125 virtual bool loadGeometryFromTable(LuaTable& tab, const GmLogCategory& logger) = 0;
126
127 template <class T, class V>
128 static T* loadIntoVector(LuaTable& tab, V validator, int n, int* realSize,
129 QString discontinuityId, const char* msg, const GmLogCategory& logger);
130
131 friend class GmDiscontinuitySet;
132
134 int _index;
138};
139
140
150template <class T, class V>
151T* GmDiscontinuity::loadIntoVector(LuaTable& tab, V validator, int n, int* realSize,
152 QString discontinuityId, const char* msg, const GmLogCategory& logger)
153{
154 S_TRACE();
155 assert(realSize);
156 assert(tab.isValid());
157
158 *realSize = 0;
159 int npoints = tab.size();
160
161 //Cannot have empty points/triangles data
162 //if(!npoints) return NULL; //Conflict with current load of dump
163
164 int nreal = 0;
165
167 if(!tvec.resize(npoints * n))
168 {
169 gmFatalMsg(logger, QObject::tr("Error allocating memory for %1 %2 points for discontinuity %3.").arg(npoints).arg(msg).arg(discontinuityId));
170 return NULL;
171 }
172
173 for(int i = 0, k = 0; i < npoints; i++)
174 {
175 LuaStackBalancer b(tab.env());
176 LuaTable entry = tab.getIndex(i + 1).value<LuaTable>();
177 if(!entry.isValid())
178 {
179 gmFatalMsg(logger, QObject::tr("Invalid %1 entry %2 for discontinuity %3. Expecting a table.").arg(msg).arg(i + 1).arg(discontinuityId));
180 return NULL;
181 }
182
183 int status;
184 for(int j = 0; j < n; j++)
185 {
186 T v = validator(j, entry.getIndex(j + 1), &status);
187 if(status == -1) // Entry should be ignored
188 break;
189 if(status == -2)
190 {
191 gmFatalMsg(logger, QObject::tr("Invalid %1 entry %2, column %3, for discontinuity %4.").arg(msg).arg(i + 1).arg(j + 1).arg(discontinuityId));
192 return NULL;
193 }
194 tvec[k+j] = v;
195 }
196
197 if(status == -1)
198 continue;
199
200 k += n;
201 nreal++;
202 }
203
204 *realSize = nreal;
205
206 // Notice that GmPODVector will store internally, after a shrink, a NULL vector if size is 0.
207 // Since the discontinuity objects can't handle properly a NULL vector for a 0 sized list,
208 // we will return a 0 length vector for those cases (which was the case on previous versions
209 // of this method, before support for partitioned meshes). This also allows us to keep returning
210 // NULL for the error case.
211 if(!nreal)
212 return new T[0]; // This will return a non NULLpointer to an "empty" vec
213
214 if(nreal != npoints)
215 {
216 tvec.resize(nreal * n);
217 tvec.shrink();
218 }
219 return tvec.takeData();
220}
221#endif // _GEMA_DISCONTINUITY_H_
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
The geometric representation for a single discontinuity from the Discontinuity set....
Definition gmDiscontinuity.h:38
int index() const
Returns this discontinuity index in the father set.
Definition gmDiscontinuity.h:44
const GmDiscontinuitySet * _ds
Our "father" discontinuity set.
Definition gmDiscontinuity.h:133
virtual void printIntersections(const GmLogCategory &logger, GmLogLevel level) const
Prints the discontinuity-mesh intersection information.
Definition gmDiscontinuity.h:110
QString _id
The discontinuity id.
Definition gmDiscontinuity.h:135
virtual int numPoints() const =0
A generic interface to return the original discontinuity data number of points.
virtual size_t usedIntersectionMemory() const
Returns an estimative of the memory used by the intersection data in bytes.
Definition gmDiscontinuity.h:113
virtual ~GmDiscontinuity()
Virtuald destructor.
Definition gmDiscontinuity.h:41
int _index
The discontinuity index in its "father" discontinuity set.
Definition gmDiscontinuity.h:134
virtual void clearGeometry()=0
Clears the original discontinuity geometry information, releasing memory.
int cellGroupIndex() const
Returns the cell group index associated with this discontinuity, if any. This is the index of the gro...
Definition gmDiscontinuity.h:53
virtual int numIntersections() const =0
A generic interface to return the number of intersections between the mesh and the user given geometr...
QString id() const
Returns the discontinuity id (name)
Definition gmDiscontinuity.h:47
virtual size_t usedGeometryMemory() const =0
Returns an estimative of the memory used by the discontinuity geometry in bytes.
virtual int numElements() const =0
A generic interface to return the original discontinuity data number of geometric elements....
GmDiscontinuity(const GmDiscontinuitySet *ds, int index, QString id, int groupIndex, const QVector< int > &psIndex)
Private constructor. Discontinuities are only created by the DiscontinuitySet.
Definition gmDiscontinuity.h:120
virtual bool extendGeometry(GmCellMesh *sMesh, double size, const GmLogCategory &logger)=0
virtual void printGeometry(const GmLogCategory &logger, GmLogLevel level) const =0
Prints the discontinuity geometry information.
int _groupIndex
The index in the mesh for the associated cell group or -1 if there is none.
Definition gmDiscontinuity.h:136
QVector< int > _psIndex
The property set line index for this discontinuity. One entry per associated property set.
Definition gmDiscontinuity.h:137
static T * loadIntoVector(LuaTable &tab, V validator, int n, int *realSize, QString discontinuityId, const char *msg, const GmLogCategory &logger)
Allocate a vector of type T with at most tab.size() * n elements and reads the tab contents into it....
Definition gmDiscontinuity.h:151
virtual int propertyIndex(int propertySet) const
Given a property set number, returns the line of the property set that contains property values for t...
Definition gmDiscontinuity.h:65
virtual bool findIntersections(const GmLogCategory &logger)
Builds the element intersection list for this discontinuity.
Definition gmDiscontinuity.h:107
virtual void setGeometry(double *dvec, int nd, int *ivec, int ni)=0
A function to set the geometry data. See the parameter descriptions on the concrete classes.
Base interface for providing discontinuity geometry information for spatial indices.
Definition gmDiscontinuitySet.h:59
Class representing a category with multiple logging levels.
Definition gmLog.h:58
A simple vector for Plain Old Data (POD) types with the control size variable type parameterized to a...
Definition gmPODVector.h:88
T * takeData()
For the bold who REALLY knows what he is doing! This is a very specialized function that takes the ow...
Definition gmPODVector.h:127
bool resize(ControlSize newSize, GmPODGrowT grow=Grow)
Resizes the vector to the given size using the specified grow policy.
Definition gmPODVector.h:182
void shrink()
Shrinks the allocated size to match the vector size if possible. Never fails but might do nothing.
Definition gmPODVector.h:234
LuaEnv * env() const
bool isValid() const
QVariant getIndex(int index, LuaEnv::StackOption opt=LuaEnv::STACK_AUTO)
int size()
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of support functions and macros for information logging.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
Implementation of the GmPODVector template class.
#define S_TRACE()
Macro for run time stack tracking at release build.
Definition gmTrace.h:44
QString tr(const char *sourceText, const char *disambiguation, int n)
T value() const const