From 9b5ac84c07bfa76eeda20699723b62287e11ccfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Aradi?= <20679946+matyasaradi@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:01:26 +0200 Subject: [PATCH 1/5] Add different ion beams for each discharges --- include/utils/prop.h | 1 + preproc/renate_od/__init__.py | 6 +++++- preproc/renate_od/interface.py | 9 +++++---- src/init/structures/beam.cu | 2 +- src/interface/parameter_reader.c | 2 ++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/utils/prop.h b/include/utils/prop.h index a1aef70..33dfa05 100644 --- a/include/utils/prop.h +++ b/include/utils/prop.h @@ -15,6 +15,7 @@ typedef struct BeamProp{ typedef struct ShotProp{ char name[STRING_LENGTH]; + char long_name[STRING_LENGTH]; char shotnumber[STRING_LENGTH]; char time[STRING_LENGTH]; char detector_mask[STRING_LENGTH]; diff --git a/preproc/renate_od/__init__.py b/preproc/renate_od/__init__.py index 8b13789..a17576e 100644 --- a/preproc/renate_od/__init__.py +++ b/preproc/renate_od/__init__.py @@ -1 +1,5 @@ - +import manager +from manager import RenateODManager +from beamlet import set_beamlet +from efit import EFITManager +from utils import * \ No newline at end of file diff --git a/preproc/renate_od/interface.py b/preproc/renate_od/interface.py index a65af3b..e3580bd 100644 --- a/preproc/renate_od/interface.py +++ b/preproc/renate_od/interface.py @@ -14,7 +14,7 @@ def export_beamlet_profile(export_root=get_home_directory() + '/input/ionProf/', r = RenateODManager(beamlet_geometry, shot_number, time, species, energy) radial_coordinate, relative_attenuation = r.get_attenuation_profile() - export_directory = export_root + '/'+shot_number+'_'+time + export_directory = export_root + '/' + shot_number + '_' + time + '/' + species + '/' + energy + '/' try: os.mkdir(export_directory) print('Create directory and write data to ' + export_directory) @@ -23,8 +23,8 @@ def export_beamlet_profile(export_root=get_home_directory() + '/input/ionProf/', else: pass print('Save RENATE-OD ionisation profile to: ' + export_directory) - radial_coordinate.fillna(0).to_csv(export_directory+'/rad.dat', index=False, header=False) - relative_attenuation.fillna(0).to_csv(export_directory+'/ionyeald.dat', index=False, header=False) + radial_coordinate.fillna(0).to_csv(export_directory + 'rad.dat', index=False, header=False) + relative_attenuation.fillna(0).to_csv(export_directory + 'ionyeald.dat', index=False, header=False) plot_attenuation_profile(shot_number, time, radial_coordinate, relative_attenuation, export_directory) @@ -56,4 +56,5 @@ def plot_attenuation_profile(shot_number, time, radial_coordinate, relative_atte if __name__ == "__main__": a_shot_number = '17178' a_time = '1097' - export_beamlet_profile(shot_number=a_shot_number, time=a_time) + a_species='Li' + export_beamlet_profile(shot_number=a_shot_number, time=a_time, species=a_species) diff --git a/src/init/structures/beam.cu b/src/init/structures/beam.cu index fef9bcb..9c5ae16 100644 --- a/src/init/structures/beam.cu +++ b/src/init/structures/beam.cu @@ -79,7 +79,7 @@ void init_beam_profile(BeamProfile *device_prof, ShotProp shot){ size_t size_prof = sizeof(BeamProfile); host_prof = (BeamProfile*)malloc(size_prof); shared_prof = (BeamProfile*)malloc(size_prof); - init_ion_profile(shot.name, host_prof); + init_ion_profile(shot.long_name, host_prof); size_t size_rad_prof = sizeof(double)*host_prof->radial_length; size_t size_cross_prof = sizeof(double)*host_prof->cross_length; diff --git a/src/interface/parameter_reader.c b/src/interface/parameter_reader.c index 965d3cd..e426165 100644 --- a/src/interface/parameter_reader.c +++ b/src/interface/parameter_reader.c @@ -77,6 +77,8 @@ int parameter_reader(BeamProp *beam, ShotProp *shot, RunProp *run){ } fclose(fp); strcpy(shot->name, concat(shot->shotnumber, "_", shot->time, NULL)); + + strcpy(shot->long_name, concat(shot->shotnumber, "_", shot->time, "/", beam->species, "/", to_str(beam->energy), NULL)); strcpy(run->folder_out, concat("results/", shot->shotnumber, "_", shot->time, NULL)); return 0; } From d3c035793085450d0fdbce4be780f4f99e95fb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Aradi?= <20679946+matyasaradi@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:29:31 +0100 Subject: [PATCH 2/5] Update path --- preproc/renate_od/interface.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/preproc/renate_od/interface.py b/preproc/renate_od/interface.py index e3580bd..68fe827 100644 --- a/preproc/renate_od/interface.py +++ b/preproc/renate_od/interface.py @@ -6,7 +6,7 @@ from utils import * -def export_beamlet_profile(export_root=get_home_directory() + '/input/ionProf/', +def export_beamlet_profile(export_root=os.path.join(get_home_directory(), 'input', 'ionProf'), shot_number='17178', time='1097', species='Li', energy='80'): z = 0 tor = 0 @@ -14,23 +14,21 @@ def export_beamlet_profile(export_root=get_home_directory() + '/input/ionProf/', r = RenateODManager(beamlet_geometry, shot_number, time, species, energy) radial_coordinate, relative_attenuation = r.get_attenuation_profile() - export_directory = export_root + '/' + shot_number + '_' + time + '/' + species + '/' + energy + '/' + export_directory = os.path.join(export_root, shot_number + '_' + time, species, energy) try: - os.mkdir(export_directory) + os.makedirs(export_directory) print('Create directory and write data to ' + export_directory) - except FileExistsError: - print('Write data to ' + export_directory) - else: - pass + except OSError as error: + print('Cannot create and write to ' + export_directory) print('Save RENATE-OD ionisation profile to: ' + export_directory) - radial_coordinate.fillna(0).to_csv(export_directory + 'rad.dat', index=False, header=False) - relative_attenuation.fillna(0).to_csv(export_directory + 'ionyeald.dat', index=False, header=False) + radial_coordinate.fillna(0).to_csv(os.path.join(export_directory, 'rad.dat'), index=False, header=False) + relative_attenuation.fillna(0).to_csv(os.path.join(export_directory, 'ionyeald.dat'), index=False, header=False) plot_attenuation_profile(shot_number, time, radial_coordinate, relative_attenuation, export_directory) def get_lcfs_radial_coordinate(shot_number, time, efit_reconstruction_id=1, database_directory='input/cdb', efit_subdir='EFITXX'): - data_directory = get_home_directory() + '/' + database_directory + '/' + str(shot_number) - efit_file = data_directory + '/' + efit_subdir + '/' + 'EFITXX.' + str(efit_reconstruction_id) + '.h5' + data_directory = os.path.join(get_home_directory(), database_directory, str(shot_number)) + efit_file = os.path.join(data_directory, efit_subdir, 'EFITXX.' + str(efit_reconstruction_id) + '.h5') efit = EFITManager(efit_file, time) return efit.get_time_sliced_data('output/separatrixGeometry/rmidplaneOut') @@ -47,14 +45,14 @@ def plot_attenuation_profile(shot_number, time, radial_coordinate, relative_atte R_LCFS = get_lcfs_radial_coordinate(shot_number, time) matplotlib.pyplot.axvline(R_LCFS, c='red', ls='--') matplotlib.pyplot.text(R_LCFS+0.005, 0.45, 'LCFS', c='red', fontsize=12) - matplotlib.pyplot.savefig(export_directory+'/attenuation.pdf') - matplotlib.pyplot.savefig(export_directory+'/attenuation.svg') - print('Attenuation profile saved as: '+export_directory+'/attenuation.pdf') + matplotlib.pyplot.savefig(os.path.join(export_directory, 'attenuation.pdf')) + matplotlib.pyplot.savefig(os.path.join(export_directory, 'attenuation.svg')) + print('Attenuation profile saved to '+ export_directory) matplotlib.pyplot.show() if __name__ == "__main__": a_shot_number = '17178' a_time = '1097' - a_species='Li' + a_species = 'Li' export_beamlet_profile(shot_number=a_shot_number, time=a_time, species=a_species) From 6d96f1bdb1d0b1c56f5962416f29a2b0dd34ea47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Aradi?= <20679946+matyasaradi@users.noreply.github.com> Date: Sun, 14 Jan 2024 00:36:35 +0100 Subject: [PATCH 3/5] Update RENATE init --- src/interface/data_import/beam_renate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/interface/data_import/beam_renate.c b/src/interface/data_import/beam_renate.c index 345d313..90bbb85 100644 --- a/src/interface/data_import/beam_renate.c +++ b/src/interface/data_import/beam_renate.c @@ -7,13 +7,11 @@ void load_beam_renate(TaigaGlobals *g, BeamProp *beam, ShotProp *shot, RunProp * long i, prof_size[2]; long radial_length, cross_length; double *radial_grid, *radial_profile, *cross_section_grid, *cross_section_profile, speed, ionisation_yeald, xsec_rad, xsec_ang; - - char* shotname = concat(shot->shotnumber, "_", shot->time, NULL); - + BeamProfile *prof; size_t size_prof = sizeof(BeamProfile); prof = (BeamProfile*)malloc(size_prof); - init_ion_profile(shotname, prof); + init_ion_profile(shot->long_name, prof); speed = calculate_speed(beam->energy, get_mass(beam->species, beam->charge)); From 7ff79cdc1c440fce1a011e3e6c8932a16233a96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Aradi?= <20679946+matyasaradi@users.noreply.github.com> Date: Sun, 14 Jan 2024 00:37:04 +0100 Subject: [PATCH 4/5] Remove breaking switch --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 71c125e..f5cd5af 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LIBS = -lcurand VERSION = -D'TAIGA_VERSION="$(shell git branch | grep \* | cut -d ' ' -f2)"' -D'GIT_REV="$(shell git show -s --pretty=format:%h)"' -DEFAULT_FLAGS = $(VERSION) -D'RENATE=0' -D'FASTMODE=0' -fcommon +DEFAULT_FLAGS = $(VERSION) -D'RENATE=0' -D'FASTMODE=0' #-fcommon RENATE_FLAGS = $(VERSION) -D'RENATE=1' -D'FASTMODE=0' RENATE_FAST_FLAGS = $(VERSION) -D'RENATE=1' -D'FASTMODE=1' From 1d243945bce6a8ac1c7bd149b6f1a38e80b96af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Aradi?= <20679946+matyasaradi@users.noreply.github.com> Date: Sun, 14 Jan 2024 00:42:24 +0100 Subject: [PATCH 5/5] Fix tests --- Makefile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f5cd5af..edf3d3d 100755 --- a/Makefile +++ b/Makefile @@ -7,9 +7,10 @@ LIBS = -lcurand VERSION = -D'TAIGA_VERSION="$(shell git branch | grep \* | cut -d ' ' -f2)"' -D'GIT_REV="$(shell git show -s --pretty=format:%h)"' -DEFAULT_FLAGS = $(VERSION) -D'RENATE=0' -D'FASTMODE=0' #-fcommon +DEFAULT_FLAGS = $(VERSION) -D'RENATE=0' -D'FASTMODE=0' RENATE_FLAGS = $(VERSION) -D'RENATE=1' -D'FASTMODE=0' RENATE_FAST_FLAGS = $(VERSION) -D'RENATE=1' -D'FASTMODE=1' +TEST_FLAGS = $(VERSION) -fcommon OBJ=build BIN=bin @@ -33,28 +34,28 @@ taiga_renate_fast.exe: src/main.cu | $(BIN) t: test test: $(OBJ)/tests.o $(OBJ)/test_bspline.o $(OBJ)/test_solver.o $(OBJ)/test_basic_functions.o $(OBJ)/basic_functions.o | $(BIN) - $(GCC) $(DEFAULT_FLAGS) -Isrc -Itests $^ -lm -o $(BIN)/test.exe + $(GCC) $(TEST_FLAGS) -Isrc -Itests $^ -lm -o $(BIN)/test.exe $(OBJ)/%.o: tests/%.c $(OBJ) - $(GCC) $(DEFAULT_FLAGS) -w -Isrc -Iinclude -Itests -c $< -lm -o $@ + $(GCC) $(TEST_FLAGS) -w -Isrc -Iinclude -Itests -c $< -lm -o $@ $(OBJ)/basic_functions.o: src/utils/basic_functions.c $(OBJ) - $(GCC) $(DEFAULT_FLAGS) -w -Isrc -Iinclude -Itests -I$utils -c $< -o $@ + $(GCC) $(TEST_FLAGS) -w -Isrc -Iinclude -Itests -I$utils -c $< -o $@ test_init: tests | $(BIN) - $(NVCC) $(CFLAGS) $(DEFAULT_FLAGS) -o $(BIN)/test_init.exe tests/test_taiga_init.cu + $(NVCC) $(CFLAGS) $(TEST_FLAGS) -o $(BIN)/test_init.exe tests/test_taiga_init.cu test_framework: tests | $(BIN) - $(GCC) $(DEFAULT_FLAGS) -o $(BIN)/test_framework.exe tests/taiga_test_example.c + $(GCC) $(TEST_FLAGS) -o $(BIN)/test_framework.exe tests/taiga_test_example.c example_solvers: $(OBJ)/example_solvers.o $(OBJ)/test_solver.o | $(BIN) - $(GCC) $(DEFAULT_FLAGS) $^ -lm -o $(BIN)/example_solvers.exe + $(GCC) $(TEST_FLAGS) $^ -lm -o $(BIN)/example_solvers.exe $(OBJ)/example_solvers.o: example/solvers/export_solver.c $(OBJ) - $(GCC) $(DEFAULT_FLAGS) -w -Isrc -Iinclude -Itests -c $< -lm -o $@ + $(GCC) $(TEST_FLAGS) -w -Isrc -Iinclude -Itests -c $< -lm -o $@ field: tests | $(BIN) - $(NVCC) $(CFLAGS) $(DEFAULT_FLAGS) -o $(BIN)/test_field.exe tests/test_field.cu + $(NVCC) $(CFLAGS) $(TEST_FLAGS) -o $(BIN)/test_field.exe tests/test_field.cu $(OBJ): mkdir $@