-
Notifications
You must be signed in to change notification settings - Fork 0
/
inout.py
116 lines (98 loc) · 3.63 KB
/
inout.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
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
import sys
def writeMesh(meshd, name):
plex = meshd.mesh.topology._plex
dim = meshd.mesh._topological_dimension
cStart, cEnd = plex.getHeightStratum(0)
eStart, eEnd = plex.getHeightStratum(1)
vStart, vEnd = plex.getDepthStratum(0)
nbrVer = vEnd - vStart
coords = meshd.mesh.coordinates.dat.data
f = open(name+".mesh", 'w')
print " %%%% file %s.mesh opened" % name
f.write("MeshVersionFormatted 1\n\nDimension 2\n\n")
f.write("Vertices\n%d\n" % nbrVer)
for iVer in range(nbrVer):
off = meshd.section.getOffset(iVer+vStart)/dim
f.write("%1.15e %1.15e 1\n" % (coords[off][0], coords[off][1]))
f.write("Triangles\n%d\n" % (cEnd-cStart))
for c in range(cStart,cEnd):
closure = plex.getTransitiveClosure(c)[0]
tri = [0,0,0]
i = 0
for cl in closure:
if (cl < vStart or cl >= vEnd): continue
tri[i] = cl-vStart+1
i += 1
f.write("%d %d %d 1\n" % (tri[0], tri[1], tri[2]))
nbrEdg = plex.getStratumSize("exterior_facets", 1)
f.write("Edges\n%d\n" % nbrEdg)
for e in range(eStart, eEnd):
l = plex.getLabelValue("boundary_ids", e)
if l != -1:
ver = plex.getCone(e)
f.write("%d %d %d\n" % (ver[0]-vStart+1, ver[1]-vStart+1, l))
f.close()
def writeMetric(meshd, metric, name):
plex = meshd.mesh.topology._plex
dim = meshd.mesh._topological_dimension
vStart, vEnd = plex.getDepthStratum(0)
NbrVer = vEnd - vStart
f = open(name+".sol", 'w')
print " %%%% file %s.sol opened" % name
f.write("MeshVersionFormatted 2\n\nDimension 2\n\n")
f.write("SolAtVertices\n%d\n1 3\n\n" % NbrVer)
for iVer in range(NbrVer):
off = meshd.section.getOffset(iVer+vStart)/dim
f.write("%f %f %f\n" % (metric.dat.data[off][0][0], metric.dat.data[off][0][1], metric.dat.data[off][1][1]))
f.write("\nEnd")
f.close()
def writeMetric2(meshd, metric, name):
plex = meshd.mesh.topology._plex
dim = meshd.mesh._topological_dimension
vStart, vEnd = plex.getDepthStratum(0)
NbrVer = vEnd - vStart
f = open(name+".sol", 'w')
print " %%%% file %s.sol opened" % name
f.write("MeshVersionFormatted 2\n\nDimension 2\n\n")
f.write("SolAtVertices\n%d\n1 3\n\n" % NbrVer)
for iVer in range(NbrVer):
f.write("%f %f %f\n" % (metric[iVer][0], metric[iVer][1], metric[iVer][2]))
f.write("\nEnd")
f.close()
def writeSol(meshd, u, name):
plex = meshd.mesh.topology._plex
dim = meshd.mesh._topological_dimension
vStart, vEnd = plex.getDepthStratum(0)
NbrVer = vEnd - vStart
f = open(name+".sol", 'w')
print " %%%% file %s.sol opened" % name
f.write("MeshVersionFormatted 2\n\nDimension 2\n\n")
f.write("SolAtVertices\n%d\n1 1\n\n" % NbrVer)
for iVer in range(NbrVer):
off = meshd.section.getOffset(iVer+vStart)/dim
f.write("%f\n" % (u.dat.data[off]))
f.write("\nEnd")
f.close()
def readMetric(meshd, metric, coordSection, name):
plex = meshd.mesh.topology._plex
dim = meshd.mesh._topological_dimension
vStart, vEnd = plex.getDepthStratum(0)
NbrVer = vEnd - vStart
f = open(name+".sol", 'r')
count = 0
iVer = 0
for line in f:
count += 1
if count < 9:
continue
h = line.split(" ")
h1 = float(h[0])
h2 = float(h[1])
h3 = float(h[2])
off = meshd.section.getOffset(iVer+vStart)/dim
metric.dat.data[off] = [[h1, h2], [h2, h3]]
iVer += 1
if iVer == NbrVer:
break
f.close()