4 #include "shapeset/shapeset_h1_all.h"
5 #include "element_to_refine.h"
6 #include "h1_proj_based_selector.h"
11 namespace RefinementSelectors
13 template<
typename Scalar>
14 const int H1ProjBasedSelector<Scalar>::H2DRS_MAX_H1_ORDER =
H2DRS_MAX_ORDER;
16 template<
typename Scalar>
20 if(user_shapeset != NULL)
22 this->warn(
"Warn: The user shapeset provided for the selector has to have a correct copy constructor implemented.");
23 this->warn(
"Warning: The functionality for cloning user shapeset is to be implemented yet.");
27 template<
typename Scalar>
30 if(!this->user_shapeset)
31 delete this->shapeset;
34 template<
typename Scalar>
38 newSelector->
set_error_weights(this->error_weight_h, this->error_weight_p, this->error_weight_aniso);
43 template<
typename Scalar>
46 this->current_max_order = this->max_order;
47 int max_element_order = (20 - element->
iro_cache)/2 - 1;
49 this->current_max_order = max_element_order;
51 this->current_max_order = std::min(this->current_max_order, max_element_order);
52 this->current_min_order = 1;
55 template<
typename Scalar>
61 while (!done && inx_trf < H2D_TRF_NUM)
64 const Trf& trf = trfs[inx_trf];
65 Hermes::vector<typename ProjBasedSelector<Scalar>::TrfShapeExp>& trf_svals = svals[inx_trf];
68 trf_svals.resize(max_shape_inx + 1);
71 const int num_shapes = (int)shapes.size();
72 for(
int i = 0; i < num_shapes; i++)
74 int inx_shape = shapes[i].inx;
78 shape_exp.allocate(H2D_H1FE_NUM, num_gip_points);
81 for(
int k = 0; k < num_gip_points; k++)
84 double ref_x = gip_points[k][
H2D_GIP2D_X] * trf.m[0] + trf.
t[0];
85 double ref_y = gip_points[k][
H2D_GIP2D_Y] * trf.m[1] + trf.
t[1];
88 shape_exp[H2D_H1FE_VALUE][k] = this->shapeset->get_fn_value(inx_shape, ref_x, ref_y, 0, mode);
89 shape_exp[H2D_H1FE_DX][k] = this->shapeset->get_dx_value(inx_shape, ref_x, ref_y, 0, mode);
90 shape_exp[H2D_H1FE_DY][k] = this->shapeset->get_dy_value(inx_shape, ref_x, ref_y, 0, mode);
95 if(inx_trf == H2D_TRF_IDENTITY)
100 if(inx_trf >= num_noni_trfs)
101 inx_trf = H2D_TRF_IDENTITY;
105 throw Exceptions::Exception(
"All transformation processed but identity transformation not found.");
108 template<
typename Scalar>
112 precalc_shapes(gip_points, num_gip_points, trfs, num_noni_trfs, shapes, max_shape_inx, svals, mode);
115 const int num_shapes = (int)shapes.size();
116 for(
int i = 0; i < num_shapes; i++)
118 const int inx_shape_i = shapes[i].inx;
121 for(
int j = 0; j < i; j++)
123 const int inx_shape_j = shapes[j].inx;
126 double product = 0.0;
127 for(
int k = 0; k < num_gip_points; k++)
130 sum += svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_VALUE][k] * svals[H2D_TRF_IDENTITY][inx_shape_j][H2D_H1FE_VALUE][k];
131 sum += svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_DX][k] * svals[H2D_TRF_IDENTITY][inx_shape_j][H2D_H1FE_DX][k];
132 sum += svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_DY][k] * svals[H2D_TRF_IDENTITY][inx_shape_j][H2D_H1FE_DY][k];
139 while (!done && inx_trf < H2D_TRF_NUM)
142 for(
int k = 0; k < num_gip_points; k++)
144 svals[inx_trf][inx_shape_i][H2D_H1FE_VALUE][k] -= product * svals[inx_trf][inx_shape_j][H2D_H1FE_VALUE][k];
145 svals[inx_trf][inx_shape_i][H2D_H1FE_DX][k] -= product * svals[inx_trf][inx_shape_j][H2D_H1FE_DX][k];
146 svals[inx_trf][inx_shape_i][H2D_H1FE_DY][k] -= product * svals[inx_trf][inx_shape_j][H2D_H1FE_DY][k];
150 if(inx_trf == H2D_TRF_IDENTITY)
155 if(inx_trf >= num_noni_trfs)
156 inx_trf = H2D_TRF_IDENTITY;
160 throw Exceptions::Exception(
"All transformation processed but identity transformation not found.");
165 double norm_squared = 0.0;
166 for(
int k = 0; k < num_gip_points; k++)
169 sum += sqr(svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_VALUE][k]);
170 sum += sqr(svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_DX][k]);
171 sum += sqr(svals[H2D_TRF_IDENTITY][inx_shape_i][H2D_H1FE_DY][k]);
174 double norm = sqrt(norm_squared);
176 throw Exceptions::Exception(
"Norm (%g) is almost zero.", norm);
181 while (!done && inx_trf < H2D_TRF_NUM)
184 for(
int k = 0; k < num_gip_points; k++)
186 svals[inx_trf][inx_shape_i][H2D_H1FE_VALUE][k] /= norm;
187 svals[inx_trf][inx_shape_i][H2D_H1FE_DX][k] /= norm;
188 svals[inx_trf][inx_shape_i][H2D_H1FE_DY][k] /= norm;
192 if(inx_trf == H2D_TRF_IDENTITY)
197 if(inx_trf >= num_noni_trfs)
198 inx_trf = H2D_TRF_IDENTITY;
202 throw Exceptions::Exception(
"All transformation processed but identity transformation not found.");
206 template<
typename Scalar>
210 Scalar** rvals_son = precalc_rvals[inx_son];
218 template<
typename Scalar>
220 const int* shape_inx,
const int num_shapes, ElementMode2D mode)
223 double** matrix = new_matrix<double>(num_shapes, num_shapes);
227 for(
int i = 0; i < num_shapes; i++, inx_row += num_shapes)
229 double* matrix_row = matrix[i];
230 int shape0_inx = shape_inx[i];
231 for(
int k = 0; k < num_shapes; k++)
233 int shape1_inx = shape_inx[k];
236 for(
int j = 0; j < num_gip_points; j++)
239 double value0 = this->shapeset->get_value(
H2D_FEI_VALUE, shape0_inx, gip_x, gip_y, 0, mode);
240 double value1 = this->shapeset->get_value(
H2D_FEI_VALUE, shape1_inx, gip_x, gip_y, 0, mode);
241 double dx0 = this->shapeset->get_value(
H2D_FEI_DX, shape0_inx, gip_x, gip_y, 0, mode);
242 double dx1 = this->shapeset->get_value(
H2D_FEI_DX, shape1_inx, gip_x, gip_y, 0, mode);
243 double dy0 = this->shapeset->get_value(
H2D_FEI_DY, shape0_inx, gip_x, gip_y, 0, mode);
244 double dy1 = this->shapeset->get_value(
H2D_FEI_DY, shape1_inx, gip_x, gip_y, 0, mode);
246 value += gip_points[j][
H2D_GIP2D_W] * (value0*value1 + dx0*dx1 + dy0*dy1);
249 matrix_row[k] = value;
256 template<
typename Scalar>
259 Scalar total_value = 0;
262 double3 &gip_pt = sub_gip.
gip_points[gip_inx];
265 double shape_value[H2D_H1FE_NUM] = {0, 0, 0};
266 shape_value[H2D_H1FE_VALUE] = sub_shape.
svals[H2D_H1FE_VALUE][gip_inx];
267 shape_value[H2D_H1FE_DX] = sub_shape.
svals[H2D_H1FE_DX][gip_inx];
268 shape_value[H2D_H1FE_DY] = sub_shape.
svals[H2D_H1FE_DY][gip_inx];
283 Scalar ref_value[H2D_H1FE_NUM];
284 ref_value[H2D_H1FE_VALUE] = sub_gip.
rvals[H2D_H1FE_VALUE][gip_inx];
285 ref_value[H2D_H1FE_DX] = sub_trf.
coef_mx * sub_gip.
rvals[H2D_H1FE_DX][gip_inx];
286 ref_value[H2D_H1FE_DY] = sub_trf.
coef_my * sub_gip.
rvals[H2D_H1FE_DY][gip_inx];
289 Scalar value = (shape_value[H2D_H1FE_VALUE] * ref_value[H2D_H1FE_VALUE])
290 + (shape_value[H2D_H1FE_DX] * ref_value[H2D_H1FE_DX])
291 + (shape_value[H2D_H1FE_DY] * ref_value[H2D_H1FE_DY]);
298 template<
typename Scalar>
301 double total_error_squared = 0;
304 double3 &gip_pt = sub_gip.
gip_points[gip_inx];
307 Scalar proj_value[H2D_H1FE_NUM] = {0, 0, 0};
311 proj_value[H2D_H1FE_VALUE] += elem_proj.
shape_coeffs[i] * elem_proj.
svals[shape_inx][H2D_H1FE_VALUE][gip_inx];
312 proj_value[H2D_H1FE_DX] += elem_proj.
shape_coeffs[i] * elem_proj.
svals[shape_inx][H2D_H1FE_DX][gip_inx];
313 proj_value[H2D_H1FE_DY] += elem_proj.
shape_coeffs[i] * elem_proj.
svals[shape_inx][H2D_H1FE_DY][gip_inx];
334 ref_value[H2D_H1FE_VALUE] = sub_gip.
rvals[H2D_H1FE_VALUE][gip_inx];
335 ref_value[H2D_H1FE_DX] = sub_trf.
coef_mx * sub_gip.
rvals[H2D_H1FE_DX][gip_inx];
336 ref_value[H2D_H1FE_DY] = sub_trf.
coef_my * sub_gip.
rvals[H2D_H1FE_DY][gip_inx];
339 double error_squared = sqr(proj_value[H2D_H1FE_VALUE] - ref_value[H2D_H1FE_VALUE])
340 + sqr(proj_value[H2D_H1FE_DX] - ref_value[H2D_H1FE_DX])
341 + sqr(proj_value[H2D_H1FE_DY] - ref_value[H2D_H1FE_DY]);
343 total_error_squared += gip_pt[
H2D_GIP2D_W] * error_squared;
346 return total_error_squared;