Пример #1
0
// Apply the ABC -- in this case, only to the left side of grid.
void abc(Grid *g) {

  /* simple ABC for left side of grid */
  Ez(0) = Ez(1);

  return;
}
Пример #2
0
/* update magnetic field */
void updateH3(Grid *g) {
  int mm;

  for (mm = 0; mm < SizeX - 1; mm++)
    Hy(mm) = Chyh(mm) * Hy(mm) +          /*@ \label{update3A} @*/
             Chye(mm) * (Ez(mm + 1) - Ez(mm));

  return;
}
Пример #3
0
/* update electric field */
void updateE3(Grid *g) {
  int mm;

  for (mm = 1; mm < SizeX - 1; mm++)
    Ez(mm) = Ceze(mm) * Ez(mm) +      /*@ \label{update3B} @*/
             Cezh(mm) * (Hy(mm) - Hy(mm - 1));

  return;
}
Пример #4
0
void tfsfUpdate(Grid *g){
    /* check if tfsfinit has run */
    if (tfsfBoundary <= 0) {
        fprintf(stderr, "tfsfinit must be called first.\n"
                "Boundary location must be a positive int.\n");
        exit(-1);
    }
    
    char filename[100], base[20]="ezinc";
    FILE *source;

    sprintf(filename, "%s.%d",base,Time);
    source = fopen(filename, "w");
    fprintf(source, "%g\n", ezInc(Time, 0));
    fclose(source);
    
    //corret hy adajcent to tfsf boundary
    
    Hy(tfsfBoundary) -= ezInc(Time, 0.0) * Chye(tfsfBoundary);
    
    // correct ez adjacnet to tfsf boundary
    
    Ez(tfsfBoundary + 1) += ezInc(Time + 0.5, -0.5);
    
    return;
}
Пример #5
0
void snapshot(Grid *g) { /*@ \label{snapTrivB} @*/
  int mm;
  char filename[100];
  FILE *snapshot;

  /* ensure temporal stride set to a reasonable value */
  if (temporalStride<=0) {
    fprintf(stderr,
      "snapshot: snapshotInit must be called before snapshot.\n"
      "          Temporal stride must be set to positive value.\n");
    exit(-1);
  }

  /* get snapshot if temporal conditions met */
  if (Time>=startTime && 
      (Time-startTime)%temporalStride == 0) {
    sprintf(filename,"%s.%d",basename,frame++);
    snapshot=fopen(filename,"w");
    for (mm=startNode; mm <= endNode; mm+=spatialStride)
      fprintf(snapshot,"%g\n",Ez(mm));
    fclose(snapshot);
  }

  return;
}
Пример #6
0
int main()
{
    Grid *g;                             /*@ \label{improved2A} @*/

    ALLOC_1D(g, 1, Grid);       // allocate memory for Grid  /*@ \label{improved2B} @*/
    gridInit2(g);               // initialize the grid      /*@ \label{improved2C} @*/

    ezIncInit(g);               // initialize source function /*@ \label{improved2H} @*/

    /* do time stepping */
    for (Time = 0; Time < MaxTime; Time++) { /*@ \label{improved2D} @*/
        updateH2(g);              // update magnetic field  /*@ \label{improved2E} @*/
        updateE2(g);              // update electric field  /*@ \label{improved2F} @*/
        Ez(0) = ezInc(Time, 0.0); // apply source function  /*@ \label{improved2Z} @*/
        printf("%g\n", Ez(50));   // print output /*@ \label{improved2G} @*/
    } // end of time-stepping

    return 0;
}
Пример #7
0
int main()
{
  Grid *g;                                   /*@ \label{improved1A} @*/
  double imp0 = 377.0; 
  int mm;

  ALLOC_1D(g, 1, Grid);               /*@ \label{improved1F} @*/

  SizeX = 200;    // size of grid           /*@ \label{improved1B} @*/
  MaxTime = 250;  // duration of simulation /*@ \label{improved1E} @*/
  Cdtds = 1.0;    // Courant number (unused)

  ALLOC_1D(g->ez, SizeX, double);            /*@ \label{improved1C} @*/
  ALLOC_1D(g->hy, SizeX, double);            /*@ \label{improved1D} @*/

  /* do time stepping */
  for (Time = 0; Time < MaxTime; Time++) { 

    /* update magnetic field */
    for (mm = 0; mm < SizeX - 1; mm++)           
      Hy(mm) = Hy(mm) + (Ez(mm + 1) - Ez(mm)) / imp0;

    /* update electric field */
    for (mm = 1; mm < SizeX; mm++)
      Ez(mm) = Ez(mm) + (Hy(mm) - Hy(mm - 1)) * imp0;

    /* hardwire a source node */
    Ez(0) = exp(-(Time - 30.0) * (Time - 30.0) / 100.0);

    printf("%g\n", Ez(50));
  } /* end of time-stepping */

  return 0;
}
Пример #8
0
void tfsfUpdate(Grid *g) {
	/* check if tfsfInit() has been called */
	if (tfsfBoundary <= 0) {
		fprintf(stderr,"tfsfUpdate: tfsfInit must be called before tfsfUpdate.\n""Boundary location must be set to positive value.\n");
		exit(-1);
	}

	/* correct Hy adjacent to TFSF boundary */
	Hy(tfsfBoundary) -= ezInc(Time, 0.0) * Chye(tfsfBoundary);

	/* correct Ez adjacent to TFSF boundary */
	Ez(tfsfBoundary + 1) += ezInc(Time + 0.5, -0.5);
	
	return;
}
Пример #9
0
void EzOutputRoutineTM::print() {
	std::ofstream file;
	std::string currentFileName = fileName+"_"+std::to_string(currentTime) + ".txt";
	file.open(currentFileName, std::ofstream::trunc);
	if (!file.is_open()) {
		return;
	}
	grid->Ez.GPUtoCPU();
	float* Ez = grid->Ez.getHostPtr();
	int sizeEz = grid->Ez.getSize();
	#define Ez(M, N) Ez[(M) * (grid->sizeY) + (N)]
	for(int i = 0; i < sizeX*sizeY; i++) {
		int xCoord = firstX+resolutionX*(i/sizeY);
		int yCoord = firstY+resolutionY*(i%sizeY);
		file << xCoord << " " << yCoord << " " << Ez(xCoord, yCoord) << std::endl;
	}
	file.close();
}
Пример #10
0
int main()
{
	Grid *g;
	ALLOC_1D(g, 1, Grid); // allocate memory for Grid
	gridInit(g); // initialize the grid
	ezIncInit(g);
	snapshotInit2d(g); // initialize snapshots

	/* do time stepping */
	for (Time = 0; Time < MaxTime; Time++) {
		updateH2d(g); // update magnetic field
		updateE2d(g); // update electric field
		Ez(SizeX / 2, SizeY / 2) = ezInc(Time, 0.0); // add a source
		snapshot2d(g); // take a snapshot (if appropriate)
	} // end of time-stepping
	
	return 0;

}
Пример #11
0
void snapshot2d(Grid *g) {
	int mm, nn;
	float dim1, dim2, temp;
	char filename[100];
	FILE *out;

	/* ensure temporal stride set to a reasonable value */
	if (temporalStride == -1) {
		return;
	} if (temporalStride < -1) {
		fprintf(stderr,"snapshot2d: snapshotInit2d must be called before snapshot.\n""Temporal stride must be set to positive value.\n");
		exit(-1);
	}

	/* get snapshot if temporal conditions met */
	if (Time >= startTime &&(Time - startTime) % temporalStride == 0) {
		sprintf(filename, "%s.%d", basename, frame++);
		out = fopen(filename, "wb");
		
		/* write dimensions to output file --
		* express dimensions as floats */
		dim1 = (endNodeX - startNodeX) / spatialStrideX + 1;
		dim2 = (endNodeY - startNodeY) / spatialStrideY + 1;
		fwrite(&dim1, sizeof(float), 1, out);
		fwrite(&dim2, sizeof(float), 1, out);

		/* write remaining data */
		for (nn = endNodeY; nn >= startNodeY; nn -= spatialStrideY)
			for (mm = startNodeX; mm <= endNodeX; mm += spatialStrideX) {
				temp = (float)Ez(mm, nn); // store data as a float
				fwrite(&temp, sizeof(float), 1, out); // write the float
			}
		
		fclose(out);
		// close file
	}

	return;
}
Пример #12
0
void Update2D(double *ez, double *hx, double *hy){

	for(int mm = 0; mm < SIZE; mm++){
		for(int nn = 0; nn < SIZE-1; nn++){
			Hx(mm,nn) = Chxh*Hx(mm,nn) -
					Chxe * ( Ez(mm, nn+1) - Ez(mm, nn));
		}
	}

	for(int mm = 0; mm < SIZE-1; mm++){
		for(int nn = 0; nn < SIZE; nn++){
					Hy(mm,nn) = Chyh*Hy(mm,nn)+Chye*( Ez( mm + 1 , nn) - Ez(mm, nn) );
				}
	}
	for(int mm = 0; mm < SIZE-1; mm++){
			for(int nn = 0; nn < SIZE-1; nn++){
				Ez(mm,nn) = Ceze*Ez(mm,nn)+
						Cezh * ( (Hy(mm,nn) - Hy(mm-1,nn))-
								(Hx(mm,nn)-Hx(mm,nn-1)));
			}
		}
}
Пример #13
0
void abc(Grid *g)
{
	int mm, nn;

	//	ABC at left side of grid	
	for (nn = 0; nn < g->sizeY; nn++)
	{
		Ez(0, nn) = coef0 * (Ez(2, nn) + EzLeft(0, 1, nn)) + coef1 * (EzLeft(0, 0, nn) + EzLeft(2, 0, nn) - Ez(1, nn) - EzLeft(1, 1, nn))
			+ coef2 * EzLeft(1, 0, nn) - EzLeft(2, 1, nn);

		/*	Now memorize old fields	*/
		for (mm = 0; mm < 3; mm++)
		{
			EzLeft(mm, 1, nn) = EzLeft(mm, 0, nn);
			EzLeft(mm, 0, nn) = Ez(mm, nn);
		}
	}

	//	ABC at right side of grid	
	for (nn = 0; nn < SizeY; nn++)
	{
		Ez(SizeX - 1, nn) = coef0 * (Ez(SizeX - 3, nn) + EzRight(0, 1, nn)) + coef1 * (EzRight(0, 0, nn) + EzRight(2, 0, nn) - Ez(SizeX - 2, nn) - EzRight(1, 1, nn))
			+ coef2 * EzRight(1, 0, nn) - EzRight(2, 1, nn);

		/*	Now memorize old fields	*/
		for (mm = 0; mm < 3; mm++)
		{
			EzRight(mm, 1, nn) = EzRight(mm, 0, nn);
			EzRight(mm, 0, nn) = Ez(SizeX - 1 - mm, nn);
		}
	}

	//	ABC at bottom of the grid	
	for (mm = 0; mm < g->sizeX; mm++)
	{
		Ez(mm, 0) = coef0 * (Ez(mm, 2) + EzBottom(0, 1, mm)) + coef1 * (EzBottom(0, 0, mm) + EzBottom(2, 0, mm) - Ez(mm, 1) - EzBottom(1, 1, mm))
			+ coef2 * EzBottom(1, 0, mm) - EzBottom(2, 1, mm);

		/*	Now memorize old fields	*/
		for (nn = 0; nn < 3; nn++)
		{
			EzBottom(nn, 1, mm) = EzBottom(nn, 0, mm);
			EzBottom(nn, 0, mm) = Ez(mm, nn);
		}
	}


	//	ABC at the top of the grid	
	for (mm = 0; mm < g->sizeX; mm++)
	{
		Ez(mm, SizeY - 1) = coef0 * (Ez(mm, SizeY - 3) + EzTop(0, 1, mm)) + coef1 * (EzTop(0, 0, mm) + EzTop(2, 0, mm) - Ez(mm, SizeY - 2) - EzTop(1, 1, mm))
			+ coef2 * EzTop(1, 0, mm) - EzTop(2, 1, mm);

		/*	Now memorize old fields	*/
		for (nn = 0; nn < 3; nn++)
		{
			EzTop(nn, 1, mm) = EzTop(nn, 0, mm);
			EzTop(nn, 0, mm) = Ez(mm, SizeY - 1 - nn);
		}
	}

	return;
}
Пример #14
0
double omegaL(double z)   /*Omega_Lambda(Z)*/
{
  return (Omega_Lambda0 / pow( Ez(z) , 2.0 ) );
}
Пример #15
0
double omegaM( double z )   /*Omega_Matter(Z)*/
{
  return ( Omega_Matter0 * pow( ( 1.0 + z ) , 3.0 ) / pow( Ez(z) , 2.0 ) );
}
Пример #16
0
/* function that applies ABC -- called once per time step */
void abc(Grid *g)
{
  int mm, nn, pp;
  
  if (abccoef == 0.0) {
    fprintf(stderr,
	    "abc: abcInit must be called before abc.  Terminating...\n");
    exit(-1);
  }

  /* ABC at "x0" */
  mm = 0;
  for (nn = 0; nn < SizeY - 1; nn++)
    for (pp = 0; pp < SizeZ; pp++) {
      Ey(mm, nn, pp) = Eyx0(nn, pp) +
	abccoef * (Ey(mm + 1, nn, pp) - Ey(mm, nn, pp));
      Eyx0(nn, pp) = Ey(mm + 1, nn, pp);
    }
  for (nn = 0; nn < SizeY; nn++)
    for (pp = 0; pp < SizeZ - 1; pp++) {
      Ez(mm, nn, pp) = Ezx0(nn, pp) +
	abccoef * (Ez(mm + 1, nn, pp) - Ez(mm, nn, pp));
      Ezx0(nn, pp) = Ez(mm + 1, nn, pp);
    }
  
  /* ABC at "x1" */
  mm = SizeX - 1;
  for (nn = 0; nn < SizeY - 1; nn++)
    for (pp = 0; pp < SizeZ; pp++) {
      Ey(mm, nn, pp) = Eyx1(nn, pp) +
	abccoef * (Ey(mm - 1, nn, pp) - Ey(mm, nn, pp));
      Eyx1(nn, pp) = Ey(mm - 1, nn, pp);
    }
  for (nn = 0; nn < SizeY; nn++)
    for (pp = 0; pp < SizeZ - 1; pp++) {
      Ez(mm, nn, pp) = Ezx1(nn, pp) +
	abccoef * (Ez(mm - 1, nn, pp) - Ez(mm, nn, pp));
      Ezx1(nn, pp) = Ez(mm - 1, nn, pp);
    }
  
  /* ABC at "y0" */
  nn = 0;
  for (mm = 0; mm < SizeX - 1; mm++)
    for (pp = 0; pp < SizeZ; pp++) {
      Ex(mm, nn, pp) = Exy0(mm, pp) +
	abccoef * (Ex(mm, nn + 1, pp) - Ex(mm, nn, pp));
      Exy0(mm, pp) = Ex(mm, nn + 1, pp);
    }
  for (mm = 0; mm < SizeX; mm++)
    for (pp = 0; pp < SizeZ - 1; pp++) {
      Ez(mm, nn, pp) = Ezy0(mm, pp) +
	abccoef * (Ez(mm, nn + 1, pp) - Ez(mm, nn, pp));
      Ezy0(mm, pp) = Ez(mm, nn + 1, pp);
    }
  
  /* ABC at "y1" */
  nn = SizeY - 1;
  for (mm = 0; mm < SizeX - 1; mm++)
    for (pp = 0; pp < SizeZ; pp++) {
      Ex(mm, nn, pp) = Exy1(mm, pp) +
	abccoef * (Ex(mm, nn - 1, pp) - Ex(mm, nn, pp));
      Exy1(mm, pp) = Ex(mm, nn - 1, pp);
    }
  for (mm = 0; mm < SizeX; mm++)
    for (pp = 0; pp < SizeZ - 1; pp++) {
      Ez(mm, nn, pp) = Ezy1(mm, pp) +
	abccoef * (Ez(mm, nn - 1, pp) - Ez(mm, nn, pp));
      Ezy1(mm, pp) = Ez(mm, nn - 1, pp);
    }
  
  /* ABC at "z0" (bottom) */
  pp = 0;
  for (mm = 0; mm < SizeX - 1; mm++)
    for (nn = 0; nn < SizeY; nn++) {
      Ex(mm, nn, pp) = Exz0(mm, nn) +
	abccoef * (Ex(mm, nn, pp + 1) - Ex(mm, nn, pp));
      Exz0(mm, nn) = Ex(mm, nn, pp + 1);
    }
  for (mm = 0; mm < SizeX; mm++)
    for (nn = 0; nn < SizeY - 1; nn++) {
      Ey(mm, nn, pp) = Eyz0(mm, nn) +
	abccoef * (Ey(mm, nn, pp + 1) - Ey(mm, nn, pp));
      Eyz0(mm, nn) = Ey(mm, nn, pp + 1);
    }
  
  /* ABC at "z1" (top) */
  pp = SizeZ - 1;
  for (mm = 0; mm < SizeX - 1; mm++)
    for (nn = 0; nn < SizeY; nn++) {
      Ex(mm, nn, pp) = Exz1(mm, nn) +
	abccoef * (Ex(mm, nn, pp - 1) - Ex(mm, nn, pp));
      Exz1(mm, nn) = Ex(mm, nn, pp - 1);
    }
  for (mm = 0; mm < SizeX; mm++)
    for (nn = 0; nn < SizeY - 1; nn++) {
      Ey(mm, nn, pp) = Eyz1(mm, nn) +
	abccoef * (Ey(mm, nn, pp - 1) - Ey(mm, nn, pp));
      Eyz1(mm, nn) = Ey(mm, nn, pp - 1);
    }
  
  return;
}  /* end abc() */
Пример #17
0
/* function which applies ABC -- called once per time step */
void abc_3d()
{
  int m, n, p;

  /* ABC at "x0" */
  m=0;
  for (n=0; n<size_y-1; n++)
    for (p=0; p<size_z; p++) {
      Ey(m,n,p) = Eyx0(n,p) + abccoef*(Ey(m+1,n,p)-Ey(m,n,p));
      Eyx0(n,p) = Ey(m+1,n,p);
    }
  for (n=0; n<size_y; n++)
    for (p=0; p<size_z-1; p++) {
      Ez(m,n,p) = Ezx0(n,p) + abccoef*(Ez(m+1,n,p)-Ez(m,n,p));
      Ezx0(n,p) = Ez(m+1,n,p);
    }
  
  /* ABC at "x1" */
  m=size_x-1;
  for (n=0; n<size_y-1; n++)
    for (p=0; p<size_z; p++) {
      Ey(m,n,p) = Eyx1(n,p) + abccoef*(Ey(m-1,n,p)-Ey(m,n,p));
      Eyx1(n,p) = Ey(m-1,n,p);
    }
  for (n=0; n<size_y; n++)
    for (p=0; p<size_z-1; p++) {
      Ez(m,n,p) = Ezx1(n,p) + abccoef*(Ez(m-1,n,p)-Ez(m,n,p));
      Ezx1(n,p) = Ez(m-1,n,p);
    }
  
  /* ABC at "y0" */
  n=0;
  for (m=0; m<size_x-1; m++)
    for (p=0; p<size_z; p++) {
      Ex(m,n,p) = Exy0(m,p) + abccoef*(Ex(m,n+1,p)-Ex(m,n,p));
      Exy0(m,p) = Ex(m,n+1,p);
    }
  for (m=0; m<size_x; m++)
    for (p=0; p<size_z-1; p++) {
      Ez(m,n,p) = Ezy0(m,p) + abccoef*(Ez(m,n+1,p)-Ez(m,n,p));
      Ezy0(m,p) = Ez(m,n+1,p);
    }

  /* ABC at "y1" */
  n=size_y-1;
  for (m=0; m<size_x-1; m++)
    for (p=0; p<size_z; p++) {
      Ex(m,n,p) = Exy1(m,p) + abccoef*(Ex(m,n-1,p)-Ex(m,n,p));
      Exy1(m,p) = Ex(m,n-1,p);
    }
  for (m=0; m<size_x; m++)
    for (p=0; p<size_z-1; p++) {
      Ez(m,n,p) = Ezy1(m,p) + abccoef*(Ez(m,n-1,p)-Ez(m,n,p));
      Ezy1(m,p) = Ez(m,n-1,p);
    }
  
  /* ABC at "z0" (bottom) */
  p=0;
  for (m=0; m<size_x-1; m++)
    for (n=0; n<size_y; n++) {
      Ex(m,n,p) = Exz0(m,n) + abccoef*(Ex(m,n,p+1)-Ex(m,n,p));
      Exz0(m,n) = Ex(m,n,p+1);
    }
  for (m=0; m<size_x; m++)
    for (n=0; n<size_y-1; n++) {
      Ey(m,n,p) = Eyz0(m,n) + abccoef*(Ey(m,n,p+1)-Ey(m,n,p));
      Eyz0(m,n) = Ey(m,n,p+1);
    }
  
  /* ABC at "z1" (top) */
  p=size_z-1;
  for (m=0; m<size_x-1; m++)
    for (n=0; n<size_y; n++) {
      Ex(m,n,p) = Exz1(m,n) + abccoef*(Ex(m,n,p-1)-Ex(m,n,p));
      Exz1(m,n) = Ex(m,n,p-1);
    }
  for (m=0; m<size_x; m++)
    for (n=0; n<size_y-1; n++) {
      Ey(m,n,p) = Eyz1(m,n) + abccoef*(Ey(m,n,p-1)-Ey(m,n,p));
      Eyz1(m,n) = Ey(m,n,p-1);
    }
  
  return;
} /* end abc_3d() */