This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialise.f90
166 lines (133 loc) · 4.52 KB
/
initialise.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
!Crown Copyright 2012 AWE.
!
! This file is part of CloverLeaf.
!
! CloverLeaf is free software: you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the
! Free Software Foundation, either version 3 of the License, or (at your option)
! any later version.
!
! CloverLeaf is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along with
! CloverLeaf. If not, see http://www.gnu.org/licenses/.
!> @brief Top level initialisation routine
!> @author Wayne Gaudin
!> @details Checks for the user input and either invokes the input reader or
!> switches to the internal test problem. It processes the input and strips
!> comments before writing a final input file.
!> It then calls the start routine.
SUBROUTINE initialise
USE clover_module
USE parse_module
USE report_module
IMPLICIT NONE
INTEGER :: ios
INTEGER :: get_unit,stat,uin,out_unit
!$ INTEGER :: OMP_GET_THREAD_NUM,OMP_GET_NUM_THREADS
CHARACTER(LEN=g_len_max) :: ltmp
IF(parallel%boss)THEN
g_out=get_unit(dummy)
OPEN(FILE='clover.out',ACTION='WRITE',UNIT=g_out,IOSTAT=ios)
IF(ios.NE.0) CALL report_error('initialise','Error opening clover.out file.')
ELSE
g_out=6
ENDIF
!$OMP PARALLEL
IF(parallel%boss)THEN
!$ IF(OMP_GET_THREAD_NUM().EQ.0) THEN
WRITE(g_out,*)
WRITE(g_out,'(a15,f8.3)') 'Clover Version ',g_version
WRITE(g_out,'(a18)') 'MPI Version'
!$ WRITE(g_out,'(a18)') 'OpenMP Version'
WRITE(g_out,'(a14,i6)') 'Task Count ',parallel%max_task !MPI
!$ WRITE(g_out,'(a15,i5)') 'Thread Count: ',OMP_GET_NUM_THREADS()
WRITE(g_out,*)
WRITE(*,*)'Output file clover.out opened. All output will go there.'
!$ ENDIF
ENDIF
!$OMP END PARALLEL
CALL clover_barrier
IF(parallel%boss)THEN
WRITE(g_out,*) 'Clover will run from the following input:-'
WRITE(g_out,*)
ENDIF
IF(parallel%boss)THEN
uin=get_unit(dummy)
OPEN(FILE='clover.in',ACTION='READ',STATUS='OLD',UNIT=uin,IOSTAT=ios)
IF(ios.NE.0) THEN
out_unit=get_unit(dummy)
OPEN(FILE='clover.in',UNIT=out_unit,STATUS='REPLACE',ACTION='WRITE',IOSTAT=ios)
WRITE(out_unit,'(A)')'*clover'
WRITE(out_unit,'(A)')' state 1 density=0.2 energy=1.0'
WRITE(out_unit,'(A)')' state 2 density=1.0 energy=2.5 geometry=rectangle xmin=0.0 xmax=5.0 ymin=0.0 ymax=2.0'
WRITE(out_unit,'(A)')' x_cells=10'
WRITE(out_unit,'(A)')' y_cells=2'
WRITE(out_unit,'(A)')' xmin=0.0'
WRITE(out_unit,'(A)')' ymin=0.0'
WRITE(out_unit,'(A)')' xmax=10.0'
WRITE(out_unit,'(A)')' ymax=2.0'
WRITE(out_unit,'(A)')' initial_timestep=0.04'
WRITE(out_unit,'(A)')' timestep_rise=1.5'
WRITE(out_unit,'(A)')' max_timestep=0.04'
WRITE(out_unit,'(A)')' end_time=3.0'
WRITE(out_unit,'(A)')' test_problem 1'
WRITE(out_unit,'(A)')'*endclover'
CLOSE(out_unit)
uin=get_unit(dummy)
OPEN(FILE='clover.in',ACTION='READ',STATUS='OLD',UNIT=uin,IOSTAT=ios)
ENDIF
out_unit=get_unit(dummy)
OPEN(FILE='clover.in.tmp',UNIT=out_unit,STATUS='REPLACE',ACTION='WRITE',IOSTAT=ios)
IF(ios.NE.0) CALL report_error('initialise','Error opening clover.in.tmp file')
stat=parse_init(uin,'')
DO
stat=parse_getline(-1_4)
IF(stat.NE.0)EXIT
WRITE(out_unit,'(A)') line
ENDDO
CLOSE(out_unit)
ENDIF
CALL clover_barrier
g_in=get_unit(dummy)
OPEN(FILE='clover.in.tmp',ACTION='READ',STATUS='OLD',UNIT=g_in,IOSTAT=ios)
IF(ios.NE.0) CALL report_error('initialise','Error opening clover.in.tmp file')
CALL clover_barrier
IF(parallel%boss)THEN
REWIND(uin)
DO
READ(UNIT=uin,IOSTAT=ios,FMT='(a100)') ltmp ! Read in next line.
IF(ios.NE.0)EXIT
WRITE(g_out,FMT='(a100)') ltmp
ENDDO
ENDIF
IF(parallel%boss)THEN
WRITE(g_out,*)
WRITE(g_out,*) 'Initialising and generating'
WRITE(g_out,*)
ENDIF
CALL read_input()
CALL clover_barrier
step=0
CALL start
CALL clover_barrier
IF(parallel%boss)THEN
WRITE(g_out,*) 'Starting the calculation'
ENDIF
CLOSE(g_in)
END SUBROUTINE initialise
FUNCTION get_unit(dummy)
INTEGER :: get_unit,dummy
INTEGER :: u
LOGICAL :: used
DO u=7,99
INQUIRE(UNIT=u,OPENED=used)
IF(.NOT.used)THEN
EXIT
ENDIF
ENDDO
get_unit=u
END FUNCTION get_unit