/* * ======== IntrinsicsSupport_maxbit ======== * Returns bit number of most significant '1' in bits argument. * Must be called with non zero bits argument. */ UInt IntrinsicsSupport_maxbit(UInt bits) { #ifdef __TI_COMPILER_VERSION__ #ifdef __16bis__ return (IntrinsicsSupport_maxbitA(bits)); #else return (31 - _norm(bits)); #endif #else return (IntrinsicsSupport_maxbitA(bits)); #endif }
/** * vsg_vector2@t@_normalize: * @vec: a #VsgVector2@t@ * * Modifies @vec so that its Euclidean norm becomes %1. Former direction * of @vec is unchanged. */ void vsg_vector2@t@_normalize(VsgVector2@t@ *vec) { @type@ n; #ifdef VSG_CHECK_PARAMS g_return_if_fail (vec != NULL); #endif n = vsg_vector2@t@_norm(vec); if (n == 0.) return; vsg_vector2@t@_scalp(vec, 1./n, vec); }
/** * vsg_vector2@t@_dist: * @vec: a #VsgVector2@t@ * @other: a #VsgVector2@t@ * * Computes Euclidean norm of the substraction between @vec and @other. * * Returns: square of @vec-@other norm. */ @type@ vsg_vector2@t@_dist (const VsgVector2@t@ *vec, const VsgVector2@t@ *other) { VsgVector2@t@ tmp; #ifdef VSG_CHECK_PARAMS g_return_val_if_fail (vec != NULL, 0.); g_return_val_if_fail (other != NULL, 0.); #endif vsg_vector2@t@_sub (vec, other, &tmp); return vsg_vector2@t@_norm (&tmp); }
/** * vsg_vector2@t@_to_polar_internal: * @vec: a #VsgVector2@t@ * @r: radius * @cost: cos (theta) * @sint: sin (theta) * * Computes @vec polar preliminary coordinates (sine and cosine). */ void vsg_vector2@t@_to_polar_internal (const VsgVector2@t@ *vec, @type@ *r, @type@ *cost, @type@ *sint) { #ifdef VSG_CHECK_PARAMS g_return_if_fail (vec != NULL); #endif *r = vsg_vector2@t@_norm (vec); if (*r > 0.) { *cost = vec->x / *r; *sint = vec->y / *r; } else { *r = 0.; *cost = 1.; *sint = 0.; } }
Real compute_area(RegionsT&& regions, ElementTypesT etypes=mesh::LagrangeP1::FaceTypes()) { Real result = 0; surface_integral(result, std::forward<RegionsT>(regions), _norm(normal), etypes); return result; }
Real compute_area(mesh::Region& root_region, ElementTypesT etypes=mesh::LagrangeP1::FaceTypes()) { Real result = 0; surface_integral(result, root_region, _norm(normal), etypes); return result; }
static void gmshLineSearch(void (*func)(std::vector<double> &x, double &Obj, bool needGrad, std::vector<double> &gradObj, void *), // the function void *data, // eventual data std::vector<double> &x, // variables std::vector<double> &p, // search direction std::vector<double> &g, // gradient double &f, double stpmax, int &check) { int i; double alam, alam2 = 1., alamin, f2 = 0., fold2 = 0., rhs1, rhs2, temp, tmplam = 0.; const double ALF = 1.e-4; const double TOLX = 1.0e-9; std::vector<double> xold(x), grad(x); double fold; (*func)(xold, fold, false, grad, data); check = 0; int n = x.size(); double norm = _norm(p); if(norm > stpmax) scale(p, stpmax / norm); double slope = 0.0; for(i = 0; i < n; i++) slope += g[i] * p[i]; double test = 0.0; for(i = 0; i < n; i++) { temp = fabs(p[i]) / std::max(fabs(xold[i]), 1.0); if(temp > test) test = temp; } alamin = TOLX / test; alam = 1.; while(1) { for(i = 0; i < n; i++) x[i] = xold[i] + alam * p[i]; (*func)(x, f, false, grad, data); if(f > 1.e280) alam *= .5; else break; } while(1) { for(i = 0; i < n; i++) x[i] = xold[i] + alam * p[i]; (*func)(x, f, false, grad, data); // printf("alam = %12.5E alamin = %12.5E f = %12.5E fold = %12.5E slope // %12.5E stuff %12.5E\n",alam,alamin,f,fold, slope, ALF * alam * // slope); // f = (*func)(x, data); if(alam < alamin) { for(i = 0; i < n; i++) x[i] = xold[i]; check = 1; return; } else if(f <= fold + ALF * alam * slope) return; else { if(alam == 1.0) tmplam = -slope / (2.0 * (f - fold - slope)); else { rhs1 = f - fold - alam * slope; rhs2 = f2 - fold2 - alam2 * slope; const double a = (rhs1 / (alam * alam) - rhs2 / (alam2 * alam2)) / (alam - alam2); const double b = (-alam2 * rhs1 / (alam * alam) + alam * rhs2 / (alam2 * alam2)) / (alam - alam2); if(a == 0.0) tmplam = -slope / (2.0 * b); else { const double disc = b * b - 3.0 * a * slope; if(disc < 0.0) Msg::Error("Roundoff problem in gmshLineSearch."); else tmplam = (-b + sqrt(disc)) / (3.0 * a); } if(tmplam > 0.5 * alam) tmplam = 0.5 * alam; } } alam2 = alam; f2 = f; fold2 = fold; alam = std::max(tmplam, 0.1 * alam); } }