示例#1
0
void problem_read_restart(MeshS *pM, FILE *fp)
{
  int nl,nd,BCFlag_ix1,BCFlag_ox1;
/* Read Omega, and with viscosity and/or resistivity, read eta_Ohm and nu_V */

#ifdef SHEARING_BOX
  Omega_0 = par_getd_def("problem","omega",1.0e-3);
  qshear  = par_getd_def("problem","qshear",1.5);
#endif
  Mp      = par_getd_def("problem","Mplanet",0.0);
  Xplanet = par_getd_def("problem","Xplanet",0.0);
  Yplanet = par_getd_def("problem","Yplanet",0.0);
  Zplanet = par_getd_def("problem","Zplanet",0.0);
  Rsoft   = par_getd_def("problem","Rsoft",0.1);
  ramp_time = 0.0;
  insert_time = par_getd_def("problem","insert_time",0.0);
#ifdef VISCOSITY
  nu_iso = par_getd_def("problem","nu_iso",0.0);
  nu_aniso = par_getd_def("problem","nu_aniso",0.0);
#endif

/* enroll gravitational potential of planet & shearing-box potential fns */

  StaticGravPot = PlanetPot;
  ShearingBoxPot = UnstratifiedDisk;

/* enroll new history variables */

  dump_history_enroll(hst_rho_Vx_dVy, "<rho Vx dVy>");
  dump_history_enroll(hst_rho_dVy2, "<rho dVy^2>");
#ifdef ADIABATIC
  dump_history_enroll(hst_E_total, "<E + rho Phi>");
#endif

  BCFlag_ix1 = par_geti_def("domain1","bc_ix1",0);
  BCFlag_ox1 = par_geti_def("domain1","bc_ox1",0);
  for (nl=0; nl<(pM->NLevels); nl++){
    for (nd=0; nd<(pM->DomainsPerLevel[nl]); nd++){
      if (pM->Domain[nl][nd].Disp[0] == 0 && BCFlag_ix1 != 4) 
        bvals_mhd_fun(&(pM->Domain[nl][nd]), left_x1,  constant_iib);
      if (pM->Domain[nl][nd].MaxX[0] == pM->Domain[nl][nd].RootMaxX[0] 
          && BCFlag_ox1 != 4)
        bvals_mhd_fun(&(pM->Domain[nl][nd]), right_x1, constant_oib);
    }
  }

  return;
}
示例#2
0
void problem_read_restart(MeshS *pM, FILE *fp)
{
  DomainS *pD = (DomainS*)&(pM->Domain[0][0]);
  GridS *pG = pD->Grid;
  ShearingBoxPot = StratifiedDisk;

  Omega_0 = par_getd("problem","omega");
  qshear = par_getd_def("problem","qshear",1.5);
  ipert = par_geti_def("problem","ipert",1);

  x1min = pG->MinX[0];
  x1max = pG->MaxX[0];
  Lx = x1max - x1min;

  x2min = pG->MinX[1];
  x2max = pG->MaxX[1];
  Ly = x2max - x2min;

  x3min = pM->RootMinX[2];
  x3max = pM->RootMaxX[2];
  Lz = x3max - x3min;

  Lg = nghost*pG->dx3; /* size of the ghost zone */

  vsc1 = par_getd_def("problem","vsc1",0.05); /* in unit of iso_sound (N.B.!) */
  vsc2 = par_getd_def("problem","vsc2",0.0);

  vsc1 = vsc1 * Iso_csound;
  vsc2 = vsc2 * Iso_csound;

  Npar  = (int)(sqrt(par_geti("particle","parnumgrid")));
  nlis = par_geti_def("problem","nlis",pG->Nx[0]*pG->Nx[1]*pG->Nx[2]);
  ntrack = par_geti_def("problem","ntrack",2000);

  dump_history_enroll(hst_rho_Vx_dVy, "<rho Vx dVy>");

  return;
}
示例#3
0
void problem(DomainS *pDomain)
{
  GridS *pGrid = pDomain->Grid;
  int is = pGrid->is, ie = pGrid->ie;
  int js = pGrid->js, je = pGrid->je;
  int ks = pGrid->ks, ke = pGrid->ke;
  int i,j,k,BCFlag;
  Real x1,x2,x3;
  Real den = 1.0, pres = 1.0e-6;
  static int frst=1;  /* flag so new history variables enrolled only once */

#ifdef SHEARING_BOX
/* specify xy (r-phi) plane */
  ShBoxCoord = xy;
#endif

/* Read problem parameters.  Note Omega_0 set to 10^{-3} by default */
#ifdef SHEARING_BOX
  Omega_0 = par_getd_def("problem","omega",1.0e-3);
  qshear  = par_getd_def("problem","qshear",1.5);
#endif
  Mp      = par_getd_def("problem","Mplanet",0.0);
  Xplanet = par_getd_def("problem","Xplanet",0.0);
  Yplanet = par_getd_def("problem","Yplanet",0.0);
  Zplanet = par_getd_def("problem","Zplanet",0.0);
  Rsoft   = par_getd_def("problem","Rsoft",0.1);
  ramp_time = 0.0;
  insert_time = par_getd_def("problem","insert_time",0.0);

/* Compute field strength based on beta.  */
#ifdef ISOTHERMAL
  pres = Iso_csound2;
#endif

  for (k=ks; k<=ke; k++) {
  for (j=js; j<=je; j++) {
    for (i=is; i<=ie; i++) {
      cc_pos(pGrid,i,j,k,&x1,&x2,&x3);

/* Initialize d, M, and P.  With FARGO do not initialize the background shear */

      pGrid->U[k][j][i].d  = den;
//      pGrid->U[k][j][i].d = 1.0+.5*(1-.02)*(tanh((x1-10.0)/3.5)-tanh((x1+10.0)/3.5))-.5*1.1*(tanh((x1-10.0)/15.0)-tanh((x1+10.0)/15.0));
      pGrid->U[k][j][i].M1 = 0.0;
      pGrid->U[k][j][i].M2 = 0.0;
#ifdef SHEARING_BOX
#ifndef FARGO
      pGrid->U[k][j][i].M2 -= den*(qshear*Omega_0*x1);
#endif
#endif
      pGrid->U[k][j][i].M3 = 0.0;
#ifdef ADIABATIC
      pGrid->U[k][j][i].E = pres/Gamma_1
        + 0.5*(SQR(pGrid->U[k][j][i].M1) + SQR(pGrid->U[k][j][i].M2) 
             + SQR(pGrid->U[k][j][i].M3))/den;
#endif

    }
  }}

/* enroll gravitational potential of planet & shearing-box potential fns */

  StaticGravPot = PlanetPot;
  ShearingBoxPot = UnstratifiedDisk;

/* enroll new history variables, only once  */

  if (frst == 1) {
    dump_history_enroll(hst_rho_Vx_dVy, "<rho Vx dVy>");
    dump_history_enroll(hst_rho_dVy2, "<rho dVy^2>");
#ifdef ADIABATIC
    dump_history_enroll(hst_E_total, "<E + rho Phi>");
#endif
    frst = 0;
  }

/* With viscosity and/or resistivity, read diffusion coeffs */
#ifdef VISCOSITY
  nu_iso = par_getd_def("problem","nu_iso",0.0);
  nu_aniso = par_getd_def("problem","nu_aniso",0.0);
#endif

/* Enroll outflow BCs if perdiodic BCs NOT selected.  This assumes the root
 * level grid is specified by the <domain1> block in the input file */

  BCFlag = par_geti_def("domain1","bc_ix1",0);
  if (BCFlag != 4) {
    if (pDomain->Disp[0] == 0) bvals_mhd_fun(pDomain, left_x1,  constant_iib);
  }
  BCFlag = par_geti_def("domain1","bc_ox1",0);
  if (BCFlag != 4) {
    if (pDomain->MaxX[0] == pDomain->RootMaxX[0])
      bvals_mhd_fun(pDomain, right_x1, constant_oib);
  }

  return;
}
示例#4
0
void problem(DomainS *pDomain)
{
    GridS *pGrid=(pDomain->Grid);
    int i, is = pGrid->is, ie = pGrid->ie;
    int j, js = pGrid->js, je = pGrid->je;
    int k, ks = pGrid->ks, ke = pGrid->ke;
    Real x1,x2,x3;
    Real rho, p, prat, density, pressure, pi, vel, n, amp, lx, ly;
    
    dt_line_integral_output = par_getd("problem", "dt_line_integral");

    
    
    /* size of the domain (in physical coordinates) */
    lx = pDomain->RootMaxX[0] - pDomain->RootMinX[0];
    ly = pDomain->RootMaxX[1] - pDomain->RootMinX[1];
    
    
    
    p  = 1.0;
    /* if prat=0.8, vx = -1.8965 (t&e find other vals)*/
    pi=3.14159;
    n = 2;                  /*Oscillations of perturbation*/
    amp = 0.05 ;              /* Size of perturbation ~ 0.05 */
    
    
    
    /* setup uniform ambient medium with spherical over-pressured region */
    
    
    for (k=ks; k<=ke; k++) {
        for (j=js; j<=je; j++) {
            for (i=is; i<=ie; i++) {
                cc_pos(pGrid,i,j,k,&x1,&x2,&x3);
                
                
                
                if (x1 > amp*sin(n*pi*x2/ly)) {
                    pressure = 0.1175;
                } else {
                    pressure = 1;
                    
                }
                
                
                if (x1 > amp*sin(n*pi*x2/ly)) {
                    vel= -1.96071;
                } else {
                    vel= -0.7;
                    
                }
                
                if (x1 > amp*sin(n*pi*x2/ly)) {
                    density= 0.357013;
                } else {
                    density= 1;
                    
                }
                
                
                
                pGrid->U[0][j][i].d = density;
                pGrid->U[0][j][i].M1 = density*vel;
                pGrid->U[0][j][i].M2 = 0.0;
#ifndef ISOTHERMAL
                pGrid->U[0][j][i].E = pressure/Gamma_1 + (SQR(pGrid->U[0][j][i].M1) + SQR(pGrid->U[0][j][i].M2))/(2.0*(pGrid->U[0][j][i].d));
                
#endif
            }
        }
    }
    
    
    
    
    /* Adding history dumps*/
    
    void dump_history_enroll(const ConsFun_t pfun, const char *label);
    
    dump_history_enroll(pleft, "<pbvals>");
    dump_history_enroll(vyintegral, "<vyintegral>");
    
    
    
    
    
    /* enroll special functions */
    bvals_mhd_fun(pDomain,left_x1, bc_ix1);
    
    return;
    
}
示例#5
0
static void initialize(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;
  int nbuf, mpierr, nx1gh, nx2gh, nx3gh;
  float kwv, kpara, kperp;
  char donedrive = 0;

/* -----------------------------------------------------------
 * Variables within this block are stored globally, and used
 * within preprocessor macros.  Don't create variables with
 * these names within your function if you are going to use
 * OFST(), KCOMP(), or KWVM() within the function! */

  /* Get local grid size */
  nx1 = (ie-is+1);
  nx2 = (je-js+1);
  nx3 = (ke-ks+1);

  /* Get global grid size */
  gnx1 = pD->ide - pD->ids + 1;
  gnx2 = pD->jde - pD->jds + 1;
  gnx3 = pD->kde - pD->kds + 1;

  /* Get extents of local FFT grid in global coordinates */
  gis=is+pGrid->idisp;  gie=ie+pGrid->idisp;
  gjs=js+pGrid->jdisp;  gje=je+pGrid->jdisp;
  gks=ks+pGrid->kdisp;  gke=ke+pGrid->kdisp;
/* ----------------------------------------------------------- */

  /* Get size of arrays with ghost cells */
  nx1gh = nx1 + 2*nghost;
  nx2gh = nx2 + 2*nghost;
  nx3gh = nx3 + 2*nghost;

  /* Get input parameters */

  /* interval for generating new driving spectrum; also interval for
   * driving when IMPULSIVE_DRIVING is used */
  dtdrive = par_getd("problem","dtdrive");
#ifdef MHD
  /* magnetic field strength */
  beta = par_getd("problem","beta");
  /* beta = isothermal pressure/magnetic pressure */
  B0 = sqrt(2.0*Iso_csound2*rhobar/beta);
#endif /* MHD */
  /* energy injection rate */
  dedt = par_getd("problem","dedt");

  /* parameters for spectrum */
  ispect = par_geti("problem","ispect");
  if (ispect == 1) {
    expo = par_getd("problem","expo");
  } else if (ispect == 2) {
    kpeak = par_getd("problem","kpeak")*2.0*PI;
  } else {
    ath_error("Invalid value for ispect\n");
  }
  /* Cutoff wavenumbers of spectrum */
  klow = par_getd("problem","klow"); /* in integer units */
  khigh = par_getd("problem","khigh"); /* in integer units */
  dkx = 2.0*PI/(pGrid->dx1*gnx1); /* convert k from integer */

  /* Driven or decaying */
  idrive = par_geti("problem","idrive");
  if ((idrive < 0) || (idrive > 1)) ath_error("Invalid value for idrive\n");
  /* If restarting with decaying turbulence, no driving necessary. */
  if ((idrive == 1) && (pGrid->nstep > 0)) {
    donedrive = 1;
  }

  if (donedrive == 0) {
    /* Allocate memory for components of velocity perturbation */
    if ((dv1=(Real***)calloc_3d_array(nx3gh,nx2gh,nx1gh,sizeof(Real)))==NULL) {
      ath_error("[problem]: Error allocating memory for vel pert\n");
    }
    if ((dv2=(Real***)calloc_3d_array(nx3gh,nx2gh,nx1gh,sizeof(Real)))==NULL) {
      ath_error("[problem]: Error allocating memory for vel pert\n");
    }
    if ((dv3=(Real***)calloc_3d_array(nx3gh,nx2gh,nx1gh,sizeof(Real)))==NULL) {
      ath_error("[problem]: Error allocating memory for vel pert\n");
    }
  }

  /* Initialize the FFT plan */
  plan = ath_3d_fft_quick_plan(pGrid, pD, NULL, ATH_FFT_BACKWARD);

  /* Allocate memory for FFTs */
  if (donedrive == 0) {
    fv1 = ath_3d_fft_malloc(plan);
    fv2 = ath_3d_fft_malloc(plan);
    fv3 = ath_3d_fft_malloc(plan);
  }

  /* Enroll outputs */
  dump_history_enroll(hst_dEk,"<dE_K>");
  dump_history_enroll(hst_dEb,"<dE_B>");

  return;
}
示例#6
0
文件: cylnewtmri.c 项目: Ingwar/amuse
void problem_read_restart(MeshS *pM, FILE *fp)
{

  R0          = par_getd_def("problem", "R0",2.0);
  Hbc       = par_getd_def("problem","Hbc",1);
  Mbc       = par_getd_def("problem","Mbc",1);

  StaticGravPot = grav_pot;
  x1GravAcc = grav_acc;
  bvals_mhd_fun(&(pM->Domain[0][0]),left_x1,disk_ir);
  bvals_mhd_fun(&(pM->Domain[0][0]),right_x1,disk_or);
#ifdef FARGO
  OrbitalProfile = Omega;
  ShearProfile = Shear;
#endif
	// Enroll history functions
	//
#ifdef MHD
	dump_history_enroll(Br, "<Br>");
	dump_history_enroll(Bp, "<Bp>");
	dump_history_enroll(Bz, "<Bz>");
	dump_history_enroll(Mrp, "<Mrp>");
	dump_history_enroll(Trp, "<Trp>");
	dump_history_enroll(MdotR1, "<MdotR1>");
	dump_history_enroll(MdotR2, "<MdotR2>");
	dump_history_enroll(MdotR3, "<MdotR3>");
	dump_history_enroll(MdotR4, "<MdotR4>");
	dump_history_enroll(Msub, "<Msub>");
	dump_history_enroll(Mrpsub, "<Mrpsub>");
	dump_history_enroll(Bpsub, "<Bpsub>");
	dump_history_enroll(Bzsub, "<Bzsub>");
	dump_history_enroll(Pbsub, "<Pbsub>");


#endif

  return;
}
示例#7
0
文件: cylnewtmri.c 项目: Ingwar/amuse
void problem(DomainS *pDomain)
{
  int i,j,k;
  int is,ie,il,iu,js,je,jl,ju,ks,ke,kl,ku;
  int nx1,nx2,nx3,myid=0;
  Real x1,x2,x3,y1, r;
	GridS *pG = pDomain->Grid;

  is = pG->is;  ie = pG->ie;  nx1 = ie-is+1;
  js = pG->js;  je = pG->je;  nx2 = je-js+1;
  ks = pG->ks;  ke = pG->ke;  nx3 = ke-ks+1;

  il = is-nghost*(nx1>1);  iu = ie+nghost*(nx1>1);  nx1 = iu-il+1;
  jl = js-nghost*(nx2>1);  ju = je+nghost*(nx2>1);  nx2 = ju-jl+1;
  kl = ks-nghost*(nx3>1);  ku = ke+nghost*(nx3>1);  nx3 = ku-kl+1;

  rho0        = par_getd_def("problem", "rho0", 100.0);
  Amp         = par_getd_def("problem", "Amp", 1.0e-2);
  Beta        = par_getd_def("problem", "Beta",100.0);
  R0          = par_getd_def("problem", "R0",2.0);
  rhomin      = par_getd_def("problem","rhomin",1.0e-3);
  Field      = par_getd_def("problem","Field",0);
  Hbc       = par_getd_def("problem","Hbc",1);
  Mbc       = par_getd_def("problem","Mbc",1);
  Mc        = par_getd_def("problem","Mc",20.0);

  srand(SEED + myID_Comm_world);
  for (k=kl; k<=ku; k++) {
    for (j=jl; j<=ju; j++) {
      for (i=il; i<=iu; i++) {
        cc_pos(pG,i,j,k,&x1,&x2,&x3);
        x1 = x1vc(pG,i);
        r = 2.0*rand()/((double)RAND_MAX) - 1.0;
        pG->U[k][j][i].d = rho0;
#ifdef FARGO
        pG->U[k][j][i].M2 = 0.0;
#else
        pG->U[k][j][i].M2 = pG->U[k][j][i].d*avg1d(vphi,pG,i,j,k);
#endif
        pG->U[k][j][i].M2 += pG->U[k][j][i].d*Amp*r*Iso_csound*ChiMag(x1);
				r = 2.0*rand()/((double)RAND_MAX)-1.0;
        pG->U[k][j][i].M1 = 0.0;
        pG->U[k][j][i].M3 = pG->U[k][j][i].d*Amp*r*Iso_csound*ChiMag(x1);
#ifdef MHD
        pG->U[k][j][i].B1c = 0.0;

        if (Field == 2) {
        	pG->U[k][j][i].B2c = BpNet(x1,x2,x3);
        } else {
          pG->U[k][j][i].B2c = 0.0;
        }
        if (Field == 0) {
          pG->U[k][j][i].B3c = BzZero(x1,x2,x3);
        } else if (Field == 1) {
          pG->U[k][j][i].B3c = BzNet(x1,x2,x3);
        } else {
        	pG->U[k][j][i].B3c = 0.0;
        }

        pG->B1i[k][j][i] = 0.0;
        pG->B2i[k][j][i] = pG->U[k][j][i].B2c;
        pG->B3i[k][j][i] = pG->U[k][j][i].B3c;

#endif

      }
    }
  }
#ifdef MHD
  if (Field != 2) {
  	ScaleToBeta(pG,Beta);
  }
#endif /* MHD */

  StaticGravPot = grav_pot;
  x1GravAcc = grav_acc;
  bvals_mhd_fun(pDomain,left_x1,disk_ir);
  bvals_mhd_fun(pDomain,right_x1,disk_or);
#ifdef FARGO
  OrbitalProfile = Omega;
  ShearProfile = Shear;
#endif
	// Enroll history functions
	//
#ifdef MHD
	dump_history_enroll(Br, "<Br>");
	dump_history_enroll(Bp, "<Bp>");
	dump_history_enroll(Bz, "<Bz>");
	dump_history_enroll(Mrp, "<Mrp>");
	dump_history_enroll(Trp, "<Trp>");
	dump_history_enroll(MdotR1, "<MdotR1>");
	dump_history_enroll(MdotR2, "<MdotR2>");
	dump_history_enroll(MdotR3, "<MdotR3>");
	dump_history_enroll(MdotR4, "<MdotR4>");
	dump_history_enroll(Msub, "<Msub>");
	dump_history_enroll(Mrpsub, "<Mrpsub>");
	dump_history_enroll(Bpsub, "<Bpsub>");
	dump_history_enroll(Bzsub, "<Bzsub>");
	dump_history_enroll(Pbsub, "<Pbsub>");

#endif
  return;

}
示例#8
0
void problem(DomainS *pDomain)
{
    GridS *pG = pDomain->Grid;
    int is = pG->is, ie = pG->ie;
    int js = pG->js, je = pG->je;
    int ks = pG->ks, ke = pG->ke;
    int ixs,jxs,kxs,i,j,k;
    long int iseed = -1; /* Initialize on the first call to ran2 */
    Real x1,x2,x3,xmin,xmax,Lx,Ly,Lz;
    Real rd, rp, rvx, rvy, rvz, rbx, rby, rbz;
    Real beta,B0,P0,kx,ky,kz,amp,press;
    Real Q,nJ,cs,cs2;
    Real time0,kxt;
#ifdef SELF_GRAVITY
    Real Gcons;
#endif

    int nwx,nwy,nwz;  /* input number of waves per Lx,Ly,Lz [default=1] */
    double rval;

    if(pG->Nx[2] == 1) ShBoxCoord = xy; /* 2D xy-plane */

    /* Read problem parameters. */
    Omega_0 = par_getd("problem","omega");
    qshear = par_getd("problem","qshear");
    amp = par_getd("problem","amp");

    /* Read parameters for magnetic field */
    beta = par_getd("problem","beta");

    /* Read parameters for self gravity */
    Q=par_getd("problem","Q");
    nJ= par_getd("problem","nJ");

    time0=par_getd_def("problem","time0",0.0);

    cs=sqrt(4.0-2.0*qshear)/PI/nJ/Q;
    cs2=SQR(cs);

#ifdef SELF_GRAVITY
    Gcons = nJ*cs2;
    grav_mean_rho = 1.0;
#ifndef SELF_GRAVITY_USING_FFT_DISK
    if(pG->Nx[2] >1) grav_mean_rho = 1.0;
#endif

    /* Set gravity constant*/
    four_pi_G = 4.0*PI*Gcons;
#endif /* SELF_GRAVITY */

    B0 = cs/sqrt(beta);
#ifndef BAROTROPIC
    P0 = cs2/Gamma;
#endif

    /* Ensure a different initial random seed for each process in an MPI calc. */
    ixs = pG->Disp[0];
    jxs = pG->Disp[1];
    kxs = pG->Disp[2];
    iseed = -1 - (ixs + pDomain->Nx[0]*(jxs + pDomain->Nx[1]*kxs));

    Lx = pDomain->RootMaxX[0] - pDomain->RootMinX[0];

    /* initialize wavenumbers, given input number of waves per L */
    nwx = par_geti_def("problem","nwx",-6);
    nwy = par_geti_def("problem","nwy",1);

    ky = nwy*2.0*PI;
    kx = nwx*2.0*PI;
    kxt = kx+qshear*Omega_0*ky*time0;

    pG->time=time0;

    for (k=ks; k<=ke; k++) {
        for (j=js; j<=je; j++) {
            for (i=is; i<=ie; i++) {
                cc_pos(pG,i,j,k,&x1,&x2,&x3);
                if (((i-pG->Disp[0]) == 58) && ((j-pG->Disp[1]) == 16))
                    printf("i=%d j=%d k=%d x1=%e x2=%e\n",i,j,k,x1,x2);

                rd  = 1.0+amp*cos(kxt*x1+ky*x2);
                rvx = amp*kx/ky*sin(kxt*x1+ky*x2);
                rvy = amp*sin(kxt*x1+ky*x2);
                rvz = 0.0;
                rp  = cs2*(rd-1.0);

                rbx = amp*nwy*cos(kxt*(x1-0.5*pG->dx1)+ky*x2);
                rby = -amp*nwx*cos(kxt*x1+ky*(x2-0.5*pG->dx2));
                rbz = 0.0;

                pG->U[k][j][i].d  = rd;
                pG->U[k][j][i].M1 = rd*rvx;
                pG->U[k][j][i].M2 = rd*rvy;
#ifndef FARGO
                pG->U[k][j][i].M2 -= rd*(qshear*Omega_0*x1);
#endif
                pG->U[k][j][i].M3 = rd*rvz;
#ifdef ADIABATIC
                pG->U[k][j][i].E = (P0+rp)/Gamma_1
                                   + 0.5*(SQR(pG->U[k][j][i].M1) + SQR(pG->U[k][j][i].M2)
                                          + SQR(pG->U[k][j][i].M3))/rd;
#endif

#ifdef MHD
                pG->B1i[k][j][i] = rbx;
                pG->B2i[k][j][i] = B0+rby;
                pG->B3i[k][j][i] = 0.0;

                if (i==ie) cc_pos(pG,ie+1,j,k,&x1,&x2,&x3);
                rbx = amp*nwy*cos(kx*(x1-0.5*pG->dx1)+ky*x2);
                if (j==je) cc_pos(pG,i,je+1,k,&x1,&x2,&x3);
                rby = -amp*nwx*cos(kx*x1+ky*(x2-0.5*pG->dx2));
                if (i==ie) pG->B1i[k][j][ie+1] = rbx;
                if (j==je) pG->B2i[k][je+1][i] = B0+rby;
                if (pG->Nx[2] > 1 && k==ke) pG->B3i[ke+1][j][i] = 0.0;
#endif /* MHD */
            }
        }
    }
#ifdef MHD
    for (k=ks; k<=ke; k++) {
        for (j=js; j<=je; j++) {
            for (i=is; i<=ie; i++) {
                pG->U[k][j][i].B1c = 0.5*(pG->B1i[k][j][i]+pG->B1i[k][j][i+1]);
                pG->U[k][j][i].B2c = 0.5*(pG->B2i[k][j][i]+pG->B2i[k][j+1][i]);
                if (pG->Nx[2] >1) pG->U[k][j][i].B3c = 0.5*(pG->B3i[k][j][i]+pG->B3i[k+1][j][i]);
                else pG->U[k][j][i].B3c =pG->B3i[k][j][i];
#ifdef ADIABATIC
                pG->U[k][j][i].E += 0.5*(SQR(pG->U[k][j][i].B1c)
                                         + SQR(pG->U[k][j][i].B2c) + SQR(pG->U[k][j][i].B3c));
#endif
            }
        }
    }
#endif /* MHD */

    /* enroll gravitational potential function */

    ShearingBoxPot = UnstratifiedDisk;

    /* enroll new history variables, only once with SMR  */

    dVol = pDomain->Nx[0]*pDomain->Nx[1]*pDomain->Nx[2];

    /* history dump for linear perturbation amplitude. See Kim & Ostriker 2001 */
    dump_history_enroll(hst_sigma, "<sigma>");
    dump_history_enroll(hst_ux, "<ux>");
    dump_history_enroll(hst_uy, "<uy>");
#ifdef MHD
    dump_history_enroll(hst_m1, "<m1>");
    dump_history_enroll(hst_m2, "<m2>");
#endif

    /* history dump for peturbed quantities at a specific grid point */
    dump_history_enroll(hst_dSigma, "<dSigma>");
    dump_history_enroll(hst_Vx, "<Vx>");
    dump_history_enroll(hst_dVy, "<dVy>");

#ifdef MHD
    dump_history_enroll(hst_Bx, "<Bx>");
    dump_history_enroll(hst_dBy, "<dBy>");
#endif /* MHD */
#ifdef SELF_GRAVITY
    dump_history_enroll(hst_Phi, "<Phi>");
    dump_history_enroll(hst_dPhi, "<dPhi>");
#endif
#ifdef ADIABATIC
    dump_history_enroll(hst_dE, "<dE>");
#endif

    printf("=== end of problem setting ===\n");
    return;
}
示例#9
0
void problem_read_restart(MeshS *pM, FILE *fp)
{
    Real beta, Q, nJ, cs, cs2, Gcons;

    /* Read problem parameters. */
    Omega_0 = par_getd("problem","omega");
    qshear = par_getd("problem","qshear");

    /* Read parameters for magnetic field */
    beta = par_getd("problem","beta");

    /* Read parameters for self gravity */
    Q=par_getd("problem","Q");
    nJ= par_getd("problem","nJ");

    cs=sqrt(4.0-2.0*qshear)/PI/nJ/Q;
    cs2=SQR(cs);

#ifdef SELF_GRAVITY
    Gcons = nJ*cs2;
    grav_mean_rho = 1.0;
#ifndef SELF_GRAVITY_USING_FFT_DISK
    if(pM->Nx[2] >1) grav_mean_rho = 1.0;
#endif

    /* Set gravity constant*/
    four_pi_G = 4.0*PI*Gcons;
#endif /* SELF_GRAVITY */

    /* enroll gravitational potential function */

    ShearingBoxPot = UnstratifiedDisk;

    /* history dump for linear perturbation amplitude. See Kim & Ostriker 2001 */
    dump_history_enroll(hst_sigma, "<sigma>");
    dump_history_enroll(hst_ux, "<ux>");
    dump_history_enroll(hst_uy, "<uy>");
#ifdef MHD
    dump_history_enroll(hst_m1, "<m1>");
    dump_history_enroll(hst_m2, "<m2>");
#endif


    /* history dump for peturbed quantities at a specific grid point */
    dump_history_enroll(hst_dSigma, "<dSigma>");
    dump_history_enroll(hst_Vx, "<Vx>");
    dump_history_enroll(hst_dVy, "<dVy>");

#ifdef MHD
    dump_history_enroll(hst_Bx, "<Bx>");
    dump_history_enroll(hst_dBy, "<dBy>");
#endif /* MHD */
#ifdef SELF_GRAVITY
    dump_history_enroll(hst_Phi, "<Phi>");
    dump_history_enroll(hst_dPhi, "<dPhi>");
#endif

    /* should be modified for SMR version */
    dVol = 1.0;
    if (pM->dx[0] > 0.0) dVol /= pM->dx[0];
    if (pM->dx[1] > 0.0) dVol /= pM->dx[1];
    if (pM->dx[2] > 0.0) dVol /= pM->dx[2];


    return;
}
示例#10
0
void problem(DomainS *pDomain)
{
  GridS *pGrid = pDomain->Grid;
  int i=0,j=0,k=0;
  int is,ie,js,je,ks,ke,iprob;
  Real amp,drat,vflow,b0,a,sigma,x1,x2,x3;
  long int iseed = -1;
  static int frst=1;  /* flag so new history variables enrolled only once */

  is = pGrid->is; ie = pGrid->ie;
  js = pGrid->js; je = pGrid->je;
  ks = pGrid->ks; ke = pGrid->ke;

/* Read problem parameters */

  iprob = par_geti("problem","iprob");
  vflow = par_getd("problem","vflow");
  drat = par_getd("problem","drat");
  amp = par_getd("problem","amp");
#ifdef MHD
  b0  = par_getd("problem","b0");
#endif

/* iprob=1.  Two uniform streams moving at +/- vflow, random perturbations */

  if (iprob == 1) {
    for (k=ks; k<=ke; k++) {
      for (j=js; j<=je; j++) {
        for (i=is; i<=ie; i++) {
          cc_pos(pGrid,i,j,k,&x1,&x2,&x3);
          pGrid->U[k][j][i].d = 1.0;
          pGrid->U[k][j][i].M1 = vflow + amp*(ran2(&iseed) - 0.5);
          pGrid->U[k][j][i].M2 = amp*(ran2(&iseed) - 0.5);
          pGrid->U[k][j][i].M3 = 0.0;
          if (fabs(x2) < 0.25) {
  	    pGrid->U[k][j][i].d = drat;
            pGrid->U[k][j][i].M1 = -drat*(vflow + amp*(ran2(&iseed) - 0.5));
            pGrid->U[k][j][i].M2 = drat*amp*(ran2(&iseed) - 0.5);
          }
/* Pressure scaled to give a sound speed of 1 with gamma=1.4 */
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E = 2.5/Gamma_1
             + 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 /* BAROTROPIC */
#ifdef MHD
          pGrid->B1i[k][j][i] = b0;
          pGrid->U[k][j][i].B1c = b0;
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E += 0.5*b0*b0;
#endif /* BAROTROPIC */
#endif /* MHD */
        }
#ifdef MHD
      pGrid->B1i[k][j][ie+1] = b0;
#endif
      }
    }
  }

/* iprob=2.  Test suggested by E. Zweibel, based on Ryu & Jones.
 * Two uniform density flows with single mode perturbation
 */

  if (iprob == 2) {
    a = 0.05;
    sigma = 0.2;
    for (k=ks; k<=ke; k++) {
      for (j=js; j<=je; j++) {
        for (i=is; i<=ie; i++) {
          cc_pos(pGrid,i,j,k,&x1,&x2,&x3);
          pGrid->U[k][j][i].d = 1.0;
          pGrid->U[k][j][i].M1 = vflow*tanh(x2/a);
          pGrid->U[k][j][i].M2 = amp*sin(2.0*PI*x1)*exp(-(x2*x2)/(sigma*sigma));
          pGrid->U[k][j][i].M3 = 0.0;
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E = 1.0/Gamma_1
             + 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 /* BAROTROPIC */
#ifdef MHD
          pGrid->B1i[k][j][i] = b0;
          pGrid->U[k][j][i].B1c = b0;
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E += 0.5*b0*b0;
#endif /* BAROTROPIC */
#endif /* MHD */
/* Use passive scalar to keep track of the fluids, since densities are same */
#if (NSCALARS > 0)
          pGrid->U[k][j][i].s[0] = 0.0;
          if (x2 > 0) pGrid->U[k][j][i].s[0] = 1.0;
#endif
        }
#ifdef MHD
      pGrid->B1i[k][j][ie+1] = b0;
#endif
      }
    }
  }

/* iprob=3.  Test in SR paper, based on iprob=2
 */

  if (iprob == 3) {
    a = 0.01;
    sigma = 0.1;
    for (k=ks; k<=ke; k++) {
      for (j=js; j<=je; j++) {
        for (i=is; i<=ie; i++) {
          cc_pos(pGrid,i,j,k,&x1,&x2,&x3);
          pGrid->U[k][j][i].d = 0.505 + 0.495*tanh((fabs(x2)-0.5)/a);
          pGrid->U[k][j][i].M1 = vflow*tanh((fabs(x2)-0.5)/a);
          pGrid->U[k][j][i].M2 = amp*vflow*sin(2.0*PI*x1)
               *exp(-((fabs(x2)-0.5)*(fabs(x2)-0.5))/(sigma*sigma));
          if (x2 < 0.0) pGrid->U[k][j][i].M2 *= -1.0;
          pGrid->U[k][j][i].M1 *= pGrid->U[k][j][i].d;
          pGrid->U[k][j][i].M2 *= pGrid->U[k][j][i].d;
          pGrid->U[k][j][i].M3 = 0.0;
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E = 1.0/Gamma_1
             + 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 /* BAROTROPIC */
#ifdef MHD
          pGrid->B1i[k][j][i] = b0;
          pGrid->U[k][j][i].B1c = b0;
#ifndef BAROTROPIC
          pGrid->U[k][j][i].E += 0.5*b0*b0;
#endif /* BAROTROPIC */
#endif /* MHD */
        }
#ifdef MHD
      pGrid->B1i[k][j][ie+1] = b0;
#endif
      }
    }
  }

/* With viscosity and/or resistivity, read diffusion coeffs */

#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 VISCOSITY
  nu_iso = par_getd_def("problem","nu_iso",0.0);
  nu_aniso = par_getd_def("problem","nu_aniso",0.0);
#endif

/* enroll new history variables, only once  */

  if (frst == 1) {
#ifdef MHD
    dump_history_enroll(hst_Bx, "<Bx>");
    dump_history_enroll(hst_By, "<By>");
    dump_history_enroll(hst_Bz, "<Bz>");
#endif /* MHD */
    frst = 0;
  }

}
示例#11
0
void problem(DomainS *pDomain)
{
  GridS *pGrid = pDomain->Grid;
  int i,j,k,ks,pt,tsmode;
  long p,q;
  Real ScaleHg,tsmin,tsmax,tscrit,amin,amax,Hparmin,Hparmax;
  Real *ep,*ScaleHpar,epsum,mratio,pwind,rhoaconv,etavk;
  Real *epsilon,*uxNSH,*uyNSH,**wxNSH,**wyNSH;
  Real rhog,h,x1,x2,x3,t,x1p,x2p,x3p,zmin,zmax,dx3_1,b;
  long int iseed = myID_Comm_world; /* Initialize on the first call to ran2 */

  if (pDomain->Nx[2] == 1) {
    ath_error("[par_strat3d]: par_strat3d only works for 3D problem.\n");
  }
  
#ifdef MPI_PARALLEL
  if (pDomain->NGrid[2] > 2) {
    ath_error(   
  "[par_strat3d]: The z-domain can not be decomposed into more than 2 grids\n");
  }
#endif

/* Initialize boxsize */
  x1min = pGrid->MinX[0];
  x1max = pGrid->MaxX[0];
  Lx = x1max - x1min;

  x2min = pGrid->MinX[1];
  x2max = pGrid->MaxX[1];
  Ly = x2max - x2min;

  x3min = par_getd("domain1","x3min");
  x3max = par_getd("domain1","x3max");
  Lz = x3max - x3min;

  Lg = nghost*pGrid->dx3; /* size of the ghost zone */

  ks = pGrid->ks;

/* Read initial conditions */
  Omega_0 = par_getd("problem","omega");
  qshear = par_getd_def("problem","qshear",1.5);
  ipert = par_geti_def("problem","ipert",1);
  vsc1 = par_getd_def("problem","vsc1",0.05); /* in unit of iso_sound (N.B.!) */
  vsc2 = par_getd_def("problem","vsc2",0.0);

  vsc1 = vsc1 * Iso_csound;
  vsc2 = vsc2 * Iso_csound;

  ScaleHg = Iso_csound/Omega_0;

  /* particle number */
  Npar  = (long)(par_geti("particle","parnumgrid"));

  pGrid->nparticle = Npar*npartypes;
  for (i=0; i<npartypes; i++)
    grproperty[i].num = Npar;

  if (pGrid->nparticle+2 > pGrid->arrsize)
    particle_realloc(pGrid, pGrid->nparticle+2);

  ep = (Real*)calloc_1d_array(npartypes, sizeof(Real));
  ScaleHpar = (Real*)calloc_1d_array(npartypes, sizeof(Real));

  epsilon = (Real*)calloc_1d_array(npartypes, sizeof(Real));
  wxNSH   = (Real**)calloc_2d_array(pGrid->Nx[2]+1, npartypes,sizeof(Real));
  wyNSH   = (Real**)calloc_2d_array(pGrid->Nx[2]+1, npartypes,sizeof(Real));
  uxNSH   = (Real*)calloc_1d_array(pGrid->Nx[2]+1, sizeof(Real));
  uyNSH   = (Real*)calloc_1d_array(pGrid->Nx[2]+1, sizeof(Real));

  /* particle stopping time */
  tsmode = par_geti("particle","tsmode");
  if (tsmode == 3) {/* fixed stopping time */
    tsmin = par_getd("problem","tsmin"); /* in code unit */
    tsmax = par_getd("problem","tsmax");
    tscrit= par_getd("problem","tscrit");

    for (i=0; i<npartypes; i++) {
      tstop0[i] = tsmin*exp(i*log(tsmax/tsmin)/MAX(npartypes-1,1.0));
      grproperty[i].rad = tstop0[i];
      /* use fully implicit integrator for well coupled particles */
      if (tstop0[i] < tscrit) grproperty[i].integrator = 3;
    }
  }
  else { 
    amin = par_getd("problem","amin");
    amax = par_getd("problem","amax");

    for (i=0; i<npartypes; i++)
      grproperty[i].rad = amin*exp(i*log(amax/amin)/MAX(npartypes-1,1.0));

    if (tsmode <= 2) {/* Epstein/General regime */
      /* conversion factor for rhoa */
      rhoaconv = par_getd_def("problem","rhoaconv",1.0);

      for (i=0; i<npartypes; i++)
        grrhoa[i]=grproperty[i].rad*rhoaconv;
    }

    if (tsmode == 1)  /* General drag formula */
      alamcoeff = par_getd("problem","alamcoeff");
  }

  /* particle scale height */
  Hparmax = par_getd("problem","hparmax"); /* in unit of gas scale height */
  Hparmin = par_getd("problem","hparmin");
  for (i=0; i<npartypes; i++) 
    ScaleHpar[i] = Hparmax*
                   exp(-i*log(Hparmax/Hparmin)/MAX(npartypes-1,1.0));

#ifdef FEEDBACK
  mratio = par_getd_def("problem","mratio",0.0); /* total mass fraction */
  pwind = par_getd_def("problem","pwind",0.0);   /* power law index */
  if (mratio < 0.0)
    ath_error("[par_strat2d]: mratio must be positive!\n");

  epsum = 0.0;
  for (i=0; i<npartypes; i++)
  {
    ep[i] = pow(grproperty[i].rad,pwind);	epsum += ep[i];
  }

  for (i=0; i<npartypes; i++)
  {
    ep[i] = mratio*ep[i]/epsum;
    grproperty[i].m = sqrt(2.0*PI)*ScaleHg/Lz*ep[i]*
                                   pGrid->Nx[0]*pGrid->Nx[1]*pGrid->Nx[2]/Npar;
  }
#else
  mratio = 0.0;
  for (i=0; i<npartypes; i++)
    ep[i] = 0.0;
#endif

  /* NSH equilibrium */
  for (k=pGrid->ks; k<=pGrid->ke+1; k++) {

    h = pGrid->MinX[2] + (k-pGrid->ks)*pGrid->dx3;
    q = k - ks;
    etavk = fabs(vsc1+vsc2*SQR(h));

    for (i=0; i<npartypes; i++) {
      epsilon[i] = ep[i]/ScaleHpar[i]*exp(-0.5*SQR(h/ScaleHg)
         *(SQR(1.0/ScaleHpar[i])-1.0))/erf(Lz/(sqrt(8.0)*ScaleHpar[i]*ScaleHg));

      if (tsmode != 3)
        tstop0[i] = get_ts(pGrid,i,exp(-0.5*SQR(h/ScaleHg)),Iso_csound,etavk);
    }

    MultiNSH(npartypes, tstop0, epsilon, etavk,
                              &uxNSH[q], &uyNSH[q], wxNSH[q], wyNSH[q]);
  }

/* Now set initial conditions for the gas */
  for (k=pGrid->ks; k<=pGrid->ke; k++) {
  for (j=pGrid->js; j<=pGrid->je; j++) {
  for (i=pGrid->is; i<=pGrid->ie; i++) {
    cc_pos(pGrid,i,j,k,&x1,&x2,&x3);

    rhog = exp(-0.5*SQR(x3/ScaleHg));
    pGrid->U[k][j][i].d = rhog;

    if (ipert != 1) {/* NSH velocity */
      pGrid->U[k][j][i].M1 = 0.5*rhog*(uxNSH[k-ks]+uxNSH[k-ks+1]);
      pGrid->U[k][j][i].M2 = 0.5*rhog*(uyNSH[k-ks]+uyNSH[k-ks+1]);
    } else {
      pGrid->U[k][j][i].M1 = 0.0;
      pGrid->U[k][j][i].M2 = 0.0;
    }

    pGrid->U[k][j][i].M3 = 0.0;
#ifndef FARGO
    pGrid->U[k][j][i].M2 -= qshear*rhog*Omega_0*x1;
#endif

  }}}

/* Now set initial conditions for the particles */
  p = 0;
  dx3_1 = 1.0/pGrid->dx3;
  zmin = pGrid->MinX[2];
  zmax = pGrid->MaxX[2];

  for (q=0; q<Npar; q++) {

    for (pt=0; pt<npartypes; pt++) {

      x1p = x1min + Lx*ran2(&iseed);
      x2p = x2min + Ly*ran2(&iseed);
      x3p = ScaleHpar[pt]*ScaleHg*Normal(&iseed);
      while ((x3p >= zmax) || (x3p < zmin))
        x3p = ScaleHpar[pt]*ScaleHg*Normal(&iseed);

      pGrid->particle[p].property = pt;
      pGrid->particle[p].x1 = x1p;
      pGrid->particle[p].x2 = x2p;
      pGrid->particle[p].x3 = x3p;

      if (ipert != 1) {/* NSH velocity */

        cellk(pGrid, x3p, dx3_1, &k, &b);
        k = k-pGrid->ks;  b = b - pGrid->ks;

        pGrid->particle[p].v1 = (k+1-b)*wxNSH[k][pt]+(b-k)*wxNSH[k+1][pt];
        pGrid->particle[p].v2 = (k+1-b)*wyNSH[k][pt]+(b-k)*wyNSH[k+1][pt];

      } else {

        pGrid->particle[p].v1 = 0.0;
        pGrid->particle[p].v2 = vsc1+vsc2*SQR(x2p);

      }

      pGrid->particle[p].v3 = 0.0;
#ifndef FARGO
      pGrid->particle[p].v2 -= qshear*Omega_0*x1p;
#endif

      pGrid->particle[p].pos = 1; /* grid particle */
      pGrid->particle[p].my_id = p;
#ifdef MPI_PARALLEL
      pGrid->particle[p].init_id = myID_Comm_world;
#endif
      p++;
  }}

/* enroll gravitational potential function, shearing sheet BC functions */
  ShearingBoxPot = StratifiedDisk;

  dump_history_enroll(hst_rho_Vx_dVy, "<rho Vx dVy>");

  /* set the # of the particles in list output
   * (by default, output 1 particle per cell)
   */
  nlis = par_geti_def("problem","nlis",pGrid->Nx[0]*pGrid->Nx[1]*pGrid->Nx[2]);

  /* set the number of particles to keep track of */
  ntrack = par_geti_def("problem","ntrack",2000);

  /* set the threshold particle density */
  dpar_thresh = par_geti_def("problem","dpar_thresh",10.0);

  /* finalize */
  free(ep);  free(ScaleHpar);
  free(epsilon);
  free_2d_array(wxNSH);  free_2d_array(wyNSH);
  free(uxNSH);           free(uyNSH);

  return;
}