diff --git a/sources/ece3-toy-model/NEMO_toy.py b/sources/ece3-toy-model/NEMO_toy.py deleted file mode 100644 index 5ef3b7987f5f18effbc62ec0b2b01912b6d5dfb7..0000000000000000000000000000000000000000 --- a/sources/ece3-toy-model/NEMO_toy.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - -if __name__ == '__main__': - - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - - # Init OASIS - comp = pyoasis.Component("NEMO_TOY") - local_comm = comp.localcomm - # Get rank in local communicator - mype = comp.localcomm.rank - npes = comp.localcomm.size - - # Unit for output messages - out_nemo = 'NEMO_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_nemo, format='%(message)s', level=logging.DEBUG) - logging.debug('-----------------------------------------------------------') - logging.debug('I am NEMO-toy process with rank : {}'.format(mype)) - logging.debug('in my local communicator gathering {} processes'.format(npes)) - logging.debug('----------------------------------------------------------') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # PARTITION DEFINITION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - # Definition of the local partition - nx = 362 * 292 - partition = pyoasis.SerialPartition(nx) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # DECLARATION OF THE COUPLING FIELDS - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - out_coupling_fields={} - out_coupling_vars=["O_SSTSST","O_TepIce","O_AlbIce","OIceFrc","OIceTck","OSnwTck"] - for v in out_coupling_vars: - out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) - - in_coupling_fields={} - in_coupling_vars=["O_OTaux1","O_OTauy1","O_ITaux1","O_ITauy1","O_OTaux2","O_OTauy2","O_ITaux2","O_ITauy2","O_QnsMix","O_QsrMix","OTotEvap","OTotRain","OTotSnow","O_QsrIce","O_QnsIce","O_dQnsdT","OIceEvap","O_Runoff","OCalving"] - for v in in_coupling_vars: - in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION OF DEFINITION PHASE - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of initialisation phase') - - comp.enddef() - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TIME STEP LOOP - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('Timestep, field min, mean and max value') - - field_data = pyoasis.asarray(np.full(nx, -1.0)) - - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): - - logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) - logging.debug(str(in_coupling_fields.keys())) - for v, field in in_coupling_fields.items(): - field.get(itap_sec, field_data) - logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( v, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) - logging.debug(str(out_coupling_fields.keys())) - for v, field in out_coupling_fields.items(): - sigma=1 - mu=1 - field_data[:]=sigma * np.random.randn(nx) + mu - field.put(itap_sec, field_data) - logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( v, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - - - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of the program') - - del comp diff --git a/sources/ece3-toy-model/RUNOFF_toy.py b/sources/ece3-toy-model/RUNOFF_toy.py deleted file mode 100644 index f6d78d50b2abd3c2fbe757813b7545c8b387e526..0000000000000000000000000000000000000000 --- a/sources/ece3-toy-model/RUNOFF_toy.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - -if __name__ == '__main__': - - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - - # Init OASIS - comp = pyoasis.Component("RUNOFF_TOY") - local_comm = comp.localcomm - # Get rank in local communicator - mype = comp.localcomm.rank - npes = comp.localcomm.size - - # Unit for output messages - out_runoff = 'RUNOFF_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_runoff, format='%(message)s', level=logging.DEBUG) - logging.debug('-----------------------------------------------------------') - logging.debug('I am RUNOFF-toy process with rank : {}'.format(mype)) - logging.debug('in my local communicator gathering {} processes'.format(npes)) - logging.debug('----------------------------------------------------------') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # PARTITION DEFINITION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - # Definition of the local partition - nx = 512*256 - partition = pyoasis.SerialPartition(nx) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # DECLARATION OF THE COUPLING FIELDS - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - out_coupling_fields={} - out_coupling_vars=["R_Runoff_oce","R_Calving_oce"] - for v in out_coupling_vars: - out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) - - in_coupling_fields={} - in_coupling_vars=["R_Runoff_atm", "R_Calving_atm"] - for v in in_coupling_vars: - in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION OF DEFINITION PHASE - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of initialisation phase') - - comp.enddef() - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TIME STEP LOOP - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('Timestep, field min, mean and max value') - - field_data = pyoasis.asarray(np.full(nx, -1.0)) - - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): - - logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) - logging.debug(str(in_coupling_fields.keys())) - for id, field in in_coupling_fields.items(): - field.get(itap_sec, field_data) - logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) - logging.debug(str(out_coupling_fields.keys())) - for id, field in out_coupling_fields.items(): - sigma=1 - mu=1 - field_data[:]=sigma * np.random.randn(nx) + mu - field.put(itap_sec, field_data) - logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of the program') - - del comp diff --git a/sources/ece3-toy-model/ifs_toy_model.yaml b/sources/ece3-toy-model/ifs_toy_model.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fcf56ff0ff71e81f472e0b6d910b6f1d1a951ba4 --- /dev/null +++ b/sources/ece3-toy-model/ifs_toy_model.yaml @@ -0,0 +1,24 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: IFS_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + # Definition of the local partition grid cell + # L080_NX = 35718 # number of LAND grid cells at T159 resolution + # L128_NX = 88838 # number of LAND grid cells at T255 resolution + # L256_NX = 348528 # number of LAND grid cells at T511 resolution + nx : 88838 + +coupling: + out_vars : [A_TauX_oce, A_TauY_oce, A_TauX_ice, A_TauY_ice, A_Qns_mix, A_Qs_mix, A_Evap_total, A_Precip_liquid, A_Precip_solid, A_Qs_ice, A_Qns_ice, A_dQns_dT, A_Evap_ice, A_Runoff, A_Calving] + + in_vars : [A_SST, A_Ice_temp, A_Ice_albedo, A_Ice_frac, A_Ice_thickness, A_Snow_thickness] + restart_file : /path/ + +... \ No newline at end of file diff --git a/sources/ece3-toy-model/launch-mn4.cmd b/sources/ece3-toy-model/launch_yaml_mn4.cmd similarity index 78% rename from sources/ece3-toy-model/launch-mn4.cmd rename to sources/ece3-toy-model/launch_yaml_mn4.cmd index f45333acc63fd22970fb876aee6fb733a7a71c56..764fe7ec27617a0447dc2b2263f9c9a1bf5cfef4 100644 --- a/sources/ece3-toy-model/launch-mn4.cmd +++ b/sources/ece3-toy-model/launch_yaml_mn4.cmd @@ -35,8 +35,10 @@ done cp -f $datadir/rmp* $rundir cp -f $srcdir/*.py $rundir cp -f $srcdir/namcouple $rundir +cp -f $srcdir/*.yaml $rundir + cd $rundir # run IFS+NEMO+runoff toy model -mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py +mpirun -np 1 python3 $srcdir/toy_model.py --yaml_file_path ifs_toy_model.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path nemo_toy_model.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path runoff_toy_model.yaml diff --git a/sources/ece3-toy-model/nemo_toy_model.yaml b/sources/ece3-toy-model/nemo_toy_model.yaml new file mode 100644 index 0000000000000000000000000000000000000000..22aa85040450133d480a59eb42af21680e1b40fd --- /dev/null +++ b/sources/ece3-toy-model/nemo_toy_model.yaml @@ -0,0 +1,19 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: NEMO_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + nx : 105704 + +coupling: + out_vars : [O_SSTSST, O_TepIce, O_AlbIce, OIceFrc, OIceTck, OSnwTck] + in_vars : [O_OTaux1, O_OTauy1, O_ITaux1, O_ITauy1, O_OTaux2, O_OTauy2, O_ITaux2, O_ITauy2, O_QnsMix, O_QsrMix, OTotEvap, OTotRain, OTotSnow, O_QsrIce, O_QnsIce, O_dQnsdT, OIceEvap, O_Runoff, OCalving] + restart_file : /path/ + +... \ No newline at end of file diff --git a/sources/ece3-toy-model/runoff_toy_model.yaml b/sources/ece3-toy-model/runoff_toy_model.yaml new file mode 100644 index 0000000000000000000000000000000000000000..308d1609527dbd90b5a47be841faa74801e66eb6 --- /dev/null +++ b/sources/ece3-toy-model/runoff_toy_model.yaml @@ -0,0 +1,20 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: RUNOFF_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + nx : 131072 + +coupling: + out_vars : [R_Runoff_oce, R_Calving_oce] + + in_vars : [R_Runoff_atm, R_Calving_atm] + restart_file : /path/ + +... \ No newline at end of file diff --git a/sources/ece3-toy-model/IFS_toy.py b/sources/ece3-toy-model/toy_model.py old mode 100755 new mode 100644 similarity index 52% rename from sources/ece3-toy-model/IFS_toy.py rename to sources/ece3-toy-model/toy_model.py index 68c2384c732607b7473dc524675886860be4caf3..5eada789db26b4b41669ce6c7d9c06ac3a14d1c5 --- a/sources/ece3-toy-model/IFS_toy.py +++ b/sources/ece3-toy-model/toy_model.py @@ -1,36 +1,71 @@ #!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Rodrigo Martín Posada (2021), updated by : Amirpasha Mozaffari (2023) +# TBD + +import yaml +from yaml.loader import SafeLoader +import logging +import argparse +import os import f90nml import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module +from pyoasis import OASIS # pylint: disable=no-name-in-module import numpy as np -import logging - -L080_NX = 35718 # number of LAND grid cells at T159 resolution -L128_NX = 88838 # number of LAND grid cells at T255 resolution -L256_NX = 348528 # number of LAND grid cells at T511 resolution - if __name__ == '__main__': - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - +### Read in YAML file + current_path = os.getcwd() + parser=argparse.ArgumentParser() + parser.add_argument("--yaml_file_path",type=str) + args = parser.parse_args() + yamel_file_path = os.path.join(current_path,args.yaml_file_path) + if os.path.isfile(yamel_file_path) == False: + print("YAML file does not exist. Aborted") + raise NameError("YAML file does not exist.") + + # Open the file and load the file + with open(yamel_file_path) as f: + read_in_data = yaml.load(f, Loader=SafeLoader) + f.close() + +### Read in file + #read_yaml(read_in_data) + model = read_in_data.get("model") + model_name = model.get("model_name") + + # Read in Simulation information + simulation = read_in_data.get("simulation") + simulation_coupling_interval = simulation.get("coupling_interval") + simulation_run_length_sec = simulation.get("run_length_sec") + simulation_nx = simulation.get("nx") + + # Read in Coupling infomration + coupling = read_in_data.get("coupling") + coupling_out_vars = coupling.get("out_vars") + coupling_in_vars = coupling.get("in_vars") + restart_file = coupling.get("restart_file") + +### Pass the values to original code + # Init OASIS - comp = pyoasis.Component("IFS_TOY") + comp = pyoasis.Component(model_name) local_comm = comp.localcomm # Get rank in local communicator mype = comp.localcomm.rank - npes = comp.localcomm.size + npes = comp.localcomm.size + + # BUG : shouldnt it be the npes and not mpye (?) + mype_value = str(100+mype) + out_model = '{model_name}.out_{mype_value}'.format(model_name = model_name, mype_value = mype_value) - # Unit for output messages - out_ifs = 'IFS_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_ifs, format='%(message)s', level=logging.DEBUG) + logging.basicConfig(filename=out_model, format='%(message)s', level=logging.DEBUG) logging.debug('-----------------------------------------------------------') - logging.debug('I am IFS-toy process with rank : {}'.format(mype)) + logging.info('I am {model_name} process with rank : {mype}'.format(model_name = model_name, + mype = mype)) + #logging.debug('I am IFS-toy process with rank : {}'.format(mype)) logging.debug('in my local communicator gathering {} processes'.format(npes)) logging.debug('----------------------------------------------------------') @@ -39,24 +74,25 @@ if __name__ == '__main__': # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Definition of the local partition - nx = L128_NX - partition = pyoasis.SerialPartition(nx) + partition = pyoasis.SerialPartition(simulation_nx) # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # DECLARATION OF THE COUPLING FIELDS # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ out_coupling_fields={} - out_coupling_vars=["A_TauX_oce","A_TauY_oce","A_TauX_ice","A_TauY_ice","A_Qns_mix","A_Qs_mix","A_Evap_total","A_Precip_liquid","A_Precip_solid","A_Qs_ice","A_Qns_ice","A_dQns_dT","A_Evap_ice","A_Runoff","A_Calving"] - for v in out_coupling_vars: + + for v in coupling_out_vars: out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) + logging.warning('var_id {}, added as OASIS_OUT var'.format(v)) + in_coupling_fields={} - in_coupling_vars=["A_SST","A_Ice_temp","A_Ice_albedo","A_Ice_frac","A_Ice_thickness","A_Snow_thickness"] - for v in in_coupling_vars: + + for v in coupling_in_vars: in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) + logging.info('var_id {}, added as OASIS_IN var'.format(v)) + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # TERMINATION OF DEFINITION PHASE @@ -70,9 +106,9 @@ if __name__ == '__main__': # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ logging.debug('Timestep, field min, mean and max value') - field_data = pyoasis.asarray(np.full(nx, -1.0)) + field_data = pyoasis.asarray(np.full(simulation_nx, -1.0)) - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): + for itap_sec in range(0, simulation_run_length_sec, simulation_coupling_interval): logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) logging.debug(str(in_coupling_fields.keys())) @@ -89,18 +125,22 @@ if __name__ == '__main__': # send dummy data (100 for runoff, random for other variables) #TODO send dummy data read from oasis restart file if id == "A_Runoff": - #field_data[:]=1.4658e-06 + field_data[:]=1.4658e-06 field_data[:]=100 else: - field_data[:]=sigma * np.random.randn(nx) + mu + field_data[:]=sigma * np.random.randn(simulation_nx) + mu field.put(itap_sec, field_data) logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) logging.debug('--------------------------------------\n') - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # TERMINATION # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ logging.debug('End of the program') + print('Model {} is finished successfully.'.format(model_name)) + del comp + + +