int init_geometry_points_allocated_jwt(RefMap* rep_reference_mapping, int order, Geom<double>*& geometry, double* jacobian_x_weights) { Element* e = rep_reference_mapping->get_active_element(); double3* pt = rep_reference_mapping->get_quad_2d()->get_points(order, e->get_mode()); int np = rep_reference_mapping->get_quad_2d()->get_num_points(order, e->get_mode()); // Init geometry and jacobian*weights. geometry = init_geom_vol(rep_reference_mapping, order); geometry->area = e->get_area(); geometry->diam = e->get_diameter(); if (rep_reference_mapping->is_jacobian_const()) { double jac = rep_reference_mapping->get_const_jacobian(); for (int i = 0; i < np; i++) jacobian_x_weights[i] = pt[i][2] * jac; } else { double* jac = rep_reference_mapping->get_jacobian(order); for (int i = 0; i < np; i++) jacobian_x_weights[i] = pt[i][2] * jac[i]; } return np; }
scalar HcurlOrthoHP::eval_error(biform_val_t bi_fn, biform_ord_t bi_ord, MeshFunction *sln1, MeshFunction *sln2, MeshFunction *rsln1, MeshFunction *rsln2, RefMap *rv1, RefMap *rv2, RefMap *rrv1, RefMap *rrv2) { // determine the integration order int inc = (rsln1->get_num_components() == 2) ? 1 : 0; Func<Ord>* ou = init_fn_ord(rsln1->get_fn_order() + inc); Func<Ord>* ov = init_fn_ord(rsln2->get_fn_order() + inc); double fake_wt = 1.0; Geom<Ord>* fake_e = init_geom_ord(); Ord o = bi_ord(1, &fake_wt, ou, ov, fake_e, NULL); int order = rrv1->get_inv_ref_order(); order += o.get_order(); limit_order(order); ou->free_ord(); delete ou; ov->free_ord(); delete ov; delete fake_e; // eval the form Quad2D* quad = sln1->get_quad_2d(); double3* pt = quad->get_points(order); int np = quad->get_num_points(order); // init geometry and jacobian*weights Geom<double>* e = init_geom_vol(rrv1, order); double* jac = rrv1->get_jacobian(order); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * jac[i]; // function values and values of external functions Func<scalar>* err1 = init_fn(sln1, rv1, order); Func<scalar>* err2 = init_fn(sln2, rv2, order); Func<scalar>* v1 = init_fn(rsln1, rrv1, order); Func<scalar>* v2 = init_fn(rsln2, rrv2, order); for (int i = 0; i < np; i++) { err1->val0[i] = err1->val0[i] - v1->val0[i]; err1->val1[i] = err1->val1[i] - v1->val1[i]; err1->curl[i] = err1->curl[i] - v1->curl[i]; err2->val0[i] = err2->val0[i] - v2->val0[i]; err2->val1[i] = err2->val1[i] - v2->val1[i]; err2->curl[i] = err2->curl[i] - v2->curl[i]; } scalar res = bi_fn(np, jwt, err1, err2, e, NULL); e->free(); delete e; delete [] jwt; err1->free_fn(); delete err1; err2->free_fn(); delete err2; v1->free_fn(); delete v1; v2->free_fn(); delete v2; return res; }
double KellyTypeAdapt::eval_volumetric_estimator(KellyTypeAdapt::ErrorEstimatorForm* err_est_form, RefMap *rm) { // determine the integration order int inc = (this->sln[err_est_form->i]->get_num_components() == 2) ? 1 : 0; Func<Ord>** oi = new Func<Ord>* [num]; for (int i = 0; i < num; i++) oi[i] = init_fn_ord(this->sln[i]->get_fn_order() + inc); // Order of additional external functions. ExtData<Ord>* fake_ext = dp.init_ext_fns_ord(err_est_form->ext); double fake_wt = 1.0; Geom<Ord>* fake_e = init_geom_ord(); Ord o = err_est_form->ord(1, &fake_wt, oi, oi[err_est_form->i], fake_e, fake_ext); int order = rm->get_inv_ref_order(); order += o.get_order(); limit_order(order); // Clean up. for (int i = 0; i < this->num; i++) if (oi[i] != NULL) { oi[i]->free_ord(); delete oi[i]; } delete [] oi; delete fake_e; delete fake_ext; // eval the form Quad2D* quad = this->sln[err_est_form->i]->get_quad_2d(); double3* pt = quad->get_points(order); int np = quad->get_num_points(order); // init geometry and jacobian*weights Geom<double>* e = init_geom_vol(rm, order); double* jac = rm->get_jacobian(order); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * jac[i]; // function values Func<scalar>** ui = new Func<scalar>* [num]; for (int i = 0; i < num; i++) ui[i] = init_fn(this->sln[i], order); ExtData<scalar>* ext = dp.init_ext_fns(err_est_form->ext, rm, order); scalar res = volumetric_scaling_const * err_est_form->value(np, jwt, ui, ui[err_est_form->i], e, ext); for (int i = 0; i < this->num; i++) if (ui[i] != NULL) { ui[i]->free_fn(); delete ui[i]; } delete [] ui; if (ext != NULL) { ext->free(); delete ext; } e->free(); delete e; delete [] jwt; return std::abs(res); }
// Actual evaluation of volume matrix form (calculates integral) scalar FeProblem::eval_form(WeakForm::MatrixFormVol *mfv, Tuple<Solution *> u_ext, PrecalcShapeset *fu, PrecalcShapeset *fv, RefMap *ru, RefMap *rv) { // determine the integration order int inc = (fu->get_num_components() == 2) ? 1 : 0; AUTOLA_OR(Func<Ord>*, oi, wf->neq); for (int i = 0; i < wf->neq; i++) oi[i] = init_fn_ord(u_ext[i]->get_fn_order() + inc); Func<Ord>* ou = init_fn_ord(fu->get_fn_order() + inc); Func<Ord>* ov = init_fn_ord(fv->get_fn_order() + inc); ExtData<Ord>* fake_ext = init_ext_fns_ord(mfv->ext); double fake_wt = 1.0; Geom<Ord>* fake_e = init_geom_ord(); Ord o = mfv->ord(1, &fake_wt, oi, ou, ov, fake_e, fake_ext); int order = ru->get_inv_ref_order(); order += o.get_order(); limit_order_nowarn(order); for (int i = 0; i < wf->neq; i++) { oi[i]->free_ord(); delete oi[i]; } ou->free_ord(); delete ou; ov->free_ord(); delete ov; delete fake_e; fake_ext->free_ord(); delete fake_ext; // eval the form Quad2D* quad = fu->get_quad_2d(); double3* pt = quad->get_points(order); int np = quad->get_num_points(order); // init geometry and jacobian*weights if (cache_e[order] == NULL) { cache_e[order] = init_geom_vol(ru, order); double* jac = ru->get_jacobian(order); cache_jwt[order] = new double[np]; for(int i = 0; i < np; i++) cache_jwt[order][i] = pt[i][2] * jac[i]; } Geom<double>* e = cache_e[order]; double* jwt = cache_jwt[order]; // function values and values of external functions AUTOLA_OR(Func<scalar>*, prev, wf->neq); for (int i = 0; i < wf->neq; i++) prev[i] = init_fn(u_ext[i], rv, order); Func<double>* u = get_fn(fu, ru, order); Func<double>* v = get_fn(fv, rv, order); ExtData<scalar>* ext = init_ext_fns(mfv->ext, rv, order); scalar res = mfv->fn(np, jwt, prev, u, v, e, ext); for (int i = 0; i < wf->neq; i++) { prev[i]->free_fn(); delete prev[i]; } ext->free(); delete ext; return res; }
int init_geometry_points(RefMap** reference_mapping, int reference_mapping_count, int order, Geom<double>*& geometry, double*& jacobian_x_weights) { Element* rep_element = nullptr; RefMap* rep_reference_mapping = nullptr; for (int i = 0; i < reference_mapping_count; i++) { if (reference_mapping[i]) { if (reference_mapping[i]->get_active_element()) { rep_element = reference_mapping[i]->get_active_element(); rep_reference_mapping = reference_mapping[i]; break; } } } double3* pt = rep_reference_mapping->get_quad_2d()->get_points(order, rep_element->get_mode()); int np = rep_reference_mapping->get_quad_2d()->get_num_points(order, rep_element->get_mode()); // Init geometry and jacobian*weights. geometry = init_geom_vol(rep_reference_mapping, order); for (int i = 0; i < reference_mapping_count; i++) if (reference_mapping[i]) if (reference_mapping[i]->get_active_element()) { { geometry->area = std::min(geometry->area, rep_element->get_area()); geometry->diam = std::min(geometry->area, rep_element->get_diameter()); } } jacobian_x_weights = new double[np]; if (rep_reference_mapping->is_jacobian_const()) { double jac = rep_reference_mapping->get_const_jacobian(); for (int i = 0; i < np; i++) jacobian_x_weights[i] = pt[i][2] * jac; } else { double* jac = rep_reference_mapping->get_jacobian(order); for (int i = 0; i < np; i++) jacobian_x_weights[i] = pt[i][2] * jac[i]; } return np; }
double KellyTypeAdapt::eval_solution_norm(Adapt::MatrixFormVolError* form, RefMap *rm, MeshFunction* sln) { // determine the integration order int inc = (sln->get_num_components() == 2) ? 1 : 0; Func<Ord>* ou = init_fn_ord(sln->get_fn_order() + inc); double fake_wt = 1.0; Geom<Ord>* fake_e = init_geom_ord(); Ord o = form->ord(1, &fake_wt, NULL, ou, ou, fake_e, NULL); int order = rm->get_inv_ref_order(); order += o.get_order(); Solution *sol = static_cast<Solution *>(sln); if(sol && sol->get_type() == HERMES_EXACT) { limit_order_nowarn(order); } else { limit_order(order); } ou->free_ord(); delete ou; delete fake_e; // eval the form Quad2D* quad = sln->get_quad_2d(); double3* pt = quad->get_points(order); int np = quad->get_num_points(order); // init geometry and jacobian*weights Geom<double>* e = init_geom_vol(rm, order); double* jac = rm->get_jacobian(order); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * jac[i]; // function values Func<scalar>* u = init_fn(sln, order); scalar res = form->value(np, jwt, NULL, u, u, e, NULL); e->free(); delete e; delete [] jwt; u->free_fn(); delete u; return std::abs(res); }