-
Notifications
You must be signed in to change notification settings - Fork 0
/
tryout.py
195 lines (145 loc) · 5.23 KB
/
tryout.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import mshr
import fenics as fn
import numpy as np
import matplotlib.pyplot as matplt
import matplotlib.tri as tri
import funcs as fu
from geometry import Geometry
import point_source_data as psd
import numpy as np
[x_inner, z_inner] = fu.read_from_file('Data', 'iter_outer2')
[x_outer, z_outer] = fu.read_from_file('Data', 'iter_inner2')
[x_FW, z_FW] = fu.read_from_file('Data', 'iter_FW2')
# x_inner = np.flip(x_inner)
# z_inner = np.flip(z_inner)
# x_outer = np.flip(x_outer)
# z_outer = np.flip(z_outer)
# x_FW = np.flip(x_FW)
# z_FW = np.flip(z_FW)
# fu.write_data_to_file('Data', 'iter_outer2', data=[x_outer, z_outer])
# fu.write_data_to_file('Data', 'iter_inner2', data=[x_inner, z_inner])
# fu.write_data_to_file('Data', 'iter_FW2', data=[x_FW, z_FW])
point_list = []
for i in range(len(x_FW)):
point_list.append(fn.Point(x_FW[i], z_FW[i]))
domain = mshr.Polygon(point_list)
mesh = mshr.generate_mesh(domain, 28)
fn.plot(mesh)
matplt.show()
print('done')
# # z_inner = z_inner + 1
# # z_outer = z_outer + 1
# # z_FW = z_FW + 1
# matplt.plot(x_inner, z_inner, c='r')
# matplt.plot(x_outer, z_outer, c='b')
# matplt.plot(x_FW, z_FW, c='k')
# matplt.gca().set_aspect("equal")
# matplt.xlim([0, 13])
# matplt.ylim([-9, 9])
# matplt.grid(True)
# matplt.show()
# fu.write_data_to_file('Data', 'iter_outer1', [x_outer, z_outer])
# fu.write_data_to_file('Data', 'iter_inner1', [x_inner, z_inner])
# fu.write_data_to_file('Data', 'iter_FW1', [x_FW, z_FW])
# ge = Geometry()
# ps = psd.PointSource(19oc v)
# r = np.transpose(ps.r)[0]
# z = np.transpose(ps.r)[1]
# ge.outer_mephist_vessel()
# ge.inner_mephist_vessel()
# matplt.plot(ge.outer_vessel_contour[0],
# ge.outer_vessel_contour[1],
# c='k', linewidth=1)
# matplt.plot(ge.inner_vessel_contour[0],
# ge.inner_vessel_contour[1],
# c='k', linewidth=1)
# matplt.scatter(r, z, c='g')
# matplt.xlabel("r, м")
# matplt.ylabel("z, м")
# matplt.xticks([0.1, 0.2, 0.3, 0.4, 0.5])
# matplt.xlim([0.05, 0.55])
# matplt.ylim([-0.4, 0.4])
# # matplt.grid(True)
# matplt.gca().set_aspect("equal")
# fu.save_contour_plot(PATH="SHOW_NOW", plot_title='')
# fu.plot_error_vs_mesh_from_file('Errors', 'Spheromak_09052022_224524', [0, 1000], "SHOW_NOW")
# fu.shrink_contour('Data',
# 'Mephist_vessel_outer_surface',
# shrunk_to_point = [0.25, 0],
# alpha_x=0.7,
# alpha_z=0.8)
# def get_column(matrix, col):
# return [row[col] for row in matrix]
# def read_data_from_file():
# file_path = "Data/Mephist_vessel_outer_surface.txt"
# with open(file_path, "r") as file: # change to Read_from_file func
# data = [[float(num) for num in line.split(',')] for line in file]
# x = np.array(get_column(data, 0))
# z = np.array(get_column(data, 1))
# return x, z
# [x,z] = read_data_from_file()
# matplt.plot(x, z)
# matplt.xticks(np.linspace(0.1, 0.4, 7))
# matplt.grid(True)
# matplt.gca().set_aspect("equal")
# # matplt.savefig('Data/Mephist_vessel_outer_surface.svg',dpi=350)
# matplt.show()
# mesh = fn.RectangleMesh(fn.Point(-1, -1), fn.Point(1, 1), 100, 100)
# f = fn.Expression("10*(1-pow(x[0] - 1, 2)-pow(x[1]-1, 2))", degree=2)
# V = fn.FunctionSpace(mesh, 'P', 1)
# print(fn.interpolate(f, V).vector().max())
# fn.plot(fn.interpolate(f, V))
# matplt.show()
# fu.plot_error_vs_mesh_from_file(folder_name='Errors', file_name='1D_problem_09052022_235717', x_lim=[0, 1000], PATH='1D_problem')
# fu.plot_Dina_results("DINA")
# x, y, z = np.genfromtxt(r'psi.dat', unpack=True)
# # x = np.unique(x)
# # y = np.unique(y)
# # z = z.reshape((len(y), len(x)))
# # triang = tri.Triangulation(x, y)
# # interpolator = tri.LinearTriInterpolator(triang, z)
# # Xi, Yi = np.meshgrid(x, y)
# # zi = interpolator(Xi, Yi)
# matplt.tricontour(x, y, z, levels = 100)
# matplt.colorbar()
# matplt.gca().set_aspect("equal")
# matplt.show()
# def Column(matrix, col):
# return [row[col] for row in matrix]
# file_path = "КонтурКамерыСредний.txt"
# with open(file_path, "r") as file: # change to Read_from_file func
# data = [[float(num) for num in line.split(' ')] for line in file]
# x = numpy.array(Column(data, 0))*1e-3
# z = numpy.array(Column(data, 1))*1e-3
# camera_height = 581.69*1e-3
# z_height = z[-2]
# x = x[0:len(x)-1]
# z = z[0:len(z)-1]
# z = z - z_height/2 * numpy.ones(len(z))
# z = z + (camera_height/2 - numpy.amax(z)) * numpy.ones(len(z))
# x = numpy.append(x, numpy.flip(x)) # move it along x axis!
# z = numpy.append(z, numpy.flip(-z))
# print(numpy.amax(x))
# print(numpy.amin(x))
# print(numpy.amax(z))
# print(numpy.amin(z))
# matplt.plot(x, z)
# matplt.grid(true)
# matplt.gca().set_aspect("equal")
# matplt.xlim(0, 0.6)
# matplt.ylim(-0.4, 0.4)
# matplt.show()
# point_list = []
# for i in range(len(x)):
# point_list.append(fenics.Point(x[i], z[i]))
# # a = fenics.Point(0,0)
# # b = fenics.Point(4,0)
# # c = fenics.Point(10,0.7)
# # d = fenics.Point(2,5)
# domain = mshr.Polygon(point_list)
# mesh = mshr.generate_mesh(domain, 20)
# fenics.plot(mesh)
# matplt.show()
# # *** Error: Unable to create polygon.
# # *** Reason: Polygon vertices must be given in counter clockwise order.
# # *** Where: This error was encountered inside CSGPrimitives2D.cpp.