@@ -2,19 +2,20 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
22 USE DefUtils, ONLY: GetSolverParams, GetMesh, GetNOFActive, &
33 DefaultVariableAdd, GetLogical, GetLogical, GetString, MAX_NAME_LEN, &
44 VariableGet, ParEnv, variable_on_elements
5+ USE GeneralUtils, ONLY: I2S
56 USE Types, ONLY: Model_t, Solver_t, Mesh_t, Variable_t, ValueList_t, dp
67 USE Messages, ONLY: Message, FATAL, INFO, USE_YAC
7- USE elmer_coupling, ONLY: coupling_setup
8+ USE elmer_coupling, ONLY: coupling_setup, is_root_rank
89 USE elmer_ebfm_coupling, ONLY: elmer_ebfm_interface, t_ice_field, smb_field, &
910 runoff_field, surface_height_field
1011 ! USE elmer_icon_coupling, ONLY: elmer_icon_interface, clt_field, pr_field
1112
1213 IMPLICIT NONE
1314
14- TYPE (Model_t) :: Model
15- TYPE (Solver_t) :: Solver
16- REAL (KIND= dp) :: dt
17- LOGICAL :: TransientSimulation
15+ TYPE (Model_t), INTENT ( IN ) :: Model
16+ TYPE (Solver_t), INTENT ( IN ) :: Solver
17+ REAL (KIND= dp), INTENT ( IN ) :: dt
18+ LOGICAL , INTENT ( IN ) :: TransientSimulation
1819
1920
2021 TYPE (ValueList_t), POINTER :: SolverParams
@@ -23,9 +24,8 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
2324 ! parameters to be read in from this solvers section in the sif
2425 LOGICAL :: couple_to_ebfm, couple_to_icon ! define which component is coupled to Elmer
2526
26- CHARACTER (LEN= 1024 ) :: config_file, grid_dir, model_tstep
27- INTEGER :: num_parts, elmer_mesh_partitions, comm_rank, comm_size, ierror
28- INTEGER :: I, t, ierr
27+ CHARACTER (LEN= 1024 ) :: config_file, model_tstep
28+ INTEGER :: I, t, ierr, dt_hours
2929 INTEGER , POINTER :: t_icePerm(:), smbPerm(:), runoffPerm(:)
3030 ! INTEGER, POINTER :: cltPerm(:), prPerm(:) ! ICON is not supported at the moment
3131 LOGICAL :: Parallel, FirstTime= .TRUE. , UnFoundFatal= .TRUE.
@@ -60,6 +60,10 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
6060 CALL FATAL(SolverName,' No keyword >Couple To ICON< found in yac2elmer solver' )
6161 END IF
6262
63+ IF (.NOT. (couple_to_ebfm .OR. couple_to_icon)) THEN
64+ CALL FATAL(SolverName,' At least one of >Couple To EBFM< or >Couple To ICON< must be TRUE' )
65+ END IF
66+
6367 ! TODO: remove this check when ICON coupling is implemented
6468 IF (couple_to_icon) THEN
6569 CALL FATAL(SolverName,' >Couple To ICON< is currently not supported. Please set to FALSE' )
@@ -68,9 +72,11 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
6872 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6973 ! retrieve the timestep in hours
7074 Mesh = > Solver % Mesh
71- write (model_tstep, * ) int (dt * 8760 )
72- WRITE (Message,* ) ' ELMER timestep size in hours:' , TRIM (model_tstep)
73- CALL INFO(SolverName,Message,Level= 3 )
75+
76+ dt_hours = int (dt * 8760 )
77+ write (model_tstep, * ) dt_hours
78+ CALL INFO(SolverName, &
79+ ' ELMER timestep size in hours:' // I2S(dt_hours), Level= 3 )
7480 IF (FirstTime) THEN
7581
7682
@@ -81,13 +87,11 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
8187 IF ((ParEnv % PEs <= 1 ) .AND. ( .NOT. ThisMesh % SingleMesh )) THEN
8288 CALL FATAL(SolverName,' Only parallel runs can use this solver' )
8389 ELSE
84- grid_dir= TRIM (ThisMesh % Name)
85- elmer_mesh_partitions = ParEnv % PEs
86- WRITE (Message,* ) ' Running on ' , TRIM (grid_dir),' with ' ,ParEnv % PEs ,' partitions'
87- CALL INFO(SolverName,Message,Level= 3 )
90+ CALL INFO(SolverName, &
91+ ' Running with ' // I2S(ParEnv % PEs) // ' partitions' , Level= 3 )
8892 END IF
8993
90- CALL coupling_setup(TRIM (grid_dir), elmer_mesh_partitions , TRIM (model_tstep), couple_to_ebfm, couple_to_icon)
94+ CALL coupling_setup(ThisMesh , TRIM (model_tstep), couple_to_ebfm, couple_to_icon)
9195
9296 IF (couple_to_ebfm) THEN
9397 ! setting up Elmer-side variables for receiving YAC variables
@@ -140,39 +144,33 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
140144
141145 FirstTime = .FALSE.
142146
143- WRITE (Message,* ) " Coupling setup with " ,TRIM (grid_dir)," on " ,&
144- elmer_mesh_partitions, " partitions for YAC coupling done"
145- CALL INFO(SolverName,Message,Level= 1 )
147+ CALL INFO(SolverName, " YAC coupling setup done" , Level= 1 )
146148 END IF
147149! !!!!!!!!! DO WE HAVE TO INITIALIZE WITH EVERY CALL ? !!!!!!!!!!!!!!
148150
149151 IF (couple_to_ebfm) THEN
150- WRITE (Message,* ) ' BEFORE ELMER EBFM INTERFACE'
151- CALL INFO(SolverName,Message,Level= 3 )
152+ CALL INFO(SolverName, ' BEFORE ELMER EBFM INTERFACE' , Level= 3 )
152153 ! couple with EBFM
153- CALL elmer_ebfm_interface(ParEnv % MyPE)
154- WRITE (Message,* ) ' AFTER ELMER EBFM INTERFACE'
155- CALL INFO(SolverName,Message,Level= 3 )
154+ CALL elmer_ebfm_interface(is_root_rank)
155+ CALL INFO(SolverName, ' AFTER ELMER EBFM INTERFACE' , Level= 3 )
156156
157157 t_iceVar = > VariableGet( Mesh % Variables, ' T_ice' )
158158 smbVar = > VariableGet( Mesh % Variables, ' smb' )
159159 runoffVar = > VariableGet( Mesh % Variables, ' runoff' )
160160 ZsSol = > VariableGet( Model % Mesh % Variables, " Zs" ,UnFoundFatal= UnFoundFatal)
161- WRITE (Message,* ) ' AFTER GETTING VARIABLES'
162- CALL INFO(SolverName,Message,Level= 3 )
161+ CALL INFO(SolverName, ' AFTER GETTING VARIABLES' , Level= 3 )
163162 IF ((.NOT. ASSOCIATED (t_iceVar)) .OR. (.NOT. ASSOCIATED (smbVar)) .OR. (.NOT. ASSOCIATED (runoffVar))) THEN
164163 CALL FATAL(SolverName,' Elmer variables not associated' )
165164 END IF
166165
167- WRITE (Message,* ) ' BEFORE WRITING NODAL VALUES'
168- CALL INFO(SolverName,Message,Level= 3 )
166+ CALL INFO(SolverName, ' BEFORE WRITING NODAL VALUES' , Level= 3 )
169167 ! write over values for nodes
170168 DO i= 1 , Mesh % NumberOfNodes
171169 t_iceVar % Values(t_iceVar % Perm(i)) = t_ice_field(i,1 )
172170 runoffVar % Values(runoffVar % Perm(i)) = runoff_field(i,1 )
173171 surface_height_field(i,1 ) = ZsSol % Values(ZsSol % Perm(i))
174172 END DO
175- CALL INFO(SolverName,Message, Level= 3 )
173+ CALL INFO(SolverName, ' BEFORE WRITING ELEMENT VALUES ' , Level= 3 )
176174 ! write over values for elements
177175 DO t= 1 , GetNOFActive(Solver)
178176 smbVar % Values(smbVar % Perm(t)) = smb_field(t,1 )
@@ -186,7 +184,7 @@ SUBROUTINE YAC2Elmer( Model,Solver,dt,TransientSimulation )
186184 IF (couple_to_icon) THEN
187185 CALL FATAL(SolverName,' ICON coupling not yet implemented' )
188186 ! TODO: stub implementation for ICON coupling
189- ! CALL elmer_icon_interface(ParEnv % MyPE )
187+ ! CALL elmer_icon_interface(is_root_rank )
190188 ! cltVar => VariableGet( Mesh % Variables, 'tas' )
191189 ! prVar => VariableGet( Mesh % Variables, 'pr_snow' )
192190 END IF
0 commit comments