pts = mesh_obj['node'] tri = mesh_obj['element'] # report the status of the 2D mesh quality.stats(pts, tri) """ 1. FEM forward simulations """ # setup EIT scan conditions el_dist, step = 7, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(mesh_obj, el_pos) # in python, index start from 0 ex_line = ex_mat[1].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'perm': 100.0}] mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0) tri_perm = mesh_new['perm'] node_perm = sim2pts(pts, tri, np.real(tri_perm)) # solving once using fem f, _ = fwd.solve(ex_line, perm=tri_perm) f = np.real(f) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(pts, tri, vertex_color=f, alpha=1.0)
im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(alpha), shading='flat') fig.colorbar(im) ax.axis('tight') ax.set_title(r'$\Delta$ Permitivity') """ 2. calculate simulated data using stack ex_mat """ el_dist, step = 7, 1 n_el = len(el_pos) ex_mat1 = eit_scan_lines(n_el, el_dist) ex_mat2 = eit_scan_lines(n_el, 1) ex_mat = np.vstack([ex_mat1, ex_mat2]) # forward solver fwd = Forward(ms, el_pos) f0 = fwd.solve(ex_mat, step, perm=ms['alpha']) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha']) """ 3. solving using dynamic EIT """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, parser='std') eit.setup(p=0.40, lamb=1e-3, method='kotre') ds = eit.solve(f1.v, f0.v) """ 4. plot """ fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=0.90, cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('tight') ax.set_title(r'$\Delta$ Permitivity Reconstructed')
ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(ms, el_pos) # in python, index start from 0 ex_line = ex_mat[2].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'alpha': 100.0}] ms_test = mesh.set_alpha(ms, anomaly=anomaly, background=1.0) tri_perm = ms_test['alpha'] node_perm = pdeprtni(no2xy, el2no, np.real(tri_perm)) # solving once using fem # f, _ = fwd.solve_once(ex_line, tri_perm) # f = np.real(f) # calculate simulated data f0 = fwd.solve(ex_mat, step=step, perm=ms['alpha']) f1 = fwd.solve(ex_mat, step=step, perm=ms_test['alpha']) """ 3. JAC solver """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.50, lamb=1e-4, method='kotre') ds = eit.solve(f1.v, f0.v) node_ds = pdeprtni(no2xy, el2no, np.real(ds)) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(no2xy, el2no, vertex_color=node_ds, alpha=1.0)
}, { 'x': 0, 'y': -0.5, 'd': 0.1, 'alpha': 0.1 }] ms1 = mesh.set_alpha(ms, anomaly=anomaly, background=1.0) alpha = np.real(ms1['alpha'] - ms0['alpha']) """ ax1. FEM forward simulations """ # setup EIT scan conditions el_dist, step = 1, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(ms, el_pos) f0 = fwd.solve(ex_mat, step=step, perm=ms0['alpha']) f1 = fwd.solve(ex_mat, step=step, perm=ms1['alpha']) """ ax2. BP """ eit = bp.BP(ms, el_pos, ex_mat=ex_mat, step=1, parser='std') ds = eit.solve(f1.v, f0.v, normalize=True) ds_bp = ds """ ax3. JAC """ eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.2, lamb=0.001, method='kotre') # parameter tuning is needed for better display ds = eit.solve(f1.v, f0.v) ds_jac = pdeprtni(no2xy, el2no, ds) """ ax4. GREIT """ eit = greit.GREIT(ms, el_pos, ex_mat=ex_mat, step=step, parser='std') ds = eit.solve(f1.v, f0.v) x, y, ds_greit = eit.mask_value(ds, mask_value=np.NAN)
fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(alpha), shading='flat', cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal') ax.set_title(r'$\Delta$ Conductivities') plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(ms, el_pos) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha'], parser='std') """ 3. solve using gaussian-newton """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat, step, perm=1.0, parser='std') eit.setup(p=0.25, lamb=1.0, method='lm') ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-4, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=1.0, cmap=plt.cm.viridis)
x, y = pts[:, 0], pts[:, 1] quality.stats(pts, tri) # change permittivity anomaly = [{"x": 0.40, "y": 0.50, "d": 0.20, "perm": 100.0}] mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0) perm = mesh_new["perm"] """ 1. FEM forward simulations """ # setup EIT scan conditions ex_dist, step = 7, 1 ex_mat = eit_scan_lines(16, ex_dist) ex_line = ex_mat[0].ravel() # calculate simulated data using FEM fwd = Forward(mesh_obj, el_pos) f, _ = fwd.solve(ex_line, perm=perm) f = np.real(f) """ 2. plot """ fig = plt.figure() ax1 = fig.add_subplot(111) # draw equi-potential lines vf = np.linspace(min(f), max(f), 32) ax1.tricontour(x, y, tri, f, vf, cmap=plt.cm.viridis) # draw mesh structure ax1.tripcolor( x, y, tri, np.real(perm), edgecolors="k", shading="flat",