PartitionGBR.py 3.49 KB
Newer Older
thomas's avatar
thomas committed
1
#
thomas's avatar
thomas committed
2
# Script to generate partitioned mesh for use with MultirateGBR.py
thomas's avatar
thomas committed
3
4
5
6
7
8
9
10
11
#   - run using the command: rundgpy PartitionGBR_StandaloneStereo.py <NB_PROCESSORS>
#

from dgpy import *
from ProjectMesh import *
from termcolor import colored
import time, math, os, sys

#-------------
thomas's avatar
thomas committed
12
#filename = "gbr300K_sgbr"
bseny's avatar
bseny committed
13
#filename = "gbr10K"
thomas's avatar
thomas committed
14
filename = sys.argv[1]
thomas's avatar
thomas committed
15
16
17
18
19
20
21
22
23
24
25
26
27
#-------------
# Multirate and Partition Parameters
RK_TYPE = ERK_22_C
mL = 1000
algo = 5
# Mesh Parameters
order = 1
dimension = 2
"""
-gbrDiff= 0: Constant Diffusion diff || 1: Parametrization of Smagorinsky 
"""
gbrDiff=1
#-------------
thomas's avatar
thomas committed
28
29
30
## Mesh projection:
#projCodeLonLat = "+proj=latlong +ellps=WGS84"
#projCodeMesh = "+proj=utm +ellps=WGS84 +zone=55 +south"
thomas's avatar
thomas committed
31
#-------------
thomas's avatar
thomas committed
32

thomas's avatar
thomas committed
33
34
35
36
37
38
39
40
#try : os.mkdir('./Meshes');
#except: 0;
#if(not os.path.exists("./Meshes/"+filename+".msh")):
  #try : os.system("make "+filename+".msh");
  #except: 0;
if(not os.path.exists("./Meshes/"+filename+"_utm.msh")):
  print'Error: projected mesh does not exist. First project mesh by running rundgpy MultirateGBR.py'
  sys.exit(1)
thomas's avatar
thomas committed
41

thomas's avatar
thomas committed
42
print"Generating partitioned mesh from 3D CARTESIAN mesh:", filename
thomas's avatar
thomas committed
43

thomas's avatar
thomas committed
44
nbProcessors = int(sys.argv[2])
thomas's avatar
thomas committed
45
46
47
48
49
50
51
52
53
54

print''
print'Number of processors partitioning for:', nbProcessors
print''

#Compile libraries
if (Msg.GetCommRank() == 0):
  functionC.buildLibraryFromFile ("./Libraries/GBR.cc", "./Libraries/lib_gbr.so")
glib = "./Libraries/lib_gbr.so"

thomas's avatar
thomas committed
55
56
#First project mesh into planar space
m2 = GModel()
thomas's avatar
thomas committed
57
58
#loadAndProjectMeshUTM(m2, filename, projCodeLonLat, projCodeMesh)
m2.load('./Meshes/'+filename+'_utm.msh')
thomas's avatar
thomas committed
59
60
61
62

#Set up model
print(colored('********** Partition mesh with algorithm %d **********', "red")%(algo))
print ''
thomas's avatar
thomas committed
63

thomas's avatar
thomas committed
64
65
66
67
68
69
70
71
72
73
74
pOpt = meshPartitionOptions()
pOpt.setNumOfPartitions(nbProcessors)

groups = dgGroupCollection(m2, dimension, order, True)
xyz = groups.getFunctionCoordinates()

#Read bathymetry
bathDC = dgDofContainer(groups, 1);
if(not os.path.exists("./Bath/"+filename+"_bath_smooth/"+filename+"_bath_smooth.idx")):
  Msg.Fatal('No valid bathymetry file found,  please launch "rundgpy DiffuseBathGBR.py"')
Msg.Info("Smoothed bathymetry already exists.")
75
bathDC.importIdx("./Bath/"+filename+"_bath_smooth/"+filename+"_bath_smooth.idx")
thomas's avatar
thomas committed
76
77
78
79
80
81
82
83
84
85
86
87
88
Msg.Info("Smoothed bathymetry read.")

# Define Conservation Law
claw = dgConservationLawShallowWater2d()
solution = dgDofContainer(groups, claw.getNbFields())

ld = functionConstant(0)
Cd = functionC(glib, "bottomDrag_old", 1, [solution.getFunction(), bathDC.getFunction()])
#Cd = functionC(glib, "bottomDrag", 1, [ solution.getFunction(), bathDC.getFunction(), reefsDC.getFunction() ]) #***
if(gbrDiff == 0):
  Di = functionConstant(diff)
elif(gbrDiff == 1):
  Di = functionC(glib, "smagorinsky", 1, [solution.getFunctionGradient()])
thomas's avatar
thomas committed
89
Coriolis = functionC(glib, "coriolisConst", 1, [xyz])
thomas's avatar
thomas committed
90
91
92
93
94
95
96
97
98
99
100
101

claw.setCoriolisFactor(Coriolis)
claw.setQuadraticDissipation(Cd)
claw.setLinearDissipation(ld)
claw.setDiffusivity(Di)
claw.setBathymetry(bathDC.getFunction())
claw.setBathymetryGradient(bathDC.getFunctionGradient())

rk = dgMultirateERK(groups, claw, RK_TYPE)
Msg.Info("Splitting groups for multirate ...")
dt = rk.splitGroupsForMultirate(mL, solution, [solution, bathDC])
rk.printMultirateInfo()
bseny's avatar
bseny committed
102
103
solution.exportGroupIdMsh()

thomas's avatar
thomas committed
104
Msg.Info("Computing optimal mesh partitions ...")
105
rk.computeMultiConstrainedPartition(pOpt, algo)
thomas's avatar
thomas committed
106
PartitionMesh(m2, pOpt)
thomas's avatar
thomas committed
107
108
rk.updatePartitionInfo(nbProcessors)
rk.printPartitionInfo()
thomas's avatar
thomas committed
109

thomas's avatar
thomas committed
110
m2.save('./Meshes/'+filename + '_utm_partitioned_'+str(nbProcessors)+'.msh')
thomas's avatar
thomas committed
111
112
113
print ''
print(colored('**********       Partition Done            **********', "red"))
print ''