Commit 8118ade1 authored by POLCHER Jan's avatar POLCHER Jan 🚴🏾
Browse files

Updates to test domain docomposition

parent 3189cf8a
......@@ -34,6 +34,11 @@ xcuserdata/
*.png
*.so
*.log
*.nc
Weights/
__pycache__/
DomainDecompTests/Output/
\ No newline at end of file
#
# Test configurations and directories
#
DomainDecompTests/Output/
DomainDecompTests/run.def
\ No newline at end of file
#
#
#
import numpy as np
import os, sys
from netCDF4 import Dataset
from mpi4py import MPI
comm = MPI.COMM_WORLD
#
sys.path.append('../')
#
# Get the information from the configuration file.
#
import configparser
config=configparser.ConfigParser({'SaveWeights':'true', "DiagLon":"0.0, 0.0", "DiagLat":"0.0, 0.0"})
config.read("../run.def")
#
import getargs
log_master, log_world = getargs.getLogger(__name__)
INFO, DEBUG, ERROR = log_master.info, log_master.debug, log_world.error
INFO_ALL, DEBUG_ALL = log_world.info, log_world.debug
#
import ModelGrid as MG
import Partition as PA
import RPPtools as RPP
#
import matplotlib.pylab as plt
import savefile
#
gg = MG.GlobalGrid()
#
szhalo=1
nbc=comm.Get_size()
rank=comm.Get_rank()
#
# Open write unit
#
if not os.path.exists('Output'):
os.makedirs('Output')
wunit = open("Output/TestDomain_out_"+str(rank)+".txt", "w")
#
wunit.write("START :: i = 0 :"+str(gg.ni-1)+" >> j = 0 :"+str(gg.nj-1)+" SZ="+str(gg.ni*gg.nj)+" nbland="+str(gg.nbland)+'\n')
wunit.write("======================================"+'\n')
#
part = PA.partition(gg.ni, gg.nj, gg.land, comm, nbc, szhalo, rank, wunit=wunit)
wunit.write("Domain on proc : "+str(part.ni)+str(part.nj)+" Offset from global domain : "+str(part.istart)+str(part.jstart)+'\n')
wunit.write("Domain with halo on proc : "+str(part.nih)+str(part.njh)+" Offset with halo : "+str(part.ihstart)+str(part.jhstart)+'\n')
wunit.write(" i inner = "+str(part.istart)+":"+str(part.istart+part.ni-1)+" i w.halo = "+str(part.ihstart)+":"+str(part.ihstart+part.nih-1))
wunit.write(" j inner = "+str(part.jstart)+":"+str(part.jstart+part.nj-1)+" j w.halo = "+str(part.jhstart)+":"+str(part.jhstart+part.njh-1)+'\n')
wunit.write("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+======================"+'\n')
x=np.zeros((part.njh,part.nih))
ihoff=part.istart-part.ihstart
jhoff=part.jstart-part.jhstart
x[jhoff:jhoff+part.nj,ihoff:ihoff+part.ni]=99
wunit.write("====== TEST FIELD START ======================"+'\n')
for j in range(part.njh) :
wunit.write(str(x[j,:].astype(int))+'\n')
part.sendtohalo(x)
wunit.write("====== TEST FIELD AFTER HALO EXCHANGE ======================"+'\n')
for j in range(part.njh) :
wunit.write(str(x[j,:].astype(int))+'\n')
x=np.zeros((part.njh,part.nih))
ihoff=part.istart-part.ihstart
jhoff=part.jstart-part.jhstart
x[jhoff:jhoff+part.nj,ihoff:ihoff+part.ni]=rank
wunit.write("====== GATHER FIELD START ======================"+'\n')
for j in range(part.njh) :
wunit.write(str(x[j,:].astype(int))+'\n')
xgather = part.gather(x)
if rank == 0 :
print("Type of gathered variable : ", xgather.astype(int))
modelgrid=MG.ModelGrid(part.ihstart+gg.igstart, part.nih, part.jhstart+gg.jgstart, part.njh)
INFO("Longitude interval on proc "+str(rank)+" = "+str(modelgrid.box_land[0][0])+" : "+str(modelgrid.box_land[0][1]))
INFO("Latitude interval on proc "+str(rank)+" = "+str(modelgrid.box_land[1][0])+" : "+str(modelgrid.box_land[1][1]))
rland=np.zeros((modelgrid.nbland))
rland[:] = rank
xland = part.landscatgat(modelgrid, rland)
if rank == 0 :
xland[~np.isnan(xland)] = 1
xland[np.isnan(xland)] = 0
print("Difference between global and and the gathered version :",np.sum(xland-gg.land))
#
# Test the landsendtohalo function
#
x=np.zeros((part.njh,part.nih))
x[:,:]=-1
ihoff=part.istart-part.ihstart
jhoff=part.jstart-part.jhstart
x[jhoff:jhoff+part.nj,ihoff:ihoff+part.ni]=rank
lx = modelgrid.landgather(x)
part.landsendtohalo(lx)
xland = part.landscatgat(modelgrid, lx)
if rank == 0 :
xland[~np.isnan(xland)] = 1
xland[np.isnan(xland)] = 0
print("Difference between global and gathered version of land only :",np.sum(xland-gg.land))
print("len areas : ", len(modelgrid.area))
areas = part.landscatgat(modelgrid, np.array(modelgrid.area))
if rank == 0 :
print(areas/1000000000.)
wunit.close()
y=np.zeros((nbc,modelgrid.nbland))
print("Test : ", y.shape, modelgrid.nbland)
y[rank,:]=rank
savefile.dumpnetcdf("TestDomainDecomp.nc", gg, modelgrid, part, rland, x, y)
......@@ -35,8 +35,10 @@ rank=comm.Get_rank()
#
# Open write unit
#
if not os.path.exists('Output'):
os.makedirs('Output')
if rank == 0 :
if not os.path.exists('Output'):
os.makedirs('Output')
comm.Barrier()
wunit = open("Output/TestDomain_out_"+str(rank)+".txt", "w")
#
wunit.write("START :: i = 0 :"+str(gg.ni-1)+" >> j = 0 :"+str(gg.nj-1)+" SZ="+str(gg.ni*gg.nj)+" nbland="+str(gg.nbland)+'\n')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment