From 9a0dd00de4195e9183a5d489fa130448792caa3f Mon Sep 17 00:00:00 2001
From: Antoine <antoine.hoffmann@epfl.ch>
Date: Thu, 7 Sep 2023 12:59:14 +0200
Subject: [PATCH] cleaning

---
 src/initial_mod.F90                  | 17 +++--------------
 src/readinputs.F90                   |  1 -
 src/utility_mod.F90                  | 17 ++++++++++++++++-
 testcases/cyclone_example/fort_00.90 |  1 -
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/initial_mod.F90 b/src/initial_mod.F90
index 4491fea1..d02af4b8 100644
--- a/src/initial_mod.F90
+++ b/src/initial_mod.F90
@@ -26,23 +26,19 @@ CONTAINS
 
   SUBROUTINE initial_readinputs
     ! Read the input parameters
-
     USE basic, ONLY : lu_in
     USE prec_const
     IMPLICIT NONE
 
     NAMELIST /INITIAL/ INIT_OPT,ACT_ON_MODES,&
-        init_amp,init_background,init_noiselvl,iseed
-
+                       init_amp,init_background,init_noiselvl,iseed
     READ(lu_in,initial)
-
   END SUBROUTINE initial_readinputs
 
   !******************************************************************************!
   !!!!!! initialize the moments and load/build coeff tables
   !******************************************************************************!
   SUBROUTINE initialize
-
     USE basic,            ONLY: speak
     USE time_integration, ONLY: set_updatetlevel
     USE collision,        ONLY: init_collision
@@ -53,9 +49,7 @@ CONTAINS
     USE model,            ONLY: LINEARITY
     USE nonlinear,        ONLY: compute_Sapj, nonlinear_init
     IMPLICIT NONE
-
     CALL set_updatetlevel(1)
-
     !!!!!! Set the moments arrays Nepj, Nipj and phi!!!!!!
     ! through loading a previous state
     IF ( job2load .GE. 0 ) THEN
@@ -129,23 +123,18 @@ CONTAINS
     CALL update_ghosts_moments
     CALL update_ghosts_EM
     !! End of phi and moments initialization
-
     ! Init collision operator
     CALL init_collision
-
     !! Preparing auxiliary arrays at initial state
     ! particle density, fluid velocity and temperature (used in diagnose)
     CALL speak('Computing fluid moments and transport')
     CALL compute_fluid_moments
     CALL compute_radial_transport
     CALL compute_radial_heatflux
-
     ! init auxval for nonlinear
     CALL nonlinear_init
     ! compute nonlinear for t=0 diagnostic
     CALL compute_Sapj ! compute S_0 = S(phi_0,N_0)
-
-
   END SUBROUTINE initialize
   !******************************************************************************!
 
@@ -591,8 +580,8 @@ CONTAINS
             DO ij=1+ngj/2,local_nj+ngj/2
               DO iz=1+ngz/2,local_nz+ngz/2
                 IF((ikx+local_nkx_offset .LE. 186) .AND. (iky+local_nky_offset .LE. 94)) THEN
-                  IF (.TRUE.) THEN
-                  ! IF ( (parray(ip) .EQ. 0) .AND. (jarray(ij) .EQ. 0) ) THEN
+                  !IF (.TRUE.) THEN
+                  IF ( (parray(ip) .EQ. 0) .AND. (jarray(ij) .EQ. 0) ) THEN
                     moments(ia,ip,ij,iky,ikx,iz,:) = scaling*(ricci_mat_real(ikx+local_nkx_offset,iky+local_nky_offset)&
                     - imagu*ricci_mat_imag(ikx+local_nkx_offset,iky+local_nky_offset))
                   ELSE
diff --git a/src/readinputs.F90 b/src/readinputs.F90
index d0550189..b6e4bac0 100644
--- a/src/readinputs.F90
+++ b/src/readinputs.F90
@@ -1,6 +1,5 @@
 SUBROUTINE readinputs
   ! Additional data specific for a new run
-
   USE grid,             ONLY: grid_readinputs
   USE diagnostics,      ONLY: diag_readinputs
   USE collision,        ONLY: collision_readinputs
diff --git a/src/utility_mod.F90 b/src/utility_mod.F90
index b8544848..be5f4812 100644
--- a/src/utility_mod.F90
+++ b/src/utility_mod.F90
@@ -1,6 +1,6 @@
 MODULE utility
   IMPLICIT NONE
-  PUBLIC :: is_nan, is_inf!. checkfield, checkelem
+  PUBLIC :: is_nan, is_inf, decomp1D!. checkfield, checkelem
 CONTAINS
 
   FUNCTION is_nan(x,str) RESULT(isn)
@@ -43,6 +43,21 @@ CONTAINS
 
   END FUNCTION is_inf
 
+  ! Distribute data among processes in a balanced way
+  SUBROUTINE decomp1D( n, numprocs, myid, is, ie )
+    INTEGER, INTENT(IN)  :: n, numprocs, myid
+    INTEGER, INTENT(OUT) :: is, ie
+    INTEGER :: nlocal
+    INTEGER :: deficit
+    nlocal   = n / numprocs
+    is        = myid * nlocal + 1
+    deficit  = MOD(n,numprocs)
+    is        = is + MIN(myid,deficit)
+    IF (myid .LT. deficit) nlocal = nlocal + 1
+    ie = is + nlocal - 1
+    IF ((ie .GT. n) .OR. (myid .EQ. numprocs-1)) ie = n
+  END SUBROUTINE decomp1D
+
   ! FUNCTION checkfield(n1,n2,n3,field,str) RESULT(mlend)
   !   use prec_const, ONLY: xp
   !   IMPLICIT NONE
diff --git a/testcases/cyclone_example/fort_00.90 b/testcases/cyclone_example/fort_00.90
index 309ceed7..efb2eeef 100644
--- a/testcases/cyclone_example/fort_00.90
+++ b/testcases/cyclone_example/fort_00.90
@@ -60,7 +60,6 @@
   nu      = 0.05
   beta    = 0.0
   ADIAB_E = .t.
-  tau_e   = 1.0
 /
 &CLOSURE
   hierarchy_closure='truncation'
-- 
GitLab