-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheg-dist2sph.py
144 lines (97 loc) · 2.85 KB
/
eg-dist2sph.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# coding: utf8
import numpy as np
from assemb import MultiTrace, checker
from time import time
import scipy.linalg as la
kRef = 0.6 * np.pi
L = 5.1
##################################
import numpy as np
import numpy.linalg as la
from subprocess import call
from domains import sanitize_config
from domains import generate_concentric_dict
from domains import write_params_geo
from domains import merge_msh_bubbles
from domains import Domains
rads = [1, 1]
phys = [(2, 1, 1), (2, 1, 1)]
centers = [ (0, 0, 0), (L, 0, 0)]
x, y, z = centers[0]
xx, yy, zz = centers[1]
d = np.sqrt( (x-xx)**2 + (y-yy)**2 + (z-zz)**2 )
if 0.99*d < rads[0]+rads[1]:
raise ValueError('The spheres are not separated!')
if len(rads) != len(centers):
raise ValueError('different length')
elif len(rads) != len(phys):
raise ValueError('different length')
else:
N = len(rads)
dgens = []
for i in range(N):
if i == 0:
truefalse = True
else:
truefalse = False
conf = sanitize_config(init_offset=truefalse,
tag=i+1,
kRef=kRef,
rad=rads[i],
phys=phys[i],
center=centers[i],
)
dgen = generate_concentric_dict(conf)
cmds = write_params_geo(conf)
call(cmds)
dgens.append(dgen)
doms = merge_msh_bubbles(dgens)
myd = Domains(doms)
myd.write2dot('graph.dot')
call(['dot', '-Teps', 'graph.dot'], stdout=open('graph.eps', 'wb'))
dd = myd
print(N)
##################################
meshname = "./geo/all.msh"
mtf = MultiTrace(kRef, meshname, dd)
At, X, J, iJ = mtf.tolinop()
shape = mtf.shape
A = 2.0 * At
A2 = A * iJ * A
Ce = 0.5 * J - At
Ci = 0.5 * J + At
Ce2 = Ce * iJ * Ce
Ci2 = Ci * iJ * Ci
x = np.random.rand(shape[0]) + 1j * np.random.rand(shape[0])
xr = np.random.rand(shape[0])
checker('A2 = J', A2, J, x)
checker('exterior Proj.', Ce2, Ce, x)
checker('interior Proj.', Ci2, Ci, x)
checker('error-Calderon with random [no-sense]', A, J, x)
#################################################
#################################################
def dir_data(x, normal, dom_ind, result):
result[0] = -np.exp( 1j * kRef * x[1])
def neu_data(x, normal, dom_ind, result):
result[0] = -1j * normal[1] * kRef * np.exp( 1j * kRef * x[1])
#################################################
#################################################
b = mtf.rhs(dir_data, neu_data)
M = A - X
print('')
print(mtf.shape, flush=True)
print('')
#################################################
#################################################
#################################################
iA = iJ * A * iJ
#################################################
Pjac = iA
E = mtf.upper()
Pgs = iA + iA * E * iA
CCi = iJ * (0.5 * J + At)
CCe = (0.5 * J - At)
B = J - X
BD = B * CCi + CCe
F = B * CCi