20 #include "shapeset/shapeset_h1_all.h"
21 #include "shapeset/shapeset_l2_all.h"
22 #include "shapeset/shapeset_hc_all.h"
23 #include "shapeset/shapeset_hd_all.h"
31 if (shapeset ==
nullptr)
32 throw Exceptions::NullException(0);
33 this->shapeset = shapeset;
39 void PrecalcShapeset::update_max_index()
73 for (
short i = 0; i < np; i++)
80 for (k = 0; k < H2D_NUM_FUNCTION_VALUES; k++)
82 for (
short i = 0; i < np; i++)
89 if (mode == HERMES_MODE_TRIANGLE)
92 for (
short i = 0; i < np; i++)
94 if (mask & idx2mask[1][0])
95 for (
short i = 0; i < np; i++)
97 if (mask & idx2mask[2][0])
98 for (
short i = 0; i < np; i++)
104 for (
short i = 0; i < np; i++)
106 if (mask & idx2mask[1][0])
107 for (
short i = 0; i < np; i++)
109 if (mask & idx2mask[2][0])
110 for (
short i = 0; i < np; i++)
117 for (k = 0; k < H2D_NUM_FUNCTION_VALUES; k++)
119 for (
short i = 0; i < np; i++)
120 this->
values[j][k][i] = shapeset->
get_value(k, index, pt[i][0], pt[i][1], j, mode);
155 #ifdef HERMES_FOR_AGROS
158 static PrecalcShapesetAssemblingStorage* PrecalcShapesetAssemblingTables[H2D_NUM_SHAPESETS] = {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr };
161 #ifndef HERMES_FOR_AGROS
162 static PrecalcShapesetAssemblingInternal temp[H2D_NUM_SHAPESETS] = { PrecalcShapesetAssemblingInternal(
new HcurlShapesetGradLeg), PrecalcShapesetAssemblingInternal(
new HdivShapesetLegendre), PrecalcShapesetAssemblingInternal(
new L2ShapesetLegendre), PrecalcShapesetAssemblingInternal(
new L2ShapesetTaylor), PrecalcShapesetAssemblingInternal(
new H1ShapesetJacobi) };
165 PrecalcShapesetAssemblingInternal::PrecalcShapesetAssemblingInternal(Shapeset* shapeset) : PrecalcShapesetAssembling(shapeset)
169 PrecalcShapesetAssemblingInternal::~PrecalcShapesetAssemblingInternal()
171 delete PrecalcShapesetAssemblingTables[(int)this->shapeset->
get_id()];
172 delete this->shapeset;
177 if (PrecalcShapesetAssemblingTables[(
int)shapeset->
get_id()])
179 this->storage = PrecalcShapesetAssemblingTables[(int)shapeset->
get_id()];
180 this->storage->ref_count++;
184 #pragma omp critical (pss_table_creation)
187 this->storage->ref_count++;
188 PrecalcShapesetAssemblingTables[(int)shapeset->
get_id()] = storage;
195 this->storage = other.storage;
196 this->storage->ref_count++;
205 if (this->attempt_to_reuse(this->
order))
206 return this->storage->PrecalculatedValues[this->
element->get_mode()][0][this->
order][this->index];
208 return &
values[component][0][0];
213 if (this->attempt_to_reuse(this->
order))
214 return this->storage->PrecalculatedValues[this->
element->get_mode()][1][this->
order][this->index];
216 return &
values[component][1][0];
221 if (this->attempt_to_reuse(this->
order))
222 return this->storage->PrecalculatedValues[this->
element->get_mode()][2][this->
order][this->index];
224 return &
values[component][2][0];
227 #ifdef H2D_USE_SECOND_DERIVATIVES
228 const double* PrecalcShapesetAssembling::get_dxx_values(
int component)
const
231 return &
values[component][3][0];
234 const double* PrecalcShapesetAssembling::get_dyy_values(
int component)
const
237 return &
values[component][4][0];
240 const double* PrecalcShapesetAssembling::get_dxy_values(
int component)
const
243 return &
values[component][5][0];
247 bool PrecalcShapesetAssembling::attempt_to_reuse(
unsigned short order_)
const
249 return (this->reuse_possible() && this->storage->PrecalculatedInfo[this->element->get_mode()][order_][this->index]);
252 bool PrecalcShapesetAssembling::reuse_possible()
const
257 const double* PrecalcShapesetAssembling::get_values(
int component,
unsigned short item)
const
266 return Function<double>::get_values(component, item);
269 void PrecalcShapesetAssembling::precalculate(
unsigned short order_,
unsigned short mask)
271 if (this->attempt_to_reuse(order_))
286 if (this->reuse_possible())
288 #pragma omp critical (precalculatingPSS)
290 double* valuePointer;
291 if (mode == HERMES_MODE_TRIANGLE)
293 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_TRIANGLE][0][order_][index];
294 for (
short i = 0; i < np; i++)
297 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_TRIANGLE][1][order_][index];
298 for (
short i = 0; i < np; i++)
301 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_TRIANGLE][2][order_][index];
302 for (
short i = 0; i < np; i++)
305 this->storage->PrecalculatedInfo[HERMES_MODE_TRIANGLE][order_][index] =
true;
309 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_QUAD][0][order_][index];
310 for (
short i = 0; i < np; i++)
313 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_QUAD][1][order_][index];
314 for (
short i = 0; i < np; i++)
317 valuePointer = this->storage->PrecalculatedValues[HERMES_MODE_QUAD][2][order_][index];
318 for (
short i = 0; i < np; i++)
321 this->storage->PrecalculatedInfo[HERMES_MODE_QUAD][order_][index] =
true;
330 for (
short i = 0; i < np; i++)
336 for (k = 0; k < H2D_NUM_FUNCTION_VALUES; k++)
338 for (
short i = 0; i < np; i++)
341 else if (mode == HERMES_MODE_TRIANGLE)
344 for (
short i = 0; i < np; i++)
346 if (mask & idx2mask[1][0])
347 for (
short i = 0; i < np; i++)
349 if (mask & idx2mask[2][0])
350 for (
short i = 0; i < np; i++)
355 if (mask & idx2mask[0][0])
356 for (
short i = 0; i < np; i++)
358 if (mask & idx2mask[1][0])
359 for (
short i = 0; i < np; i++)
361 if (mask & idx2mask[2][0])
362 for (
short i = 0; i < np; i++)
372 for (
short i = 0; i < np; i++)
379 for (k = 0; k < H2D_NUM_FUNCTION_VALUES; k++)
380 if (mask & idx2mask[k][j])
381 for (
short i = 0; i < np; i++)
387 for (k = 0; k < H2D_NUM_FUNCTION_VALUES; k++)
388 if (mask & idx2mask[k][j])
389 for (
short i = 0; i < np; i++)
390 this->
values[j][k][i] = shapeset->
get_value(k, index, pt[i][0], pt[i][1], j, mode);
396 PrecalcShapesetAssemblingStorage::PrecalcShapesetAssemblingStorage(Shapeset* shapeset) : shapeset_id(shapeset->get_id()), ref_count(0)
398 this->max_index[0] = shapeset->get_max_index(HERMES_MODE_TRIANGLE);
399 this->max_index[1] = shapeset->get_max_index(HERMES_MODE_QUAD);
403 unsigned short g_max, np;
404 if (i == HERMES_MODE_TRIANGLE)
406 g_max = g_max_tri + 1 + 3 * g_max_tri + 3;
407 np = H2D_MAX_INTEGRATION_POINTS_COUNT_TRI;
411 g_max = g_max_quad + 1 + 4 * g_max_quad + 4;
412 np = H2D_MAX_INTEGRATION_POINTS_COUNT_QUAD;
415 unsigned short local_base_size = this->max_index[i] + 1;
417 this->PrecalculatedInfo[i] = malloc_with_check<bool*>(g_max);
419 for (
int j = 0; j < H2D_NUM_FUNCTION_VALUES; j++)
421 this->PrecalculatedValues[i][j] = malloc_with_check<double**>(g_max);
423 for (
int k = 0; k < g_max; k++)
425 this->PrecalculatedValues[i][j][k] = malloc_with_check<double*>(local_base_size);
427 this->PrecalculatedInfo[i][k] = calloc_with_check<bool>(local_base_size);
429 for (
int l = 0; l < local_base_size; l++)
430 this->PrecalculatedValues[i][j][k][l] = malloc_with_check<double>(np);
436 PrecalcShapesetAssemblingStorage::~PrecalcShapesetAssemblingStorage()
440 unsigned short g_max;
441 if (i == HERMES_MODE_TRIANGLE)
442 g_max = g_max_tri + 1 + 3 * g_max_tri + 3;
444 g_max = g_max_quad + 1 + 4 * g_max_quad + 4;
446 unsigned short local_base_size = this->max_index[i] + 1;
448 for (
int j = 0; j < H2D_NUM_FUNCTION_VALUES; j++)
450 for (
int k = 0; k < g_max; k++)
452 for (
int l = 0; l < local_base_size; l++)
453 free_with_check(this->PrecalculatedValues[i][j][k][l]);
454 free_with_check(this->PrecalculatedValues[i][j][k]);
456 free_with_check(this->PrecalculatedInfo[i][k]);
459 free_with_check(this->PrecalculatedValues[i][j]);
460 free_with_check(this->PrecalculatedInfo[i][j]);
virtual ~PrecalcShapesetAssembling()
Destructor.
PrecalcShapeset variant for fast assembling.
double get_value(int n, int index, double x, double y, unsigned short component, ElementMode2D mode)
double get_fn_value_0_quad(int index, double x, double y)
The most used calls are distinguished for optimization.
virtual void free()
Frees all precalculated tables.
Caches precalculated shape function values.
const double * get_fn_values(int component=0) const
Returns function values.
SpaceType get_space_type() const
Returns type of space.
static int idx2mask[H2D_NUM_FUNCTION_VALUES][2]
Index to mask table.
const double * get_dx_values(int component=0) const
Returns the x partial derivative.
Quad2D * get_quad_2d() const
Returns the current quadrature points.
Common definitions for Hermes2D.
int get_active_shape() const
Returns the index of the active shape (can be negative if the shape is constrained).
virtual void precalculate(unsigned short order, unsigned short mask)
precalculates the current function at the current integration points.
double get_dx_value_0_quad(int index, double x, double y)
The most used calls are distinguished for optimization.
virtual void precalculate(unsigned short order, unsigned short mask)
precalculates the current function at the current integration points.
#define H2D_NUM_MODES
Internal.
double values[H2D_MAX_SOLUTION_COMPONENTS][H2D_NUM_FUNCTION_VALUES][H2D_MAX_INTEGRATION_POINTS_COUNT]
The data.
double get_fn_value_0_tri(int index, double x, double y)
The most used calls are distinguished for optimization.
#define H2D_GET_H_ORDER(encoded_order)
Macros for combining quad horizontal and vertical encoded_orders.
virtual SpaceType get_space_type() const =0
double2 t
The 2x2 diagonal transformation matrix.
virtual unsigned char get_id() const =0
Represents an arbitrary function defined on an element.
virtual unsigned short get_edge_fn_order(int edge)
Returns the polynomial order of the active shape function on given edge.
Should be exactly the same as is the count of enum ShapesetType.
PrecalcShapesetAssembling common storage.
bool values_valid
Flag that the data are not 'dirty'.
virtual ~PrecalcShapeset()
Destructor.
double get_dy_value_0_tri(int index, double x, double y)
The most used calls are distinguished for optimization.
unsigned char get_num_components() const
Returns 2 if this is a vector shapeset, 1 otherwise.
PrecalcShapesetAssembling(Shapeset *shapeset)
Constructs a standard (master) precalculated shapeset class.
double get_dy_value_0_quad(int index, double x, double y)
The most used calls are distinguished for optimization.
unsigned char num_components
Number of vector components.
virtual void set_quad_2d(Quad2D *quad_2d)
Selects the quadrature points in which the function will be evaluated.
double get_dx_value_0_tri(int index, double x, double y)
The most used calls are distinguished for optimization.
virtual void set_quad_2d(Quad2D *quad_2d)
Selects the quadrature points in which the function will be evaluated.
Quad2D * quads[H2D_MAX_QUADRATURES]
List of available quadratures.
int cur_quad
Active quadrature (index into 'quads')
unsigned short get_order(int index, ElementMode2D mode) const
PrecalcShapeset(Shapeset *shapeset)
Constructs a standard (master) precalculated shapeset class.
int order
Current function polynomial order.
const double * get_dy_values(int component=0) const
Returns the y partial derivative.
Shapeset * get_shapeset() const
Returns a pointer to the shapeset which is being precalculated.
double2 ref_points[H2D_MAX_INTEGRATION_POINTS_COUNT]
Transformed points to the reference domain, used by precalculate.
virtual unsigned short get_max_index(ElementMode2D mode) const =0
Returns the highest shape function index.
virtual void set_active_shape(int index)