Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kmos/fortran_src/base_otf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ subroutine add_proc(proc, site, rate)
! ARGUMENTS
!
! * ``proc`` positive integer number that represents the process to be added.
! * ``site`` positive integer number that represents the site to be manipulated
! * ``site`` positive integer that represents the site to be manipulated
!******
integer(kind=iint), intent(in) :: proc, site
real(kind=rdouble), intent(in) :: rate
Expand Down
20 changes: 5 additions & 15 deletions kmos/fortran_src/proclist_constants_otf.mpy
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@ gpl = self._gpl_message()
#@
#@ module {module_name}
#@ use kind_values
#@ use lattice, only: &
site_params = []
for layer in data.layer_list:
#@ {layer.name}, &
for site in layer.sites:
site_params.append((site.name, layer.name))

for i, (site, layer) in enumerate(site_params):
#@ {layer}_{site}, &
#@ get_species
#@
#@
#@
#@
#@ implicit none
#@
#@
#@
#@
#@
#@

# initialize various parameter kind of data
#@ ! Species constants
Expand Down
74 changes: 68 additions & 6 deletions kmos/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,19 @@ def write_proclist_pars_otf(self, data, out, separate_files=False):
out.write("use kind_values\n")
out.write("use base, only: &\n")
out.write("%srates\n" % (" " * indent))
out.write("use proclist_constants\n")
# Import species and process constants from proclist_constants
# Avoid importing species that conflict with user parameter names
parameter_names = [p.name for p in data.parameter_list]
out.write("use proclist_constants, only: &\n")
for i, species in enumerate(data.species_list):
# Only import species that don't conflict with user parameters
if species.name not in parameter_names:
out.write("%s%s, &\n" % (" " * indent, species.name))
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out.write("%s%s, &\n" % (" " * indent, process.name))
else:
out.write("%s%s\n" % (" " * indent, process.name))
out.write("use lattice, only: &\n")
site_params = []
for layer in data.layer_list:
Expand All @@ -2762,7 +2774,14 @@ def write_proclist_pars_otf(self, data, out, separate_files=False):
for site, layer in site_params:
out.write("%s%s_%s, &\n" % (" " * indent, layer, site))
out.write("%sget_species\n" % (" " * indent))
out.write("\nimplicit none\n\n")
out.write("\nimplicit none\n")
# Make rate_* functions private so f2py doesn't try to wrap them
out.write("private :: ")
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out.write("rate_{0}, ".format(process.name))
else:
out.write("rate_{0}\n\n".format(process.name))

units_list, masses_list, chempot_list = self._otf_get_auxilirary_params(data)

Expand Down Expand Up @@ -3235,8 +3254,23 @@ def write_proclist_otf(self, data, out, separate_files=True, debug=False):
)

out.write(" get_species\n")
out.write("use proclist_constants\n")
out.write("use proclist_pars\n")
# Import species and processes from proclist_constants to avoid conflicts
out.write("use proclist_constants, only: &\n")
out.write(" default_species, &\n")
for i, species in enumerate(data.species_list):
out.write(" %s, &\n" % species.name)
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out.write(" %s, &\n" % process.name)
else:
out.write(" %s\n" % process.name)
# Import only gr_* functions from proclist_pars to avoid conflicts with user parameters
out.write("use proclist_pars, only: &\n")
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out.write(" gr_%s, &\n" % process.name)
else:
out.write(" gr_%s\n" % process.name)
if separate_files and self.separate_proclist_pars:
for i in range(len(data.process_list)):
out.write("use run_proc_{0:04d}; use gr_{0:04d}\n".format(i + 1))
Expand Down Expand Up @@ -3394,8 +3428,36 @@ def write_proclist_run_proc_name_otf(
out2 = open("{0}/run_proc_{1:04d}.f90".format(self.dir, iproc + 1), "w")
out2.write("module run_proc_{0:04d}\n\n".format(iproc + 1))
out2.write("use kind_values\n")
out2.write("use lattice\n")
out2.write("use proclist_pars\n")
# Import lattice manipulation functions from lattice module
# (lattice provides wrappers that accept arrays and convert internally)
out2.write("use lattice, only: &\n")
site_params = []
for layer in data.layer_list:
for site in layer.sites:
site_params.append((site.name, layer.name))
for i, (site, layer) in enumerate(site_params):
out2.write("%s%s_%s, &\n" % (" " * indent, layer, site))
out2.write("%scan_do, &\n" % (" " * indent))
out2.write("%sdel_proc, &\n" % (" " * indent))
out2.write("%sadd_proc, &\n" % (" " * indent))
out2.write("%sreplace_species, &\n" % (" " * indent))
out2.write("%sget_species\n" % (" " * indent))
# Import species and processes from proclist_constants to avoid conflict with parameter indices
out2.write("use proclist_constants, only: &\n")
for i, species in enumerate(data.species_list):
out2.write("%s%s, &\n" % (" " * indent, species.name))
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out2.write("%s%s, &\n" % (" " * indent, process.name))
else:
out2.write("%s%s\n" % (" " * indent, process.name))
# Import only gr_* functions from proclist_pars to avoid conflicts with user parameters
out2.write("use proclist_pars, only: &\n")
for i, process in enumerate(data.process_list):
if i < len(data.process_list) - 1:
out2.write("%sgr_%s, &\n" % (" " * indent, process.name))
else:
out2.write("%sgr_%s\n" % (" " * indent, process.name))
if self.separate_proclist_pars:
for i in range(nprocs):
out2.write("use gr_{0:04d}\n".format(i + 1))
Expand Down
34 changes: 27 additions & 7 deletions kmos/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,29 @@ def import_selected_kind():
"f2py_selected_kind",
]
print("%s\n" % os.path.abspath(os.curdir))

# Find gfortran compiler
import shutil

gfortran_path = shutil.which("gfortran")

# Set up environment with correct compiler paths
env_vars = {
"LIBRARY_PATH": os.environ.get("LIBRARY_PATH", "")
+ ":/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
}
if gfortran_path:
env_vars["FC"] = gfortran_path

result = subprocess.run(
f2py_command,
capture_output=True,
text=True,
env=dict(
os.environ,
**{
"LIBRARY_PATH": os.environ.get("LIBRARY_PATH", "")
+ ":/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
},
),
env=dict(os.environ, **env_vars),
)
print(result.stdout)
if result.stderr:
print(result.stderr)
try:
import f2py_selected_kind
except Exception as e:
Expand Down Expand Up @@ -489,6 +499,16 @@ def build(options):
# Set FC for meson backend (Python >= 3.12) to compiler name only
# Meson has issues with FC containing full paths
if sys.version_info >= (3, 12):
# Ensure gfortran is in PATH for meson to find
import shutil

gfortran_path = shutil.which("gfortran")
if gfortran_path:
gfortran_dir = os.path.dirname(gfortran_path)
current_path = os.environ.get("PATH", "")
if gfortran_dir not in current_path:
os.environ["PATH"] = f"{gfortran_dir}:{current_path}"

fc_map = {
"gfortran": "gfortran",
"gnu95": "gfortran",
Expand Down
2 changes: 1 addition & 1 deletion tests/export_test/reference_export_intZGB_otf/base.f90
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ subroutine add_proc(proc, site, rate)
! ARGUMENTS
!
! * ``proc`` positive integer number that represents the process to be added.
! * ``site`` positive integer number that represents the site to be manipulated
! * ``site`` positive integer that represents the site to be manipulated
!******
integer(kind=iint), intent(in) :: proc, site
real(kind=rdouble), intent(in) :: rate
Expand Down
28 changes: 26 additions & 2 deletions tests/export_test/reference_export_intZGB_otf/proclist.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,32 @@ module proclist
update_rates_matrix, &
spuck, &
get_species
use proclist_constants
use proclist_pars
use proclist_constants, only: &
default_species, &
CO, &
O, &
empty, &
CO_ads, &
CO_des, &
CO_oxidation_00, &
CO_oxidation_01, &
CO_oxidation_02, &
CO_oxidation_03, &
O2_des_right, &
O2_des_up, &
O_ads_00, &
O_ads_01
use proclist_pars, only: &
gr_CO_ads, &
gr_CO_des, &
gr_CO_oxidation_00, &
gr_CO_oxidation_01, &
gr_CO_oxidation_02, &
gr_CO_oxidation_03, &
gr_O2_des_right, &
gr_O2_des_up, &
gr_O_ads_00, &
gr_O_ads_01
use run_proc_0001
use run_proc_0002
use run_proc_0003
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

module proclist_constants
use kind_values
use lattice, only: &
square, &
square_default, &
get_species


implicit none
Expand Down
16 changes: 15 additions & 1 deletion tests/export_test/reference_export_intZGB_otf/proclist_pars.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,27 @@ module proclist_pars
use kind_values
use base, only: &
rates
use proclist_constants
use proclist_constants, only: &
CO, &
O, &
empty, &
CO_ads, &
CO_des, &
CO_oxidation_00, &
CO_oxidation_01, &
CO_oxidation_02, &
CO_oxidation_03, &
O2_des_right, &
O2_des_up, &
O_ads_00, &
O_ads_01
use lattice, only: &
square, &
square_default, &
get_species

implicit none
private :: rate_CO_ads, rate_CO_des, rate_CO_oxidation_00, rate_CO_oxidation_01, rate_CO_oxidation_02, rate_CO_oxidation_03, rate_O2_des_right, rate_O2_des_up, rate_O_ads_00, rate_O_ads_01

! User parameters
integer(kind=iint), public :: J_CO_CO = 1
Expand Down
34 changes: 32 additions & 2 deletions tests/export_test/reference_export_intZGB_otf/run_proc_0001.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
module run_proc_0001

use kind_values
use lattice
use proclist_pars
use lattice, only: &
square_default, &
can_do, &
del_proc, &
add_proc, &
replace_species, &
get_species
use proclist_constants, only: &
CO, &
O, &
empty, &
CO_ads, &
CO_des, &
CO_oxidation_00, &
CO_oxidation_01, &
CO_oxidation_02, &
CO_oxidation_03, &
O2_des_right, &
O2_des_up, &
O_ads_00, &
O_ads_01
use proclist_pars, only: &
gr_CO_ads, &
gr_CO_des, &
gr_CO_oxidation_00, &
gr_CO_oxidation_01, &
gr_CO_oxidation_02, &
gr_CO_oxidation_03, &
gr_O2_des_right, &
gr_O2_des_up, &
gr_O_ads_00, &
gr_O_ads_01

implicit none
contains
Expand Down
34 changes: 32 additions & 2 deletions tests/export_test/reference_export_intZGB_otf/run_proc_0002.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
module run_proc_0002

use kind_values
use lattice
use proclist_pars
use lattice, only: &
square_default, &
can_do, &
del_proc, &
add_proc, &
replace_species, &
get_species
use proclist_constants, only: &
CO, &
O, &
empty, &
CO_ads, &
CO_des, &
CO_oxidation_00, &
CO_oxidation_01, &
CO_oxidation_02, &
CO_oxidation_03, &
O2_des_right, &
O2_des_up, &
O_ads_00, &
O_ads_01
use proclist_pars, only: &
gr_CO_ads, &
gr_CO_des, &
gr_CO_oxidation_00, &
gr_CO_oxidation_01, &
gr_CO_oxidation_02, &
gr_CO_oxidation_03, &
gr_O2_des_right, &
gr_O2_des_up, &
gr_O_ads_00, &
gr_O_ads_01

implicit none
contains
Expand Down
34 changes: 32 additions & 2 deletions tests/export_test/reference_export_intZGB_otf/run_proc_0003.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
module run_proc_0003

use kind_values
use lattice
use proclist_pars
use lattice, only: &
square_default, &
can_do, &
del_proc, &
add_proc, &
replace_species, &
get_species
use proclist_constants, only: &
CO, &
O, &
empty, &
CO_ads, &
CO_des, &
CO_oxidation_00, &
CO_oxidation_01, &
CO_oxidation_02, &
CO_oxidation_03, &
O2_des_right, &
O2_des_up, &
O_ads_00, &
O_ads_01
use proclist_pars, only: &
gr_CO_ads, &
gr_CO_des, &
gr_CO_oxidation_00, &
gr_CO_oxidation_01, &
gr_CO_oxidation_02, &
gr_CO_oxidation_03, &
gr_O2_des_right, &
gr_O2_des_up, &
gr_O_ads_00, &
gr_O_ads_01

implicit none
contains
Expand Down
Loading
Loading