forked from floli/PyRBF
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_BlockNew.py
787 lines (657 loc) · 26.7 KB
/
demo_BlockNew.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
""" Generates data to show the effect of rescaling. Low density basisfunctions used. """
import pandas
import os
import logging
from rbf import *
import basisfunctions, testfunctions
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from mpl_toolkits import mplot3d
import time
import mesh
import math
from random import randint
from scipy import spatial
from halton import *
import vtk
import mesh_io
#from mpi4py import MPI
'''
############################################################
IMPORTANT!
1. Eigenvalue decomposition does not work with 100x100 input matrix - too large for memory
2. Difficult to run global input mesh with 100x100
############################################################
'''
class Mesh:
"""
A Mesh consists of:
- Points: A list of tuples of floats representing coordinates of points
- Cells: A list of tuples of ints representing mesh elements
- Pointdata: A list of floats representing data values at the respective point
"""
def __init__(self, points = None, cells = None, cell_types = None, pointdata = None):
if points is not None:
self.points = points
else:
self.points = []
if cells is not None:
assert(cell_types is not None)
self.cells = cells
self.cell_types = cell_types
else:
self.cells = []
self.cell_types = []
if pointdata is not None:
self.pointdata = pointdata
else:
self.pointdata = []
def __str__(self):
return "Mesh with {} Points and {} Cells ({} Cell Types)".format(len(self.points), len(self.cells), len(self.cell_types))
def read_mesh(filename):
points, cells, cell_types, pointdata = mesh_io.read_mesh(filename)
#print("Points: ", len(points))
#print("Point data: ", pointdata)
return Mesh(points, cells, cell_types, pointdata)
#print("Hi, I'm process: ", rank)
#print(MPI.COMM_WORLD.rank)
#if (MPI.COMM_WORLD.rank == 0):
# print("This is the master rank")
#Xtest = np.outer(np.linspace(-2, 2, 100), np.ones(100))
#Ytest = Xtest.copy().T # transpose
#Xtest, Ytest = np.meshgrid(Xtest, Ytest)
#Ztest = np.cos(Xtest ** 2 + Ytest ** 2)
#fig = plt.figure()
#ax = fig.gca(projection='3d')
#ax.set_title('Test grid')
#ax.plot_surface(Xtest, Ytest, Ztest,cmap='viridis',linewidth=0,edgecolor='black')
#plt.show()
mesh_name = "Mesh/Plate/l1Data.vtk"
mesh = read_mesh(mesh_name)
#print("Number of points: ", mesh.points)
start = time.time()
j = 0
#nPoints = len(mesh.points)
nPoints = 100
nPointsOut = 500
#print("Number of points: ",nPoints)
######################################################
######################################################
'''
Define the parameters of in and out meshes
'''
######################################################
######################################################
#inLenTotal = 60 #now xMesh
#outLenTotal = 45 # now yMesh
xInMesh = 90
yInMesh = 90
print("Total number in input mesh vertices: ", xInMesh*yInMesh)
xOutMesh = 120
yOutMesh = 120
print("Total number in output mesh vertices: ", xOutMesh*yOutMesh)
xMin = 0.0
xMax = 3.0
yMin = 0.0
yMax = 3.0
TotalXLength = xMax - xMin
TotalYLength = yMax - yMin
alphaInX = TotalXLength/xInMesh
alphaInY = TotalYLength/yInMesh
alphaOutX = TotalXLength/xOutMesh
alphaOutY = TotalYLength/yOutMesh
InedgeLengthX = 3.0
InedgeLengthY = 3.0
OutedgeLengthX = 3.0
OutedgeLengthY = 3.0
InxMinLength = 0.0
InyMinLength = 0.0
OutxMinLength = 0.0
OutyMinLength = 0.0
#alpha = TotalXLength/inLenTotal
domainXLenghtMin = 0.0
domainXLenghtMax = 3.0
domainLength = domainXLenghtMax - domainXLenghtMin
######################################################
######################################################
'''
Define which problems to solve:
Global - Regular
Global - Rational
Local - Regular
Local - Rational
'''
regularGlobal = 1
rationalGlobal = 0
regularLocal = 1
rationalLocal = 0
######################################################
######################################################
######################################################
######################################################
'''
How many blocks in each direction to break problem into
'''
######################################################
######################################################
# Domain decomposition. Grid mesh size/domainDecompo must be integer value
xDomainDecomposition = 3
yDomainDecomposition = 3
xStep = TotalXLength/xDomainDecomposition
yStep = TotalYLength/yDomainDecomposition
xGridStepIn = xInMesh/xDomainDecomposition
yGridStepIn = yInMesh/yDomainDecomposition
xGridStepOut = xOutMesh/xDomainDecomposition
yGridStepOut = yOutMesh/yDomainDecomposition
#inLen = int(inLenTotal/domainDecomposition)
#outLen = int(outLenTotal/domainDecomposition)
#inLen = 20
#outLen = 30
#### Even numbers only!!!!
xBoundaryExtension = 10
yBoundaryExtension = 10
#edgeLengthX = InedgeLengthX/domainDecomposition
#edgeLengthY = InedgeLengthY/domainDecomposition
xMinLength = xMin
yMinLength = yMin
globalRegularL2Error = 0
globalRationalL2Error = 0
######################################################
######################################################
######################################################
xInMesh += 1
yInMesh += 1
xOutMesh += 1
yOutMesh += 1
#in_size = np.linspace(xMinLength, edgeLengthX + xMinLength, inLenTotal)
#out_size = np.linspace(yMinLength, edgeLengthY + yMinLength, outLenTotal)
in_mesh = np.random.random(((xInMesh*yInMesh),2))
out_mesh = np.random.random((xOutMesh*yOutMesh,2))
out_mesh_Combined = np.random.random((xOutMesh*yOutMesh,2))
out_mesh_Split = np.random.random((xOutMesh*yOutMesh,2))
out_mesh_Combined_value = []
out_mesh_Split_value = []
for j in range(0,yInMesh):
for i in range(0,xInMesh):
#in_mesh[j+i*inLenTotal,0] = (InedgeLengthX/inLenTotal)*j
#in_mesh[j+i*inLenTotal,1] = (InedgeLengthY/inLenTotal)*i
in_mesh[i+j*xInMesh,0] = alphaInX*i
in_mesh[i+j*xInMesh,1] = alphaInY*j
#print("Original inmesh length: ", jj)
for j in range(0,yOutMesh):
for i in range(0,xOutMesh):
#out_mesh[j+i*outLenTotal,0] = (OutedgeLengthX/outLenTotal)*j + OutxMinLength
out_mesh[i+j*xOutMesh,0] = alphaOutX*i
out_mesh[i+j*xOutMesh,1] = alphaOutY*j
out_mesh_Combined[i+j*xOutMesh,0] = alphaOutX*i
out_mesh_Combined[i+j*xOutMesh,1] = alphaOutY*j
out_mesh_Split[i+j*xOutMesh,0] = alphaOutX*i
out_mesh_Split[i+j*xOutMesh,1] = alphaOutY*j
#print("Original inmesh: ", in_mesh)
#print("Original outmesh: ", out_mesh)
#print("Original outmesh length: ", kk)
#mesh_size = 1/math.sqrt(nPoints)
mesh_size = alphaInX
shape_parameter = 4.55228/((4.0)*mesh_size)
print("shape_parameter: ", shape_parameter)
bf = basisfunctions.Gaussian(shape_parameter)
##########################################################
##########################################################
'''
Functions to test
'''
func = lambda x,y: 0.5*np.sin(2*x*y)+(0.0000001*y)
## Complex sin function
lambda x,y: 0.5*np.sin(2*x*y)+(0.0000001*y)
## Rosenbrock function
lambda x,y: pow(1-x,2) + 100*pow(y-pow(x,2),2)
## Arctan function (STEP FUNCTION)
lambda x,y: np.arctan(125*(pow(pow(x-1.5,2) + pow(y-0.25,2),0.5) - 0.92))
## Unit values
lambda x: np.ones_like(x)
stepFunction = 0 # Apply step function values if = 1
##########################################################
##########################################################
in_vals = func(in_mesh[:,0],in_mesh[:,1])
out_vals = func(out_mesh[:,0],out_mesh[:,1])
out_vals_global = func(out_mesh[:,0],out_mesh[:,1])
k = 0
if (stepFunction == 1):
for j in range(0,yInMesh):
for i in range(0,xInMesh):
if (in_mesh[i+j*xInMesh,0] <= 0.5 and in_mesh[i+j*xInMesh,1] <= 0.5):
in_vals[k] = 2
if (in_mesh[i+j*xInMesh,0] <= 0.5 and in_mesh[i+j*xInMesh,1] > 0.5):
in_vals[k] = 5
if (in_mesh[i+j*xInMesh,0] > 0.5 and in_mesh[i+j*xInMesh,1] > 0.5):
in_vals[k] = 7
if (in_mesh[i+j*xInMesh,0] > 0.5 and in_mesh[i+j*xInMesh,1] <= 0.5):
in_vals[k] = 9
k += 1
k = 0
for j in range(0,yOutMesh):
for i in range(0,xOutMesh):
if (out_mesh[i+j*xOutMesh,0] <= 0.5 and out_mesh[i+j*xOutMesh,1] <= 0.5):
out_vals[k] = 2
out_vals_global[k] = 2
if (out_mesh[i+j*xOutMesh,0] <= 0.5 and out_mesh[i+j*xOutMesh,1] > 0.5):
out_vals[k] = 5
out_vals_global[k] = 5
if (out_mesh[i+j*xOutMesh,0] > 0.5 and out_mesh[i+j*xOutMesh,1] > 0.5):
out_vals[k] = 7
out_vals_global[k] = 7
if (out_mesh[i+j*xOutMesh,0] > 0.5 and out_mesh[i+j*xOutMesh,1] <= 0.5):
out_vals[k] = 9
out_vals_global[k] = 9
k += 1
out_vals_global_rational = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_global_regular = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_split_rational = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_split_regular = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_split_rational_error = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_split_regular_error = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_global_rational_error = 0*func(out_mesh[:,0],out_mesh[:,1])
out_vals_global_regular_error = 0*func(out_mesh[:,0],out_mesh[:,1])
if (rationalGlobal == 1):
start = time.time()
interpRational = Rational(bf, in_mesh, in_vals, rescale = False)
end = time.time()
print("Time for Global rational inversion: ", end-start)
start = time.time()
fr = interpRational(in_vals, out_mesh)
end = time.time()
print("Time for Global eigen decomposition: ", end-start)
else:
print("Not running the Global Rational RBF")
fr = func(out_mesh[:,0],out_mesh[:,1])
if (regularGlobal == 1):
start = time.time()
interp = NoneConsistent(bf, in_mesh, in_vals, rescale = False)
fr_regular = interp(out_mesh)
end = time.time()
print("Time for Global regular solve: ", end-start)
else:
print("Not running the Global Regular RBF")
fr_regular = func(out_mesh[:,0],out_mesh[:,1])
#out_vals = funcTan(out_mesh[:,0], out_mesh[:,1])
#print("out_vals: ", max(fr))
#print("Error fr= ", np.linalg.norm(out_vals - fr, 2))
#print("max fr: ", max(out_vals - fr))
#print("Error fr_regular= ", np.linalg.norm(out_vals - fr_regular, 2))
maxRegError = max(out_vals - fr_regular)
#print("max fr: ", max(out_vals - fr))
#print("max regular: ", maxRegError)
globalRegularL2Error = np.linalg.norm(out_vals - fr_regular, 2)
globalRationalL2Error = np.linalg.norm(out_vals - fr, 2)
Xtotal = np.linspace(xMin, xMax, xOutMesh)
Ytotal = np.linspace(yMin, yMax, yOutMesh)
#Y = np.arange(-5, 5, 0.25)
Xtotal, Ytotal = np.meshgrid(Xtotal, Ytotal)
#R = np.sqrt(X**2 + Y**2)
#Z = np.sin(R)
X = np.linspace(xMin, xMax, xInMesh)
Y = np.linspace(yMin, yMax, yInMesh)
X, Y = np.meshgrid(X, Y)
Zin = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
Z = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_combined = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_split = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_regular = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_regular_error = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_global = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_error = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_error_final = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_regular_error_global = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_error_global = 0*np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
k=0
for j in range(0,yInMesh):
for i in range(0,xInMesh):
Zin[i,j] = in_vals[k]
k += 1
k=0
for j in range(0,yOutMesh):
for i in range(0,xOutMesh):
Z[i,j] = out_vals[k]
#Z_combined[i,j] = out_vals[k]
out_vals_global_rational[k] = fr[k]
out_vals_global_regular[k] = fr_regular[k]
#out_vals_global_regular_error[k] = fr_regular[k] - out_vals[k]
#Z_split[i,j] = 0
#Z_rational[i,j] = fr[k]
#Z_rational_global[i,j] = fr[k]
#Z_rational_error[i,j] = out_vals[k]- fr[k]
#Z_rational_error_global[i,j] = out_vals[k] - fr[k]
#Z_regular[i,j] = fr_regular[k]
#Z_regular_error[i,j] = out_vals[k] - fr_regular[k]
#Z_regular_error_global[i,j] = out_vals[k]- fr_regular[k]
k += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('In Grid')
ax.plot_surface(X, Y, Zin,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
#save_plot(fileName='plot_01.py',obj=sys.argv[0],sel='plot',ctx=libscript.get_ctx(ctx_global=globals(),ctx_local=locals()))
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Actual - out Grid')
ax.plot_surface(Xtotal, Ytotal, Z,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
'''
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Regular')
ax.plot_surface(Xtotal, Ytotal, Z_regular,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Rational')
ax.plot_surface(Xtotal, Ytotal, Z_rational,cmap='viridis',linewidth=0)
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Regular - error')
ax.plot_surface(Xtotal, Ytotal, Z_regular_error,cmap='viridis',linewidth=0)
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Rational - error')
#ax.set_zlim(-0.001, 0.001)
ax.plot_surface(Xtotal, Ytotal, Z_rational_error,cmap='viridis',linewidth=0)
plt.show()
'''
#Z = in_vals
# Plot the surface.
#surf = ax.plot_surface(X, Y, Z,cmap='viridis',linewidth=0)
#ax.plot_surface(X, Y, Z_regular,cmap='viridis',linewidth=0)
# Customize the z axis.
#ax.set_zlim(-4.0, 4.0)
#ax.zaxis.set_major_locator(LinearLocator(10))
#ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
#fig.colorbar(surf, shrink=0.5, aspect=5)
#ax.plot_surface(X, Y, Z_regular,cmap='viridis',linewidth=0)
#ax.plot_surface(X, Y, Z_rational,cmap='viridis',linewidth=0)
#plt.show()
#fig, axs = plt.subplots(2, 2)
#axs[0, 0].plot_surface(X, Y, Z,cmap='viridis',linewidth=0)
#axs[0, 0].set_title('Axis [0, 0]')
#axs[0, 1].plot_surface(X, Y, Z_regular,cmap='viridis',linewidth=0)
#axs[0, 1].set_title('Axis [0, 1]')
#axs[1, 0].plot_surface(X, Y, Z_rational,cmap='viridis',linewidth=0)
#axs[1, 0].set_title('Axis [1, 0]')
######################################################
######################################################
######################################################
'''
Begin local RBF
'''
print("#############################################")
print("Beginning local RBF")
print("#############################################")
######################################################
######################################################
######################################################
xGridStepInSet = xGridStepIn
yGridStepInSet = yGridStepIn
xGridStepOutSet = xGridStepOut
yGridStepOutSet = yGridStepOut
start = time.time()
domainCount= 0
for dd2 in range(0,yDomainDecomposition):
for dd1 in range(0,xDomainDecomposition):
if (dd1 == 0):
shiftX = 0.0
elif (dd1 == xDomainDecomposition-1):
shiftX = (dd1)*xStep - xBoundaryExtension*alphaInX
else:
shiftX = (dd1)*xStep- (xBoundaryExtension/2)*alphaInX
if (dd2 == 0):
shiftY = 0.0
elif (dd2 == yDomainDecomposition-1):
shiftY = (dd2)*yStep - yBoundaryExtension*alphaInY
else:
shiftY = (dd2)*yStep - (yBoundaryExtension/2)*alphaInY
xMinLength = xMin + shiftX
yMinLength = yMin + shiftY
xMinLengthOut = xMin + dd1*xStep
yMinLengthOut = yMin + dd2*yStep
#print("Properties: ",xMinLength,yMinLength,xMinLengthOut, yMinLengthOut,dd1,dd2)
#print("Alpha X: ", alphaOutX, alphaOutY)
print("Local Domain Number: ",domainCount + 1)
domainCount += 1
if (dd1 == xDomainDecomposition-1):
xGridStepIn = xGridStepInSet + 1
xGridStepOut = xGridStepOutSet + 1
else:
xGridStepIn = xGridStepInSet + 1
xGridStepOut = xGridStepOutSet
if (dd2 == yDomainDecomposition-1):
yGridStepIn = yGridStepInSet + 1
yGridStepOut = yGridStepOutSet + 1
else:
yGridStepIn = yGridStepInSet + 1
yGridStepOut = yGridStepOutSet
in_size = np.linspace(xMinLength, alphaInX*(xGridStepIn+xBoundaryExtension+1), int(xGridStepIn+xBoundaryExtension))
#print("in_size: ", in_size)
#in_size = np.linspace(xMinLength, edgeLengthX + xMinLength, inLen)
out_size = np.linspace(yMinLength, alphaInY*(yGridStepIn+yBoundaryExtension+1), int(yGridStepIn+yBoundaryExtension))
#print("out_size: ", out_size)
in_mesh = np.random.random((int(xGridStepIn+xBoundaryExtension)*int(yGridStepIn+yBoundaryExtension),2))
out_mesh = np.random.random((int(xGridStepOut)*int(yGridStepOut),2))
print("Local domain input vertices: ", int(yGridStepIn+yBoundaryExtension)*int(xGridStepIn+xBoundaryExtension))
for j in range(0,int(yGridStepIn+yBoundaryExtension)):
for i in range(0,int(xGridStepIn+xBoundaryExtension)):
in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0] = alphaInX*i + xMinLength
in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),1] = alphaInY*j + yMinLength
#if i == 0:
#print("in_mesh: ",in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0])
print("Local domain output vertices: ", int(yGridStepOut)*int(xGridStepOut))
for j in range(0,int(yGridStepOut)):
for i in range(0,int(xGridStepOut)):
out_mesh[i+j*int(xGridStepOut),0] = alphaOutX*i + xMinLengthOut
out_mesh[i+j*int(xGridStepOut),1] = alphaOutY*j + yMinLengthOut
#if i == 0:
# print("out_mesh: ",out_mesh[j+i*outLen,0])
#print(len(out_mesh))
#mesh_size = 1/math.sqrt(nPoints)
#mesh_size = edgeLengthX/inLen
#shape_parameter = 4.55228/((4.0)*mesh_size)
#print("Min input mesh: ", in_mesh[0,0], in_mesh[0,1])
#print("Max inout mesh: X", in_mesh[int(xGridStepIn+xBoundaryExtension)*int(yGridStepIn+yBoundaryExtension)-1,0], " - and Y: ", in_mesh[int(yGridStepIn+yBoundaryExtension)*int(xGridStepIn+xBoundaryExtension)-1,1])
#print("Min output mesh: ", out_mesh[0,0], out_mesh[0,1])
#print("Max output mesh: ", out_mesh[int((xGridStepOut*yGridStepOut)-1),0], out_mesh[int((xGridStepOut*yGridStepOut)-1),1])
#print("shape_parameter: ", shape_parameter)
#bf = basisfunctions.Gaussian(shape_parameter)
#func = lambda x,y: 0.5*np.sin(2*x*y)+(0.0000001*y)
#funcTan = lambda x,y: np.arctan(125*(pow(pow(x-1.5,2) + pow(y-0.25,2),0.5) - 0.92))
#rosenbrock_func = lambda x,y: pow(1-((x-0.5)*4),2) + (100*pow(((y-0.5)*4)-pow((x-0.5)*4,2),2))
#rosenbrock_func = lambda x,y: pow(1-x,2) + (100*pow(y-pow(x,2),2))
#one_func = lambda x: np.ones_like(x)
in_vals = func(in_mesh[:,0],in_mesh[:,1])
out_vals = func(out_mesh[:,0],out_mesh[:,1])
k = 0
if (stepFunction == 1):
for j in range(0,int(yGridStepIn+yBoundaryExtension)):
for i in range(0,int(xGridStepIn+xBoundaryExtension)):
if (in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0] <= 0.5 and in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),1] <= 0.5):
in_vals[k] = 2
if (in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0] <= 0.5 and in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),1] > 0.5):
in_vals[k] = 5
if (in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0] > 0.5 and in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),1] > 0.5):
in_vals[k] = 7
if (in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),0] > 0.5 and in_mesh[i+j*int(xGridStepIn+xBoundaryExtension),1] <= 0.5):
in_vals[k] = 9
k += 1
k = 0
for j in range(0,int(yGridStepOut)):
for i in range(0,int(xGridStepOut)):
if (out_mesh[i+j*int(xGridStepOut),0] <= 0.5 and out_mesh[i+j*int(xGridStepOut),1] <= 0.5):
out_vals[k] = 2
if (out_mesh[i+j*int(xGridStepOut),0] <= 0.5 and out_mesh[i+j*int(xGridStepOut),1] > 0.5):
out_vals[k] = 5
if (out_mesh[i+j*int(xGridStepOut),0] > 0.5 and out_mesh[i+j*int(xGridStepOut),1] > 0.5):
out_vals[k] = 7
if (out_mesh[i+j*int(xGridStepOut),0] > 0.5 and out_mesh[i+j*int(xGridStepOut),1] <= 0.5):
out_vals[k] = 9
k += 1
if (rationalLocal == 1):
print("Using local Rational RBFs")
interpRational = Rational(bf, in_mesh, in_vals, rescale = False)
fr = interpRational(in_vals, out_mesh)
else:
print("NOT Using local Rational RBFs")
fr = func(out_mesh[:,0],out_mesh[:,1])
if (regularLocal == 1):
print("Using local Regular RBFs")
interp = NoneConsistent(bf, in_mesh, in_vals, rescale = False)
fr_regular = interp(out_mesh)
else:
print("NOT Using local Regular RBFs")
fr_regular = func(out_mesh[:,0],out_mesh[:,1])
#out_vals = funcTan(out_mesh[:,0], out_mesh[:,1])
#print("out_vals: ", max(fr))
#print("Error fr= ", np.linalg.norm(out_vals - fr, 2))
#print("Error fr_regular= ", np.linalg.norm(out_vals - fr_regular, 2))
maxRegError = max(out_vals - fr_regular)
#print("max fr: ", max(out_vals - fr))
#print("max regular: ", maxRegError)
#print("Out mesh print: ", xMinLengthOut, yMinLengthOut, alphaOutX, alphaOutY, xGridStepOut, yGridStepOut)
X = 0
Y = 0
X = np.linspace(xMinLengthOut, xMinLengthOut + alphaOutX*xGridStepOut, int(xGridStepOut))
#print("Printing X: ", X)
Y = np.linspace(yMinLengthOut, yMinLengthOut + alphaOutY*yGridStepOut, int(yGridStepOut))
X, Y = np.meshgrid(X, Y)
#Z = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
#Z_regular = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
#Z_regular_error = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
#Z_rational = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
#Z_rational_error = np.arctan(125*(pow(pow(X-1.5,2) + pow(Y-0.25,2),0.5) - 0.92))
k=0
#print(len(Z))
#print(len(fr))
#print(len(out_vals_split))
for j in range(0,int(yGridStepOut)):
for i in range(0,int(xGridStepOut)):
#Z[i,j] = out_vals[k]
#Z_split[i+int(xGridStepOutSet*dd1),j+int(yGridStepOutSet*dd2)] = fr[k]
w = int((i+(dd1*xGridStepOutSet)) + ((j+(dd2*yGridStepOutSet))*(xOutMesh)))
#print(w)
out_vals_split_rational[w] = fr[k]
out_vals_split_regular[w] = fr_regular[k]
#Z_rational[i,j] = fr[k]
#Z_rational_error[i,j] = out_vals[k]- fr[k]
#Z_regular[i,j] = fr_regular[k]
#Z_regular_error[i,j] = out_vals[k]- fr_regular[k]
k += 1
#print("j: ", j)
k = 0
for j in range(0,yOutMesh):
for i in range(0,xOutMesh):
Z_rational[i,j] = out_vals_split_rational[k]
Z_regular[i,j] = out_vals_split_regular[k]
k += 1
'''
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_title('Split mesh - Rational')
ax.plot_surface(Xtotal, Ytotal, Z_rational,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_title('Split mesh - Regular')
ax.plot_surface(Xtotal, Ytotal, Z_regular,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
'''
end = time.time()
print("Time for decomposed problem eigen decomposition: ", end-start)
#fig = plt.figure()
#ax = fig.gca(projection='3d')
#ax.set_xlabel('Regular')
#ax.plot_surface(Xtotal, Ytotal, Z_split,cmap='viridis',linewidth=0,edgecolor='black')
#plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Regular')
ax.plot_surface(Xtotal, Ytotal, Z_regular,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Rational')
ax.plot_surface(Xtotal, Ytotal, Z_rational,cmap='viridis',linewidth=0)
plt.show()
'''
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('Regular Error')
ax.plot_surface(X, Y, Z_regular_error,cmap='viridis',linewidth=0)
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('Rational Error')
ax.plot_surface(X, Y, Z_rational_error,cmap='viridis',linewidth=0)
plt.show()
'''
Z_split_error = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_error_diff = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_error = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_regular_error = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_rational_diff = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
Z_regular_diff = np.arctan(125*(pow(pow(Xtotal-1.5,2) + pow(Ytotal-0.25,2),0.5) - 0.92))
global_local_rational_difference = []
global_local_regular_difference = []
k = 0
for j in range(0,yOutMesh):
for i in range(0,xOutMesh):
#Z_split_error[i,j] = Z_combined[i,j] - Z_split[i,j]
#Z_rational_diff[i,j] = Z_rational_global[i,j] - Z_split[i,j]
#Z_error_diff[i,j] = Z_rational_error_global[i,j] - Z_split_error[i,j]
out_vals_split_rational_error[k] = out_vals_split_rational[k] - out_vals_global[k]
out_vals_split_regular_error[k] = out_vals_split_regular[k] - out_vals_global[k]
out_vals_global_rational_error[k] = out_vals_global_rational[k] - out_vals_global[k]
out_vals_global_regular_error[k] = out_vals_global_regular[k] - out_vals_global[k]
global_local_rational_difference.append(out_vals_split_rational[k] - out_vals_global_rational[k])
global_local_regular_difference.append(out_vals_split_regular[k] - out_vals_global_regular[k])
Z_rational_error[i,j] = out_vals_split_rational_error[k]
Z_regular_error[i,j] = out_vals_split_regular_error[k]
Z_rational_diff[i,j] = out_vals_split_rational[k] - out_vals_global_rational[k]
Z_regular_diff[i,j] = out_vals_split_regular[k] - out_vals_global_regular[k]
k += 1
print("Error of Global Rational RBF: ", np.linalg.norm(out_vals_global_rational_error, 2))
print("Error of Local Rational RBF sub-domains: ", np.linalg.norm(out_vals_split_rational_error, 2))
print("Max Global Rational RBF Error: ", max(abs(out_vals_global_rational_error)))
print("Max Local Rational RBF Error: ", max(abs(out_vals_split_rational_error)))
print("Error of Global Regular RBF: ", np.linalg.norm(out_vals_global_regular_error, 2))
print("Error of Local Regular RBF sub-domains: ", np.linalg.norm(out_vals_split_regular_error, 2))
print("Max Global Regular RBF Error: ", max(abs(out_vals_global_regular_error)))
print("Max Local Regular RBF Error: ", max(abs(out_vals_split_regular_error)))
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Rational RBF Local - Error')
#ax.set_zlim(-0.00025, 0.00025)
ax.plot_surface(Xtotal, Ytotal, Z_rational_error,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Regular RBF Local - Error')
#ax.set_zlim(-0.00025, 0.00025)
ax.plot_surface(Xtotal, Ytotal, Z_regular_error,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Rational RBF Local - Global Difference')
#ax.set_zlim(-0.00025, 0.00025)
ax.plot_surface(Xtotal, Ytotal, Z_rational_diff,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_title('Regular RBF Local - Global Difference')
#ax.set_zlim(-0.00025, 0.00025)
ax.plot_surface(Xtotal, Ytotal, Z_regular_diff,cmap='viridis',linewidth=0,edgecolor='black')
plt.show()