Blog: BE update: problem.f90

File problem.f90, 5.5 KB (added by Erica Kaminski, 14 years ago)
Line 
1!============================================================================
2! This problem places a bonner ebert sphere in the center of the grid.
3!============================================================================
4
5
6MODULE PROBLEM
7
8 USE DataDeclarations
9 USE GlobalDeclarations
10 USE PhysicsDeclarations
11 USE BE_MODULE
12 USE WINDS
13
14 IMPLICIT NONE ! It's safer to require explicit declarations
15 SAVE ! Save module information
16 PRIVATE
17
18 PUBLIC ProblemModuleInit, ProblemGridInit, &
19 ProblemBeforeStep, ProblemAfterStep, ProblemSetErrFlag
20 TYPE(pWindDef), DIMENSION(:), ALLOCATABLE :: MyWinds
21 INTEGER :: nWinds
22 REAL(KIND=qPrec) :: central_rho, xi, clump_rad, rho_out, m_star, at, rho_c, gravo_thermal, time_f, iso_t
23 NAMELIST /ProblemData/ central_rho, xi, clump_rad, gravo_thermal
24
25CONTAINS
26
27 SUBROUTINE ProblemModuleInit
28 INTEGER :: i, edge
29
30 ! Read in problem params and vars
31
32 OPEN(UNIT = PROBLEM_DATA_HANDLE, FILE = 'problem.data')
33 READ(PROBLEM_DATA_HANDLE, NML=ProblemData)
34 CLOSE(PROBLEM_DATA_HANDLE)
35 central_rho = central_rho*hmass*Xmu ! now is g/cc
36 CALL CalcAmbientParams(central_rho, REAL(xi), clump_rad, M_star, at, rho_out, iso_t)
37 gravo_thermal = Sqrt((4*pi*G*central_rho)/(at**2)) ! Gravo_thermal radius -- constant that scales r to xi
38 IF (MPI_ID == 0) THEN
39
40 WRITE (*,*) 'The mass (in solar masses) of your star is:' , M_star/msolar
41 WRITE (*,*) 'The isothermal sound speed (m/s) of your star and surrounding medium is:' , aT
42 WRITE (*,*) 'The isothermal temperature (K) of your star and surrounding medium is:', iso_T
43
44 IF ((central_rho/rho_out) < 14.1) THEN
45 WRITE (*,*) 'Your BE sphere IS stable. Rho_c/Rho_o = ', central_rho/rho_out, "(less than 14.1)"
46 ELSE
47 WRITE(*,*) '!!Your BE sphere is NOT stable!! Rho_c/Rho_o =', central_rho/rho_out, "(greater than 14.1)"
48 END IF
49 time_f = clump_rad/at !sound crossing time in cgs
50 time_f = time_f/timeScale !sound crossing time in cu
51 WRITE(*,*) 'The sound crossing time for your clump in computational units is:', time_f
52 WRITE(*,*) 'The central density of your clump (in CGS) is:', central_rho
53
54 END IF
55
56 ALLOCATE(MyWinds(6))
57 nWinds = 0
58 Do i=1, nDim
59 Do edge= 1,2
60 IF (Gmthbc(i,edge) ==1) THEN
61 nWinds=nWinds +1
62 ALLOCATE(MyWinds(nWinds)%p)
63 MyWinds(nWinds)%p%dir=i
64 MyWinds(nWinds)%p%edge=edge
65 CALL InitializeWind(MyWinds(nWinds)%p)
66 END IF
67 END DO
68 END DO
69
70 END SUBROUTINE ProblemModuleInit
71
72 SUBROUTINE ProblemGridInit(Info) !Specific for each info structure
73 Type (InfoDef) :: Info
74 INTEGER :: i, j, k, mx, my, mz
75 INTEGER :: mbc, rmbc, zrmbc
76 INTEGER :: nx, ny, nz
77 INTEGER :: ndim
78 REAL(KIND=xPrec):: x, y, z, xlower, ylower, zlower,dx, dy, dz, r, gravo_thermal, at
79
80
81 ! Assigning shorthand notation for variables already defined in Info
82 rmbc=levels(Info%level)%gmbc(levels(Info%level)%step)! Sets up ghost cells and boundaries
83 mx=Info%mx(1); xlower=Info%Xbounds(1,1)
84 my=Info%mx(2); ylower=Info%Xbounds(2,1)
85 mz=Info%mx(3); zlower=Info%Xbounds(3,1)
86
87 dx=levels(Info%level)%dx
88
89 ! These seem to be "nested" variable declarations a=b=c...?
90
91
92 SELECT CASE(nDim)
93 CASE(2)
94 zrmbc=0
95 mz=1
96 zlower=0
97 dz=0
98 CASE(3)
99 zrmbc=rmbc
100 END SELECT
101
102 ! Initializing the environment
103 Info%q(:,:,:,:)=0.d0 ! Sanity check -- setting grid to zero
104 at = (2*clump_rad*SQRT(PI*G*central_rho))/xi
105 gravo_thermal = Sqrt((4*pi*G*central_rho)/(at**2)) ! Gravo_thermal radius -- constant that scales r to xi
106 ! Must I allocate an array anywhere for Astrobear 2.0?
107 ! i,j,k are indices of cells, and x,y,z are spatial cartesian coords
108 Do k=1-zrmbc, mz+zrmbc
109 Do j=1-rmbc, my+rmbc
110 Do i=1-rmbc, mx+rmbc
111 x=(xlower + (REAL(i, xPrec)-half)*dx)
112 y=(ylower + (REAL(j, xPrec)-half)*dx)
113 z=(zlower + (REAL(k, xPrec)-half)*dx)
114 r = Sqrt(x**2+y**2+z**2)
115 r = (r*lscale)*gravo_thermal ! takes r to xi
116 IF (r <= xi) THEN ! if r<pc
117 Info%q(i,j,k,1) = (central_rho*BE_RHO(REAL(r)))/rscale
118 ELSE
119 Info%q(i,j,k,1) = rho_out/rscale
120 END IF
121 ! M_star = 8*PI*central_rho*clump_rad**3 *((1 + alpha)/(6 + xi**2) - (6*alpha)/(6 + xi**2)**2 - alpha/(3**(1/alpha)*12*e + xi**2) + D*(2**(-alpha)-1)/ (1+2**(-alpha) * D* xi**2)*(1+D*xi**2))
122 Info%q(i,j,k,iE) = (((Info%q(i,j,k,1)*rscale*(aT**2))/gamma)*gamma7)/pScale
123 END DO
124 END DO
125 END DO
126
127
128 IF ((central_rho/rho_out) < 14.1) THEN
129 WRITE (191,*) '#Your BE sphere IS stable.'
130 ELSE
131 WRITE(191,*) '#Your BE sphere is NOT stable!!'
132 END IF
133
134
135 END SUBROUTINE ProblemGridInit
136
137 ! Applies Boundary Conditions
138 SUBROUTINE ProblemBeforeStep(INFO)
139
140 TYPE(INFODEF) :: INFO
141 INTEGER :: i
142
143 END SUBROUTINE ProblemBeforeStep
144
145 SUBROUTINE ProblemAfterStep(INFO)
146 TYPE(INFODEF) :: INFO
147 ! No special after step instructions needed; this is a stub.
148
149 END SUBROUTINE ProblemAfterStep
150
151 SUBROUTINE ProblemSetErrFlag(INFO)
152 TYPE(INFODEF) :: INFO
153 ! No special instructions needed; this is a stub.
154
155 END SUBROUTINE ProblemSetErrFlag
156
157
158END MODULE PROBLEM