Esempio n. 1
0
scalar liform_surf(int n, double *wt, Func<scalar> *u_ext[], Func<double> *v, Geom<double> *e, ExtData<scalar> *ext)
{
  cplx ii = cplx(0.0, 1.0);
  scalar result = 0;
  for (int i = 0; i < n; i++) {
    scalar dx[3], dy[3], dz[3];
    scalar3 ev;
    ev[0] = exact(e->x[i], e->y[i], e->z[i], dx, dy, dz)[0];
    ev[1] = exact(e->x[i], e->y[i], e->z[i], dx, dy, dz)[0];
    ev[2] = exact(e->x[i], e->y[i], e->z[i], dx, dy, dz)[0];

    scalar curl_e[3];
    calc_curl(dx, dy, dz, curl_e);
    scalar tpe[3];
    calc_tan_proj(e->nx[i], e->ny[i], e->nz[i], ev, tpe);

    scalar g[3] = {
      (e->nz[i] * curl_e[1] - e->ny[i] * curl_e[2]) - ii * kappa * tpe[0],
      (e->nx[i] * curl_e[2] - e->nz[i] * curl_e[0]) - ii * kappa * tpe[1],
      (e->ny[i] * curl_e[0] - e->nx[i] * curl_e[1]) - ii * kappa * tpe[2],
    };

    // tpv is tangencial projection of v (test function)
    scalar vv[3] = { v->val0[i], v->val1[i], v->val2[i] };
    scalar tpv[3];
    calc_tan_proj(e->nx[i], e->ny[i], e->nz[i], vv, tpv);

    result += wt[i] * (g[0] * tpv[0] + g[1] * tpv[1] + g[2] * tpv[2]);
  }

  return result;
}
Esempio n. 2
0
int main(void)
{
	int n,m;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);
		getchar();
		--m;
		fgets(temp,N,stdin);
		exact();
		strcpy(idf,idt);
		strcpy(idl,idt);
		strcpy(f,ft);
		strcpy(l,lt);
		while(m--){
			fgets(temp,N,stdin);
			exact();
			if(strcmp(ft,f)<0){
				strcpy(idf,idt);
				strcpy(f,ft);
			}
			if(strcmp(lt,l)>0){
				strcpy(idl,idt);
				strcpy(l,lt);
			}
		}
		printf("%s %s\n",idf,idl);
	}
	return 0;
}
Esempio n. 3
0
char *
has_ident(const char *name,
	  char *first,
	  char *last)
{
    char *base;
    char *s, *t, *d, c;

    name = leaf_of(name);

    s = first;
    while ((t = base = strchr(s, '$')) != 0 && (t < last)) {
	t++;
	if ((s = exact(skip_camel(t), "Id")) != 0
	    || (s = exact(t, "Header")) != 0) {
	    if (*s == '$') {
		return base;
	    } else if ((*s == ':')
		       && is_inline(t, '$')) {
		/* RCS identifier can have pathname prepended */
		s = skip_white(s + 1);
		d = skip_text(s);
		c = *d;
		*d = EOS;
		while (is_inline(s, '/'))
		    s++;
		*d = c;
		if ((s = same_name(s, name)) != 0
		    && (s = exact(s, ",v")) != 0
		    && isspace(*s))
		    return base;
	    }
	}
	s = t;
    }

    s = first;
    while ((t = base = strchr(s, '@')) != 0 && (t < last)) {
	t++;
	if ((s = exact(t, "(#)")) != NULL) {
	    t = s;
	    /* some versions of SCCS don't do module-name */
	    if ((s = same_name(t, name)) != NULL)
		return base;

	    t = skip_text(t);	/* module-name, if any */
	    t = skip_white(t);
	    if ((s = same_name(t, name)) != NULL)
		return base;
	}
	s = t;
    }
    return 0;
}
Esempio n. 4
0
void test_multipole(int p=0,std::string qq="No"){
    TestDensity_Hernquist rho(1.,10.,{1.,0.9,0.7});
    TriaxialPotential T(&rho,1e6);
    MultipoleExpansion ME2(&rho,100,30,16,6,1.,0.01,2000.,false,true,true);
    ME2.output_to_file("me.tmp");
    ME2.visualize("me.vis");
    MultipoleExpansion ME("me.tmp");
    VecDoub X = {0.001,0.001,0.01};
    double centre2 = 0.;//T.Phi(X);
    double centre3 = 0.;//ME2.Phi(X);

    int NMAX = 200;
    VecDoub xx(NMAX,0), exact(NMAX,0), triaxial(NMAX,0), multipole(NMAX,0);

    #pragma omp parallel for schedule(dynamic)
    for(int xn = 0; xn<NMAX; xn++){
        double x = (double)xn+1.;
        xx[xn] = x;
        VecDoub X2=X;
        X2[p]=x;
        if(qq=="general"){
            X[0]=x/2.;X[1]=x/3.;X[2]=x/2.;
        }
        triaxial[xn] = (T.Phi(X2)-centre2);
        multipole[xn] = (ME2.Phi(X2)-centre3);
    }

    Gnuplot G("lines ls 1");
    G.set_xrange(0.9*Min(xx),1.1*Max(xx));
    G.set_yrange(0.9*Min(multipole),1.1*Max(multipole));
    G.set_xlabel("x").set_ylabel("Potential");
    G.savetotex("multipole_density_test").plot_xy(xx,triaxial);
    G.set_style("lines ls 3").plot_xy(xx,multipole);
    G.outputpdf("multipole_density_test");
}
Esempio n. 5
0
QString KDBSearchEngine2::translate(const QString text)
{
	ExactSearchAlgorithm exact(di,&settings);

	return exact.exec(text)[0].result();

}
Esempio n. 6
0
int main() {
  typedef TempKernel kernel_type;
  typedef kernel_type::source_type source_type;
  typedef kernel_type::charge_type charge_type;
  typedef kernel_type::target_type target_type;
  typedef kernel_type::result_type result_type;

  kernel_type K;

  // init source
  std::vector<source_type> sources(2);

  // init charge
  std::vector<charge_type> charges(sources.size());

  // init target
  std::vector<target_type> targets(2);

  // init results vectors for exact
  std::vector<result_type> exact(targets.size());

  // test direct
  fmmtl::direct(K, sources, charges, targets, exact);
  std::cout << exact[0] << "\n";
  fmmtl::direct(K, sources, charges, exact);
  std::cout << exact[0] << "\n";
}
Esempio n. 7
0
    // TODO: shortcut number of comparisons
    Interval::IntervalComparison Interval::compare(const Interval& other) const {

        //
        // Intersect cases
        //

        if (intersects(*this, other)) {
            if (exact(*this, other)) {
                return INTERVAL_EQUALS;
            }
            if (within(*this, other)) {
                return INTERVAL_WITHIN;
            }
            if (within(other, *this)) {
                return INTERVAL_CONTAINS;
            }
            if (precedes(*this, other)) {
                    return INTERVAL_OVERLAPS_BEFORE;
            }
            return INTERVAL_OVERLAPS_AFTER;
        }

        //
        // Non-intersect cases
        //

        if (precedes(*this, other)) {
            return INTERVAL_PRECEDES;
        }
        return INTERVAL_SUCCEDS;
    }
Esempio n. 8
0
double MothurFisher::fexact(double n11_, double n12_, double n21_, double n22_, string o)  {
	try {
		sleft = 0.0; sright = 0.0; sless = 0.0; slarg = 0.0;
        otuLabel = o;
		
		if(n11_<0) n11_ *= -1;
		if(n12_<0) n12_ *= -1;
		if(n21_<0) n21_ *= -1;
		if(n22_<0) n22_ *= -1; 
        
		double n1_ = n11_+n12_;
		double n_1 = n11_+n21_;
		double n   = n11_ +n12_ +n21_ +n22_;
        
        if (m->debug) { m->mothurOut("[DEBUG]: fisher:fexact n11_, n1_, n_1, n " + toString(n11_) + " " + toString(n1_) + " " + toString(n_1) + " " + toString(n) + " \n"); }
		exact(n11_,n1_,n_1,n);
		double twotail = sleft+sright;
		
		if(twotail>1) twotail=1;
		double result = twotail;
		return result; 
		
	}catch(exception& e) {
		m->errorOut(e, "MothurFisher", "fexact");
		exit(1);
	}	
}
Esempio n. 9
0
      /**
       * @ingroup VanDerPol
       */
      double run_vdp_sdc(const size_t nsteps, const double dt, const size_t nnodes,
                         const size_t niters, const double nu, const double x0,
                         const double y0, const quadrature::QuadratureType nodetype)
      {
        SDC<> sdc;

        auto quad = quadrature::quadrature_factory(nnodes, nodetype);

        // van der Pol oscillator (as first order system) has two components
        auto factory = make_shared<encap::VectorFactory<double>>(2);
        // input is parameter nu and initial values for position and velocity
        auto sweeper = make_shared<VdpSweeper<>>(nu, x0, y0);

        sweeper->set_quadrature(quad);
        sweeper->set_factory(factory);

        sdc.add_level(sweeper);

        // Final time Tend = dt*nsteps
        sdc.set_duration(0.0, dt*nsteps, dt, niters);
        sdc.setup();

        auto q0 = sweeper->get_start_state();
        sweeper->exact(q0, 0.0);

        sdc.run();

        return sweeper->get_errors();
      }
Esempio n. 10
0
void test_multipole_axisymmetric(int p=0){
    Miyamoto_NagaiDensity rho(1.,1.,0.7);
    MultipoleExpansion_Axisymmetric ME2(&rho,100,30,16,1.,0.01,100.);
    ME2.output_to_file("me.tmp");
    ME2.visualize("me.vis");
    MultipoleExpansion ME("me.tmp");
    VecDoub X = {0.001,0.001,0.01};
    double centre2 = rho.Phi(X);
    double centre3 = ME2.Phi(X);

    int NMAX = 50;
    VecDoub xx(NMAX,0), exact(NMAX,0), triaxial(NMAX,0), multipole(NMAX,0);

    #pragma omp parallel for schedule(dynamic)
    for(int xn = 0; xn<NMAX; xn++){
        double x = 0.1*(double)xn;
        xx[xn] = x;
        VecDoub X2=X;
        X2[p]=x;
        triaxial[xn] = (rho.Phi(X2)-centre2);
        multipole[xn] = (ME2.Phi(X2)-centre3);
    }

    Gnuplot G("lines ls 1");
    G.set_xrange(0.9*Min(xx),1.1*Max(xx));
    G.set_yrange(0.9*Min(multipole),1.1*Max(multipole));
    G.set_xlabel("x").set_ylabel("Potential");
    G.savetotex("multipole_density_test").plot_xy(xx,triaxial);
    G.set_style("lines ls 3").plot_xy(xx,multipole);
    G.outputpdf("multipole_density_test");
}
Esempio n. 11
0
void test_multipole_forces_stackel(int p=0, int q=0,std::string qq="No"){

    TestDensity_Stackel rho(1.,-30.,-10.);
    TriaxialPotential T(&rho,1e8);
    MultipoleExpansion ME(&rho,100,30,16,-1,10.,0.01,100.,false,true,true);
    ME.visualize("me.vis");

    int NMAX = 50;
    VecDoub xx(NMAX,0), exact(NMAX,0), triaxial(NMAX,0), multipole(NMAX,0);

    #pragma omp parallel for schedule(dynamic)
    for(int xn = 0; xn<NMAX; xn++){
        double x = (double)xn+.1;
        xx[xn] = x;
        VecDoub X(3,1);
        X[p]=x;
        if(qq=="general"){
            X[0]=x/2.;X[1]=x/3.;X[2]=x;
        }
        exact[xn] = rho.Forces(X)[q];
        triaxial[xn] = T.Forces(X)[q];
        multipole[xn] = ME.Forces(X)[q];
    }

    Gnuplot G("lines ls 1");
    G.set_xrange(0.9*Min(xx),1.1*Max(xx));
    G.set_yrange(0.9*Min(exact),1.1*Max(exact));
    G.set_xlabel("x").set_ylabel("Potential");
    G.savetotex("multipole_density_test").plot_xy(xx,exact);
    G.set_style("lines ls 2").plot_xy(xx,triaxial);
    G.set_style("lines ls 3").plot_xy(xx,multipole);
    G.outputpdf("multipole_density_test");
}
Esempio n. 12
0
void test_multipole_spherical(int p=0){
    TestDensity_Hernquist rho(1.,1.,{1.,1.,1.});
    MultipoleExpansion_Spherical ME(&rho,100,1.,0.01,200.);
    VecDoub X = {1e-5,1e-5,1e-5};
    double centre2 = rho.Phi(X);
    double centre3 = ME.Phi(X);

    int NMAX = 200;
    VecDoub xx(NMAX,0), exact(NMAX,0), triaxial(NMAX,0), multipole(NMAX,0);

    // #pragma omp parallel for schedule(dynamic)
    for(int xn = 0; xn<NMAX; xn++){
        double x = 0.0001*(double)xn+.0001;
        xx[xn] = x;
        VecDoub X2 = X;
        X2[p]=x;
        exact[xn] = rho.Phi(X2);
        multipole[xn] = ME.Phi(X2);
    }

    Gnuplot G("lines ls 1");
    G.set_xrange(0.9*Min(xx),1.1*Max(xx));
    G.set_yrange(0.9*Min(multipole),1.1*Max(multipole));
    G.set_xlabel("x").set_ylabel("Potential");
    G.savetotex("multipole_density_test").plot_xy(xx,exact);
    G.set_style("lines ls 3").plot_xy(xx,multipole);
    G.outputpdf("multipole_density_test");
}
Esempio n. 13
0
int main(int argc, char **argv)
{
  int numBodies = 1000;
  bool checkErrors = true;

  // Parse custom command line args
  for (int i = 1; i < argc; ++i) {
    if (strcmp(argv[i],"-N") == 0) {
      i++;
      numBodies = atoi(argv[i]);
    } else if (strcmp(argv[i],"-nocheck") == 0) {
      checkErrors = false;
    }
  }

  // Init the FMM Kernel and options
  FMMOptions opts = get_options(argc, argv);
  typedef UnitKernel kernel_type;
  kernel_type K;

  typedef kernel_type::point_type point_type;
  typedef kernel_type::source_type source_type;
  typedef kernel_type::target_type target_type;
  typedef kernel_type::charge_type charge_type;
  typedef kernel_type::result_type result_type;

  // Init points and charges
  std::vector<source_type> points(numBodies);
  for (int k = 0; k < numBodies; ++k)
    points[k] = source_type(drand(), drand(), drand());

  std::vector<charge_type> charges(numBodies);
  for (int k = 0; k < numBodies; ++k)
    charges[k] = drand();

  // Build the FMM
  //fmm_plan plan = fmm_plan(K, bodies, opts);
  FMM_plan<kernel_type> plan = FMM_plan<kernel_type>(K, points, opts);

  // Execute the FMM
  //fmm_execute(plan, charges, target_points);
  std::vector<result_type> result = plan.execute(charges);

  // Check the result
  if (checkErrors) {
    std::vector<result_type> exact(numBodies);

    // Compute the result with a direct matrix-vector multiplication
    Direct::matvec(K, points, charges, exact);

    int wrong_results = 0;
    for (unsigned k = 0; k < result.size(); ++k) {
      printf("[%03d] exact: %lg, FMM: %lg\n", k, exact[k], result[k]);

      if ((exact[k] - result[k]) / exact[k] > 1e-13)
        ++wrong_results;
    }
    printf("Wrong counts: %d\n", wrong_results);
  }
}
Esempio n. 14
0
int main(int argc, char **argv)
{
  int N = 10000;
  bool checkErrors = true;

  // Parse custom command line args
  for (int i = 1; i < argc; ++i) {
    if (strcmp(argv[i],"-N") == 0) {
      N = atoi(argv[++i]);
    } else if (strcmp(argv[i],"-nocheck") == 0) {
      checkErrors = false;
    }
  }

  // Init the FMM Kernel and options
  FMMOptions opts = get_options(argc, argv);
  //typedef UnitExpansion kernel_type;
  typedef ExpExpansion kernel_type;
  kernel_type K;

  typedef kernel_type::point_type point_type;
  typedef kernel_type::source_type source_type;
  typedef kernel_type::target_type target_type;
  typedef kernel_type::charge_type charge_type;
  typedef kernel_type::result_type result_type;

  // Init points and charges
  std::vector<source_type> points = fmmtl::random_n(N);
  std::vector<charge_type> charges = fmmtl::random_n(N);

  // Build the FMM
  //fmmtl::kernel_matrix<kernel_type> A = fmmtl::make_matrix(K, points);
  fmmtl::kernel_matrix<kernel_type> A = K(points, points);
  A.set_options(opts);

  // Execute the FMM
  std::vector<result_type> result = A * charges;

  // Check the result
  if (checkErrors) {
    std::cout << "Computing direct matvec..." << std::endl;

    std::vector<result_type> exact(N);

    // Compute the result with a direct matrix-vector multiplication
    fmmtl::direct(K, points, charges, exact);

    int wrong_results = 0;
    for (unsigned k = 0; k < result.size(); ++k) {
      if ((exact[k] - result[k]) / (exact[k]) > 1e-13) {
        std::cout << "[" << std::setw(log10(N)+1) << k << "]"
                  << " Exact: " << exact[k]
                  << ", FMM: " << result[k] << std::endl;
        std::cout << (exact[k] - result[k]) / (exact[k]) << std::endl;
        ++wrong_results;
      }
    }
    std::cout << "Wrong counts: " << wrong_results << " of " << N << std::endl;
  }
}
Esempio n. 15
0
    // TODO: shortcut number of comparisons
    Interval::IntervalComparison Interval::compare(const Interval& other) const {
        //
        // Intersect cases
        //

        // TODO: rewrite this to be member functions so semantics are clearer.
        if (intersects(*this, other)) {
            if (exact(*this, other)) {
                return INTERVAL_EQUALS;
            }
            if (within(*this, other)) {
                return INTERVAL_WITHIN;
            }
            if (within(other, *this)) {
                return INTERVAL_CONTAINS;
            }
            if (precedes(*this, other)) {
                return INTERVAL_OVERLAPS_BEFORE;
            }
            return INTERVAL_OVERLAPS_AFTER;
        }

        //
        // Non-intersect cases
        //

        if (precedes(*this, other)) {
            if (0 == end.woCompare(other.start, false)) {
                return INTERVAL_PRECEDES_COULD_UNION;
            }
            return INTERVAL_PRECEDES;
        }

        return INTERVAL_SUCCEEDS;
    }
Esempio n. 16
0
      /**
       * Advection/diffusion example using an encapsulated IMEX sweeper.
       *
       * This example uses a vanilla SDC sweeper.
       *
       * @ingroup AdvectionDiffusion
       */
      error_map run_vanilla_sdc(double abs_residual_tol, double rel_residual_tol=0.0)
      {
        SDC<> sdc;

        auto const nnodes = config::get_value<size_t>("num_nodes", 3);
        auto const ndofs  = config::get_value<size_t>("spatial_dofs", 64);
        auto const quad_type = \
          config::get_value<quadrature::QuadratureType>("nodes_type", quadrature::QuadratureType::GaussLegendre);

        auto quad    = quadrature::quadrature_factory(nnodes, quad_type);
        auto factory = make_shared<encap::VectorFactory<double>>(ndofs);
        auto sweeper = make_shared<AdvectionDiffusionSweeper<>>(ndofs);

        sweeper->set_quadrature(quad);
        sweeper->set_factory(factory);
        sweeper->set_residual_tolerances(abs_residual_tol, rel_residual_tol);

        sdc.add_level(sweeper);
        sdc.set_duration(0.0, 4*0.01, 0.01, 4);
        sdc.set_options();
        sdc.setup();

        auto q0 = sweeper->get_start_state();
        sweeper->exact(q0, 0.0);

        sdc.run();

        fftw_cleanup();

        return sweeper->get_errors();
      }
Esempio n. 17
0
void test_multipole_forces(int p=0, int q=0, std::string qq = "No"){
    TestDensity_Hernquist rho(1.,10.,{1.,0.6,0.3});
    // TestDensity_Isochrone rho(1.,10.,{1.,0.9,0.7});
    TriaxialPotential T(&rho,1e6);
    MultipoleExpansion ME(&rho,200,20,8,-1,10.,0.001,5000.,false,true,true);

    int NMAX = 100;
    VecDoub xx(NMAX,0), exact(NMAX,0), multipole(NMAX,0), triaxial(NMAX,0);

    // #pragma omp parallel for schedule(dynamic)
    for(int xn = 0; xn<NMAX; xn++){
        double x = 0.01*(double)xn+1e-3;
        xx[xn] = x;
        VecDoub X(3,1e-4);
        X[p]=x;
        if(qq=="general"){
            X[0]=x/2.;X[1]=x;X[2]=x/4.;
        }
        exact[xn] = rho.Forces(X)[q];
        triaxial[xn] = T.Forces(X)[q];
        multipole[xn] = ME.Forces(X)[q];
    }

    Gnuplot G("lines ls 1");
    G.set_xrange(0.9*Min(xx),1.1*Max(xx));
    G.set_yrange(1.1*Min(exact),1e-6);
    G.set_xlabel("x").set_ylabel("Force");
    G.savetotex("multipole_density_test").plot_xy(xx,multipole);
    G.set_style("lines ls 3").plot_xy(xx,triaxial);
    G.outputpdf("multipole_density_test");
}
double l1_error ( int n, double x[], double u[], double exact ( double x ) )

/******************************************************************************/
/*
  Purpose:

    L1_ERROR estimates the l1 error norm of a finite element solution.

  Discussion:

    We assume the finite element method has been used, over an interval [A,B]
    involving N nodes.

    The coefficients U(1:N) have been computed, and a formula for the
    exact solution is known.

    This function estimates the little l1 norm of the error:
      L1_NORM = sum ( 1 <= I <= N ) abs ( U(i) - EXACT(X(i)) )

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    14 June 2014

  Author:

    John Burkardt

  Parameters:

    Input, int N, the number of nodes.

    Input, double X[N], the mesh points.

    Input, double U[N], the finite element coefficients.

    Input, function EQ = EXACT ( X ), returns the value of the exact
    solution at the point X.

    Output, double L1_ERROR, the little l1 norm of the error.
*/
{
  int i;
  double e1;

  e1 = 0.0;

  for ( i = 0; i < n; i++ )
  {
    e1 = e1 + fabs ( u[i] - exact ( x[i] ) );
  }

  e1 = e1 / ( double ) n;

  return e1;
}
Esempio n. 19
0
WebString BooleanConstraint::toString() const {
  StringBuilder builder;
  builder.append('{');
  maybeEmitNamedBoolean(builder, m_hasExact, "exact", exact());
  maybeEmitNamedBoolean(builder, m_hasIdeal, "ideal", ideal());
  builder.append('}');
  return builder.toString();
}
Esempio n. 20
0
void reduce(sample& r1) {
    int s1 = exact(abs(r1.pp), r1.qq);
    r1.pp = r1.pp/s1;
    r1.qq = r1.qq/s1;
    if(r1.qq < 0) {
         r1.pp= -r1.pp;
         r1.qq= -r1.qq;
    }
}
Esempio n. 21
0
int main( int argc, char * argv[] )
{
        const char* s1 = "1234567890b1234567890";
        const char* s2 = "abcdefghijklmnop";
        const char* s3 = "13579";

        int r = substr( s1, s2 );
        fprintf( stderr, "Result: %d\n", r );

        r = substr( s1, s3);
        fprintf( stderr, "Result: %d\n", r );

        r = exact( s3, s3);
        fprintf( stderr, "Result: %d\n", r );

        r = exact( s1, s2);
        fprintf( stderr, "Result: %d\n", r );

        return 0;
}
Esempio n. 22
0
int MtxLP::Simplex(bool presolve){
    int rv;
    glp_smcp parm;
    init_smcp(&parm);
    parm.presolve = presolve;
    parm.msg_lev = msg_lev;
    parm.it_lim = it_lim;
    parm.tm_lim = tm_lim;
    rv = simplex(&parm);
    if (kind == EXACT)
        rv = exact(&parm);
    return rv;
}
void run_test(const Opm::ParameterGroup& param)
{
    int N=4;
    auto mat = createLaplacian(N);
    std::vector<double> x(N*N), b(N*N);
    createRandomVectors(100*100, x, b, *mat);
    std::vector<double> exact(x);
    std::fill(x.begin(), x.end(), 0.0);
    Opm::LinearSolverFactory ls(param);
    ls.solve(N*N, mat->data.size(), &(mat->rowStart[0]),
             &(mat->colIndex[0]), &(mat->data[0]), &(b[0]),
             &(x[0]));
}
Esempio n. 24
0
 virtual void report(StringBuffer &out)
 {
     unsigned __int64 d = distinct();
     out.append("<Field name=\"").append(fieldname).append("\"");
     if (exact())
     {
         out.append(" distinct=\"").append(d).append("\">\n");
         reportValues(out);
         out.append("</Field>\n");
     }
     else
         out.append(" estimate=\"").append(d).append("\"/>\n");
 }
void run_test(const Opm::parameter::ParameterGroup& param)
{
    int N=100;
    int procs, rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &procs);
    int n = N/procs; // number of unknowns per process
    int bigger = N%procs; // number of process with n+1 unknows


    int start, end, istart, iend;
    // Compute owner region
    if(rank<bigger) {
        start = rank*(n+1);
        end   = start+(n+1);
    }else{
        start = bigger*(n+1) + (rank-bigger) * n;
        end   = start+n;
    }
    // Compute owner region
    if(rank<bigger) {
        istart = rank*(n+1);
        iend   = start+(n+1);
    }else{
        istart = bigger*(n+1) + (rank-bigger) * n;
        iend   = start+n;
    }

    // Compute overlap region
    if(istart>0)
        start = istart - 1;
    else
        start = istart;
    
    if(iend<N)
        end = iend + 1;
    else
        end = iend;

    Opm::ParallelISTLInformation comm(MPI_COMM_WORLD);
    auto mat = create1DLaplacian(*comm.indexSet(), N, start, end, istart, iend);
    std::vector<double> x(end-start), b(end-start);
    createRandomVectors(comm, end-start, x, b, *mat);
    std::vector<double> exact(x);
    std::fill(x.begin(), x.end(), 0.0);
    Opm::LinearSolverFactory ls(param);
    boost::any anyComm(comm);
    ls.solve(b.size(), mat->data.size(), &(mat->rowStart[0]),
             &(mat->colIndex[0]), &(mat->data[0]), &(b[0]),
             &(x[0]), anyComm);
}
Esempio n. 26
0
//---------------------------------------------------------------------
// set the boundary values of dependent variables
//---------------------------------------------------------------------
void setbv()
{
    //---------------------------------------------------------------------
    // local variables
    //---------------------------------------------------------------------
    int i, j, k, m;
    double temp1[5], temp2[5];

    //---------------------------------------------------------------------
    // set the dependent variable values along the top and bottom faces
    //---------------------------------------------------------------------
    #pragma omp parallel default(shared) private(i,j,k,m,temp1,temp2) \
    shared(nx,ny,nz)
    {
        #pragma omp for schedule(static)
        for (j = 0; j < ny; j++) {
            for (i = 0; i < nx; i++) {
                exact( i, j, 0, temp1 );
                exact( i, j, nz-1, temp2 );
                for (m = 0; m < 5; m++) {
                    u[0][j][i][m] = temp1[m];
                    u[nz-1][j][i][m] = temp2[m];
                }
            }
        }

        //---------------------------------------------------------------------
        // set the dependent variable values along north and south faces
        //---------------------------------------------------------------------
        #pragma omp for schedule(static) nowait
        for (k = 0; k < nz; k++) {
            for (i = 0; i < nx; i++) {
                exact( i, 0, k, temp1 );
                exact( i, ny-1, k, temp2 );
                for (m = 0; m < 5; m++) {
                    u[k][0][i][m] = temp1[m];
                    u[k][ny-1][i][m] = temp2[m];
                }
            }
        }

        //---------------------------------------------------------------------
        // set the dependent variable values along east and west faces
        //---------------------------------------------------------------------
        #pragma omp for schedule(static) nowait
        for (k = 0; k < nz; k++) {
            for (j = 0; j < ny; j++) {
                exact( 0, j, k, temp1 );
                exact( nx-1, j, k, temp2 );
                for (m = 0; m < 5; m++) {
                    u[k][j][0][m] = temp1[m];
                    u[k][j][nx-1][m] = temp2[m];
                }
            }
        }
    } //end parallel
}
inline T l2_norm(
    array3d<T, layout_left> const& u
  , Exact&& exact
    ) noexcept
{ // {{{
    auto const nx = u.nx();
    auto const ny = u.ny();
    auto const nz = u.nz();

    T l2 = 0.0;

    TSB_ASSUME(0 == (nx % 16)); // Assume unit stride is divisible by 16.

    for (auto j = 0; j < ny; ++j)
        for (auto i = 0; i < nx; ++i)
        {
            T sum = 0.0;

            T const* __restrict__ up = u(i, j, _);

            auto const stride = u.stride_z();

            TSB_ASSUME_ALIGNED_TO_TYPE(up);

            // NOTE: Strided access.
            #pragma simd
            for (auto k = 0; k < nz; ++k)
            {
                auto const ks = k * stride;

                T const abs_term = std::fabs(up[ks] - exact(k));
                sum = sum + abs_term * abs_term;
            }

            T const l2_here = std::sqrt(sum);

            if ((0 == i) && (0 == j))
                // First iteration, so we have nothing to compare against.
                l2 = l2_here;
            else
                // All the columns are the same, so the L2 norm for each
                // column should be the same.
                TSB_ASSUME(fp_equals(l2, l2_here));
        }

    return l2;
} // }}}
void run_test(const Opm::parameter::ParameterGroup& param)
{
    int N=100;
    int start, end, istart, iend;
    std::tie(start,istart,iend,end) = computeRegions(N);
    Opm::ParallelISTLInformation comm(MPI_COMM_WORLD);
    auto mat = create1DLaplacian(*comm.indexSet(), N, start, end, istart, iend);
    std::vector<double> x(end-start), b(end-start);
    createRandomVectors(comm, end-start, x, b, *mat);
    std::vector<double> exact(x);
    std::fill(x.begin(), x.end(), 0.0);
    Opm::LinearSolverFactory ls(param);
    boost::any anyComm(comm);
    ls.solve(b.size(), mat->data.size(), &(mat->rowStart[0]),
             &(mat->colIndex[0]), &(mat->data[0]), &(b[0]),
             &(x[0]), anyComm);
}
int main(int argc, char **argv){
  double y0 = 1;
  double x0 = 0;
  double exact_1 = exact(1);
  printf("#h implicit rk2 rk3 rk4");
  for(unsigned n = 2; n <= (1 << 15); n*=2){
    double h = subdivide(x0, 1, n);
    printf(
      "\n%e %e %e %e %e",
      h,
      rel_abs_diff(implicit_method(&test_function_g, x0, y0, 1, n),exact_1),
      rel_abs_diff(rk_2(&test_function_drv, x0, y0, 1, n),exact_1),
      rel_abs_diff(rk_3(&test_function_drv, x0, y0, 1, n),exact_1),
      rel_abs_diff(rk_4(&test_function_drv, x0, y0, 1, n),exact_1)
    );
  }
  return 0;
}
Esempio n. 30
0
QString KDBSearchEngine2::searchTranslation( const QString text, int & score )
{
	GenericSearchAlgorithm strategy(di,&settings);
	strategy.setMaxResultNumber(1);

	ExactSearchAlgorithm exact(di,&settings);
	AlphaSearchAlgorithm alpha(di,&settings);
	SentenceArchiveSearchAlgorithm sent(di,&settings);

	strategy.addAlgorithm(&exact);
	strategy.addAlgorithm(&alpha);
	strategy.addAlgorithm(&sent);

	QueryResult firstRes=strategy.exec(text)[0];
	score=firstRes.score();
	return firstRes.result();

}