Skip to content

Commit 7170899

Browse files
Sam Coxspco
authored andcommitted
tools/mech_converter.py no longer creates ro2-rates.f90, which needs adding in at compilation time. Instead, it creates mechanism.ro2, which is read in at run-time. This commit contains all the changes to the testing and reference outputs to match this change.
1 parent b3ed2ba commit 7170899

71 files changed

Lines changed: 1490 additions & 1529 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/atchem2.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ end subroutine FCVFUN
198198
write (*, '(A, I0)') ' Species requiring detailed rate output (number of species found): ', size( detailedRatesSpeciesName )
199199
write (*,*)
200200

201+
! Read in the numbers of RO2 species from mechanism.ro2
202+
call readRO2species()
203+
201204
! Read in and set solver parameters
202205
call set_solver_parameters( getParametersFromFile( trim( param_dir ) // "/solver.parameters" ) )
203206
write (*,*)

src/dataStructures.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ module env_vars_mod
236236
real(kind=DP), allocatable :: envVarX (:,:), envVarY (:,:)
237237
integer(kind=NPI), allocatable :: envVarNumberOfPoints(:)
238238
real(kind=DP) :: ro2
239+
integer(kind=NPI), allocatable :: ro2Numbers(:)
239240

240241
end module env_vars_mod
241242

src/inputFunctions.f90

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,41 @@ subroutine readSpeciesConstraints( t, y )
13261326
return
13271327
end subroutine readSpeciesConstraints
13281328

1329+
! ----------------------------------------------------------------- !
1330+
! Read in the contents of model/configuration/ro2-rates.list and add
1331+
! its contents to the variable ro2Numbers
1332+
subroutine readRO2species()
1333+
use types_mod
1334+
use env_vars_mod, only : ro2Numbers
1335+
use storage_mod, only : maxFilepathLength
1336+
use directories_mod, only : param_dir
1337+
implicit none
1338+
1339+
integer(kind=NPI) :: j, numberOfRO2Species
1340+
character(len=maxFilepathLength) :: fileLocation
1341+
1342+
write (*, '(A)') ' Reading ro2 numbers from mechanism.ro2...'
1343+
fileLocation=trim( param_dir ) // '/mechanism.ro2'
1344+
1345+
! Read in ro2 species numbers from model/configuration/mechanism.ro2
1346+
! to ro2Numbers
1347+
1348+
call inquire_or_abort( fileLocation, 'readSpecies()')
1349+
numberOfRO2Species = count_lines_in_file( fileLocation, .true. )
1350+
allocate(ro2Numbers(numberOfRO2Species))
1351+
1352+
open (10, file=fileLocation) ! input file
1353+
! skip first line
1354+
read (10,*)
1355+
do j = 1, numberOfRO2Species
1356+
read (10,*) ro2Numbers(j)
1357+
end do
1358+
close (10, status='keep')
1359+
write (*, '(A)') ' Finished reading ro2 numbers.'
1360+
1361+
return
1362+
end subroutine readRO2species
1363+
13291364
! ----------------------------------------------------------------- !
13301365
! Given a filename, count the number of lines. Optional argument
13311366
! skip_first_line_in ignores the first line if it exists.

src/outputFunctions.f90

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ module output_functions_mod
2424
! Returns the sum of all ro2 species' concentrations
2525
pure function ro2Sum( y ) result ( ro2 )
2626
use types_mod
27+
use env_vars_mod, only : ro2Numbers
2728
implicit none
2829

2930
real(kind=DP), intent(in) :: y(*)
3031
real(kind=DP) :: ro2
32+
integer(kind=NPI) :: i
3133

32-
include './gen/ro2-rates.f90'
33-
34+
ro2 = 0.0_DP
35+
if ( size( ro2Numbers ) > 0 ) then
36+
do i = 1, size( ro2Numbers )
37+
ro2 = ro2 + y(ro2Numbers(i))
38+
end do
39+
end if
3440
return
3541
end function ro2Sum
3642

src/solverFunctions.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ subroutine mechanism_rates( t, y, p )
244244
j(constrainedPhotoNumbers(i)) = photoRateAtT
245245
end do
246246
end if
247-
247+
!TODO: is this necessary a second time?
248248
ro2 = ro2sum( y )
249249

250250
include './gen/mechanism-rate-coefficients.f90'

tools/mech_converter.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,20 @@ def convert(input_file, output_dir, mc_dir, mcm_dir):
221221

222222
# loop over RO2 and write the necessary line to mechanism-rate-coefficients.f90, using the species number of the RO2
223223
print 'adding RO2 to src/gen/ro2-rates.f90'
224-
with open(os.path.join(output_dir, 'ro2-rates.f90'), 'w') as ro2_file:
225-
ro2_file.write("""! Note that this file is generated by tools/mech_converter.py
226-
! based upon the file tools/mcm_example.fac
227-
! Any manual edits to this file will be overwritten when
228-
! calling tools/mech_converter.py
229-
230-
ro2 = 0.00e+00_DP\n""")
224+
with open(os.path.join(mc_dir, 'mechanism.ro2'), 'w') as ro2_file:
225+
ro2_file.write("""! Note that this file is generated by tools/mech_converter.py based upon the file tools/mcm_example.fac. Any manual edits to this file will be overwritten when calling tools/mech_converter.py
226+
""")
231227

232228
for ro2List_i in ro2List:
233229
for speciesNumber, y in zip(range(1, len(speciesList) + 1), speciesList):
234230
if ro2List_i.strip() == y.strip():
235-
ro2_file.write('ro2 = ro2 + y(' + str(speciesNumber) + ')!' + ro2List_i.strip() + '\n')
231+
ro2_file.write(str(speciesNumber) + ' !' + ro2List_i.strip() + '\n')
236232
# Exit loop early if species found
237233
break
238234
# This code only executes if the break is NOT called, i.e. if the loop runs to completion without the RO2 being
239235
# found in the species list
240236
else:
241-
ro2_file.write('\t ! error RO2 not in mechanism: ' + ro2List_i + '\n')
237+
ro2_file.write('0 ! error RO2 not in mechanism: ' + ro2List_i + '\n')
242238

243239

244240
coeffSpeciesList = ['N2', 'O2', 'M', 'RH', 'H2O', 'DEC', 'BLH', 'DILUTE', 'JFAC', 'ROOFOPEN']

travis/run_tests.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,6 @@ $this_file_failures"
137137
elif [ $exitcode -eq 1 ]; then
138138
this_test_failures="$this_test_failures
139139
140-
$this_file_failures"
141-
else
142-
echo 'Numdiff gave an error. Aborting.'
143-
exit 1
144-
fi
145-
done
146-
147-
# Apply numdiff to ro2-rates.f90.cmp, a special case. If the numdiff gives differences,
148-
# then add the numdiff output to $this_test_failures via $this_file_failures,.
149-
for filename in $TESTS_DIR/$test/ro2-rates.f90.cmp; do
150-
echo 'Checking' $filename
151-
this_file_failures=$(test_output_file src/gen/ro2-rates.f90 $filename)
152-
exitcode=$?
153-
if [ $exitcode -eq 0 ]; then
154-
continue
155-
elif [ $exitcode -eq 1 ]; then
156-
this_test_failures="$this_test_failures
157-
158140
$this_file_failures"
159141
else
160142
echo 'Numdiff gave an error. Aborting.'

travis/tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/output/instantaneousRates/*
55
*/model/configuration/mechanism.prod
66
*/model/configuration/mechanism.reac
7+
*/model/configuration/mechanism.ro2
78
*/model/configuration/mechanism.species
89
testsuite.log
910

travis/tests/firstorder/firstorder.out.cmp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ AtChem2 v1.1-dev
4141
Finished reading which species require detailed rate output.
4242
Species requiring detailed rate output (number of species found): 2
4343

44+
Reading ro2 numbers from mechanism.ro2...
45+
Finished reading ro2 numbers.
4446
Reading solver parameters from file...
4547
------------------
4648
Solver parameters:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
! Note that this file is generated by tools/mech_converter.py based upon the file tools/mcm_example.fac. Any manual edits to this file will be overwritten when calling tools/mech_converter.py

0 commit comments

Comments
 (0)