Beispiel #1
0
static dErr JakoSIAVelocity(VHTCase scase,dReal b,dReal h,dReal dh[2],dReal z,dScalar u[3])
{
  struct VHTRheology *rheo = &scase->rheo;
  const dReal
    p = rheo->pe,
    n = 1 ? 1 : 1./(p-1),
    B = rheo->B0 * pow(2*rheo->gamma0,(n-1)/(2*n)), // reduce to Stress = B |Du|^{1/n}
    A = pow(B,-n);
  const dScalar
    slope = dSqrt(dSqr(dh[0]) + dSqr(dh[1])),
    sliding = 0,
    hmz = z > h ? 0 : (z < b ? h-b : h-z),
    // The strain rate is: Du = A tau^n
    // where: tau = rho*grav*(h-z)*dh
    int_bz = -1. / (n+1) * (pow(hmz,n+1) - pow(h-b,n+1)), // \int_b^z (h-z)^n
    //bstress = rheo->rhoi * dAbs(rheo->gravity[2]) * (h-b) * slope, // diagnostic
    //rstress = dUnitNonDimensionalizeSI(scase->utable.Pressure,1e5),
    siaspeed = sliding + A * pow(rheo->rhoi * dAbs(rheo->gravity[2]) * slope, n) * int_bz, // Integrate strain rate from the bottom
    speed = siaspeed * (5 + 0 * (1 + tanh((z-b)/100))/2);
  u[0] = -speed / slope * dh[0];
  u[1] = -speed / slope * dh[1];
  u[2] = 0; // Would need another derivative to evaluate this and it should not be a big deal for this stationary computation
  //printf("u0 %g  u1 %g  rho %g  grav %g  stress %g  1bar %g  dh[2] %g %g  A %g  B %g;\n",u[0],u[1],rheo->rhoi,rheo->gravity[2],bstress,rstress,dh[0],dh[1],A,B);
  return 0;
}
Beispiel #2
0
// Advection model
static dErr VHTCaseSolution_Wind(VHTCase scase,const dReal x[3],dScalar rhou[],dScalar drhou[],dScalar *p,dScalar dp[],dScalar *E,dScalar dE[])
{                               /* Defines inhomogeneous Dirichlet boundary conditions */
  const dReal L[3] = {0.5*(scase->bbox[0][1] - scase->bbox[0][0]),
                      0.5*(scase->bbox[1][1] - scase->bbox[1][0]),
                      0.5*(scase->bbox[2][1] - scase->bbox[2][0])}; // Each var is in [-L,L]
  const dReal X[3] = {x[0]/L[0],x[1]/L[1],x[2]/L[2]};
  dReal z = (1 + X[2])/2; // in range [0,1]
  dReal depth = 1-z;
  rhou[0] = (1 - dSqr(X[1])) * (1 - pow(depth,2));
  rhou[1] = 0;
  rhou[2] = 0;
  for (dInt i=0; i<9; i++) drhou[i] = 0;
  *p = 0;
  for (dInt i=0; i<3; i++) dp[i] = 0;
  *E = -X[0] * (1 - dSqr(X[1]));
  for (dInt i=0; i<3; i++) dE[i] = 0;
  return 0;
}
Beispiel #3
0
static dErr JakoInternalEnergy_Smooth(VHTCase scase,dReal b,dReal h,const dReal x[],dScalar *e)
{
  struct VHTRheology *rheo = &scase->rheo;
  dReal z,t,T;

  dFunctionBegin;
  z = (x[2] - b) / (h-b); // Normalize to [0,1] plus possible fuzz
  z = dMax(0,dMin(1,z)); // Clip to [0,1]
  t = 90*dSqr(z)*exp(-5*z); // hump with maximum value close to 2
  T = rheo->T3 - (rheo->T3 - rheo->T0)*t; // Maximum value is at the bed and equal to T3, extends past T0
  *e = rheo->c_i * (T - rheo->T0);        // energy/mass
  dFunctionReturn(0);
}
int main(){
	double lightspeed, Newton_G, mass;
	double R_sch; 
	double xp[STEPS], yp[STEPS][NVAR], Ene[STEPS];
	double apo, per, Va, Vp, E, AngMom, Vc, ecc, mjAxis;
	double rIni, vIni, T;
	int i, j, k, loop;
	double y1[NVAR], y[NVAR], Ene1, x1, x2, xbin, xend, delX;
	double eps, h0, hmax;
	inData data;
	void *custom_data = &data;
	int flag, nvar;
	fluxfn fn;
	fluxEn En;
	FILE *fp;
	char *str;
	char str1[] = "result_NT";
	char str2[] = "result_WG";
	char str3[] = "result_SG";
	char str4[] = "result_GN";

// Integration-----------------------------------------------------------
	lightspeed = 10;
	Newton_G = 1;
	mass = 1e6;
	R_sch = 2 * Newton_G * mass / dSqr(lightspeed);

	per = 5.0 * R_sch;
	ecc = 0.998;
	apo = (1 + ecc) / (1 - ecc) * per;
	mjAxis = (per + apo) / 2.0;
	E = -0.5 * Newton_G * mass / mjAxis;
	Va = pow(2 * (E + (Newton_G * mass / apo)), 0.5);
	Vp = pow(2 * (E + (Newton_G * mass / per)), 0.5);

	rIni = apo;
	vIni = Va;
//	rIni = per;
//	vIni = Vp;
	AngMom = rIni * vIni;
	T = 2.0 * PI * pow(mjAxis, 1.5) * pow((Newton_G * mass), -0.5);
	Vc = pow((Newton_G * mass / rIni), 0.5);
	
/*	rIni = 10000.0;
	vIni = 4;
	E = 0.5 * vIni*vIni - (Newton_G * mass / rIni);
	AngMom = rIni * vIni;
	mjAxis = -1.0 * Newton_G * mass / (2 * E);
	ecc = pow((1.0 - dSqr(AngMom) / (Newton_G * mass * mjAxis)), 0.5);
	apo = mjAxis * (1.0 + ecc);
	per = mjAxis * (1.0 - ecc);
	T = 2.0 * PI * pow(mjAxis, 1.5) * pow((Newton_G * mass), -0.5);
	Vc = pow((Newton_G * mass / rIni), 0.5);
*/

for(loop = 1; loop <= 4; loop++){	
	switch (loop){
		case 1:
			fn = F_NT;
			En = E_NT;
			str = &str1[0];
			break;
		case 2:
			fn = F_WG;
			En = E_WG;
			str = &str2[0];
			break;
		case 3:
			fn = F_SG;
			En = E_SG;
			str = &str3[0];
			break;
		case 4:
			fn = F_GN;
			En = E_GN;
			str = &str4[0];
			break;
	}
	printf("%s\n", str);


	x1 = 0;
	x2 = 6.0 * T;
	delX = (x2 - x1) / STEPS;
	eps = 1e-13;
	hmax = delX / HACCU;
	h0 = 1e-10;
	nvar = NVAR;
	data.mass = mass;
	data.lightspeed = lightspeed;
	data.Newton_G = Newton_G;

	for(i = 0; i < NVAR; i++){
		y1[i] = 0;
	}
	y1[1] = -1.0 * rIni;
	y1[2] = vIni;
	for(i = 0; i < NVAR; i++){
		y[i] = y1[i];
	}
	Ene1 = En(nvar, y, custom_data);
// Run--------------------------------------------------------------
	for(i = 0; i < STEPS; i++){
		xbin = x1 + delX * i;
		xend = x1 + delX * (i + 1);
		flag = dopri8(fn, nvar, xbin, y, xend, eps, hmax, &h0, NULL, NULL, custom_data);
		if(flag == 0) printf("!!%d\n", i);
		Ene[i] = En(nvar, y, custom_data);
		for(j = 0; j < NVAR; j++) yp[i][j] = y[j];
		xp[i] = xend;
	}	

	fp = fopen(str,"w+");
	if(fp == NULL)
		printf("Cannot open the file!\n");
	
	fprintf(fp, "%10.6f \t", x1);
	for(j = 0; j < NVAR; j++){
		fprintf(fp, "%20.15f \t", y1[j]);
	}
	fprintf(fp, "%20.15f \n", Ene1);
	for(i = 0; i < STEPS; i++){
		fprintf(fp, "%10.6f \t", xp[i]);
		for(j = 0; j < NVAR; j++){
			fprintf(fp, "%20.15f \t", yp[i][j]);
		}
		fprintf(fp, "%20.15f \n", Ene[i]);
	}
	fclose(fp);
}
	
	printf("END-----------------------------------\n");
	printf("R_sch = %e, Vc = %e\n", R_sch, Vc);
	printf("apo = %e, per = %e, ecc = %e, mjAxis = %e\n", apo, per, ecc, mjAxis);
	printf("Va = %e, Vp = %e\n", Va, Vp);
	printf("Initial quantities:\n");
	printf("rIni = %e, vIni = %e, T = %e\n", rIni, vIni, T);
	printf("E = %e, apo = %e\n", E, apo);
}