Example #1
0
 bool parse(Iterator& f, const Iterator& l, Attribute& a) const {
   if (!container::parse(lhs_, f, l, a))
     return false;
   auto save = f;
   while (rhs_(f, l, unused) && container::parse(lhs_, f, l, a))
     save = f;
   f = save;
   return true;
 }
Example #2
0
/*<       subroutine adv_fe(y, n, t, dt, scratch) >*/
/* Subroutine */ int adv_fe__(doublereal *y, integer *n, doublereal *t, 
	doublereal *dt, doublereal *scratch)
{
    /* System generated locals */
    integer i__1;

    /* Local variables */
    integer i__;
    extern /* Subroutine */ int rhs_(doublereal *, doublereal *, integer *, 
	    doublereal *);

/*<       integer n, i >*/
/*<       real*8 y(n), t, dt, scratch(n) >*/
/*<       call rhs(scratch, y, n, t) >*/
#line 43 "oscillator.f"
    /* Parameter adjustments */
#line 43 "oscillator.f"
    --scratch;
#line 43 "oscillator.f"
    --y;
#line 43 "oscillator.f"

#line 43 "oscillator.f"
    /* Function Body */
#line 43 "oscillator.f"
    rhs_(&scratch[1], &y[1], n, t);
/*     Forward Euler scheme: */
/*<       do 10 i = 1,n >*/
#line 45 "oscillator.f"
    i__1 = *n;
#line 45 "oscillator.f"
    for (i__ = 1; i__ <= i__1; ++i__) {
/*<          y(i) = y(i) + dt*scratch(i) >*/
#line 46 "oscillator.f"
	y[i__] += *dt * scratch[i__];
/*<  10   continue >*/
#line 47 "oscillator.f"
/* L10: */
#line 47 "oscillator.f"
    }
/*<       return >*/
#line 48 "oscillator.f"
    return 0;
/*<       end >*/
} /* adv_fe__ */
Example #3
0
void run_Zmatrices_calculation_scattered_field(Zmatrices& Z_matrices, UINT Lagrange_degree,
	MATRIX M, MATRIX J, GRID& rho, double material_param, const char* result_file)
{
	// Simulation parameters
	int N_T = Z_matrices.z_N_T;
	double dt = Z_matrices.z_dt;
	double c = Z_matrices.z_c;
	UINT inner_points = 1;
	printf("\nSimulation parameters for scattered field:"
		"\n\tNumber of grid vertices = %i"
		"\n\tMaterial parameter = %e"
		"\n\tc = %e"
		"\n\tdt = %e"
		"\n\tN_T = %i"
		"\n\tinner_points = %i"
		"\n\tLagrange_degree = %i\n\n",
		(int)rho.size(), material_param, c, dt, N_T, inner_points, Lagrange_degree);

	// Lagrange interpolators (temporal basis functions)
	CLagrange_interp timeBasis = CLagrange_interp(dt, Lagrange_degree);
	Z_matrices.timeBasis_D = timeBasis;
	CLagrange_interp timeBasis_Ns = timeBasis;
	timeBasis_Ns.diff();
	Z_matrices.timeBasis_Ns = timeBasis_Ns;

	Z_matrices.z_inner_points = inner_points;

	// do main computation
	cube S, D;
#ifdef OS_WIN
	clock_t t;
#else
	struct timeval * t = new struct timeval;
#endif
	start_timing(t);
	Z_matrices.compute_fields(S, D, rho);
	S *= material_param;
	finish_timing(t);

	start_timing(t);
	MATRIX rhs(D.n_rows, N_T, fill::zeros);
	VECTOR rhs_(D.n_rows, fill::zeros);
	printf("%s\n\n", "Marching on in time...");
	int j(0), k(0);
//#pragma omp parallel default(shared) private(j,k)
	for (j = 0; j < N_T; j++)
	{
//#pragma omp for
		for (k = 0; k < j+1; k++)
		{
			rhs_ += D.slice(k)*M.col(j - k) - S.slice(k)*J.col(j - k);
		}

		rhs.col(j) = rhs_;
		rhs_.zeros();

		//Status
		printf("\r%i ", j + 1);
		fflush(stdout);
	}

	finish_timing(t);

	// Output MAT file that stores the operators
	printf("Compressing matrices into Matlab form...");
	mat_t *matfpZ = NULL;
	matvar_t *matvar = NULL;

	// Save matrices as separate matlab variables
	if (CreateMatFile(&matfpZ, result_file) == -1)
	{
		return;
	}
	else
	{
		double NT = (double)N_T;
		InsertVar(&matfpZ, "N_T", &NT);
		InsertMatrix(&matfpZ, "E", rhs);
		FinishMatFile(&matfpZ);

		// free memory
		S.clear(), D.clear();

		printf("\t- done.\nOutput file location: %s\n\n", result_file);
	}
}
Example #4
0
/*<       subroutine adv_rk2(y, n, t, dt, scratch1, scratch2) >*/
/* Subroutine */ int adv_rk2__(doublereal *y, integer *n, doublereal *t, 
	doublereal *dt, doublereal *scratch1, doublereal *scratch2)
{
    /* System generated locals */
    integer i__1;

    /* Local variables */
    integer i__;
    doublereal t2;
    extern /* Subroutine */ int rhs_(doublereal *, doublereal *, integer *, 
	    doublereal *);

/*<       integer n, i >*/
/*<       real*8 y(n), t, dt, scratch1(n), scratch2(n), t2 >*/
/*<       call rhs(scratch1, y, n, t) >*/
#line 55 "oscillator.f"
    /* Parameter adjustments */
#line 55 "oscillator.f"
    --scratch2;
#line 55 "oscillator.f"
    --scratch1;
#line 55 "oscillator.f"
    --y;
#line 55 "oscillator.f"

#line 55 "oscillator.f"
    /* Function Body */
#line 55 "oscillator.f"
    rhs_(&scratch1[1], &y[1], n, t);
/*<       do 10 i = 1,n >*/
#line 56 "oscillator.f"
    i__1 = *n;
#line 56 "oscillator.f"
    for (i__ = 1; i__ <= i__1; ++i__) {
/*<          scratch2(i) = y(i) + dt*scratch1(i) >*/
#line 57 "oscillator.f"
	scratch2[i__] = y[i__] + *dt * scratch1[i__];
/*<  10   continue >*/
#line 58 "oscillator.f"
/* L10: */
#line 58 "oscillator.f"
    }
/*<       t2 = t + dt >*/
#line 59 "oscillator.f"
    t2 = *t + *dt;
/*<       call rhs(scratch2, scratch2, n, t2) >*/
#line 60 "oscillator.f"
    rhs_(&scratch2[1], &scratch2[1], n, &t2);
/*<       do 20 i = 1,n >*/
#line 61 "oscillator.f"
    i__1 = *n;
#line 61 "oscillator.f"
    for (i__ = 1; i__ <= i__1; ++i__) {
/*<          y(i) = y(i) + 0.5*dt*(scratch1(i) + scratch2(i)) >*/
#line 62 "oscillator.f"
	y[i__] += *dt * .5f * (scratch1[i__] + scratch2[i__]);
/*<  20   continue >*/
#line 63 "oscillator.f"
/* L20: */
#line 63 "oscillator.f"
    }
/*<       return >*/
#line 64 "oscillator.f"
    return 0;
/*<       end >*/
} /* adv_rk2__ */
Example #5
0
 constexpr auto operator()(Args... args) const {
   return atan2(lhs_(args...), rhs_(args...));
 }