The Basic Knowledge of AMRVAC – 3. Initial Condition

In this part, with the knowledge of LASY in the previous part, I will tell you how to set initial conditions in AMRVAC.

First, remember to write this line,

usr_init_one_grid => initonegrid_usr

in subroutine usr_init().

Then, all your settings for initial condition could be wrote in subroutine initongrid_usr(ixI^L,ixO^L,w,x).
A typical 2D MHD example would be:

 subroutine initonegrid_usr(ixI^L,ixO^L,w,x)
    integer, intent(in) :: ixI^L, ixO^L
    double precision, intent(in) :: x(ixI^S,1:ndim)
    double precision, intent(inout) :: w(ixI^S,1:nw)

    w(ixO^S,rho_)=1.d0
    w(ixO^S,mom(1))=0.d0
    w(ixO^S,mom(2))=0.d0
    w(ixO^S,p_)=0.d0
    w(ixO^S,mag(1))=0.d0
    w(ixO^S,mag(2))=0.d0
    call mhd_to_conserved(ixI^L,ixO^L,w,x)
end subroutine initonegrid_usr

First, ixI^L and ixO^L can be convert to ixImin1,ixImax1,ixImin2,ixImax2 and ixOmin1,ixOmax1,ixOmin2,ixOmax2, respectively, which have been explained in the previous note. Here, ixI^L means the indices of the input zone and ixO^L is the output zone. For example, you have 16 grids in one block, then, in most cases, ixImin1=1, ixImax1=16; while for ixO^L, it will be a smaller zone, for example, ixOmin1=3, ixOmax1=14 or something like that. In this case, the difference between the input and output zone is caused by the so-called ghostcells, which are used to provide boundary conditions for the output zone near the boundary.

x is the variable that saves all the coordinate information. For example, x(ixI^S,1) saves the x information and x(ixI^S,2) saves the y information if it is a Cartesian coordinate.

w is the variable that saves all the physical variable in. Its spatial size is the same with x, and will have an extra dimension which is same with the number of variables, nw. For 3D MHD, the most complicated case, nw = 8, which in the order of rho_, mom(1), mom(2), mom(3), e_, mag(1), mag(2), mag(3) which means density, momentum in 3 directions, volumetric energy density, magnetic induction in 3 directions. This is the so-called conservation form of variables. The corresponding primitive form is density, velocity, thermal pressure and magnetic induction. In addition, we have prepared another for energy density which is p_, means thermal pressure, you can uses it instead of e_ when representing primitive variables, but actually they have no differences, p_ and e_ are treated in the same way by the code. It is just used for you to distinguish them when writing the code.

Then, giving initial condition means giving values to w in the zone x(ixO^S). Since usually, we prefer to define thermal pressure and velocity instead of energy density and momentum when giving initial condition, you can give them define them all in the primitive form. However, the code will treat all the variables as conservation variables, you should convert them into conservation form by call mhd_to_conserved(ixI^L,ixO^L,w,x), whose meaning is obvious. And a corresponding subroutine is mhd_to_primitive.

These two subroutines, subroutine initonegrid_usr and subroutine usr_init(), should be written in the mod_usr.t file in all meaningful cases. You can run a simulation just with this two subroutines wirtten in mod_usr.t. For other subroutines, we will talk about it later after we finished talking about amrvac.par in the next note.

发表评论

邮箱地址不会被公开。 必填项已用*标注