DiscontinuousFunc<Scalar>* NeighborSearch<Scalar>::init_ext_fn(MeshFunction<Scalar>* fu) { _F_; Func<Scalar>* fn_central = init_fn(fu, get_quad_eo(false)); uint64_t original_transform = fu->get_transform(); // Change the active element of the function. Note that this also resets the transformations on the function. fu->set_active_element(neighbors[active_segment]); if (neighbor_transformations.present(active_segment)) neighbor_transformations.get(active_segment)->apply_on(fu); Func<Scalar>* fn_neighbor = init_fn(fu, get_quad_eo(true)); // Restore the original function. fu->set_active_element(central_el); fu->set_transform(original_transform); return new DiscontinuousFunc<Scalar>(fn_central, fn_neighbor, (neighbor_edge.orientation == 1)); //NOTE: This function is not very efficient, since it sets the active elements and possibly pushes transformations // for each mesh function in each cycle of the innermost assembly loop. This is neccessary because only in // this innermost cycle (in function DiscreteProblem::eval_form), we know the quadrature order (dependent on // the actual basis and test function), which is needed for creating the Func<Scalar> objects via init_fn. // The reason for storing the central and neighbor values of any given function in these objects is that otherwise // we would have to have one independent copy of the function for each of the neighboring elements. However, it // could unify the way PrecalcShapesets and MeshFunctions are treated in NeighborSearch and maybe these additional // deep memory copying, performed only after setting the active edge part (before the nested loops over basis and // test functions), would be actually more efficient than this. This would require implementing copy for Filters. }
double DiscontinuityDetector::calculate_relative_flow_direction(Element* e, int edge_i) { // Set active element to the two solutions (density_vel_x, density_vel_y). solutions[1]->set_active_element(e); solutions[2]->set_active_element(e); // Set Geometry. SurfPos surf_pos; surf_pos.marker = e->marker; surf_pos.surf_num = edge_i; int eo = solutions[1]->get_quad_2d()->get_edge_points(surf_pos.surf_num, 5); double3* pt = solutions[1]->get_quad_2d()->get_points(eo); int np = solutions[1]->get_quad_2d()->get_num_points(eo); Geom<double>* geom = init_geom_surf(solutions[1]->get_refmap(), &surf_pos, eo); double3* tan = solutions[1]->get_refmap()->get_tangent(surf_pos.surf_num, eo); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * tan[i][2]; // Calculate. Func<scalar>* density_vel_x = init_fn(solutions[1], eo); Func<scalar>* density_vel_y = init_fn(solutions[2], eo); double result = 0.0; for(int point_i = 0; point_i < np; point_i++) result += jwt[point_i] * density_vel_x->val[point_i] * geom->nx[point_i] + density_vel_y->val[point_i] * geom->ny[point_i]; return result; };
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; }
// Actual evaluation of surface linear form (calculates integral) scalar FeProblem::eval_form(WeakForm::VectorFormSurf *vfs, Tuple<Solution *> u_ext, PrecalcShapeset *fv, RefMap *rv, EdgePos* ep) { // eval the form Quad2D* quad = fv->get_quad_2d(); int eo = quad->get_edge_points(ep->edge); double3* pt = quad->get_points(eo); int np = quad->get_num_points(eo); // init geometry and jacobian*weights if (cache_e[eo] == NULL) { cache_e[eo] = init_geom_surf(rv, ep, eo); double3* tan = rv->get_tangent(ep->edge); cache_jwt[eo] = new double[np]; for(int i = 0; i < np; i++) cache_jwt[eo][i] = pt[i][2] * tan[i][2]; } Geom<double>* e = cache_e[eo]; double* jwt = cache_jwt[eo]; // 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, eo); Func<double>* v = get_fn(fv, rv, eo); ExtData<scalar>* ext = init_ext_fns(vfs->ext, rv, eo); scalar res = vfs->fn(np, jwt, prev, v, e, ext); for (int i = 0; i < wf->neq; i++) { prev[i]->free_fn(); delete prev[i]; } ext->free(); delete ext; return 0.5 * res; }
/********************************************************************** * %FUNCTION: load_handler * %ARGUMENTS: * fname -- filename to load * %RETURNS: * -1 on error, 0 if OK * %DESCRIPTION: * Dynamically-loads a handler and initializes it. If fname is not * an absolute path name, we load the handler from /usr/lib/l2tp/plugins ***********************************************************************/ int l2tp_load_handler(EventSelector *es, char const *fname) { char buf[1024]; void *handle; void *init; void (*init_fn)(EventSelector *); if (*fname == '/') { handle = dlopen(fname, RTLD_NOW); } else { snprintf(buf, sizeof(buf), PREFIX"/lib/l2tp/%s", fname); buf[sizeof(buf)-1] = 0; handle = dlopen(buf, RTLD_NOW); } if (!handle) { l2tp_set_errmsg("Could not dload %s: %s", fname, dlerror()); return -1; } init = dlsym(handle, "handler_init"); if (!init) { dlclose(handle); l2tp_set_errmsg("No handler_init found in %s", fname); return -1; } init_fn = (void (*)(EventSelector *)) init; init_fn(es); return 0; }
int arm_pmu_device_probe(struct platform_device *pdev, const struct of_device_id *of_table, const struct pmu_probe_info *probe_table) { const struct of_device_id *of_id; armpmu_init_fn init_fn; struct device_node *node = pdev->dev.of_node; struct arm_pmu *pmu; int ret = -ENODEV; pmu = armpmu_alloc(); if (!pmu) return -ENOMEM; pmu->plat_device = pdev; ret = pmu_parse_irqs(pmu); if (ret) goto out_free; if (node && (of_id = of_match_node(of_table, pdev->dev.of_node))) { init_fn = of_id->data; pmu->secure_access = of_property_read_bool(pdev->dev.of_node, "secure-reg-access"); /* arm64 systems boot only as non-secure */ if (IS_ENABLED(CONFIG_ARM64) && pmu->secure_access) { pr_warn("ignoring \"secure-reg-access\" property for arm64\n"); pmu->secure_access = false; } ret = init_fn(pmu); } else if (probe_table) { cpumask_setall(&pmu->supported_cpus); ret = probe_current_pmu(pmu, probe_table); } if (ret) { pr_info("%pOF: failed to probe PMU!\n", node); goto out_free; } ret = armpmu_request_irqs(pmu); if (ret) goto out_free_irqs; ret = armpmu_register(pmu); if (ret) goto out_free; return 0; out_free_irqs: armpmu_free_irqs(pmu); out_free: pr_info("%pOF: failed to register PMU devices!\n", node); armpmu_free(pmu); return ret; }
jint initialize(JavaVM* vm, void(*init_fn)()) noexcept { static std::once_flag init_flag; static auto failed = false; std::call_once(init_flag, [vm] { try { Environment::initialize(vm); internal::initExceptionHelpers(); } catch (std::exception& ex) { log("Failed to initialize fbjni: %s", ex.what()); failed = true; } catch (...) { log("Failed to initialize fbjni"); failed = true; } }); if (failed) { return JNI_ERR; } try { init_fn(); } catch (...) { translatePendingCppExceptionToJavaException(); // So Java will handle the translated exception, fall through and // return a good version number. } return JNI_VERSION_1_6; }
of_object_t * of_object_dup_(of_object_t *src) { of_object_t *dst; of_object_init_f init_fn; if ((dst = (of_object_t *)MALLOC(sizeof(of_generic_t))) == NULL) { return NULL; } MEMSET(dst, 0, sizeof(*dst)); /* Allocate a minimal wire buffer assuming we will not write to it. */ if ((dst->wire_object.wbuf = of_wire_buffer_new(src->length)) == NULL) { FREE(dst); return NULL; } dst->wire_object.owned = 1; init_fn = of_object_init_map[src->object_id]; init_fn(dst, src->version, src->length, 0); MEMCPY(OF_OBJECT_BUFFER_INDEX(dst, 0), OF_OBJECT_BUFFER_INDEX(src, 0), src->length); return dst; }
auto_release_ptr<Plugin> PluginCache::load(const char* path) { boost::lock_guard<boost::mutex> lock(g_plugin_cache_mutex); // Check if we loaded this plugin before. PluginCacheType::iterator it = g_plugin_cache.find(path); if (it != g_plugin_cache.end()) { if (boost::shared_ptr<SharedLibrary> lib = it->second.lock()) { Plugin::Impl* impl = new Plugin::Impl(lib); return auto_release_ptr<Plugin>(new Plugin(impl)); } } // If this plugin is not in the cache, load the shared lib. boost::shared_ptr<SharedLibrary> lib(new SharedLibrary(path), PluginDeleter()); // Try to call the initialization function if defined. Plugin::InitPluginFnType init_fn = reinterpret_cast<Plugin::InitPluginFnType>( lib->get_symbol("initialize_plugin")); if (init_fn) { if (!init_fn()) throw ExceptionPluginInitializationFailed(); } Plugin::Impl* impl = new Plugin::Impl(lib); g_plugin_cache[path] = boost::weak_ptr<SharedLibrary>(lib); return auto_release_ptr<Plugin>(new Plugin(impl)); }
JABBERWERX_API bool jw_sasl_mech_instance_create( jw_htable *config, jw_sasl_mech *mech, jw_sasl_mech_instance **instance, jw_err *err) { JW_LOG_TRACE_FUNCTION("mech=%p", (void *)mech); assert(mech); assert(instance); size_t inst_size = sizeof(struct _jw_sasl_mech_instance); jw_sasl_mech_instance *ret_inst = jw_data_malloc(inst_size); if (NULL == ret_inst) { jw_log(JW_LOG_WARN, "failed to allocate sasl mechanism instance"); JABBERWERX_ERROR(err, JW_ERR_NO_MEMORY); return false; } memset(ret_inst, 0, inst_size); ret_inst->mech = mech; jw_sasl_mech_init_fn init_fn = mech->fn_table.init_fn; if (NULL != init_fn && !init_fn(ret_inst, config, err)) { jw_log_err(JW_LOG_WARN, err, "mechanism init fn failed"); jw_data_free(ret_inst); return false; } *instance = ret_inst; return true; }
int sechk_lib_init_modules(sechk_lib_t * lib) { int retv, error = 0; size_t i; sechk_module_t *mod = NULL; sechk_mod_fn_t init_fn = NULL; if (lib == NULL || lib->modules == NULL) { errno = EINVAL; return -1; } for (i = 0; i < apol_vector_get_size(lib->modules); i++) { mod = apol_vector_get_element(lib->modules, i); if (!mod->selected) continue; init_fn = sechk_lib_get_module_function(mod->name, SECHK_MOD_FN_INIT, lib); if (!init_fn) { error = errno; fprintf(stderr, "Error: could not initialize module %s\n", mod->name); errno = error; return -1; } retv = init_fn(mod, lib->policy, NULL); if (retv) return retv; } return 0; }
static struct jit_reader * jit_reader_load (const char *file_name) { reader_init_fn_type *init_fn; struct gdb_reader_funcs *funcs = NULL; if (jit_debug) fprintf_unfiltered (gdb_stdlog, _("Opening shared object %s.\n"), file_name); gdb_dlhandle_up so = gdb_dlopen (file_name); init_fn = (reader_init_fn_type *) gdb_dlsym (so, reader_init_fn_sym); if (!init_fn) error (_("Could not locate initialization function: %s."), reader_init_fn_sym); if (gdb_dlsym (so, "plugin_is_GPL_compatible") == NULL) error (_("Reader not GPL compatible.")); funcs = init_fn (); if (funcs->reader_version != GDB_READER_INTERFACE_VERSION) error (_("Reader version does not match GDB version.")); return new jit_reader (funcs, std::move (so)); }
double KellyTypeAdapt::eval_boundary_estimator(KellyTypeAdapt::ErrorEstimatorForm* err_est_form, RefMap *rm, SurfPos* surf_pos) { // 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_edge_fn_order(surf_pos->surf_num) + inc); // Order of additional external functions. ExtData<Ord>* fake_ext = dp.init_ext_fns_ord(err_est_form->ext, surf_pos->surf_num); 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(); int eo = quad->get_edge_points(surf_pos->surf_num, order); double3* pt = quad->get_points(eo); int np = quad->get_num_points(eo); // init geometry and jacobian*weights Geom<double>* e = init_geom_surf(rm, surf_pos, eo); double3* tan = rm->get_tangent(surf_pos->surf_num, eo); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * tan[i][2]; // function values Func<scalar>** ui = new Func<scalar>* [num]; for (int i = 0; i < num; i++) ui[i] = init_fn(this->sln[i], eo); ExtData<scalar>* ext = dp.init_ext_fns(err_est_form->ext, rm, eo); scalar res = boundary_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(0.5*res); // Edges are parameterized from 0 to 1 while integration weights // are defined in (-1, 1). Thus multiplying with 0.5 to correct // the weights. }
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); }
// Initialize shape function values and derivatives (fill in the cache) Func<double>* FeProblem::get_fn(PrecalcShapeset *fu, RefMap *rm, const int order) { Key key(256 - fu->get_active_shape(), order, fu->get_transform(), fu->get_shapeset()->get_id()); if (cache_fn[key] == NULL) cache_fn[key] = init_fn(fu, rm, order); return cache_fn[key]; }
double DiscontinuityDetector::calculate_jumps(Element* e, int edge_i) { // Set active element to the solutions. solutions[0]->set_active_element(e); solutions[1]->set_active_element(e); solutions[2]->set_active_element(e); solutions[3]->set_active_element(e); // Set Geometry. SurfPos surf_pos; surf_pos.marker = e->marker; surf_pos.surf_num = edge_i; int eo = solutions[0]->get_quad_2d()->get_edge_points(surf_pos.surf_num, 5); double3* pt = solutions[0]->get_quad_2d()->get_points(eo); int np = solutions[0]->get_quad_2d()->get_num_points(eo); Geom<double>* geom = init_geom_surf(solutions[0]->get_refmap(), &surf_pos, eo); double3* tan = solutions[0]->get_refmap()->get_tangent(surf_pos.surf_num, eo); double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * tan[i][2]; // Prepare functions on the central element. Func<scalar>* density = init_fn(solutions[0], eo); Func<scalar>* density_vel_x = init_fn(solutions[1], eo); Func<scalar>* density_vel_y = init_fn(solutions[2], eo); Func<scalar>* density_energy = init_fn(solutions[3], eo); // Set neighbor element to the solutions. solutions[0]->set_active_element(e->get_neighbor(edge_i)); solutions[1]->set_active_element(e->get_neighbor(edge_i)); solutions[2]->set_active_element(e->get_neighbor(edge_i)); solutions[3]->set_active_element(e->get_neighbor(edge_i)); // Prepare functions on the neighbor element. Func<scalar>* density_neighbor = init_fn(solutions[0], eo); Func<scalar>* density_vel_x_neighbor = init_fn(solutions[1], eo); Func<scalar>* density_vel_y_neighbor = init_fn(solutions[2], eo); Func<scalar>* density_energy_neighbor = init_fn(solutions[3], eo); DiscontinuousFunc<scalar> density_discontinuous(density, density_neighbor, true); DiscontinuousFunc<scalar> density_vel_x_discontinuous(density_vel_x, density_vel_x_neighbor, true); DiscontinuousFunc<scalar> density_vel_y_discontinuous(density_vel_y, density_vel_y_neighbor, true); DiscontinuousFunc<scalar> density_energy_discontinuous(density_energy, density_energy_neighbor, true); double result = 0.0; for(int point_i = 0; point_i < np; point_i++) result += jwt[point_i] * ( std::pow(density_discontinuous.get_val_central(point_i) - density_discontinuous.get_val_neighbor(point_i), 2) + std::pow(density_vel_x_discontinuous.get_val_central(point_i) - density_vel_x_discontinuous.get_val_neighbor(point_i), 2) + std::pow(density_vel_y_discontinuous.get_val_central(point_i) - density_vel_y_discontinuous.get_val_neighbor(point_i), 2) + std::pow(density_energy_discontinuous.get_val_central(point_i) - density_energy_discontinuous.get_val_neighbor(point_i), 2)); return std::sqrt(result); };
DiscontinuousFunc<scalar>* NeighborSearch::init_ext_fn(MeshFunction* fu) { ensure_active_segment(this); ensure_set_quad_order(central_quad); ensure_set_quad_order(neighb_quad); if(fu->get_active_element() != central_el) { // Just in case - the input function should have the active element set to the central element from get_next_state // called in the assembling procedure. fu->set_active_element(central_el); fu->set_transform(original_central_el_transform); } if (neighborhood_type == H2D_DG_GO_DOWN) // Shrink the bigger central element to match the smaller neighbor (shrinks the active edge to the active segment). for(int i = 0; i < n_trans[active_segment]; i++) fu->push_transform(transformations[active_segment][i]); Func<scalar>* fn_central = init_fn(fu, fu->get_refmap(), get_quad_eo(false)); // Change the active element of the function. Note that this also resets the transformations on the function. fu->set_active_element(neighb_el); if (neighborhood_type == H2D_DG_GO_UP) // Shrink the bigger neighbor to match the smaller central element. for(int i = 0; i < n_trans[active_segment]; i++) fu->push_transform(transformations[active_segment][i]); Func<scalar>* fn_neighbor = init_fn(fu, fu->get_refmap(), get_quad_eo(true)); // Restore the original function. fu->set_active_element(central_el); fu->set_transform(original_central_el_transform); return new DiscontinuousFunc<scalar>(fn_central, fn_neighbor, (neighbor_edges[active_segment].orientation == 1)); //NOTE: This function is not very efficient, since it sets the active elements and possibly pushes transformations // for each mesh function in each cycle of the innermost assembly loop. This is neccessary because only in // this innermost cycle (in function DiscreteProblem::eval_form), we know the quadrature order (dependent on // the actual basis and test function), which is needed for creating the Func<scalar> objects via init_fn. // The reason for storing the central and neighbor values of any given function in these objects is that otherwise // we would have to have one independent copy of the function for each of the neighboring elements. However, it // could unify the way PrecalcShapesets and MeshFunctions are treated in NeighborSearch and maybe these additional // deep memory copying, performed only after setting the active edge part (before the nested loops over basis and // test functions), would be actually more efficient than this. This would require implementing copy for Filters. }
void DiscreteProblemFormAssembler<Scalar>::assemble_vector_form(VectorForm<Scalar>* form, int order, Func<double>** test_fns, Func<Scalar>** ext, Func<Scalar>** u_ext, AsmList<Scalar>* current_als_i, Traverse::State* current_state, int n_quadrature_points, Geom<double>* geometry, double* jacobian_x_weights) { bool surface_form = (dynamic_cast<VectorFormVol<Scalar>*>(form) == nullptr); Func<Scalar>** local_ext = ext; // If the user supplied custom ext functions for this form. if(form->ext.size() > 0) { int local_ext_count = form->ext.size(); local_ext = malloc_with_check(local_ext_count, this); for(int ext_i = 0; ext_i < local_ext_count; ext_i++) if(form->ext[ext_i]) local_ext[ext_i] = init_fn(form->ext[ext_i].get(), order); else local_ext[ext_i] = nullptr; } // Account for the previous time level solution previously inserted at the back of ext. if(rungeKutta) u_ext += form->u_ext_offset; // Actual form-specific calculation. for (unsigned int i = 0; i < current_als_i->cnt; i++) { if(current_als_i->dof[i] < 0) continue; // Is this necessary, i.e. is there a coefficient smaller than Hermes::HermesSqrtEpsilon? if(std::abs(current_als_i->coef[i]) < Hermes::HermesSqrtEpsilon) continue; Func<double>* v = test_fns[i]; Scalar val; if(surface_form) val = 0.5 * form->value(n_quadrature_points, jacobian_x_weights, u_ext, v, geometry, local_ext) * form->scaling_factor * current_als_i->coef[i]; else val = form->value(n_quadrature_points, jacobian_x_weights, u_ext, v, geometry, local_ext) * form->scaling_factor * current_als_i->coef[i]; current_rhs->add(current_als_i->dof[i], val); } if(form->ext.size() > 0) { for(int ext_i = 0; ext_i < form->ext.size(); ext_i++) if(form->ext[ext_i]) { local_ext[ext_i]->free_fn(); delete local_ext[ext_i]; } free_with_check(local_ext); } if(rungeKutta) u_ext -= form->u_ext_offset; }
static eOresult_t s_eon_sys_start(void (*init_fn)(void)) { // exec the init belonging to the system object: do it before any tick is started if(NULL != init_fn) { init_fn(); } return(eores_OK); }
static int cpu_pmu_device_probe(struct platform_device *pdev) { const struct of_device_id *of_id; const int (*init_fn)(struct arm_pmu *); struct device_node *node = pdev->dev.of_node; struct arm_pmu *pmu; int ret = -ENODEV; if (cpu_pmu) { pr_info("attempt to register multiple PMU devices!\n"); return -ENOSPC; } pmu = kzalloc(sizeof(struct arm_pmu), GFP_KERNEL); if (!pmu) { pr_info("failed to allocate PMU device!\n"); return -ENOMEM; } cpu_pmu = pmu; cpu_pmu->plat_device = pdev; if (node && (of_id = of_match_node(cpu_pmu_of_device_ids, pdev->dev.of_node))) { init_fn = of_id->data; ret = of_pmu_irq_cfg(pdev); if (!ret) ret = init_fn(pmu); } else { ret = probe_current_pmu(pmu); } if (ret) { pr_info("failed to probe PMU!\n"); goto out_free; } ret = cpu_pmu_init(cpu_pmu); if (ret) goto out_free; ret = armpmu_register(cpu_pmu, -1); if (ret) goto out_destroy; return 0; out_destroy: cpu_pmu_destroy(cpu_pmu); out_free: pr_info("failed to register PMU devices!\n"); kfree(pmu); return ret; }
// Initialize external functions (obtain values, derivatives,...) ExtData<scalar>* FeProblem::init_ext_fns(std::vector<MeshFunction *> &ext, RefMap *rm, const int order) { ExtData<scalar>* ext_data = new ExtData<scalar>; Func<scalar>** ext_fn = new Func<scalar>*[ext.size()]; for (unsigned i = 0; i < ext.size(); i++) ext_fn[i] = init_fn(ext[i], rm, order); ext_data->nf = ext.size(); ext_data->fn = ext_fn; return ext_data; }
// 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 psci_init(void) { struct device_node *np; const struct of_device_id *matched_np; psci_initcall_t init_fn; np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np); if (!np) return -ENODEV; init_fn = (psci_initcall_t)matched_np->data; return init_fn(np); }
void modules_init(void) { sw_dev_head_init(); mod_init_fn_call init_fn; u32* init_fn_addr, init_start_addr, init_end_addr; init_start_addr = get_mod_init_start_addr(); init_end_addr = get_mod_init_end_addr(); for(init_fn_addr = init_start_addr; init_fn_addr < init_end_addr; init_fn_addr++){ init_fn = *(init_fn_addr); if(init_fn != NULL){ init_fn(); } } }
DiscontinuousFunc<double>* NeighborSearch::ExtendedShapeset::ExtendedShapeFunction::get_fn( std::map< PrecalcShapeset::Key, Func< double >*, PrecalcShapeset::Compare >& ext_cache_fn ) { int eo = neibhood->get_quad_eo(support_on_neighbor); PrecalcShapeset::Key key( 256 - active_pss->get_active_shape(), eo, active_pss->get_transform(), active_pss->get_shapeset()->get_id() ); if (ext_cache_fn[key] == NULL) ext_cache_fn[key] = init_fn(active_pss, active_rm, eo); return extend_by_zero( ext_cache_fn[key] ); }
int __init psci_dt_init(void) { //SMP 아키텍처에서 psci 기능이 지원되는 경우 해당 초기화 함수를 동작시켜 //각 기능에 해당하는 핸들러 함수 연결 struct device_node *np; const struct of_device_id *matched_np; psci_initcall_t init_fn; //DT에서 psci_of_match에 있는 디바이스 중 하나라도 일치되는 노드를 찾아 리턴하고 출력인수 matched_up에 psci_of_match에 있는 of_device_id 구조체 엔트리 중 매치된 엔트리 포인터 저장. np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np); if (!np) return -ENODEV; init_fn = (psci_initcall_t)matched_np->data;//psci_of_match 각 엔트리에 있는 data 콜백 return init_fn(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); }
bool panda_load_plugin(const char *filename) { // don't load the same plugin twice uint32_t i; for (i=0; i<nb_panda_plugins_loaded; i++) { if (0 == (strcmp(filename, panda_plugins_loaded[i]))) { printf ("panda_load_plugin: %s already loaded\n", filename); return true; } } // NB: this is really a list of plugins for which we have started loading // and not yet called init_plugin fn. needed to avoid infinite loop with panda_require panda_plugins_loaded[nb_panda_plugins_loaded] = strdup(filename); nb_panda_plugins_loaded ++; printf ("loading %s\n", filename); void *plugin = dlopen(filename, RTLD_NOW); if(!plugin) { fprintf(stderr, "Failed to load %s: %s\n", filename, dlerror()); return false; } bool (*init_fn)(void *) = dlsym(plugin, "init_plugin"); if(!init_fn) { fprintf(stderr, "Couldn't get symbol %s: %s\n", "init_plugin", dlerror()); dlclose(plugin); return false; } // populate this element in list *before* calling init_fn, please. // otherwise, when osi panda_requires win7x86intro and that does some PPP_REG_CB("osi"..), // that will fail bc it traverses this list to obtain osi handle. ugh! panda_plugins[nb_panda_plugins].plugin = plugin; strncpy(panda_plugins[nb_panda_plugins].name, basename((char *) filename), 256); nb_panda_plugins++; if(init_fn(plugin)) { // TRL: Don't do this here! See above // panda_plugins[nb_panda_plugins].plugin = plugin; // strncpy(panda_plugins[nb_panda_plugins].name, basename((char *) filename), 256); // nb_panda_plugins++; fprintf (stderr, "Success\n"); return true; } else { dlclose(plugin); fprintf (stderr, "Fail. init_fn returned 0\n"); return false; } }
int ldb_try_load_dso(struct ldb_context *ldb, const char *name) { char *path; void *handle; int (*init_fn) (void); char *modulesdir; #ifdef HAVE_DLOPEN if (getenv("LD_LDB_MODULE_PATH") != NULL) { modulesdir = talloc_strdup(ldb, getenv("LD_LDB_MODULE_PATH")); } else { #ifdef _SAMBA_BUILD_ modulesdir = talloc_asprintf(ldb, "%s/ldb", dyn_MODULESDIR); #else modulesdir = talloc_strdup(ldb, MODULESDIR); #endif } path = talloc_asprintf(ldb, "%s/%s.%s", modulesdir, name, SHLIBEXT); talloc_free(modulesdir); ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path); handle = dlopen(path, RTLD_NOW); if (handle == NULL) { ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror()); return -1; } init_fn = (int (*)(void))dlsym(handle, "init_module"); if (init_fn == NULL) { ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `init_module' found in %s: %s\n", path, dlerror()); return -1; } talloc_free(path); return init_fn(); #else ldb_debug(ldb, LDB_DEBUG_TRACE, "no dlopen() - not trying to load %s module\n", name); return -1; #endif }
void *list_objects_filter__init( struct oidset *omitted, struct list_objects_filter_options *filter_options, filter_object_fn *filter_fn, filter_free_fn *filter_free_fn) { filter_init_fn init_fn; assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT); if (filter_options->choice >= LOFC__COUNT) BUG("invalid list-objects filter choice: %d", filter_options->choice); init_fn = s_filters[filter_options->choice]; if (init_fn) return init_fn(omitted, filter_options, filter_fn, filter_free_fn); *filter_fn = NULL; *filter_free_fn = NULL; return NULL; }