-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitialiseND_mhd.f90
333 lines (322 loc) · 9.41 KB
/
initialiseND_mhd.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
!------------------------------------------------------------------------------!
! NDSPMHD: A Smoothed Particle (Magneto)Hydrodynamics code for (astrophysical) !
! fluid dynamics simulations in 1, 2 and 3 spatial dimensions. !
! !
! (c) 2002-2015 Daniel Price !
! !
! http://users.monash.edu.au/~dprice/ndspmhd !
! daniel.price@monash.edu -or- dprice@cantab.net (forwards to current address) !
! !
! NDSPMHD comes with ABSOLUTELY NO WARRANTY. !
! This is free software; and you are welcome to redistribute !
! it under the terms of the GNU General Public License !
! (see LICENSE file for details) and the provision that !
! this notice remains intact. If you modify this file, please !
! note section 2a) of the GPLv2 states that: !
! !
! a) You must cause the modified files to carry prominent notices !
! stating that you changed the files and the date of any change. !
! !
! ChangeLog: !
!------------------------------------------------------------------------------!
!!-----------------------------------------------------------------
!! This subroutine initialises everything needed for the run
!!-----------------------------------------------------------------
subroutine initialise
!
!--include relevant global variables
!
! use dimen_mhd
use debug, only:trace
use loguns, only:iprint,ievfile,ifile,rootname
use artvi
use bound
use derivb
use eos
use fmagarray
use kernels,only:setkern,setkernels,kernelname,kernelnamealt,radkern,&
setkerndrag,kernelnamedrag
use hterms
use rates
use timestep
use options
use part
use part_in
use setup_params
use infiles, only:read_infile
use dumpfiles, only:read_dump
use convert, only:convert_setup
use cons2prim, only:primitive2conservative
use dust, only:init_drag
!
!--define local variables
!
implicit none
character(len=len(rootname)+3) :: infile,evfile,dumpfile
character(len=len(rootname)+6) :: logfile ! rootname is global in loguns
integer :: i,j,idash,idot,ierr,idotin,ierr1,ierr2
logical :: iexist
real :: radkernold
!
!--if filename is of the form crap_xxxxx.dat restart from a given dump
!
idash = index(rootname,'_')
idot = index(rootname,'.dat')
if (idash.ne.0) then
if (idot.eq.0) then
idot = len_trim(rootname)+1
dumpfile = trim(rootname)//'.dat'
!!write(dumpfile,"(a,i5.5,'.dat')") trim(rootname),ifile
else
dumpfile = trim(rootname)
endif
read(rootname(idash+1:idot-1),*,iostat=ierr) ifile
if (ierr /=0) then
print*,'***could not extract dump number ***'
print*,'***starting new run using dumpfile***'
ifile = 0
endif
rootname = rootname(1:idash-1)
print*,'ifile = ',ifile,'rootname = ',trim(rootname)
!!ifile = ifile - 1
!stop
else
!
!--trim the .in if present
!
idotin = index(rootname,'.in')
if (idotin.gt.0) rootname = rootname(1:idotin-1)
ifile = -1
endif
!
!--add extensions to set filenames (remove trailing blanks)
!
infile = TRIM(rootname)//'.in'
evfile = TRIM(rootname)//'.ev'
!! datfile = TRIM(rootname)//'.dat'
logfile = TRIM(rootname)//'.log'
!
!--Initialise log file (if used)
!
if (iprint.ne.6) then
if (ifile.le.0) then
open(unit=iprint,file=logfile,err=669,status='replace',form='formatted')
else
inquire(file=logfile,exist=iexist)
if (iexist) then
i = 0
do while(iexist)
i = i + 1
write(logfile,"(a,i2.2,'.log')") trim(rootname),i
inquire(file=logfile,exist=iexist)
enddo
endif
open(unit=iprint,file=logfile,err=669,status='new',form='formatted')
endif
else
logfile = 'screen '
endif
!
!--start tracing flow into logfile
!
if (trace) write(iprint,*) ' entering subroutine initialise'
!
!--set some global parameters based on ndim
!
if (ndim.gt.3 .or. ndim.le.0 .or. ndimv.gt.3 .or. ndimv.le.0) then
stop 'ERROR ndim <=0 or >3: We leave string theory for later'
else
dndim = 1./real(ndim)
endif
time = 0.
nsteps = 0
xmin = 0.
xmax = 0.
nbpts = 0
bconst(:) = 0.
vsig2max = 0.
!
!--read parameters from the infile
!
call set_default_options ! set the default options
call read_infile(infile)
! geom = 'cylrpz'
onef_dust = (idust==1 .or. idust==3 .or. idust==4)
!
!--Open data/ev files
!
if (ifile.gt.0) then
inquire(file=evfile,exist=iexist)
if (iexist) then
i = 0
do while(iexist)
i = i + 1
write(evfile,"(a,i2.2,'.ev')") trim(rootname),i
inquire(file=evfile,exist=iexist)
enddo
endif
endif
open(unit=ievfile,err=668,file=evfile,status='replace',form='formatted')
!
!--work out multiplication factor for source term in morris and monaghan scheme
! (just from gamma)
if (abs(gamma-1.).gt.1.e-3) then ! adiabatic
avfact = log(4.)/(log((gamma+1.)/(gamma-1.)))
else
avfact = 1.0 ! isothermal
endif
!
!--write first header to logfile/screen
!
call write_header(1,infile,evfile,logfile)
!
!--setup kernel tables
!
if (ibiascorrection.gt.0) then
ikernel = 3
ikernelalt = 2
elseif (usenumdens) then
ikernelalt = ikernel !43
else
ikernelalt = ikernel
endif
call setkernels(ikernel,ikernelalt,ndim,ierr1,ierr2)
write(iprint,"(/,' Smoothing kernel = ',a)") trim(kernelname)
radkernold = radkern
!
!--setup drag kernel ONLY if idrag_nature > 0
! also radkern MUST match between kernels
!
ierr = 0
if (idust /= 0) then
select case(ikernel)
case(0)
call setkerndrag(41,ndim,ierr)
case(2)
call setkerndrag(42,ndim,ierr)
case(3)
call setkerndrag(43,ndim,ierr)
case(99)
call setkerndrag(99,ndim,ierr)
print*,'CAREFUL, HEXIC/HEPTIC DOUBLE HUMP NOT IMPLEMENTED YET'
case(100)
call setkerndrag(100,ndim,ierr)
print*,'CAREFUL, HEXIC/HEPTIC DOUBLE HUMP NOT IMPLEMENTED YET'
case default
call setkerndrag(41,ndim,ierr)
if (idrag_nature.gt.0) stop 'cannot get matching drag kernel'
end select
if (radkern.ne.radkernold) stop 'drag kernel has different support radius'
write(iprint,"(' Drag kernel = ',a)") trim(kernelnamedrag)
endif
if (ikernelalt.ne.ikernel) write(iprint,"(' Number density kernel = ',a)") trim(kernelnamealt)
if (ierr1.ne.0 .or. ierr2.ne.0 .or. ierr.ne.0) stop 'error with kernel setup'
npart = 0
!
!--initialise drag terms
!
if (idust /= 0) call init_drag(ierr,gamma)
if (ifile.lt.0) then
write(iprint,"(1x,80('-'))")
call setup ! setup particles, allocation of memory is called
write(iprint,"(1x,80('-'))")
else
call read_dump(trim(dumpfile),time) ! or read from dumpfile
endif
!
!--change coordinate systems if necessary
!
if (ifile.eq.0) call modify_dump
print*,'geometry = ',geomsetup,geom
if (geomsetup.ne.geom) call convert_setup(geomsetup,geom)
call check_setup ! check for errors in the particle setup
!
!--setup additional quantities that are not done in setup
!
alpha(1,:) = alphamin
alpha(2,:) = alphaumin
alpha(3,:) = alphaBmin
divB = 0.
curlB = 0.
fmag = 0.
if (iprterm.ne.11 .and. .not.have_setup_psi) psi = 0.
sqrtg = 1.
if (imhd.eq.0) then
Bfield = 0. ! zero mag field if turned off
Bevol = 0.
endif
!
!--set velocities to zero if damping is set
!
if (damp.gt.tiny(damp)) then
write(iprint,*) 'SETTING VELS TO ZERO FOR RELAXATION RUN'
vel = 0.
endif
!
!--set minimum density if using variable particle masses
! and density iterations
!
if (any(pmass(1:npart).ne.pmass(1)) .and. icty.eq.0 .and. ikernav.eq.3) then
rhomin = 0.
!!rhomin = minval(dens(1:npart))
write(iprint,*) 'rhomin = ',rhomin
else
rhomin = 0.
write(iprint,*) 'particle mass = ',pmass(1)
endif
h_min = 0.0
!
!--if using fixed particle boundaries, set them up
!
if (any(ibound.eq.1)) call set_fixedbound
!
!--Set derivatives to zero until calculated
!
drhodt = 0.
dudt = 0.
dendt = 0.
force = 0.
dhdt = 0.
daldt = 0.
dBevoldt = 0.
dpsidt = 0.
gradpsi = 0.
!
!--calculate the conservative quantities (rho, en, B/rho)
! this also sets the smoothing length
!
call primitive2conservative
! call check_neighbourlist
do i=1,npart
xin(:,i) = x(:,i)
velin(:,i) = vel(:,i)
Bevolin(:,i) = Bevol(:,i)
rhoin(i) = rho(i)
hhin(i) = hh(i)
enin(i) = en(i)
alphain(:,i) = alpha(:,i)
psiin(i) = psi(i)
enddo
!
!--make sure ghost particle quantities are the same
! (copy both conservative and primitive here)
!
if (any(ibound.gt.1) .and. .not.any(ibound.eq.6)) then
do i=npart+1,ntotal
j = ireal(i)
call copy_particle(i,j)
enddo
endif
!
!--write second header to logfile/screen
!
call write_header(2,infile,evfile,logfile)
return
!
!--error control
!
668 write(iprint,*) 'Initialise: Error opening ev file, exiting...'
call quit
669 write(iprint,*) 'Initialise: Error opening log file, exiting...'
call quit
end subroutine initialise