Exemplo n.º 1
0
void free_preconditioner(struct preconditioner *precon, int id)
{
	if (id == 0) {
		free_3d_array(precon->inverse_mass);
		for (int i = 0; i < precon->nlevels; ++i) {
			free_3d_array(precon->poisson_diag[i]);
			free_3d_array(precon->helmholtz_diag[i]);
			free_3d_array(precon->stiffsum_scale[i]);
			free_3d_array(precon->dirichlet_mask[i]);
		}
	}
	for (int i = 1; i < precon->nlevels; ++i) {
		if (precon->geom[i])
			free_geometry(precon->geom[i]);
		if (precon->sendcounts[i])
			free_int_array(precon->sendcounts[i]);
		if (precon->senddispls[i])
			free_int_array(precon->senddispls[i]);
	}
	for (int i = 1; i < (2 * precon->nlevels - 1); ++i)
		if (precon->basis[i])
			free_basis(precon->basis[i]);
	free_ptr_array(precon->basis, 0, NULL);
	free_ptr_array(precon->geom, 0, NULL);
	free_ptr_array(precon->poisson_diag, 0, NULL);
	free_ptr_array(precon->helmholtz_diag, 0, NULL);
	free_ptr_array(precon->stiffsum_scale, 0, NULL);
	free_ptr_array(precon->dirichlet_mask, 0, NULL);
	free_ptr_array(precon->sendcounts, 0, NULL);
	free_ptr_array(precon->senddispls, 0, NULL);
	free_int_array(precon->nmg);
	free_1d_array(precon->poisson_eigen_max);
	free_1d_array(precon->helmholtz_eigen_max);
	free(precon);
}
Exemplo n.º 2
0
int surfw_res(PROT prot, int ir, float probe_rad)
{ int   i, j, k;

  PROBE_RAD  = probe_rad;       /* get parameters */
  grid_interval = PROBE_RAD + ATOM_RAD;
  num_pts = 122;

  set_vdw_rad(prot, PROBE_RAD);

  /* make the surface for each atom */
  for (j = 0; j < prot.res[ir].n_conf; j++) {
     for (i=0; i<prot.res[ir].n_conf; i++) {
        if (i==j) prot.res[ir].conf[i].on = 1;
        else prot.res[ir].conf[i].on = 0;
     }

     get_pdb_size(prot);
     extend_grid();
     calc_gsize();
     gindex.x = gsize.x - 1;
     gindex.y = gsize.y - 1;
     gindex.z = gsize.z - 1;
     alloc_3d_array(gsize.x, gsize.y, gsize.z);
     fill_grid(prot);

     for (k = 0; k < prot.res[ir].conf[j].n_atom; k++) {
        if (!(prot.res[ir].conf[j].atom[k].on)) continue;
        mkacc(&(prot.res[ir].conf[j].atom[k]));
     }
     free_3d_array(gsize.x, gsize.y, gsize.z);

  }

  /* turn off conformers in this residue */
  for (i=2; i<prot.res[ir].n_conf; i++) prot.res[ir].conf[i].on = 0;
  if (prot.res[ir].n_conf > 1) prot.res[ir].conf[1].on = 1;
  prot.res[ir].conf[0].on = 1;


  reset_atom_rad(prot, PROBE_RAD);

  return 0;

}
Exemplo n.º 3
0
void problem(Grid *pGrid, Domain *pD)
{
  int i, is=pGrid->is, ie = pGrid->ie;
  int j, js=pGrid->js, je = pGrid->je;
  int k, ks=pGrid->ks, ke = pGrid->ke;

  rseed = (pGrid->my_id+1);
  initialize(pGrid, pD);
  tdrive = 0.0;

  /* Initialize uniform density and momenta */
  for (k=ks-nghost; k<=ke+nghost; k++) {
    for (j=js-nghost; j<=je+nghost; j++) {
      for (i=is-nghost; i<=ie+nghost; i++) {
        pGrid->U[k][j][i].d = rhobar;
        pGrid->U[k][j][i].M1 = 0.0;
        pGrid->U[k][j][i].M2 = 0.0;
        pGrid->U[k][j][i].M3 = 0.0;
      }
    }
  }

#ifdef MHD
  /* Initialize uniform magnetic field */
  for (k=ks-nghost; k<=ke+nghost; k++) {
    for (j=js-nghost; j<=je+nghost; j++) {
      for (i=is-nghost; i<=ie+nghost; i++) {
        pGrid->U[k][j][i].B1c  = B0;
        pGrid->U[k][j][i].B2c  = 0.0;
        pGrid->U[k][j][i].B3c  = 0.0;
        pGrid->B1i[k][j][i] = B0;
        pGrid->B2i[k][j][i] = 0.0;
        pGrid->B3i[k][j][i] = 0.0;
      }
    }
  }
#endif /* MHD */

  /* Set the initial perturbations.  Note that we're putting in too much
   * energy this time.  This is okay since we're only interested in the
   * saturated state. */
  generate();
  perturb(pGrid, dtdrive);

  /* If decaying turbulence, no longer need the driving memory */
  if (idrive == 1) {
    ath_pout(0,"De-allocating driving memory.\n");

    /* Free Athena-style arrays */
    free_3d_array(dv1);
    free_3d_array(dv2);
    free_3d_array(dv3);

    /* Free FFTW-style arrays */
    ath_3d_fft_free(fv1);
    ath_3d_fft_free(fv2);
    ath_3d_fft_free(fv3);
  }

  return;
}
Exemplo n.º 4
0
void dump_binary(MeshS *pM, OutputS *pOut)
{
  GridS *pGrid;
  PrimS ***W;
  FILE *p_binfile;
  char *fname,*plev=NULL,*pdom=NULL;
  char levstr[8],domstr[8];
  int n,ndata[7];
/* Upper and Lower bounds on i,j,k for data dump */
  int i,j,k,il,iu,jl,ju,kl,ku,nl,nd;
  Real dat[2],*datax,*datay,*dataz;
  Real *pData,x1,x2,x3;
  int coordsys = -1;

/* Loop over all Domains in Mesh, and output Grid data */

  for (nl=0; nl<(pM->NLevels); nl++){
    for (nd=0; nd<(pM->DomainsPerLevel[nl]); nd++){
      if (pM->Domain[nl][nd].Grid != NULL){

/* write files if domain and level match input, or are not specified (-1) */ 
      if ((pOut->nlevel == -1 || pOut->nlevel == nl) &&
          (pOut->ndomain == -1 || pOut->ndomain == nd)){
        pGrid = pM->Domain[nl][nd].Grid;

        il = pGrid->is, iu = pGrid->ie;
        jl = pGrid->js, ju = pGrid->je;
        kl = pGrid->ks, ku = pGrid->ke;

#ifdef WRITE_GHOST_CELLS
        il = pGrid->is - nghost;
        iu = pGrid->ie + nghost;

        if(pGrid->Nx[1] > 1){
          jl = pGrid->js - nghost;
          ju = pGrid->je + nghost;
        }

        if(pGrid->Nx[2] > 1){
          kl = pGrid->ks - nghost;
          ku = pGrid->ke + nghost;
        }
#endif /* WRITE_GHOST_CELLS */

        ndata[0] = iu-il+1;
        ndata[1] = ju-jl+1;
        ndata[2] = ku-kl+1;

/* calculate primitive variables, if needed */

        if(strcmp(pOut->out,"prim") == 0) {
          if((W = (PrimS***)
            calloc_3d_array(ndata[2],ndata[1],ndata[0],sizeof(PrimS))) == NULL)
            ath_error("[dump_bin]: failed to allocate Prim array\n");

          for (k=kl; k<=ku; k++) {
          for (j=jl; j<=ju; j++) {
          for (i=il; i<=iu; i++) {
            W[k-kl][j-jl][i-il] = Cons_to_Prim(&(pGrid->U[k][j][i]));
          }}}
        }

/* construct filename, open file */
        if (nl>0) {
          plev = &levstr[0];
          sprintf(plev,"lev%d",nl);
        }
        if (nd>0) {
          pdom = &domstr[0];
          sprintf(pdom,"dom%d",nd);
        }
        if((fname = ath_fname(plev,pM->outfilename,plev,pdom,num_digit,
            pOut->num,NULL,"bin")) == NULL){
          ath_error("[dump_binary]: Error constructing filename\n");
        }

        if((p_binfile = fopen(fname,"wb")) == NULL){
          ath_error("[dump_binary]: Unable to open binary dump file\n");
          return;
        }
        free(fname);

/* Write the coordinate system information */
#if defined CARTESIAN
        coordsys = -1;
#elif defined CYLINDRICAL
        coordsys = -2;
#elif defined SPHERICAL
        coordsys = -3;
#endif
        fwrite(&coordsys,sizeof(int),1,p_binfile);

/* Write number of zones and variables */
        ndata[3] = NVAR;
        ndata[4] = NSCALARS;
#ifdef SELF_GRAVITY
        ndata[5] = 1;
#else
        ndata[5] = 0;
#endif
#ifdef PARTICLES
        ndata[6] = 1;
#else
        ndata[6] = 0;
#endif
        fwrite(ndata,sizeof(int),7,p_binfile);

/* Write (gamma-1) and isothermal sound speed */

#ifdef ISOTHERMAL
        dat[0] = (Real)0.0;
        dat[1] = (Real)Iso_csound;
#elif defined ADIABATIC
        dat[0] = (Real)Gamma_1 ;
        dat[1] = (Real)0.0;
#else
        dat[0] = dat[1] = 0.0; /* Anything better to put here? */
#endif
        fwrite(dat,sizeof(Real),2,p_binfile);

/* Write time, dt */

        dat[0] = (Real)pGrid->time;
        dat[1] = (Real)pGrid->dt;
        fwrite(dat,sizeof(Real),2,p_binfile);
 
/* Allocate Memory */

        if((datax = (Real *)malloc(ndata[0]*sizeof(Real))) == NULL){
          ath_error("[dump_binary]: malloc failed for temporary array\n");
          return;
        }
        if((datay = (Real *)malloc(ndata[1]*sizeof(Real))) == NULL){
          ath_error("[dump_binary]: malloc failed for temporary array\n");
          return;
        }
        if((dataz = (Real *)malloc(ndata[2]*sizeof(Real))) == NULL){
          ath_error("[dump_binary]: malloc failed for temporary array\n");
          return;
        }

/* compute x,y,z coordinates of cell centers, and write out */

        for (i=il; i<=iu; i++) {
          cc_pos(pGrid,i,jl,kl,&x1,&x2,&x3);
          pData = ((Real *) &(x1));
          datax[i-il] = (Real)(*pData);
        }
        fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);

        for (j=jl; j<=ju; j++) {
          cc_pos(pGrid,il,j,kl,&x1,&x2,&x3);
          pData = ((Real *) &(x2));
          datay[j-jl] = (Real)(*pData);
        }
        fwrite(datay,sizeof(Real),(size_t)ndata[1],p_binfile);

        for (k=kl; k<=ku; k++) {
          cc_pos(pGrid,il,jl,k,&x1,&x2,&x3);
          pData = ((Real *) &(x3));
          dataz[k-kl] = (Real)(*pData);
        }
        fwrite(dataz,sizeof(Real),(size_t)ndata[2],p_binfile);

/* Write cell-centered data (either conserved or primitives) */

        for (n=0;n<NVAR; n++) {
          for (k=0; k<ndata[2]; k++) {
          for (j=0; j<ndata[1]; j++) {
            for (i=0; i<ndata[0]; i++) {

              if (strcmp(pOut->out,"cons") == 0){
                pData = ((Real*)&(pGrid->U[k+kl][j+jl][i+il])) + n;
              } else if(strcmp(pOut->out,"prim") == 0) {
                pData = ((Real*)&(W[k][j][i])) + n;
              }
              datax[i] = (Real)(*pData);

            }
            fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);

          }}
        }

#ifdef SELF_GRAVITY
        for (k=0; k<ndata[2]; k++) {
        for (j=0; j<ndata[1]; j++) {
          for (i=0; i<ndata[0]; i++) {
            pData = &(pGrid->Phi[k+kl][j+jl][i+il]);
            datax[i] = (Real)(*pData);
          }
          fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);
        }}
#endif

#ifdef PARTICLES
        if (pOut->out_pargrid) {
          for (k=0; k<ndata[2]; k++) {
          for (j=0; j<ndata[1]; j++) {
            for (i=0; i<ndata[0]; i++) {
              datax[i] = pGrid->Coup[k+kl][j+jl][i+il].grid_d;
            }
            fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);
          }}
          for (k=0; k<ndata[2]; k++) {
          for (j=0; j<ndata[1]; j++) {
            for (i=0; i<ndata[0]; i++) {
              datax[i] = pGrid->Coup[k+kl][j+jl][i+il].grid_v1;
            }
            fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);
          }}
          for (k=0; k<ndata[2]; k++) {
          for (j=0; j<ndata[1]; j++) {
            for (i=0; i<ndata[0]; i++) {
              datax[i] = pGrid->Coup[k+kl][j+jl][i+il].grid_v2;
            }
            fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);
          }}
          for (k=0; k<ndata[2]; k++) {
          for (j=0; j<ndata[1]; j++) {
            for (i=0; i<ndata[0]; i++) {
              datax[i] = pGrid->Coup[k+kl][j+jl][i+il].grid_v3;
            }
            fwrite(datax,sizeof(Real),(size_t)ndata[0],p_binfile);
          }}
        }
#endif

/* close file and free memory */
        fclose(p_binfile); 
        free(datax); 
        free(datay); 
        free(dataz); 
        if(strcmp(pOut->out,"prim") == 0) free_3d_array(W);
      }}
    }
  }
}
Exemplo n.º 5
0
void problem(DomainS *pDomain)
{
  GridS *pGrid = pDomain->Grid;
  int i=0,j=0,k=0;
  int is,ie,js,je,ks,ke,nx1,nx2,nx3,iprob;
  Real x1c,x2c,x3c,x1f,x2f,x3f;       /* cell- and face-centered coordinates */
  Real x1size,x2size,x3size,lambda=0.0,ang_2=0.0,sin_a2=0.0,cos_a2=1.0,x,y;
  Real rad,amp,vflow,drat,diag;
  Real ***az,***ay,***ax;
#ifdef MHD
  int ku;
#endif
#if (NSCALARS > 0)
  int n;
#endif

  is = pGrid->is; ie = pGrid->ie;
  js = pGrid->js; je = pGrid->je;
  ks = pGrid->ks; ke = pGrid->ke;
  nx1 = (ie-is)+1 + 2*nghost;
  nx2 = (je-js)+1 + 2*nghost;
  nx3 = (ke-ks)+1 + 2*nghost;

  if (((je-js) == 0)) {
    ath_error("[field_loop]: This problem can only be run in 2D or 3D\n");
  }

  if ((ay = (Real***)calloc_3d_array(nx3, nx2, nx1, sizeof(Real))) == NULL) {
    ath_error("[field_loop]: Error allocating memory for vector pot\n");
  }
  if ((az = (Real***)calloc_3d_array(nx3, nx2, nx1, sizeof(Real))) == NULL) {
    ath_error("[field_loop]: Error allocating memory for vector pot\n");
  }
  if ((ax = (Real***)calloc_3d_array(nx3, nx2, nx1, sizeof(Real))) == NULL) {
    ath_error("[field_loop]: Error allocating memory for vector pot\n");
  }

/* Read initial conditions, diffusion coefficients (if needed) */

  rad = par_getd("problem","rad");
  amp = par_getd("problem","amp");
  vflow = par_getd("problem","vflow");
  drat = par_getd_def("problem","drat",1.0);
  iprob = par_getd("problem","iprob");
#ifdef RESISTIVITY
  eta_Ohm = par_getd_def("problem","eta_O",0.0);
  Q_Hall  = par_getd_def("problem","Q_H",0.0);
  Q_AD    = par_getd_def("problem","Q_AD",0.0);
#endif
#ifdef THERMAL_CONDUCTION
  kappa_iso = par_getd_def("problem","kappa_iso",0.0);
  kappa_aniso = par_getd_def("problem","kappa_aniso",0.0);
#endif

/* For (iprob=4) -- rotated cylinder in 3D -- set up rotation angle and
 * wavelength of cylinder */

  if(iprob == 4){
    x1size = pDomain->RootMaxX[0] - pDomain->RootMinX[0];
    x3size = pDomain->RootMaxX[2] - pDomain->RootMinX[2];

/* We put 1 wavelength in each direction.  Hence the wavelength
 *     lambda = x1size*cos_a;
 *     AND   lambda = x3size*sin_a;
 *     are both satisfied. */

    if(x1size == x3size){
      ang_2 = PI/4.0;
      cos_a2 = sin_a2 = sqrt(0.5);
    }
    else{
      ang_2 = atan(x1size/x3size);
      sin_a2 = sin(ang_2);
      cos_a2 = cos(ang_2);
    }
/* Use the larger angle to determine the wavelength */
    if (cos_a2 >= sin_a2) {
      lambda = x1size*cos_a2;
    } else {
      lambda = x3size*sin_a2;
    }
  }

/* Use vector potential to initialize field loop */

  for (k=ks; k<=ke+1; k++) {
  for (j=js; j<=je+1; j++) {
  for (i=is; i<=ie+1; i++) {
    cc_pos(pGrid,i,j,k,&x1c,&x2c,&x3c);
    x1f = x1c - 0.5*pGrid->dx1;
    x2f = x2c - 0.5*pGrid->dx2;
    x3f = x3c - 0.5*pGrid->dx3;
     
/* (iprob=1): field loop in x1-x2 plane (cylinder in 3D) */

    if(iprob==1) {  
      ax[k][j][i] = 0.0;
      ay[k][j][i] = 0.0;
      if ((x1f*x1f + x2f*x2f) < rad*rad) {
        az[k][j][i] = amp*(rad - sqrt(x1f*x1f + x2f*x2f));
      } else {
        az[k][j][i] = 0.0;
      }
    }

/* (iprob=2): field loop in x2-x3 plane (cylinder in 3D) */

    if(iprob==2) {  
      if ((x2f*x2f + x3f*x3f) < rad*rad) {
        ax[k][j][i] = amp*(rad - sqrt(x2f*x2f + x3f*x3f));
      } else {
        ax[k][j][i] = 0.0;
      }
      ay[k][j][i] = 0.0;
      az[k][j][i] = 0.0;
    }

/* (iprob=3): field loop in x3-x1 plane (cylinder in 3D) */

    if(iprob==3) {  
      if ((x1f*x1f + x3f*x3f) < rad*rad) {
        ay[k][j][i] = amp*(rad - sqrt(x1f*x1f + x3f*x3f));
      } else {
        ay[k][j][i] = 0.0;
      }
      ax[k][j][i] = 0.0;
      az[k][j][i] = 0.0;
    }

/* (iprob=4): rotated cylindrical field loop in 3D.  Similar to iprob=1
 * with a rotation about the x2-axis.  Define coordinate systems (x1,x2,x3)
 * and (x,y,z) with the following transformation rules:
 *    x =  x1*cos(ang_2) + x3*sin(ang_2)
 *    y =  x2
 *    z = -x1*sin(ang_2) + x3*cos(ang_2)
 * This inverts to:
 *    x1  = x*cos(ang_2) - z*sin(ang_2)
 *    x2  = y
 *    x3  = x*sin(ang_2) + z*cos(ang_2)
 */

    if(iprob==4) {
      x = x1c*cos_a2 + x3f*sin_a2;
      y = x2f;
/* shift x back to the domain -0.5*lambda <= x <= 0.5*lambda */
      while(x >  0.5*lambda) x -= lambda;
      while(x < -0.5*lambda) x += lambda;
      if ((x*x + y*y) < rad*rad) {
        ax[k][j][i] = amp*(rad - sqrt(x*x + y*y))*(-sin_a2);
      } else {
        ax[k][j][i] = 0.0;
      }

      ay[k][j][i] = 0.0;

      x = x1f*cos_a2 + x3c*sin_a2;
      y = x2f;
/* shift x back to the domain -0.5*lambda <= x <= 0.5*lambda */
      while(x >  0.5*lambda) x -= lambda;
      while(x < -0.5*lambda) x += lambda;
      if ((x*x + y*y) < rad*rad) {
        az[k][j][i] = amp*(rad - sqrt(x*x + y*y))*(cos_a2);
      } else {
        az[k][j][i] = 0.0;
      }
    }

/* (iprob=5): spherical field loop in rotated plane */

    if(iprob==5) { 
      ax[k][j][i] = 0.0;
      if ((x1f*x1f + x2c*x2c + x3f*x3f) < rad*rad) {
        ay[k][j][i] = amp*(rad - sqrt(x1f*x1f + x2c*x2c + x3f*x3f));
      } else {
        ay[k][j][i] = 0.0;
      }
      if ((x1f*x1f + x2f*x2f + x3c*x3c) < rad*rad) {
        az[k][j][i] = amp*(rad - sqrt(x1f*x1f + x2f*x2f + x3c*x3c));
      } else {
        az[k][j][i] = 0.0;
      }
    }

  }}}

/* Initialize density and momenta.  If drat != 1, then density and temperature
 * will be different inside loop than background values
 */

  x1size = pDomain->RootMaxX[0] - pDomain->RootMinX[0];
  x2size = pDomain->RootMaxX[1] - pDomain->RootMinX[1];
  x3size = pDomain->RootMaxX[2] - pDomain->RootMinX[2];
  diag = sqrt(x1size*x1size + x2size*x2size + x3size*x3size);
  for (k=ks; k<=ke; k++) {
  for (j=js; j<=je; j++) {
  for (i=is; i<=ie; i++) {
     pGrid->U[k][j][i].d = 1.0;
     pGrid->U[k][j][i].M1 = pGrid->U[k][j][i].d*vflow*x1size/diag;
     pGrid->U[k][j][i].M2 = pGrid->U[k][j][i].d*vflow*x2size/diag;
     pGrid->U[k][j][i].M3 = pGrid->U[k][j][i].d*vflow*x3size/diag;

     cc_pos(pGrid,i,j,k,&x1c,&x2c,&x3c);
     if ((x1c*x1c + x2c*x2c + x3c*x3c) < rad*rad) {
       pGrid->U[k][j][i].d = drat;
       pGrid->U[k][j][i].M1 = pGrid->U[k][j][i].d*vflow*x1size/diag;
       pGrid->U[k][j][i].M2 = pGrid->U[k][j][i].d*vflow*x2size/diag;
       pGrid->U[k][j][i].M3 = pGrid->U[k][j][i].d*vflow*x3size/diag;
     }
#if (NSCALARS > 0)
     for (n=0; n<NSCALARS; n++) pGrid->U[k][j][i].s[n] = 0.0;
     if ((x1c*x1c + x2c*x2c + x3c*x3c) < rad*rad) {
       for (n=0; n<NSCALARS; n++)  pGrid->U[k][j][i].s[n] = 1.0;
     }
#endif
  }}}

/* boundary conditions on interface B */

#ifdef MHD
  for (k=ks; k<=ke; k++) {
  for (j=js; j<=je; j++) {
  for (i=is; i<=ie+1; i++) {
    pGrid->B1i[k][j][i] = (az[k][j+1][i] - az[k][j][i])/pGrid->dx2 -
                          (ay[k+1][j][i] - ay[k][j][i])/pGrid->dx3;
  }}}
  for (k=ks; k<=ke; k++) {
  for (j=js; j<=je+1; j++) {
  for (i=is; i<=ie; i++) {
    pGrid->B2i[k][j][i] = (ax[k+1][j][i] - ax[k][j][i])/pGrid->dx3 -
                          (az[k][j][i+1] - az[k][j][i])/pGrid->dx1;
  }}}
  if (ke > ks) {
    ku = ke+1;
  } else {
    ku = ke;
  }
  for (k=ks; k<=ku; k++) {
  for (j=js; j<=je; j++) {
  for (i=is; i<=ie; i++) {
    pGrid->B3i[k][j][i] = (ay[k][j][i+1] - ay[k][j][i])/pGrid->dx1 -
                          (ax[k][j+1][i] - ax[k][j][i])/pGrid->dx2;
  }}}
#endif

/* initialize total energy and cell-centered B */

#if defined MHD || !defined ISOTHERMAL
  for (k=ks; k<=ke; k++) {
    for (j=js; j<=je; j++) {
      for (i=is; i<=ie; i++) {
#ifdef MHD
        pGrid->U[k][j][i].B1c = 0.5*(pGrid->B1i[k][j][i  ] + 
                                     pGrid->B1i[k][j][i+1]);
        pGrid->U[k][j][i].B2c = 0.5*(pGrid->B2i[k][j  ][i] +
                                     pGrid->B2i[k][j+1][i]);
	if (ke > ks)
	  pGrid->U[k][j][i].B3c = 0.5*(pGrid->B3i[k  ][j][i] + 
                                       pGrid->B3i[k+1][j][i]);
	else
	  pGrid->U[k][j][i].B3c = pGrid->B3i[k][j][i];
#endif

#ifndef ISOTHERMAL
	pGrid->U[k][j][i].E = 1.0/Gamma_1
#ifdef MHD
	  + 0.5*(SQR(pGrid->U[k][j][i].B1c) + SQR(pGrid->U[k][j][i].B2c)
               + SQR(pGrid->U[k][j][i].B3c))
#endif
	  + 0.5*(SQR(pGrid->U[k][j][i].M1) + SQR(pGrid->U[k][j][i].M2)
               + SQR(pGrid->U[k][j][i].M3))/pGrid->U[k][j][i].d;
#endif /* ISOTHERMAL */
      }
    }
  }
#endif

  free_3d_array((void***)az);
  free_3d_array((void***)ay);
  free_3d_array((void***)ax);
}
Exemplo n.º 6
0
int main(int argc, char* argv[]){

  int i, j, k, n;
  char *out_name=NULL;

  if(argc < 5)
    join_error("Usage: %s -o <out_name.vtk> file1.vtk file2.vtk ...\n",argv[0]);

  file_count = argc-3; /* Number of input vtk files */

  /* Parse the command line for the output filename */
  for(i=1; i<argc-1; i++){
    if(strcmp(argv[i],"-o") == 0){
      i++; /* increment to the filename */
      if((out_name = my_strdup(argv[i])) == NULL)
	join_error("out_name = my_strdup(\"%s\") failed\n",argv[i]);
      break;
    }
  }

  /* An output filename is required */
  if(out_name == NULL)
    join_error("Usage: %s -o <out_name.vtk> file1.vtk file2.vtk ...\n",argv[0]);

  printf("Output filename is \"%s\"\n",out_name);
  printf("Found %d files on the command line\n",file_count);

  /* ====================================================================== */

  domain_1d = (VTK_Domain*)calloc(file_count,sizeof(VTK_Domain));
  if(domain_1d == NULL)
    join_error("calloc returned a NULL pointer for domain_1d\n");

  /* Populate the 1d domain array with the filenames */
  for(n=0, i=1; i<argc; i++){
    if(strcmp(argv[i],"-o") == 0){
      i++; /* increment to the filename */
    }
    else{
      if((domain_1d[n].fname = my_strdup(argv[i])) == NULL){
	join_error("domain_1d[%d].fname = my_strdup(\"%s\") failed\n",
		   n,argv[i]);
      }
      /* printf("domain_1d[%d].fname = \"%s\"\n",n,domain_1d[n].fname); */
      n++; /* increment the domain counter */
    }
  }

  init_domain_1d(); /* Read in the header information */

  sort_domain_1d(); /* Sort the VTK_Domain elements in [k][j][i] order */

  /* Allocate the domain_3d[][][] array */
  domain_3d = (VTK_Domain***)
    calloc_3d_array(NGrid_z, NGrid_y, NGrid_x, sizeof(VTK_Domain));
  if(domain_3d == NULL)
    join_error("calloc_3d_array() returned a NULL pointer\n");

  /* Copy the contents of the domain_1d[] array to the domain_3d[][][] array */
  n=0;
  for(k=0; k<NGrid_z; k++){
    for(j=0; j<NGrid_y; j++){
      for(i=0; i<NGrid_x; i++){
	domain_3d[k][j][i] = domain_1d[n++];
      }
    }
  }

  /* For debugging purposes, write out the origin for all of the grid
     domains in what should now be an ascending order for a [k][j][i] array. */
  /* This mimics the output in sort_domain_1d() and a diff should show
     that they are exactly the same. */
  /* for(k=0; k<NGrid_z; k++){
     for(j=0; j<NGrid_y; j++){
     for(i=0; i<NGrid_x; i++){
     printf("[%d]: ox=%e  oy=%e  oz=%e\n",i + NGrid_x*(j + k*NGrid_y),
     domain_3d[k][j][i].ox, domain_3d[k][j][i].oy, 
     domain_3d[k][j][i].oz);
     }
     }
     } */

  /* TO MAKE THIS CODE MORE BULLETPROOF ADD A CALL TO SOME FUNCTION TO
     CHECK THAT THIS DOMAIN ARRAY SATISFIES A SET OF CONSISTENCY
     CONDITIONS LIKE Nx IS CONSTANT ALONG Y- AND Z-DIRECTIONS, ETC. */

  /* ====================================================================== */

  write_joined_vtk(out_name);

  /* ====================================================================== */

  /* Now we need to do some cleanup */
  free_3d_array((void ***)domain_3d);
  domain_3d = NULL;

  /* Now close the input files and free the input file names */
  for(i=0; i<file_count; i++){
    fclose(domain_1d[i].fp);
    free(domain_1d[i].fname);
    domain_1d[i].fname = NULL;
    free(domain_1d[i].comment);
    domain_1d[i].comment = NULL;
  }

  free(domain_1d);
  domain_1d = NULL;

  free(out_name);
  out_name = NULL;

  return(0) ;
}