Skip to content

Commit cb156f3

Browse files
committed
update the build system to support standalone networks
this allows us to output a network outside of Microphysics/networks/ and initiate a build there. This will be used to support pynucastro unit tests / comparsions to other pynucastro nets
1 parent df323de commit cb156f3

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

Make.Microphysics

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ifdef MICROPHYSICS_HOME
119119
endif
120120

121121
EXTERN_PARAMETERS := $(shell $(MICROPHYSICS_HOME)/util/build_scripts/findparams.py $(EXTERN_SEARCH))
122-
122+
EXTERN_PARAMETERS += $(CUSTOM_PARAMETERS)
123123

124124
$(MICROPHYSICS_AUTO_SOURCE_DIR)/extern_parameters.cpp: $(MICROPHYSICS_AUTO_SOURCE_DIR)/extern_parameters.H
125125

Make.Microphysics_extern

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ endif
6666

6767

6868
EOS_PATH := $(MICROPHYSICS_HOME)/EOS/$(strip $(EOS_DIR))
69-
NETWORK_PATH := $(MICROPHYSICS_HOME)/networks/$(strip $(NETWORK_DIR))
69+
ifneq ($(NETWORK_CUSTOM_PATH),)
70+
NETWORK_PATH := $(NETWORK_CUSTOM_PATH)
71+
else
72+
NETWORK_PATH := $(MICROPHYSICS_HOME)/networks/$(strip $(NETWORK_DIR))
73+
endif
7074
ifeq ($(USE_CONDUCTIVITY), TRUE)
7175
CONDUCTIVITY_PATH := $(MICROPHYSICS_HOME)/conductivity/$(strip $(CONDUCTIVITY_DIR))
7276
endif

networks/Make.package

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ AUTO_BUILD_SOURCES += $(NETWORK_OUTPUT_PATH)/network_properties.H
9090
net_prop_debug: $(NETWORK_OUTPUT_PATH)/network_properties.H
9191

9292
ifneq ($(NETWORK_DIR), general_null)
93-
NAUX := $(shell PYTHONPATH=$(MICROPHYSICS_HOME)/networks/general_null $(MICROPHYSICS_HOME)/networks/get_naux.py --microphysics_path "$(MICROPHYSICS_HOME)" --defines "$(DEFINES)" --net "$(NETWORK_DIR)")
93+
NAUX := $(shell PYTHONPATH=$(MICROPHYSICS_HOME)/networks/general_null $(MICROPHYSICS_HOME)/networks/get_naux.py \
94+
--microphysics_path "$(MICROPHYSICS_HOME)" \
95+
--defines "$(DEFINES)" \
96+
--net "$(NETWORK_DIR)" \
97+
--net-custom-path "$(NETWORK_CUSTOM_PATH)")
9498
DEFINES += "-DNAUX_NET=$(NAUX)"
9599

96100
$(NETWORK_OUTPUT_PATH)/network_properties.H:
97101
PYTHONPATH=$(MICROPHYSICS_HOME)/networks/general_null $(MICROPHYSICS_HOME)/networks/update_headers.py \
98102
--microphysics_path $(MICROPHYSICS_HOME) \
99-
--net $(NETWORK_DIR) \
103+
--net "$(NETWORK_DIR)" \
104+
--net-custom-path "$(NETWORK_CUSTOM_PATH)" \
100105
--odir $(NETWORK_OUTPUT_PATH) \
101106
--defines "$(DEFINES)"
102107

networks/general_null/network_param_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def parse(species, extra_species, aux_vars, net_file, defines):
7676
try:
7777
f = open(net_file)
7878
except OSError:
79-
sys.exit(f"write_network.py: ERROR: file {net_file} does not exist")
79+
sys.exit(f"network_param_file.py: ERROR: file {net_file} does not exist")
8080

8181
line = get_next_line(f)
8282

networks/general_null/write_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def write_network(header_template,
6262
try:
6363
template = open(tmp)
6464
except OSError:
65-
sys.exit(f"write_network.py: ERROR: file {tmp} does not exist")
65+
sys.exit(f"write_network.py: ERROR: template file {tmp} does not exist")
6666
else:
6767
template_lines = template.readlines()
6868
template.close()

networks/get_naux.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import argparse
5+
from pathlib import Path
56

67
from general_null import network_param_file
78

@@ -30,15 +31,22 @@ def main():
3031
help="path to Microphysics/")
3132
parser.add_argument("--net", type=str, default="",
3233
help="name of the network")
34+
parser.add_argument("--net-custom-path", type=str, default="",
35+
help="full path to the network if it lives outside of Microphysics")
3336

3437
args = parser.parse_args()
3538

3639
micro_path = args.microphysics_path
3740
net = args.net
3841

39-
net_file = os.path.join(micro_path, "networks", net, f"{net}.net")
40-
if not os.path.isfile(net_file):
41-
net_file = os.path.join(micro_path, "networks", net, "pynucastro.net")
42+
if args.net_custom_path is None:
43+
base_path = Path(micro_path) / "networks" / "net"
44+
else:
45+
base_path = Path(args.net_custom_path)
46+
47+
net_file = base_path / "pynucastro.net"
48+
if not net_file.exists() and len(net) > 0:
49+
net_file = base_path / f"{net}.net"
4250

4351
get_naux(net_file, args.defines)
4452

networks/update_headers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import argparse
5+
from pathlib import Path
56

67
from general_null import write_network
78

@@ -13,6 +14,8 @@ def main():
1314
help="path to Microphysics/")
1415
parser.add_argument("--net", type=str, default="",
1516
help="name of the network")
17+
parser.add_argument("--net-custom-path", type=str, default="",
18+
help="full path to the network if it lives outside of Microphysics")
1619
parser.add_argument("--odir", type=str, default="",
1720
help="output directory")
1821
parser.add_argument("--defines", type=str, default="",
@@ -23,9 +26,15 @@ def main():
2326
micro_path = args.microphysics_path
2427
net = args.net
2528

26-
net_file = os.path.join(micro_path, "networks", net, f"{net}.net")
27-
if not os.path.isfile(net_file):
28-
net_file = os.path.join(micro_path, "networks", net, "pynucastro.net")
29+
30+
if args.net_custom_path is None:
31+
base_path = Path(micro_path) / "networks" / "net"
32+
else:
33+
base_path = Path(args.net_custom_path)
34+
35+
net_file = base_path / "pynucastro.net"
36+
if not net_file.exists() and len(net) > 0:
37+
net_file = base_path / f"{net}.net"
2938

3039
cxx_template = os.path.join(micro_path, "networks",
3140
"general_null/network_header.template")
@@ -36,6 +45,7 @@ def main():
3645
except FileExistsError:
3746
pass
3847

48+
print(f"calling with {cxx_template}, {net_file}")
3949
write_network.write_network(cxx_template,
4050
net_file,
4151
cxx_name, args.defines)

0 commit comments

Comments
 (0)