[cig-commits] commit: zy smoothing seems to work
Mercurial
hg at geodynamics.org
Fri Feb 10 15:59:58 PST 2012
changeset: 2:c44834c77baa
user: Walter Landry <wlandry at caltech.edu>
date: Thu Aug 04 00:22:36 2011 -0700
files: main.cxx
description:
zy smoothing seems to work
diff -r 49a5cfe71a1e -r c44834c77baa main.cxx
--- a/main.cxx Wed Aug 03 23:57:31 2011 -0700
+++ b/main.cxx Thu Aug 04 00:22:36 2011 -0700
@@ -31,12 +31,13 @@ int main()
{
double x(i*h), y((j+0.5)*h);
- if(i==0 || i==N)
- zx[i][j]=0;
- else
- zx[i][j]=1.2 + 3.4*x + 4.5*y;
+ // if(i==0 || i==N)
+ // zx[i][j]=0;
+ // else
+ // zx[i][j]=1.2 + 3.4*x + 4.5*y;
- // zx[i][j]=0;
+ zx[i][j]=0;
+
fx[i][j]=0;
if(model==Model::solCx)
{
@@ -69,12 +70,17 @@ int main()
if(i<N)
{
double x((i+0.5)*h), y(j*h);
- // zy[i][j]=5.6 + 7.8*x + 9.0*y + 2.1*x*y;
- zy[i][j]=0;
+
+ if(j==0 || j==N)
+ zy[i][j]=0;
+ else
+ zy[i][j]=5.6 + 7.8*x + 9.0*y + 2.1*x*y;
+ // zy[i][j]=0;
if(model==Model::solCx || model==Model::solKz)
{
- fy[i][j]=sin(pi*y)*cos(pi*x);
+ fy[i][j]=0;
+ // fy[i][j]=sin(pi*y)*cos(pi*x);
if(model==Model::solCx)
{
log_etay[i][j]=y*log_max_eta;
@@ -112,129 +118,203 @@ int main()
for(int sweep=0;sweep<n_sweeps;++sweep)
{
+ // for(int rb=0;rb<2;++rb)
+ // {
+ // for(int j=0;j<N;++j)
+ // {
+ // int i_min=(j+rb)%2;
+ // for(int i=i_min;i<N+1;i+=2)
+ // {
+ // if(i==0 || i==N)
+ // {
+ // zx[i][j]=0;
+ // }
+ // else
+ // {
+ // /* Do the finite difference parts */
+
+ // /* Derivatives of z */
+ // double dzx_xx=(zx[i-1][j] - 2*zx[i][j] + zx[i+1][j])/(h*h);
+
+ // double dzy_xy=((zy[i][j+1] - zy[i-1][j+1])
+ // - (zy[i][j] - zy[i-1][j]))/(h*h);
+
+ // double dzx_x=(zx[i+1][j] - zx[i-1][j])/(2*h);
+ // double dzy_y=(zy[i][j+1] - zy[i][j]
+ // + zy[i-1][j+1] - zy[i-1][j])/(2*h);
+
+ // double dzx_y, dzx_yy;
+ // if(j==0)
+ // {
+ // dzx_yy=(-zx[i][j] + zx[i][j+1])/(h*h);
+ // dzx_y=(zx[i][j+1] - zx[i][j])/(2*h);
+ // }
+ // else if(j==N-1)
+ // {
+ // dzx_yy=(zx[i][j-1] - zx[i][j])/(h*h);
+ // dzx_y=(zx[i][j] - zx[i][j-1])/(2*h);
+ // }
+ // else
+ // {
+ // dzx_yy=(zx[i][j-1] - 2*zx[i][j] + zx[i][j+1])/(h*h);
+ // dzx_y=(zx[i][j+1] - zx[i][j-1])/(2*h);
+ // }
+
+ // /* Derivatives of p and eta. Eta is collocated
+ // with z. Maybe eta should be cell & vertex
+ // centered? It would simplify most of these
+ // differences, but it would make dlog_etaxy
+ // more messy. Also, with it collocated with z,
+ // it is easy to compute v=z/eta. */
+
+ // double dp_x=(p[i][j]-p[i-1][j])/h;
+
+ // double dlog_etaxx=
+ // ((log_etay[i][j+1] + log_etay[i][j])/2
+ // - 2*log_etax[i][j]
+ // + (log_etay[i-1][j+1] + log_etay[i-1][j])/2)/(h*h/4);
+ // double dlog_etax=
+ // ((log_etay[i][j+1] + log_etay[i][j])/2
+ // - (log_etay[i-1][j+1] + log_etay[i-1][j])/2)/h;
+
+ // double dlog_etayy=
+ // ((log_etay[i][j+1] + log_etay[i-1][j+1])/2
+ // - 2*log_etax[i][j]
+ // + (log_etay[i][j] + log_etay[i-1][j])/2)/(h*h/4);
+
+ // double dlog_etay=
+ // ((log_etay[i][j+1] + log_etay[i-1][j+1])
+ // - (log_etay[i][j] + log_etay[i-1][j]))/(2*h);
+
+ // double dlog_etaxy=
+ // ((log_etay[i][j+1] - log_etay[i-1][j+1])
+ // - (log_etay[i][j] - log_etay[i-1][j]))/(h*h);
+
+ // const double zy_avg=(zy[i][j] + zy[i-1][j] +
+ // zy[i][j+1] + zy[i-1][j+1])/4;
+
+ // /* Now do the jump conditions */
+
+
+ // /* Compute the residual and update zx */
+
+ // double Rx=2*dzx_xx + dzx_yy + dzy_xy
+ // + 2*(dlog_etaxx*zx[i][j] + dlog_etax*dzx_x)
+ // + dlog_etayy*zx[i][j] + dlog_etay*dzx_y
+ // + dlog_etaxy*zy_avg + dlog_etax*dzy_y
+ // + dp_x - fx[i][j];
+
+ // double dRx_dzx=-6/(h*h) + 2*dlog_etaxx + dlog_etayy;
+
+ // zx[i][j]-=theta_mom*Rx/dRx_dzx;
+ // }
+ // }
+ // }
+ // }
+
+
for(int rb=0;rb<2;++rb)
{
- for(int j=0;j<N;++j)
+ for(int j=0;j<N+1;++j)
{
int i_min=(j+rb)%2;
- for(int i=i_min;i<N+1;i+=2)
+ for(int i=i_min;i<N;i+=2)
{
- if(i==0 || i==N)
+ if(j==0 || j==N)
{
- zx[i][j]=0;
+ zy[i][j]=0;
}
else
{
/* Do the finite difference parts */
/* Derivatives of z */
- double dzx_xx=(zx[i-1][j] - 2*zx[i][j] + zx[i+1][j])/(h*h);
+ double dzy_yy=(zy[i][j-1] - 2*zy[i][j] + zy[i][j+1])/(h*h);
- double dzy_xy=((zy[i][j+1] - zy[i-1][j+1])
- - (zy[i][j] - zy[i-1][j]))/(h*h);
+ double dzx_yx=((zx[i+1][j] - zx[i+1][j-1])
+ - (zx[i][j] - zx[i][j-1]))/(h*h);
- double dzx_x=(zx[i+1][j] - zx[i-1][j])/(2*h);
- double dzy_y=(zy[i][j+1] - zy[i][j]
- + zy[i-1][j+1] - zy[i-1][j])/(2*h);
+ double dzy_y=(zy[i][j+1] - zy[i][j-1])/(2*h);
+ double dzx_x=(zx[i+1][j] - zx[i][j]
+ + zx[i+1][j-1] - zx[i][j-1])/(2*h);
- double dzx_y, dzx_yy;
- if(j==0)
+ double dzy_x, dzy_xx;
+ if(i==0)
{
- dzx_yy=(-zx[i][j] + zx[i][j+1])/(h*h);
- dzx_y=(zx[i][j+1] - zx[i][j])/(2*h);
+ dzy_xx=(-zy[i][j] + zy[i+1][j])/(h*h);
+ dzy_x=(zy[i+1][j] - zy[i][j])/(2*h);
}
- else if(j==N-1)
+ else if(i==N-1)
{
- dzx_yy=(zx[i][j-1] - zx[i][j])/(h*h);
- dzx_y=(zx[i][j] - zx[i][j-1])/(2*h);
+ dzy_xx=(zy[i-1][j] - zy[i][j])/(h*h);
+ dzy_x=(zy[i][j] - zy[i-1][j])/(2*h);
}
else
{
- dzx_yy=(zx[i][j-1] - 2*zx[i][j] + zx[i][j+1])/(h*h);
- dzx_y=(zx[i][j+1] - zx[i][j-1])/(2*h);
+ dzy_xx=(zy[i-1][j] - 2*zy[i][j] + zy[i+1][j])/(h*h);
+ dzy_x=(zy[i+1][j] - zy[i-1][j])/(2*h);
}
/* Derivatives of p and eta. Eta is collocated
- with z. Maybe eta should be cell & vertex
- centered? It would simplify most of these
- differences, but it would make dlog_etaxy
- more messy. Also, with it collocated with z,
- it is easy to compute v=z/eta. */
+ with z. Maxbe eta should be cell & vertey
+ centered? It would simplifx most of these
+ differences, but it would make dlog_etayx
+ more messx. Also, with it collocated with z,
+ it is easx to compute v=z/eta. */
- double dp_x=(p[i][j]-p[i-1][j])/h;
+ double dp_y=(p[i][j]-p[i][j-1])/h;
+
+ double dlog_etayy=
+ ((log_etax[i+1][j] + log_etax[i][j])/2
+ - 2*log_etay[i][j]
+ + (log_etax[i+1][j-1] + log_etax[i][j-1])/2)/(h*h/4);
+ double dlog_etay=
+ ((log_etax[i+1][j] + log_etax[i][j])/2
+ - (log_etax[i+1][j-1] + log_etax[i][j-1])/2)/h;
double dlog_etaxx=
- ((log_etay[i][j+1] + log_etay[i][j])/2
- - 2*log_etax[i][j]
- + (log_etay[i-1][j+1] + log_etay[i-1][j])/2)/(h*h/4);
+ ((log_etax[i+1][j] + log_etax[i+1][j-1])/2
+ - 2*log_etay[i][j]
+ + (log_etax[i][j] + log_etax[i][j-1])/2)/(h*h/4);
+
double dlog_etax=
- ((log_etay[i][j+1] + log_etay[i][j])/2
- - (log_etay[i-1][j+1] + log_etay[i-1][j])/2)/h;
+ ((log_etax[i+1][j] + log_etax[i+1][j-1])
+ - (log_etax[i][j] + log_etax[i][j-1]))/(2*h);
- double dlog_etayy=
- ((log_etay[i][j+1] + log_etay[i-1][j+1])/2
- - 2*log_etax[i][j]
- + (log_etay[i][j] + log_etay[i-1][j])/2)/(h*h/4);
+ double dlog_etayx=
+ ((log_etax[i+1][j] - log_etax[i+1][j-1])
+ - (log_etax[i][j] - log_etax[i][j-1]))/(h*h);
- double dlog_etay=
- ((log_etay[i][j+1] + log_etay[i-1][j+1])
- - (log_etay[i][j] + log_etay[i-1][j]))/(2*h);
-
- double dlog_etaxy=
- ((log_etay[i][j+1] - log_etay[i-1][j+1])
- - (log_etay[i][j] - log_etay[i-1][j]))/(h*h);
-
- const double zy_avg=(zy[i][j] + zy[i-1][j] +
- zy[i][j+1] + zy[i-1][j+1])/4;
+ const double zx_avg=(zx[i][j] + zx[i][j-1] +
+ zx[i+1][j] + zx[i+1][j-1])/4;
/* Now do the jump conditions */
- /* Compute the residual and update zx */
+ /* Compute the residual and update zy */
- double Rx=2*dzx_xx + dzx_yy + dzy_xy
- + 2*(dlog_etaxx*zx[i][j] + dlog_etax*dzx_x)
- + dlog_etayy*zx[i][j] + dlog_etay*dzx_y
- + dlog_etaxy*zy_avg + dlog_etax*dzy_y
- + dp_x - fx[i][j];
+ double Ry=2*dzy_yy + dzy_xx + dzx_yx
+ + 2*(dlog_etayy*zy[i][j] + dlog_etay*dzy_y)
+ + dlog_etaxx*zy[i][j] + dlog_etax*dzy_x
+ + dlog_etayx*zx_avg + dlog_etay*dzx_x
+ + dp_y - fy[i][j];
- double dRx_dzx=-6/(h*h) + 2*dlog_etaxx + dlog_etayy;
+ double dRy_dzy=-6/(h*h) + 2*dlog_etayy + dlog_etaxx;
- zx[i][j]-=theta_mom*Rx/dRx_dzx;
-
- // const double x(i*h), y((j+0.5)*h);
- // std::cout << i << " "
- // << j << " "
- // << x << " "
- // << y << " "
- // // << h << " "
- // << zx[i][j] << " "
- // << dzx_x << " "
- // << dzx_xx << " "
- // << dzx_y << " "
- // << dzx_yy << " "
- // << dzy_y << " "
- // << dzy_xy << " "
-
- // // << log_etax[i][j] << " "
- // // << log_max_eta << " "
- // // << dlog_etax << " "
- // // << dlog_etay << " "
- // // << dlog_etaxx << " "
- // // << dlog_etayy << " "
- // // << dlog_etaxy << " "
- // << "\n";
+ zy[i][j]-=theta_mom*Ry/dRy_dzy;
}
}
}
}
+
+
std::cout << sweep << " "
- << zx[1][1] << " "
- << zx[10][10] << " "
- << zx[32][32] << " "
- << zx[63][63] << " "
+ << zy[1][1] << " "
+ << zy[10][10] << " "
+ << zy[32][32] << " "
+ << zy[63][63] << " "
<< "\n";
}
}
More information about the CIG-COMMITS
mailing list