コード例 #1
0
ファイル: meshGEdge.cpp プロジェクト: kevinr2763/gmsh
static void RecursiveIntegration(GEdge *ge, IntPoint *from, IntPoint *to,
                                 double (*f) (GEdge *e, double X),
                                 std::vector<IntPoint> &Points,
                                 double Prec, int *depth)
{
  IntPoint P, p1;

  (*depth)++;

  P.t = 0.5 * (from->t + to->t);
  P.lc = f(ge, P.t);

  double val1 = trapezoidal(from, to);
  double val2 = trapezoidal(from, &P);
  double val3 = trapezoidal(&P, to);
  double err = fabs(val1 - val2 - val3);

  if(((err < Prec) && (*depth > 6)) || (*depth > 25)) {
    p1 = Points.back();
    P.p = p1.p + val2;
    Points.push_back(P);

    p1 = Points.back();
    to->p = p1.p + val3;
    Points.push_back(*to);
  }
  else {
    RecursiveIntegration(ge, from, &P, f, Points, Prec, depth);
    RecursiveIntegration(ge, &P, to, f, Points, Prec, depth);
  }

  (*depth)--;
}
コード例 #2
0
void trapezoidalSquareTest() {
    double tol = 1e-6;
    std::cout << "Trapezoidal Square Test ... ";
    unsigned int N = 5000;
    bool pass = abs(trapezoidal(sqr, -3.0, 4.0, N) - sqrint(-3.0,4.0)) < tol;   
    if(pass) std::cout << "PASS" << std::endl;
    else {
        std::cout << "FAIL" << std::endl;
        std::cout << "expected " << sqrint(-3.0,4.0) << ", but was " << trapezoidal(sqr, -3.0, 4.0, N) << std::endl;
    }
}
コード例 #3
0
ファイル: trap.cpp プロジェクト: wtmcneill/HPC
int main(int argc, char ** argv)
{
	MPI_Init(&argc, &argv);
	int rank, size;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	
	// Arguments...
	const unsigned long int precision = 4e9;
	const double a = 0.0;
	const double b = 10.0;
	
	double start_time = MPI_Wtime();
	
	// compute integral
	double integral = trapezoidal(a,b,precision);	
	
	double end_time = MPI_Wtime();
		
	if( rank == 0)
		std::cout <<  size << " " << integral << " " << end_time - start_time << std::endl << std::endl;
	
	MPI_Finalize();
	
	return 1;
}
コード例 #4
0
ファイル: anfis.c プロジェクト: aguperezpala/2009-famaf-2011
/* Evaluates the specified membership function in the given 'x' value */
static double
eval_MF (MF_t mf, double x)
{
	switch (mf.k) {
	
	case (triang):
		return triangular (mf.p[0], mf.p[1], mf.p[2], x);
		break;
		
	case (trap):
		return trapezoidal (mf.p[0], mf.p[1], mf.p[2], mf.p[3], x);
		break;
		
	case (gauss):
		return gaussian (mf.p[0], mf.p[1], x);
		break;
		
	case (bell):
		return belly (mf.p[0], mf.p[1], mf.p[2], x);
		break;
		
	default:
		fprintf (stderr, "anfis.c: eval_MF: ERROR: unknown MF\n");
		return 0.0;
		break;
	}
}
コード例 #5
0
int main(int argc,char *argv[]) {
  double xstart,xstop,xinc;

  if (argc != 6) {
    fprintf(stderr,"%s <e> <Semi-Major axis> <xstart> <xstop> <xinc>\n",argv[0]);
    exit(1);
  }
  e = atof(argv[1]);
  a = atof(argv[2]);
  xstart = atof(argv[3]);
  xstop = atof(argv[4]);
  xinc = atof(argv[5]);
  printf("Trapezoidal rule:\n");
  trapezoidal(function,xstart,xstop,xinc);
  printf("Simpson's rule:\n");
  simpson(function,xstart,xstop,xinc);
  exit(0);
}
コード例 #6
0
int main() {

// Height of the capillary interface for the grid
CpuPtr_2D height_distribution(nx, ny, 0, true);
computeRandomHeights(0, H, height_distribution);

// Density difference between brine and CO2
float delta_rho = 500;
// Gravitational acceleration
float g = 9.87;
// Non-dimensional constant that scales the strength of the capillary forces
float c_cap = 1.0/6.0;
// Permeability data (In real simulations this will be a table based on rock data, here we use a random distribution )
float k_data[10] = {0.9352, 1.0444, 0.9947, 0.9305, 0.9682, 1.0215, 0.9383, 1.0477, 0.9486, 1.0835};
float k_heights[10] = {10, 20, 25, 100, 155, 193, 205, 245, 267, 300};

//Inside Kernel
// Converting the permeability data into a table of even subintervals in the z-directions
//float k_values[n+1];
//kDistribution(dz, h, k_heights, k_data, k_values);

// MOBILITY
// The mobility is a function of the saturation, which is directly related to the capillary pressure
// Pressure at capillary interface, which is known
float p_ci = 1;
// Table of capillary pressure values for our subintervals along the z-axis ranging from 0 to h
float resolution = 0.01;
int size = 1/resolution + 1;
float p_cap_ref_table[size];
float s_b_ref_table[size];
createReferenceTable(g, H, delta_rho, c_cap, resolution, p_cap_ref_table, s_b_ref_table);

// Set block and grid sizes and initialize gpu pointer
dim3 grid;
dim3 block;
computeGridBlock(dim3& grid, dim3& block, nx, ny, block_x, block_y);

// Allocate and set data on the GPU
GpuPtr_2D Lambda_device(nx, ny, 0, NULL);
GpuPtr_1D k_data_device(10, k_data);
GpuPtr_1D k_heights_device(10, k_heights);
GpuPtr_1D p_cap_ref_table_device(size, p_cap_ref_table);
GpuPtr_1D s_b_ref_table_device(size, s_b_ref_table);

cudaHostAlloc(&args, sizeof(CoarsePermIntegrationKernelArgs), cudaHostAllocWriteCombined);

// Set arguments and run coarse integration kernel
CoarsePermIntegrationArgs coarse_perm_int_args;
setCoarsePermIntegrationArgs(coarse_perm_int_args,\
							Lambda_device.getRawPtr(),\
							k_data_device.getRawPtr(),\
							k_heights_device.getRawPtr(),\
							p_cap_ref_table_device.getRawPtr(),\
							s_b_ref_table_device.getRawPtr(),\
							nx, ny, 0);
callCoarseIntegrationKernel(grid, block, coarse_perm_int_args);

float p_cap_values[n+1];
computeCapillaryPressure(p_ci, g, delta_rho, h, dz, n, p_cap_values);
float s_b_values[n+1];
inverseCapillaryPressure(n, g, h, delta_rho, c_cap, p_cap_values, s_b_values);
printArray(n+1, s_b_values);
// End point mobility lambda'_b, a known quantity
float lambda_end_point = 1;
float lambda_values[n+1];
computeMobility(n, s_b_values, lambda_end_point, lambda_values);

// Multiply permeability values with lambda values
float f_values[n+1];
multiply(n+1, lambda_values, k_values, f_values);

//Numerical integral with trapezoidal
float K = trapezoidal(dz, n, k_values);
float L = trapezoidal(dz, n, f_values)/K;
printf("Value of integral K. %.4f", K);
printf("Value of integral L. %.4f", L);

}