-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo_ptfx.py
106 lines (81 loc) · 3.98 KB
/
algo_ptfx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from firedrake import *
#import numpy as np
#from numpy import linalg as LA
import sys, os, time, gc
from multiprocessing import Pool
from options import *
from mesh import *
from inout import *
from solve import *
from adapt import *
from interpol import *
def ptfx (options) :
print "DEBUG generating initial unit mesh"
chrono1 = time.clock()
if options.dim == 2 :
mesh = Meshd(UnitSquareMesh(options.n, options.n))
else :
mesh = Meshd(UnitCubeMesh(options.n, options.n, options.n))
chrono2 = time.clock()
print "DEBUG done generating initial mesh. Elapsed time: %1.2e" %(chrono2-chrono1); sys.stdout.flush()
dtAdap = float(options.Tend)/options.nbrAdap
for i in range(options.nbrPtfxIte) :
print "\n\n\n########## i: %d\n" % i ; sys.stdout.flush()
j = 0
globNormCoef = 0.
for j in range(1, options.nbrAdap+1) :
print "\n##### j: %d\n" % j ; sys.stdout.flush()
# interpolate previous solution on new mesh if necessary (ie i > 0 and j > 0)
if i == 0:
if j == 1 :
#### Initial solution
solIni = solIniAdvec(mesh)
writeGmf(mesh.mesh, 1, "boundary_ids", "bubble.0", solIni, 1, "bubble.0", mesh.section)
else :
solIni = sol
else :
mesh = Meshd(readGmfMesh("newmesh.%d" %j, options.dim, "boundary_ids"))
if j == 1 :
#### Initial solution
solIni = solIniAdvec(mesh)
writeGmf(mesh.mesh, 1, "boundary_ids", "bubble.0", solIni, 1, "bubble.0", mesh.section)
else :
solIni = Function(FunctionSpace(mesh.mesh, 'CG', 1))
print "DEBUG interpolation"; sys.stdout.flush()
chrono1 = time.clock()
interpol(sol, meshOld, solIni, mesh)
chrono2 = clock()
print "DEBUG end interpolation. Elapsed time: %1.2e" %(chrono2-chrono1); sys.stdout.flush()
# solve
tIni, tEnd = (j-1)*dtAdap, j*dtAdap
sol, hesMet, t = solveAdvec(mesh, solIni, tIni, tEnd, options)
globNormCoef = computeGlobalNormalizationCoef(options, mesh, hesMet, globNormCoef)
print "DEBUG globNormCoef: %1.18e" % globNormCoef
writeGmf(mesh.mesh, 1, "boundary_ids", "bubble.%d" % j, sol, 1, "bubble.%d" % j, mesh.section)
writeGmf(mesh.mesh, 0, "boundary_ids", "", hesMet, 5, "hesmet.%d" %j, mesh.section)
if options.nbrSav > 0 :
kIni = (j-1)*options.nbrSav
for k in range(options.nbrSav+1) :
kGlob = kIni + k
print "DEBUG film.%d -> film.%d" %(k, kGlob)
if k == 0 :
os.rename("film_tmp.%d.meshb" % k, "film.%d.meshb" % kGlob)
else :
if os.path.exists("film.%d.meshb" % kGlob) : os.remove("film.%d.meshb" % kGlob)
os.symlink("film.%d.meshb" % kIni, "film.%d.meshb" % kGlob)
os.rename("film_tmp.%d.solb" % k, "film.%d.solb" % kGlob)
meshOld = mesh
gc.collect()
######## End of the loop over sub-intervals
if i < (options.nbrPtfxIte-1) :
# normalizeMetric
print "########## Metrics computation" ; sys.stdout.flush()
chrono1 = time.clock()
metrics = normalizeUnsteadyMetrics(options, globNormCoef)
print "########## End metrics computation. Elapsed time: %1.2e" %(chrono2-chrono1) ; sys.stdout.flush()
gc.collect()
# generate meshes
print "########## Meshes generation" ; sys.stdout.flush()
pool = Pool(15)
pool.map(adaptInternal_star, zip(range(1,options.nbrAdap+1), [options.dim]*options.nbrAdap))
gc.collect()