Esempio n. 1
0
def test_1():
    bg = 0  # background
    val = 2  # values

    space = 10
    thick = 1

    NWorldFine = np.array([128, 128])

    CoefClass = buildcoef2d.Coefficient2d(NWorldFine,
                                          bg=bg,
                                          val=val,
                                          length=1,
                                          thick=thick,
                                          space=space,
                                          probfactor=1,
                                          right=1,
                                          down=0,
                                          diagr1=0,
                                          diagr2=0,
                                          diagl1=0,
                                          diagl2=0,
                                          LenSwitch=None,
                                          thickSwitch=None,
                                          equidistant=True,
                                          ChannelHorizontal=None,
                                          ChannelVertical=True,
                                          BoundarySpace=True)

    A = CoefClass.BuildCoefficient().flatten()

    plt.figure("Coefficient_test_1")
    drawCoefficient(NWorldFine, A)
Esempio n. 2
0
def test_2():
    bg = 0  # background
    val = 2  # values

    space = 10
    thick = 1
    fine = 64
    NWorldFine = np.array([fine, fine])

    ChoosingShapes = np.array([
        # shape , len, thick, space
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1],
        [4, fine - 2, 1, 5],
        [4, fine - 2, 1, 5],
        [4, fine - 2, 1, 5]
    ])

    CoefClass = buildcoef2d.Coefficient2d(NWorldFine,
                                          bg=bg,
                                          val=val,
                                          right=1,
                                          LenSwitch=None,
                                          thickSwitch=None,
                                          equidistant=True,
                                          ChannelHorizontal=None,
                                          ChannelVertical=None,
                                          BoundarySpace=True,
                                          probfactor=1,
                                          ChoosingShapes=ChoosingShapes)

    A = CoefClass.BuildCoefficient().flatten()
    Correct = CoefClass.SpecificVanish(Number=[10, 11])
    plt.figure("Coefficient_test_1")
    drawCoefficient(NWorldFine, Correct.flatten())

    Number = [10, 11]
    random.seed(32)
    lis = np.zeros(80)
    lis[0] = 1
    for i in range(np.shape(CoefClass.ShapeRemember)[0]):
        Number.append(i * random.sample(list(lis), 1)[0])
    plt.figure("Perturbation")
    Perturbed = CoefClass.SpecificVanish(Number=Number,
                                         Original=True).flatten()
    drawCoefficient(NWorldFine, Perturbed)
Esempio n. 3
0
                                    diagr1              = 0, 
                                    diagr2              = 0, 
                                    diagl1              = 0, 
                                    diagl2              = 0, 
                                    LenSwitch           = None, 
                                    thickSwitch         = None, 
                                    equidistant         = True, 
                                    ChannelHorizontal   = None, 
                                    ChannelVertical     = None,
                                    BoundarySpace       = True)

A = CoefClass.BuildCoefficient()
ABase = A.flatten()

plt.figure("OriginalCoefficient")
drawCoefficient(NWorldFine, ABase)

#potentially updated
fig = plt.figure("Correcting")
ax = fig.add_subplot(2,3,1)
ax.set_title('Original', fontsize=7)
drawCoefficientwg(NWorldFine, ABase,fig,ax,Greys=True)

numbers = [2,70,97,153,205]

D = CoefClass.SpecificVanish(           Number              = numbers,
                                        probfactor          = 1,
                                        PartlyVanish        = None,
                                        Original            = True)
                                
value2 = 50
Esempio n. 4
0
        writer.writerow([val])

# fine-fem
f_fine = np.ones(NpFine)

uFineFem, AFine, MFine = femsolver.solveFine(world, ABase, f_fine, None,
                                             boundaryConditions)

# fine solution
with open("%s/finescale.txt" % ROOT, 'w') as csvfile:
    writer = csv.writer(csvfile)
    for val in uFineFem:
        writer.writerow([val])

plt.figure("Original")
drawCoefficient(NWorldFine, ABase, greys=True)
plt.title("Original coefficient")

# random seed
random.seed(20)

# decision
valc = np.shape(CoefClass.ShapeRemember)[0]
numbers = []
decision = np.zeros(100)
decision[0] = 1

for i in range(0, valc):
    a = random.sample(list(decision), 1)[0]
    if a == 1:
        numbers.append(i)
Esempio n. 5
0
E = CoefClass4.BuildCoefficient()
F = CoefClass5.BuildCoefficient()

# modifications
A = CoefClass.SpecificVanish(Number=[0, 2])
B = CoefClass1.SpecificVanish(Number=[0, 2])

A1 = A.flatten()
A4 = B.flatten()
A2 = C.flatten()
A3 = D.flatten()
A5 = E.flatten()
A6 = F.flatten()

plt.figure("Shape 1")
drawCoefficient(NWorldFine, A1)
plt.figure("Shape 2")
drawCoefficient(NWorldFine, A2)
plt.figure("Shape 3")
drawCoefficient(NWorldFine, A3)
plt.figure("Shape 4")
drawCoefficient(NWorldFine, A4)
plt.figure("Shape 5")
drawCoefficient(NWorldFine, A5)
plt.figure("Shape 6")
drawCoefficient(NWorldFine, A6)

plt.figure("All shapes")
AllshapesSixdrawCoefficient(NWorldFine, A1, A2, A3, A4, A5, A6)

plt.show()
Esempio n. 6
0
                        diagr2              = 0, 
                        diagl1              = 1, 
                        diagl2              = 0, 
                        LenSwitch           = [4,5,6,7,8], 
                        thickSwitch         = None, 
                        equidistant         = None, 
                        ChannelHorizontal   = None, 
                        ChannelVertical     = None,
                        BoundarySpace       = None) 

#Build Coefficients
A1 = CoefClass1.BuildCoefficient()
A2 = CoefClass2.BuildCoefficient()
A3 = CoefClass3.BuildCoefficient()
A4 = CoefClass4.BuildCoefficient()
        
A1 = A1.flatten()
A2 = A2.flatten()
A3 = A3.flatten()
A4 = A4.flatten()

plt.figure("Coefficient 1")
drawCoefficient(NWorldFine, A1, greys=True)
plt.figure("Coefficient 2")
drawCoefficient(NWorldFine, A2, greys=True)
plt.figure("Coefficient 3")
drawCoefficient(NWorldFine, A3, greys=True)
plt.figure("Coefficient 4")
drawCoefficient(NWorldFine, A4, greys=True)

plt.show()
Esempio n. 7
0
NWorldFine = world.NWorldCoarse * world.NCoarseElement

# fine grid elements and nodes
xt = util.tCoordinates(NFine).flatten()
xp = util.pCoordinates(NFine).flatten()

# time step parameters
tau = 0.1
numTimeSteps = 150
n = 2

# ms coefficient B
B = np.kron(np.random.rand(fine / n, fine / n) * 0.9 + 0.1, np.ones((n, n)))
bFine = B.flatten()
plt.figure("OriginalCoefficient")
drawCoefficient(NWorldFine, bFine)
plt.title('$B(x,y)$', fontsize=24)
plt.show()

# ms coefficient A
A = np.kron(np.random.rand(fine / n, fine / n) * 0.9 + 0.1, np.ones((n, n)))
aFine = A.flatten()
plt.figure("OriginalCoefficient")
drawCoefficient(NWorldFine, aFine)
plt.title('$A(x,y)$', fontsize=24)
plt.show()

# localization and mesh width parameters
N = 16
k = log(N, 2)
lList = [
Esempio n. 8
0
                           randomstep=None,
                           randomDirection=None,
                           Right=1,
                           BottomRight=1,
                           Bottom=1,
                           BottomLeft=1,
                           Left=1,
                           TopLeft=1,
                           Top=1,
                           TopRight=1,
                           Original=True)

A = A.flatten()
B = B.flatten()
C = C.flatten()
D = D.flatten()

plt.figure("original")
drawCoefficient(NWorldFine, A)

plt.figure("1")
drawCoefficient(NWorldFine, B)
plt.figure("2")
drawCoefficient(NWorldFine, C)
plt.figure("3")
drawCoefficient(NWorldFine, D)

plt.figure('all')
ExtradrawCoefficient(NWorldFine, A, B, C, D)

plt.show()