Ejemplo n.º 1
0
# Discretize domain INTERIOR:
discNum = 50
he = (lim[1] - lim[0]) / (discNum)
coordinates = np.linspace(lim[0] + he, lim[1] - he, discNum)
coordinates = np.reshape(coordinates, [discNum, 1])

# Discretize domain boundaries:
bIndNum = 2
bdof = np.ones(bIndNum, dtype=int)
bCoordinates = reshape(lim, [bIndNum, 1, dim])

# Dirichlet boundary conditions:
bInput = []
biDof = []
for bInd in range(bIndNum):
    bInpuTmp = uf.pairMats(bCoordinates[bInd], t_coordinates)
    biDof.append(len(bInpuTmp))  # number of boundary nodes
    bInput.append(bInpuTmp)  # append boundary input
bInput = uf.vstack(bInput)

# Input to model
iInput = np.concatenate([coordinates, np.zeros([discNum, 1])],
                        axis=1)  # Initial condition
biInput = uf.vstack([bInput, iInput])  # Boundary condition
Input = uf.pairMats(coordinates, t_coordinates)

#%% Training Points:

nt = 10  # number of temporal training points
ht = T / nt  # element size
Time = np.linspace(0 + ht, T, nt)
Ejemplo n.º 2
0
    c2_n = (-1)**p*(2*p+1)*cos((p+0.5)*pi*x)*exp(-D*(2*p+1)**2*pi**2*t/4)
    c2_d = u**4 + (u*pi*D)**2*(8*p**2+8*p+10) + (pi*D)**4*(4*p**2+4*p-3)**2
    c2 = np.cosh(u/D/2)*np.sum(c2_n/c2_d, axis=-1, keepdims=True)       # second component of the solution
    
    # Output:
    c = c0*(c1+c2)
    c[ind0] = cInit
    
    return c


# Exact solution values for the cases that the analytical solution is unstable:
# Accuracy points for D = 0.01/pi:
xEx1 = np.array([[0.9, 0.94, 0.96, 0.98, 0.99, 0.999, 1.0]]).T
tEx1 = np.array([[0.8]])
inpEx1 = uf.pairMats(xEx1, tEx1)
cEx1 = np.array([[-0.30516, -0.42046, -0.47574, -0.52913, -0.55393, -0.26693, 0.0]]).T
plt.plot(xEx1, cEx1)

xEx2 = np.array([[0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.94, 0.98, 0.99, 0.999, 1.0]]).T
tEx2 = np.array([[1.0]])
inpEx2 = uf.pairMats(xEx2, tEx2)
cEx2 = np.array([[0.93623, 0.98441, 0.93623, 0.79641, 0.57862, 0.30420, 0.18446, 0.06181, 0.03098, 0.00474, 0.0]]).T
plt.plot(xEx2, cEx2)

xEx3 = xEx1
tEx3 = np.array([[1.6]])
inpEx3 = uf.pairMats(xEx3, tEx3)
cEx3 = np.array([[0.78894, 0.85456, 0.88237, 0.90670, 0.91578, 0.43121, 0.0]]).T
plt.plot(xEx3, cEx3)
plt.title('$D = 0.01/\pi$')
Ejemplo n.º 3
0
    c2 = np.cosh(
        u / D / 2) * np.sum(c2_n / c2_d, axis=-1,
                            keepdims=True)  # second component of the solution

    # Output:
    c = c0 * (c1 + c2)
    c[ind0] = cInit

    return c


# Exact solution values for D=0.01/pi:
if D == 0.01 / pi:
    xEx1 = np.array([[0.9, 0.94, 0.96, 0.98, 0.99, 0.999, 1.0]]).T
    tEx1 = np.array([[0.8]])
    inpEx1 = uf.pairMats(xEx1, tEx1)
    cEx1 = np.array(
        [[-0.30516, -0.42046, -0.47574, -0.52913, -0.55393, -0.26693, 0.0]]).T
    plt.plot(xEx1, cEx1)

    xEx2 = np.array(
        [[0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.94, 0.98, 0.99, 0.999, 1.0]]).T
    tEx2 = np.array([[1.0]])
    inpEx2 = uf.pairMats(xEx2, tEx2)
    cEx2 = np.array([[
        0.93623, 0.98441, 0.93623, 0.79641, 0.57862, 0.30420, 0.18446, 0.06181,
        0.03098, 0.00474, 0.0
    ]]).T
    plt.plot(xEx2, cEx2)

    xEx3 = xEx1
Ejemplo n.º 4
0
            folderpath)  # backup current operator settings

VarNet_2d.train(folderpath, weight=[5, 1, 1], smpScheme='uniform')

#%% Simulation results:

VarNet_2d.loadModel()
VarNet_2d.simRes()

# Solution error:
tcoord = reshape(np.linspace(0, T, num=nt), [nt, 1])  # temporal discretization
coord = domain.getMesh(discNum=[40, 20],
                       bDiscNum=20).coordinates  # spatial discretization
cEx = cExFun(coord)
cEx = reshape(cEx, newshape=(-1, 1))
Input = uf.pairMats(coord, tcoord)
cApp = VarNet_2d.evaluate(x=Input[:, :2], t=Input[:, 2:3])

string = '\n==========================================================\n'
string += 'Simulation results:\n\n'
string += 'Normalized approximation error: %2.5f' % uf.l2Err(cEx, cApp)
print(string)
VarNet_2d.trainRes.writeComment(string)

#%% Plots for the paper:

## Load the model:
##folderpath = '/Users/Riza/Documents/Python/TF_checkpoints'
#folderpath = '/home/reza/Documents/Python/TF_checkpoints2'           # Linux
#VarNet_2d.loadModel(folderpath=folderpath)
#