Skip to content

Commit

Permalink
Added ability to specify custom fortran functions that can be called …
Browse files Browse the repository at this point in the history
…in the mechanism file.
  • Loading branch information
AlfredMayhew committed Jan 11, 2024
1 parent 63cf98e commit 75ddc38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions build/mech_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ def convert_to_fortran(input_file, mech_dir, mcm_vers):
continue

# -------------------------------------------------
# Read in the names of user-defined custom rate functions and add them
# to the list of reserved names so that they will be carried through the
# rate definitions (in a similar manner to LOG10)
with open(mech_dir + '/customRateFuncs.f90') as custom_func_file:
func_def_pat = "function +([a-zA-Z0-9_]*) *\("
custom_func_names = re.findall(func_def_pat, custom_func_file.read(), re.I)

for n in custom_func_names:
reservedOtherList.append(n)

# Initialise list, dictionary and a counter.
mechanism_rates_coeff_list = []
Expand Down Expand Up @@ -551,6 +560,7 @@ def convert_to_fortran(input_file, mech_dir, mcm_vers):
subroutine update_p(p, q, TEMP, N2, O2, M, RH, H2O, BLHEIGHT, DEC, JFAC, DILUTE, ROOFOPEN, ASA, J, RO2) bind(c,name='update_p')
use custom_functions_mod
integer, parameter :: DP = selected_real_kind( p = 15, r = 307 )
real(c_double), intent(inout) :: p(*), q(*)
real(c_double), intent(in) :: TEMP, N2, O2, M, RH, H2O, BLHEIGHT, DEC, JFAC, DILUTE, ROOFOPEN, ASA, J(*), RO2
Expand Down
1 change: 1 addition & 0 deletions model/configuration/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Ignore auto-generated mechanism files in this directory
mechanism.*
customRateFuncs.o
14 changes: 14 additions & 0 deletions model/configuration/customRateFuncs.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! ******************************************************************** !
! ATCHEM2 -- MODULE customRateFunctions
!
! This module contains user-defined functions that can be referenced
! in the mechanism file
! ******************************************************************** !
module custom_functions_mod
implicit none

contains

!Define your functions here.

end module custom_functions_mod
3 changes: 2 additions & 1 deletion tools/install/Makefile.skel
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ include tests/makefile.tests
all: $(AOUT)

sharedlib:
$(FORT_COMP) -c $(SHAREDLIBDIR)/customRateFuncs.f90 $(FSHAREDFLAGS) -o $(SHAREDLIBDIR)/customRateFuncs.o -J$(OBJ)
$(FORT_COMP) -c $(SHAREDLIBDIR)/mechanism.f90 $(FSHAREDFLAGS) -o $(SHAREDLIBDIR)/mechanism.o -J$(OBJ)
$(FORT_COMP) -shared -o $(SHAREDLIBDIR)/mechanism.so $(SHAREDLIBDIR)/mechanism.o
$(FORT_COMP) -shared -o $(SHAREDLIBDIR)/mechanism.so $(SHAREDLIBDIR)/mechanism.o $(SHAREDLIBDIR)/customRateFuncs.o

clean:
rm -f $(AOUT)
Expand Down

0 comments on commit 75ddc38

Please sign in to comment.