bool Solver::postLessEqualZero(const LinearExprRepr& l) { if (!bValid) return false; if (l.vars.size()==0) return l.free <= 0; ++stats.nbPosts; if (l.vars.size()==1 and *l.coeffs.begin()==1) { ++stats.nbColUpdates; bValid = postLessEqual(l.vars.begin()->id, -l.free); return bValid; } Idxs idxs(l.vars.size()); uint c = 0; for (auto it = l.vars.begin(); it != l.vars.end(); ++it) idxs[c++] = it->id; Coeffs coeffs(l.vars.size()); c = 0; for (auto it = l.coeffs.begin(); it != l.coeffs.end(); ++it) coeffs[c++] = *it; postLessEqual(idxs,coeffs,-l.free); bPending = true; return true; }
/*! * This is called if a 'Adsorbate' node is found in the XML input. * * @param f XML Node that contains the parameterization */ static SpeciesThermoInterpType* newAdsorbateThermoFromXML(const XML_Node& f) { vector_fp freqs; doublereal pref = OneAtm; double tmin = fpValue(f["Tmin"]); double tmax = fpValue(f["Tmax"]); if (f.hasAttrib("P0")) { pref = fpValue(f["P0"]); } if (f.hasAttrib("Pref")) { pref = fpValue(f["Pref"]); } if (tmax == 0.0) { tmax = 1.0e30; } if (f.hasChild("floatArray")) { getFloatArray(f.child("floatArray"), freqs, false); } for (size_t n = 0; n < freqs.size(); n++) { freqs[n] *= 3.0e10; } vector_fp coeffs(freqs.size() + 2); coeffs[0] = static_cast<double>(freqs.size()); coeffs[1] = getFloat(f, "binding_energy", "toSI"); copy(freqs.begin(), freqs.end(), coeffs.begin() + 2); return new Adsorbate(tmin, tmax, pref, &coeffs[0]); }
void add_ineq() { pb_util pb(m); expr_ref fml(m), tmp(m); th_rewriter rw(m); vector<rational> coeffs(vars.size()); expr_ref_vector args(vars); while (true) { rational k(rand(6)); for (unsigned i = 0; i < coeffs.size(); ++i) { int v = 3 - rand(5); coeffs[i] = rational(v); if (coeffs[i].is_neg()) { args[i] = m.mk_not(args[i].get()); coeffs[i].neg(); k += coeffs[i]; } } fml = pb.mk_ge(args.size(), coeffs.c_ptr(), args.c_ptr(), k); rw(fml, tmp); rw(tmp, tmp); if (pb.is_ge(tmp)) { fml = tmp; break; } } std::cout << "(assert " << fml << ")\n"; ctx.assert_expr(fml); }
const unsigned char* TrgbPrimaries::getAvisynthYCbCr2RgbMatrix(int &rgb_add) { static const int64_t avisynthMmxMatrixConstants[10]= { 0x0080008000800080LL, 0x0080008000800080LL, 0x00FF00FF00FF00FFLL, 0x00FF00FF00FF00FFLL, 0x0000200000002000LL, 0x0000200000002000LL, 0xFF000000FF000000LL, 0xFF000000FF000000LL, 0xFF00FF00FF00FF00LL, 0xFF00FF00FF00FF00LL }; TYCbCr2RGB_coeffs coeffs((ffYCbCr_RGB_MatrixCoefficientsType)cspOptionsIturBt,cspOptionsWhiteCutoff,cspOptionsBlackCutoff,cspOptionsChromaCutoff,cspOptionsRGB_WhiteLevel,cspOptionsRGB_BlackLevel); // Avisynth YUY2->RGB short *avisynthMmxMatrix = (short*)getAlignedPtr(avisynthMmxMatrixBuf); int cy =short(coeffs.y_mul * 16384 + 0.5); short crv=short(coeffs.vr_mul * 8192 + 0.5); short cgu=short(-coeffs.ug_mul * 8192 - 0.5); short cgv=short(-coeffs.vg_mul * 8192 - 0.5); short cbu=short(coeffs.ub_mul * 8192 + 0.5); memcpy(&avisynthMmxMatrix[8], avisynthMmxMatrixConstants, 80); // common part int *avisynthMmxMatrixInt = (int*)avisynthMmxMatrix; avisynthMmxMatrix[0] = avisynthMmxMatrix[1] = avisynthMmxMatrix[2] = avisynthMmxMatrix[3] = // This is wrong for mmx ([2] and [3] should be 0). Fortunately, these bytes are ignored. short(coeffs.Ysub); avisynthMmxMatrixInt[2] = avisynthMmxMatrixInt[3] = 0; avisynthMmxMatrixInt[24] = avisynthMmxMatrixInt[25] = avisynthMmxMatrixInt[26] = avisynthMmxMatrixInt[27] = coeffs.RGB_add3; avisynthMmxMatrixInt[28] = avisynthMmxMatrixInt[29] = avisynthMmxMatrixInt[30] = avisynthMmxMatrixInt[31] = cy; avisynthMmxMatrixInt[32] = avisynthMmxMatrixInt[33] = avisynthMmxMatrixInt[34] = avisynthMmxMatrixInt[35] = crv << 16; avisynthMmxMatrix[72] = avisynthMmxMatrix[74] = avisynthMmxMatrix[76] = avisynthMmxMatrix[78] = cgu; avisynthMmxMatrix[73] = avisynthMmxMatrix[75] = avisynthMmxMatrix[77] = avisynthMmxMatrix[79] = cgv; avisynthMmxMatrixInt[40] = avisynthMmxMatrixInt[41] = avisynthMmxMatrixInt[42] = avisynthMmxMatrixInt[43] = cbu; rgb_add = coeffs.RGB_add1; return (const unsigned char*)avisynthMmxMatrix; // none 0 value indiates that adding ofs_rgb_add to RGB is necessary. }
/** * Return the coefficients for KRON. * * Parameters: linOp LIN with type KRON * Returns: vector containing the coefficient matrix for the Kronecker product. */ std::vector<Matrix> get_kron_mat(LinOp &lin) { assert(lin.type == KRON); Matrix constant = get_constant_data(lin, false); int lh_rows = constant.rows(); int lh_cols = constant.cols(); int rh_rows = lin.args[0]->size[0]; int rh_cols = lin.args[0]->size[1]; int rows = rh_rows * rh_cols * lh_rows * lh_cols; int cols = rh_rows * rh_cols; Matrix coeffs(rows, cols); std::vector<Triplet> tripletList; tripletList.reserve(rh_rows * rh_cols * constant.nonZeros()); for ( int k = 0; k < constant.outerSize(); ++k ) { for ( Matrix::InnerIterator it(constant, k); it; ++it ) { int row = (rh_rows * rh_cols * (lh_rows * it.col())) + (it.row() * rh_rows); int col = 0; for(int j = 0; j < rh_cols; j++){ for(int i = 0; i < rh_rows; i++) { tripletList.push_back(Triplet(row + i, col, it.value())); col++; } row += lh_rows * rh_rows; } } } coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
/** * Return the coefficients for UPPER_TRI: an ENTRIES by ROWS * COLS matrix * where the i, j entry in the original matrix has a 1 in row COUNT and * corresponding column if j > i and 0 otherwise. * * Parameters: LinOp with type UPPER_TRI. * Returns: vector of coefficients for upper triangular matrix linOp */ std::vector<Matrix> get_upper_tri_mat(LinOp &lin) { assert(lin.type == UPPER_TRI); int rows = lin.args[0]->size[0]; int cols = lin.args[0]->size[1]; int entries = lin.size[0]; Matrix coeffs(entries, rows * cols); std::vector<Triplet> tripletList; tripletList.reserve(entries); int count = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (j > i) { // index in the extracted vector int row_idx = count; count++; // index in the original matrix int col_idx = j * rows + i; tripletList.push_back(Triplet(row_idx, col_idx, 1.0)); } } } coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
// create PolyVol representation of the basis function PolyVol<double> PolyVolBasisFunc::CreatePolyVol() const { Matrix3D<double> coeffs(ordu,ordv,ordw,0.0); coeffs[indexu-1][indexv-1][indexw-1]=1.0; return PolyVol<double>(coeffs,ordu,ordv,ordw,leftlimitu,rightlimitu,leftlimitv,rightlimitv,leftlimitw,rightlimitw); }
Polynomial<Type, OrthogonalLegendreBasis<Type> > GenerateLeastSquaresPolynomialProjection(unsigned int projectionOrder, unsigned int integrationOrder, const boost::function1<Type, Type>& f) { std::vector<Type> coeffs(projectionOrder+1, 0); const std::vector<Type>* nodes; const std::vector<Type>* weights; const unsigned int n = integrationOrder; GaussLegendreNodesAndWeights<double>::GenerateGaussLegendreNodesAndWeights( nodes, weights, n+1); std::vector<Type> vals(n); for(unsigned int j = 0; j < n; ++j) { vals[j] = f((*nodes)[j]); } for(unsigned int c_index = 0; c_index <= projectionOrder; ++c_index) { coeffs[c_index] = 0.0; for(unsigned int k = 0; k < n; ++k) { coeffs[c_index] += vals[k] * OrthogonalLegendreBasis<Type>::eval(c_index, (*nodes)[k]) * (*weights)[k]; } } return Polynomial<Type, OrthogonalLegendreBasis<Type> >(coeffs); }
static void installAdsorbateThermoFromXML(std::string speciesName, SpeciesThermo& sp, int k, const XML_Node& f) { vector_fp freqs; doublereal tmin, tmax, pref = OneAtm; int nfreq = 0; tmin = fpValue(f["Tmin"]); tmax = fpValue(f["Tmax"]); if (f.hasAttrib("P0")) { pref = fpValue(f["P0"]); } if (f.hasAttrib("Pref")) { pref = fpValue(f["Pref"]); } if (tmax == 0.0) tmax = 1.0e30; if (f.hasChild("floatArray")) { getFloatArray(f.child("floatArray"), freqs, false); nfreq = freqs.size(); } for (int n = 0; n < nfreq; n++) { freqs[n] *= 3.0e10; } vector_fp coeffs(nfreq + 2); coeffs[0] = nfreq; coeffs[1] = getFloat(f, "binding_energy", "toSI"); copy(freqs.begin(), freqs.end(), coeffs.begin() + 2); //posc = new Adsorbate(k, tmin, tmax, pref, // DATA_PTR(coeffs)); (&sp)->install(speciesName, k, ADSORBATE, &coeffs[0], tmin, tmax, pref); }
/** * Return the coefficients for RMUL (right multiplication): a ROWS * N * by COLS * N matrix given by the kronecker product between the * transpose of the constant matrix CONSTANT and a N x N identity matrix. * * Parameters: linOp of type RMUL * * Returns: vector containing the corresponding coefficient matrix COEFFS * */ std::vector<Matrix> get_rmul_mat(LinOp &lin) { assert(lin.type == RMUL); Matrix constant = get_constant_data(lin, false); int rows = constant.rows(); int cols = constant.cols(); int n = lin.size[0]; Matrix coeffs(cols * n, rows * n); std::vector<Triplet> tripletList; tripletList.reserve(n * constant.nonZeros()); for ( int k = 0; k < constant.outerSize(); ++k ) { for ( Matrix::InnerIterator it(constant, k); it; ++it ) { double val = it.value(); // each element of CONSTANT occupies an N x N block in the matrix int row_start = it.col() * n; int col_start = it.row() * n; for (int i = 0; i < n; i++) { int row_idx = row_start + i; int col_idx = col_start + i; tripletList.push_back(Triplet(row_idx, col_idx, val)); } } } coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
Polynomial PolyDomain::operator()(const std::initializer_list<BigUnsigned>& c) const { std::vector<FieldElement> coeffs(c.size()); std::transform(c.begin(), c.end(), coeffs.begin(), [&](const BigUnsigned& b) { return field->makeElement(b); }); return makeElement(coeffs); }
double Gas_Impl::getViscosity(double temperature) const { std::string gasType = this->gasType(); std::vector<double> coeffs(3); if (openstudio::istringEqual(gasType,"Air")) { coeffs = FenestrationMaterial::airViscosityCoefficients(); } else if (openstudio::istringEqual(gasType,"Argon")) { coeffs = FenestrationMaterial::argonViscosityCoefficients(); } else if (openstudio::istringEqual(gasType,"Krypton")) { coeffs = FenestrationMaterial::kryptonViscosityCoefficients(); } else if (openstudio::istringEqual(gasType,"Xenon")) { coeffs = FenestrationMaterial::xenonViscosityCoefficients(); } else if (openstudio::istringEqual(gasType,"Custom")) { OptionalDouble A = customViscosityCoefficientA(); OptionalDouble B = customViscosityCoefficientB(); OptionalDouble C = customViscosityCoefficientC(); if (!(A && B && C)) { LOG_AND_THROW("Gas " << briefDescription() << " has gasType == 'Custom', but no " << "viscosity coefficients set. Cannot calculate viscosity."); } coeffs[0] = *A; coeffs[1] = *B; coeffs[2] = *C; } else { LOG_AND_THROW("Unknown gasType listed in " << briefDescription() << "."); } return coeffs[0] + (coeffs[1]* temperature) + (coeffs[2] * ::pow(temperature,2)); }
Foam::autoPtr<Foam::liquid> Foam::liquid::New(Istream& is) { if (debug) { Info<< "liquid::New(Istream&) : " << "constructing liquid" << endl; } word liquidType(is); word coeffs(is); if (coeffs == "defaultCoeffs") { ConstructorTable::iterator cstrIter = ConstructorTablePtr_->find(liquidType); if (cstrIter == ConstructorTablePtr_->end()) { FatalErrorIn("liquid::New(Istream&)") << "Unknown liquid type " << liquidType << nl << nl << "Valid liquid types are:" << nl << ConstructorTablePtr_->sortedToc() << abort(FatalError); } return autoPtr<liquid>(cstrIter()()); } else if (coeffs == "coeffs") { IstreamConstructorTable::iterator cstrIter = IstreamConstructorTablePtr_->find(liquidType); if (cstrIter == IstreamConstructorTablePtr_->end()) { FatalErrorIn("liquid::New(Istream&)") << "Unknown liquid type " << liquidType << endl << endl << "Valid liquid types are:" << nl << IstreamConstructorTablePtr_->sortedToc() << abort(FatalError); } return autoPtr<liquid>(cstrIter()(is)); } else { FatalErrorIn("liquid::New(Istream&)") << "liquid type " << liquidType << ", option " << coeffs << " given" << ", should be coeffs or defaultCoeffs" << abort(FatalError); return autoPtr<liquid>(NULL); } }
rectangle_packer (int _nb_screen, const pair & vscreen_min_size, const pair & vscreen_max_size, const pair_list & screen_sizes, const sequence_pair & layout) : nb_screen (_nb_screen) { init_solver (); // Virtual screen boundaries more_than_const (v_vscreen_size (X), vscreen_min_size.x); less_than_const (v_vscreen_size (X), vscreen_max_size.x); more_than_const (v_vscreen_size (Y), vscreen_min_size.y); less_than_const (v_vscreen_size (Y), vscreen_max_size.y); // Screens inside virtual screen for (int sc = 0; sc < nb_screen; ++sc) { positive_or_zero (v_screen_pos (sc, X)); offseted_less_than_var (v_screen_pos (sc, X), screen_sizes[sc].x, v_vscreen_size (X)); positive_or_zero (v_screen_pos (sc, Y)); offseted_less_than_var (v_screen_pos (sc, Y), screen_sizes[sc].y, v_vscreen_size (Y)); } // Screen ordering constraints for (int sa = 0; sa < nb_screen; ++sa) for (int sb = 0; sb < sa; ++sb) switch (layout.ordering (sa, sb)) { case left: offseted_less_than_var (v_screen_pos (sa, X), screen_sizes[sa].x, v_screen_pos (sb, X)); break; case right: offseted_less_than_var (v_screen_pos (sb, X), screen_sizes[sb].x, v_screen_pos (sa, X)); break; case above: offseted_less_than_var (v_screen_pos (sa, Y), screen_sizes[sa].y, v_screen_pos (sb, Y)); break; case under: offseted_less_than_var (v_screen_pos (sb, Y), screen_sizes[sb].y, v_screen_pos (sa, Y)); break; default: throw std::runtime_error ("rectangle_packer: unordered screens despite sequence pair"); } /* Objective function. sum of : * - constraint gap length * - distance between centers on second axis */ const int constraint_gap_coeff = 1; const int center_distance_coeff = 1; std::vector< int > coeffs (v_nb (), 0); // More practical to gather coeffs coeffs[v_objective ()] = -1; // 0 = -o + sum(...) for (int sa = 0; sa < nb_screen; ++sa) for (int sb = 0; sb < sa; ++sb) switch (layout.ordering (sa, sb)) { case left: coeffs[v_screen_pos (sa, X)] -= constraint_gap_coeff; coeffs[v_screen_pos (sb, X)] += constraint_gap_coeff; // o += sb.x - sa.x coeffs[distance_var (v_screen_pos (sa, Y), screen_sizes[sa].y, v_screen_pos (sb, Y), screen_sizes[sb].y)] += center_distance_coeff; // o += dist (sa.cy, sb.cy) break; case right: coeffs[v_screen_pos (sb, X)] -= constraint_gap_coeff; coeffs[v_screen_pos (sa, X)] += constraint_gap_coeff; // o += sa.x - sb.x coeffs[distance_var (v_screen_pos (sb, Y), screen_sizes[sb].y, v_screen_pos (sa, Y), screen_sizes[sa].y)] += center_distance_coeff; // o += dist (sb.cy, sa.cy) break; case above: coeffs[v_screen_pos (sa, Y)] -= constraint_gap_coeff; coeffs[v_screen_pos (sb, Y)] += constraint_gap_coeff; // o += sb.y - sa.y coeffs[distance_var (v_screen_pos (sa, X), screen_sizes[sa].x, v_screen_pos (sb, X), screen_sizes[sb].x)] += center_distance_coeff; // o += dist (sa.cx, sb.cx) break; case under: coeffs[v_screen_pos (sb, Y)] -= constraint_gap_coeff; coeffs[v_screen_pos (sa, Y)] += constraint_gap_coeff; // o += sa.y - sb.y coeffs[distance_var (v_screen_pos (sb, X), screen_sizes[sb].x, v_screen_pos (sa, X), screen_sizes[sa].x)] += center_distance_coeff; // o += dist (sb.cx, sa.cx) break; default: break; // Error handled before } equality (coeffs); }
IplImage* prop_match(IplImage *src, IplImage *dst) { int *srcdata, *dstdata; CvSize src_size = cvGetSize(src), dst_size = cvGetSize(dst); int w1 = src_size.width - 8 + 1, h1 = src_size.height - 8 + 1; int sz = w1*h1, plane_coeffs[] = {2, 9, 5}; int dim = plane_coeffs[0] + plane_coeffs[1] + plane_coeffs[2]; kd_tree kdt; IplImage *matched; coeffs(src, dim, plane_coeffs, &srcdata); coeffs(dst, dim, plane_coeffs, &dstdata); memset(&kdt, 0, sizeof(kdt)); kdt_new(&kdt, srcdata, sz, dim); matched = match(&kdt, dstdata, src, dst_size); free(srcdata); free(dstdata); kdt_free(&kdt); return matched; }
void EEG_DEv_Filter::load(const char* fname) { ifstream ifs(fname); istream_iterator<double> in(ifs); vector<double> coeffs(in,istream_iterator<double>()); Filter->set_Coefficients(&coeffs); ifs.close(); }
bool TargaImage::Filter_Gaussian_N( unsigned int N ) { assert(N > 1); //assert(N < 15); //Overflows value unsigned char *rgb = To_RGB_All(); int n = (int) N; int i, j, b, c; //Overwrite original image so that unfiltered edge pixels have their alpha multiplied out memcpy(data, rgb, sizeof(unsigned char) * width * height * 4); vector < int > coeffs(n); //Binomial coefficients for(i = 0; i<=n/2; ++i) { b = Binomial((n-1),i); coeffs[i] = b; //Fill first half coeffs[n - i - 1] = b; //Fill second half } vector< vector<int> > filter(n, vector<int>(n)); //nxn gaussian filter int x, y; for(y=0; y<n; ++y) { for(x=0; x<n; ++x) { filter[y][x] = coeffs[x]*coeffs[y]; } } double scalar = 1/pow(2.0, 2*(n-1)); //Used to keep sum of filter elements equal to 1 //Apply the filter to the image, read from rgb[], write to data[] int offset = n/2; //Closest to the edge the filter can be centered unsigned __int64 value; //Large type to prevent common overflows for (c=0; c<3; ++c) { //For each color channel for (y = offset; y < (height - offset); ++y) { for (x = offset; x < (width - offset); ++x) { //For each point in the image value = 0; //Reset for each filtering for (j=0; j<n; ++j) { //For each value in the filter for (i=0; i<n; ++i) { value += rgb[((y - offset+j)*width +(x - offset+i))*4 + c] * filter[j][i]; }//i }//j //Assign value to result image data[(y*width + x)*4 + c] = (int) floor(scalar*value + 0.5); }//x }//y }//c delete rgb; return true; }// Filter_Gaussian_N
const int32_t* TrgbPrimaries::toSwscaleTable(void) { TYCbCr2RGB_coeffs coeffs((ffYCbCr_RGB_MatrixCoefficientsType)cspOptionsIturBt,cspOptionsWhiteCutoff,cspOptionsBlackCutoff,cspOptionsChromaCutoff,cspOptionsRGB_WhiteLevel,cspOptionsRGB_BlackLevel); swscaleTable[0] = int32_t(coeffs.vr_mul * 65536 + 0.5); swscaleTable[1] = int32_t(coeffs.ub_mul * 65536 + 0.5); swscaleTable[2] = int32_t(coeffs.ug_mul * 65536 + 0.5); swscaleTable[3] = int32_t(coeffs.vg_mul * 65536 + 0.5); swscaleTable[4] = int32_t(coeffs.y_mul * 65536 + 0.5); swscaleTable[5] = int32_t(coeffs.Ysub * 65536); swscaleTable[6] = coeffs.RGB_add1; return swscaleTable; }
const QVector<double> TimeSeriesMotion::baselineFit( const int term, const QVector<double> & series ) const { Q_ASSERT(term >= 3); // Create the matrix of terms. The first column is x_i^0 (1), second // column is x_i^1 (x), third is x_i^2, etc. gsl_matrix* X = gsl_matrix_alloc(series.size(), term); gsl_vector* y = gsl_vector_alloc(series.size()); for (int i = 0; i < series.size(); ++i) { gsl_vector_set( y, i, series.at(i)); for (int j = 0; j < term; ++j) { if ( j < 2 ) { // Don't use the first two terms in the fitting gsl_matrix_set(X, i, j, 0); } else { gsl_matrix_set(X, i, j, pow(m_timeStep * i, j)); } } } // Co-variance matrix gsl_matrix * cov = gsl_matrix_alloc(term, term); // Coefficients gsl_vector * c = gsl_vector_alloc(term); // Fit the data series gsl_multifit_linear_workspace * work = gsl_multifit_linear_alloc(series.size(), term); double chisq = 0; gsl_multifit_linear(X, y, c, cov, &chisq, work); // Copy coefficients over to m_coeffs QVector<double> coeffs(term); for ( int i = 0; i < term; ++i ) coeffs[i] = gsl_vector_get(c, i); // Clear the variables gsl_matrix_free(X); gsl_vector_free(y); gsl_vector_free(c); gsl_matrix_free(cov); gsl_multifit_linear_free (work); return coeffs; }
/** * @brief Compute the projection for the linear advection equation. * * @param inarray Given fields. * @param outarray Calculated solution. * @param time Time. */ void UnsteadyAdvection::DoOdeProjection( const Array<OneD, const Array<OneD, NekDouble> >&inarray, Array<OneD, Array<OneD, NekDouble> >&outarray, const NekDouble time) { // Counter variable int i; // Number of fields (variables of the problem) int nVariables = inarray.num_elements(); // Set the boundary conditions SetBoundaryConditions(time); // Switch on the projection type (Discontinuous or Continuous) switch(m_projectionType) { // Discontinuous projection case MultiRegions::eDiscontinuous: { // Number of quadrature points int nQuadraturePts = GetNpoints(); // Just copy over array for(i = 0; i < nVariables; ++i) { Vmath::Vcopy(nQuadraturePts, inarray[i], 1, outarray[i], 1); } break; } // Continuous projection case MultiRegions::eGalerkin: case MultiRegions::eMixed_CG_Discontinuous: { Array<OneD, NekDouble> coeffs(m_fields[0]->GetNcoeffs(),0.0); for(i = 0; i < nVariables; ++i) { m_fields[i]->FwdTrans(inarray[i], coeffs); m_fields[i]->BwdTrans_IterPerExp(coeffs, outarray[i]); } break; } default: ASSERTL0(false,"Unknown projection scheme"); break; } }
Foam::fanFvPatchField<Foam::scalar>::fanFvPatchField ( const fvPatch& p, const DimensionedField<scalar, volMesh>& iF, const dictionary& dict ) : uniformJumpFvPatchField<scalar>(p, iF), phiName_(dict.lookupOrDefault<word>("phi", "phi")), rhoName_(dict.lookupOrDefault<word>("rho", "rho")) { if (this->cyclicPatch().owner()) { if (dict.found("f")) { // Backwards compatibility Istream& is = dict.lookup("f"); is.format(IOstream::ASCII); scalarList f(is); label nPows = 0; forAll(f, powI) { if (mag(f[powI]) > VSMALL) { nPows++; } } List<Tuple2<scalar, scalar> > coeffs(nPows); nPows = 0; forAll(f, powI) { if (mag(f[powI]) > VSMALL) { coeffs[nPows++] = Tuple2<scalar, scalar>(f[powI], powI); } } this->jumpTable_.reset ( new PolynomialEntry<scalar>("jumpTable", coeffs) ); } else { // Generic input constructed from dictionary this->jumpTable_ = DataEntry<scalar>::New("jumpTable", dict);
void read_blottner_data_ascii( MixtureViscosity<BlottnerViscosity<NumericType>,NumericType >& mu, const std::string &filename ) { std::ifstream in(filename.c_str()); if(!in.is_open()) { std::cerr << "ERROR: unable to load file " << filename << std::endl; antioch_error(); } // skip the header skip_comment_lines(in, '#'); std::string name; NumericType a, b, c; while (in.good()) { in >> name; // Species Name in >> a; // in >> b; // in >> c; // // If we are still good, we have a valid set of transport // data for this species. Otherwise, we read past end-of-file // in the section above if (in.good()) { const ChemicalMixture<NumericType>& chem_mixture = mu.chemical_mixture(); // Check if this is a species we want. if( chem_mixture.species_name_map().find(name) != chem_mixture.species_name_map().end() ) { // Pack up coefficients std::vector<NumericType> coeffs(3); coeffs[0] = a; coeffs[1] = b; coeffs[2] = c; mu.add(name, coeffs); } } } in.close(); return; }
/** * Return the coefficients for DIAG_VEC (vector to diagonal matrix): a * N^2 by N matrix where each column I has a 1 in row I * N + I * corresponding to the diagonal entry and 0 otherwise. * * Parameters: linOp of type DIAG_VEC * * Returns: vector containing coefficient matrix COEFFS * */ std::vector<Matrix> get_diag_vec_mat(LinOp &lin) { assert(lin.type == DIAG_VEC); int rows = lin.size[0]; Matrix coeffs(rows * rows, rows); std::vector<Triplet> tripletList; tripletList.reserve(rows); for (int i = 0; i < rows; i++) { // index in the diagonal matrix int row_idx = i * rows + i; //index in the original vector int col_idx = i; tripletList.push_back(Triplet(row_idx, col_idx, 1.0)); } coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
/** * Create a stat mech based property solver for a species * @deprecated */ static StatMech* newStatMechThermoFromXML(const std::string& speciesName, XML_Node& f) { doublereal tmin = fpValue(f["Tmin"]); doublereal tmax = fpValue(f["Tmax"]); doublereal pref = OneAtm; if (f.hasAttrib("P0")) { pref = fpValue(f["P0"]); } if (f.hasAttrib("Pref")) { pref = fpValue(f["Pref"]); } // set properties tmin = 0.1; vector_fp coeffs(1); coeffs[0] = 0.0; return new StatMech(0, tmin, tmax, pref, &coeffs[0], speciesName); }
/** * Return the coefficients for MUL_ELEM: an N x N diagonal matrix where the * n-th element on the diagonal corresponds to the element n = j*rows + i in * the data matrix CONSTANT. * * Parameters: linOp of type MUL_ELEM * * Returns: vector containing the coefficient matrix COEFFS * */ std::vector<Matrix> get_mul_elemwise_mat(LinOp &lin) { assert(lin.type == MUL_ELEM); Matrix constant = get_constant_data(lin, true); int n = constant.rows(); // build a giant diagonal matrix std::vector<Triplet> tripletList; tripletList.reserve(n); for ( int k = 0; k < constant.outerSize(); ++k ) { for ( Matrix::InnerIterator it(constant, k); it; ++it ) { tripletList.push_back(Triplet(it.row(), it.row(), it.value())); } } Matrix coeffs(n, n); coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
void LinearConstraint::addToSpace() const { int size = _varsIDs->size(); // vars is an array of the IntVar instances implicated in the constraint IntVarArgs vars(size); // coeffs is an array of integer coefficients for the variables IntArgs coeffs(size); for (int i=0; i<size; i++) { IntegerVariable *iv = _solver->varFromID(_varsIDs->at(i)); vars[i] = _solver->getSpace()->getIntVar(iv->getTotalIndex()); coeffs[i] = _varsCoeffs->at(i); } //TODO: avant "Gecode::linear((Space*)_solver->getSpace(), coeffs, vars, _relType, _val);" Gecode::linear(*(Space*)_solver->getSpace(), coeffs, vars, _relType, _val); }
/** * Return the coefficients for TRANSPOSE: a ROWS*COLS by ROWS*COLS matrix * such that element ij in the vectorized matrix is mapped to ji after * multiplication (i.e. entry (rows * j + i, i * cols + j) = 1 and else 0) * * Parameters: linOp of type TRANSPOSE * * Returns: vector containing coefficient matrix COEFFS * */ std::vector<Matrix> get_transpose_mat(LinOp &lin) { assert(lin.type == TRANSPOSE); int rows = lin.size[0]; int cols = lin.size[1]; Matrix coeffs(rows * cols, rows * cols); std::vector<Triplet> tripletList; tripletList.reserve(rows * cols); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { int row_idx = rows * j + i; int col_idx = i * cols + j; tripletList.push_back(Triplet(row_idx, col_idx, 1.0)); } } coeffs.setFromTriplets(tripletList.begin(), tripletList.end()); coeffs.makeCompressed(); return build_vector(coeffs); }
std::pair<double, bool > find_param(point2d_t const & p, monomial_form < point2d_t > const & mf ) { std::vector<double> coeffs(mf.size()); auto a = [&mf](int i){ return mf[i][0];}; auto b = [&mf](int i){ return mf[i][1];}; std::vector<double > l0j(mf.size()); for(int j = 0;j < mf.degree(); ++j) { size_t m = j + 1; l0j[j] = (b(m) - b(0)) * p[0] + (a(0) - a(m)) * p[1] + (a(m) * b(0) - b(m) * a(0)); } bspline < double > bzf( ops::to_bezier(monomial_form < double > (l0j, mf.start_param(), mf.end_param()) )); return find_next_rootc(bzf, mf.start_param(), tol::resabs); }
std::vector<complex_t> createSampleCoefficients(const ShapeEnum<D,MultiIndex>& enumeration) { std::vector<complex_t> coeffs(enumeration.n_entries()); real_t norm = 0.0; std::size_t ordinal = 0; for (int islice = 0; islice < enumeration.n_slices(); islice++) { for (auto index : enumeration.slice(islice)) { real_t falloff = 0.1; real_t x = 0.0; real_t y = 0.0; int sum = 0; for (dim_t d = 0; d < D; d++) { x += std::sin(index[d] + 1.0*(d+1)/real_t(D)); y += std::cos(index[d] + 1.5*(d+1)/real_t(D)); sum += index[d]; } x *= std::exp(-falloff*sum); y *= std::exp(-falloff*sum); coeffs[ordinal] = complex_t(x,y); //std::cout << index << ": " << coeffs[ordinal] << std::endl; norm += x*x + y*y; ordinal++; } } //normalize wavepacket for (auto & c : coeffs) c /= norm; return coeffs; }
/*! * Given a collection of points X(I) and a set of values Y(I) which * correspond to some function or measurement at each of the X(I), * subroutine DPOLFT computes the weighted least-squares polynomial * fits of all degrees up to some degree either specified by the user * or determined by the routine. The fits thus obtained are in * orthogonal polynomial form. Subroutine DP1VLU may then be * called to evaluate the fitted polynomials and any of their * derivatives at any point. The subroutine DPCOEF may be used to * express the polynomial fits as powers of (X-C) for any specified * point C. * * @param n The number of data points. * * @param x A set of grid points on which the data is specified. * The array of values of the independent variable. These * values may appear in any order and need not all be * distinct. There are n of them. * * @param y array of corresponding function values. There are n of them * * @param w array of positive values to be used as weights. If * W[0] is negative, DPOLFT will set all the weights * to 1.0, which means unweighted least squares error * will be minimized. To minimize relative error, the * user should set the weights to: W(I) = 1.0/Y(I)**2, * I = 1,...,N . * * @param maxdeg maximum degree to be allowed for polynomial fit. * MAXDEG may be any non-negative integer less than N. * Note -- MAXDEG cannot be equal to N-1 when a * statistical test is to be used for degree selection, * i.e., when input value of EPS is negative. * * @param ndeg output degree of the fit computed. * * @param eps Specifies the criterion to be used in determining * the degree of fit to be computed. * (1) If EPS is input negative, DPOLFT chooses the * degree based on a statistical F test of * significance. One of three possible * significance levels will be used: .01, .05 or * .10. If EPS=-1.0 , the routine will * automatically select one of these levels based * on the number of data points and the maximum * degree to be considered. If EPS is input as * -.01, -.05, or -.10, a significance level of * .01, .05, or .10, respectively, will be used. * (2) If EPS is set to 0., DPOLFT computes the * polynomials of degrees 0 through MAXDEG . * (3) If EPS is input positive, EPS is the RMS * error tolerance which must be satisfied by the * fitted polynomial. DPOLFT will increase the * degree of fit until this criterion is met or * until the maximum degree is reached. * * @param r Output vector containing the first LL+1 Taylor coefficients * where LL=ABS(ndeg). * P(X) = r[0] + r[1]*(X-C) + ... + r[ndeg] * (X-C)**ndeg * ( here C = 0.0) * * @return returns the RMS error of the polynomial of degree ndeg . */ doublereal polyfit(int n, doublereal* x, doublereal* y, doublereal* w, int maxdeg, int& ndeg, doublereal eps, doublereal* r) { integer nn = n; integer mdeg = maxdeg; integer ndg = ndeg; doublereal epss = eps; integer ierr; int worksize = 3*n + 3*maxdeg + 3; vector_fp awork(worksize,0.0); vector_fp coeffs(n+1, 0.0); doublereal zer = 0.0; _DPOLFT_(&nn, x, y, w, &mdeg, &ndg, &epss, &coeffs[0], &ierr, &awork[0]); if (ierr != 1) throw CanteraError("polyfit", "DPOLFT returned error code IERR = " + int2str(ierr) + "while attempting to fit " + int2str(n) + " data points " + "to a polynomial of degree " + int2str(maxdeg)); ndeg = ndg; _DPCOEF_(&ndg, &zer, r, &awork[0]); return epss; }