ymin = 0
ymax = 1
domainCorners = np.array([[xmin, ymin], [xmin, ymax], [xmax, ymin],
                          [xmax, ymax]])
myQuad = Quadrilateral(domainCorners)

numPtsU = 28
numPtsV = 28
xPhys, yPhys = myQuad.getUnifIntPts(numPtsU, numPtsV, [0, 0, 0, 0])
data_type = "float32"

Xint = np.concatenate((xPhys, yPhys), axis=1).astype(data_type)
Yint = np.zeros_like(Xint)

# Generate the training data for the Neumann boundary
xPhysNeu, yPhysNeu, xNormNeu, yNormNeu = myQuad.getUnifEdgePts(
    numPtsU, numPtsV, [1, 0, 1, 1])
XbndNeu = np.concatenate((xPhysNeu, yPhysNeu, xNormNeu, yNormNeu),
                         axis=1).astype(data_type)
dwdx_neu, dwdy_neu = deriv_exact_sol(xPhysNeu, yPhysNeu)

Ybnd_neu_real = np.real(dwdx_neu * XbndNeu[:, 2:3] +
                        dwdy_neu * XbndNeu[:, 3:4])
Ybnd_neu_imag = np.imag(dwdx_neu * XbndNeu[:, 2:3] +
                        dwdy_neu * XbndNeu[:, 3:4])
YbndNeu = np.concatenate((Ybnd_neu_real, Ybnd_neu_imag),
                         axis=1).astype(data_type)

# Generating the training data for the Robin boundary
xPhysRobin, yPhysRobin, xNormRobin, yNormRobin = myQuad.getUnifEdgePts(
    numPtsU, numPtsV, [0, 1, 0, 0])
XbndRobin = np.concatenate((xPhysRobin, yPhysRobin, xNormRobin, yNormRobin),
numPtsU = 80
numPtsV = 40
#xPhys, yPhys = myQuad.getRandomIntPts(numPtsU*numPtsV)
xPhys, yPhys = geomDomain.getUnifIntPts(numPtsU, numPtsV, [0, 0, 0, 0])
data_type = "float32"

Xint = np.concatenate((xPhys, yPhys), axis=1).astype(data_type)
Yint = np.zeros_like(Xint).astype(data_type)

# prepare boundary points in the fromat Xbnd = [Xcoord, Ycoord, dir] and
# Ybnd = [trac], where Xcoord, Ycoord are the x and y coordinate of the point,
# dir=0 for the x-component of the traction and dir=1 for the y-component of
# the traction

#bottom boundary, include both x and y directions
xPhysBndB, yPhysBndB, xNormB, yNormB = geomDomain.getUnifEdgePts(
    numPtsU, numPtsV, [1, 0, 0, 0])
dirB0 = np.zeros_like(xPhysBndB)
dirB1 = np.ones_like(xPhysBndB)
XbndB0 = np.concatenate((xPhysBndB, yPhysBndB, xNormB, yNormB, dirB0),
                        axis=1).astype(data_type)
XbndB1 = np.concatenate((xPhysBndB, yPhysBndB, xNormB, yNormB, dirB1),
                        axis=1).astype(data_type)

#boundary for x=beam_length, include both the x and y directions
xPhysBndC, yPhysBndC, xNormC, yNormC = geomDomain.getUnifEdgePts(
    numPtsU, numPtsV, [0, 1, 0, 0])
dirC0 = np.zeros_like(xPhysBndC)
dirC1 = np.ones_like(xPhysBndC)
XbndC0 = np.concatenate((xPhysBndC, yPhysBndC, xNormC, yNormC, dirC0),
                        axis=1).astype(data_type)
XbndC1 = np.concatenate((xPhysBndC, yPhysBndC, xNormC, yNormC, dirC1),
Esempio n. 3
0
    xmin = 0
    xmax = 1
    ymin = 0
    ymax = 1
    domainCorners = np.array([[xmin,ymin], [xmin,ymax], [xmax,ymin], [xmax,ymax]])
    myQuad = Quadrilateral(domainCorners)

    numPtsU = 28
    numPtsV = 28
    xPhys, yPhys = myQuad.getUnifIntPts(numPtsU, numPtsV, [0,0,0,0])
    data_type = "float32"
    
    Xint = np.concatenate((xPhys,yPhys),axis=1).astype(data_type)
    Yint = rhs_fun(Xint[:,[0]], Xint[:,[1]])
    
    xPhysBnd, yPhysBnd, _, _s = myQuad.getUnifEdgePts(numPtsU, numPtsV, [1,1,1,1])
    Xbnd = np.concatenate((xPhysBnd, yPhysBnd), axis=1).astype(data_type)
    Ybnd = exact_sol(Xbnd[:,[0]], Xbnd[:,[1]])
    
    #define the model 
    tf.keras.backend.set_floatx(data_type)
    l1 = tf.keras.layers.Dense(20, "tanh")
    l2 = tf.keras.layers.Dense(20, "tanh")
    l3 = tf.keras.layers.Dense(20, "tanh")
    l4 = tf.keras.layers.Dense(1, None)
    train_op = tf.keras.optimizers.Adam()
    num_epoch = 5000
    print_epoch = 100
    pred_model = Poisson2D_coll([l1, l2, l3, l4], train_op, num_epoch, print_epoch)
    
    #convert the training data to tensors
Esempio n. 4
0
    xmax = 4
    tmin = 0
    tmax = 2
    domainCorners = np.array([[xmin,tmin], [xmin,tmax], [xmax,tmin], [xmax,tmax]])
    domainGeom = Quadrilateral(domainCorners)

    numPtsU = 101
    numPtsV = 101
    xPhys, yPhys = domainGeom.getUnifIntPts(numPtsU,numPtsV,[0,0,0,0])
    data_type = "float32"
    
    Xint = np.concatenate((xPhys,yPhys),axis=1).astype(data_type)
    Yint = np.zeros_like(xPhys).astype(data_type)
    
    #boundary conditions at x=0
    xPhysBnd, tPhysBnd, _, _ = domainGeom.getUnifEdgePts(numPtsU, numPtsV, [0,0,0,1])
    Xbnd = np.concatenate((xPhysBnd, tPhysBnd), axis=1).astype(data_type)
    Ybnd = np.where(tPhysBnd<=1, -np.sin(np.pi*tPhysBnd), 0).astype(data_type)
    
    #initial conditions (displacement and velocity) for t=0
    xPhysInit, tPhysInit, _, _ = domainGeom.getUnifEdgePts(numPtsU, numPtsV, [1,0,0,0])
    Xinit = np.concatenate((xPhysInit, tPhysInit), axis=1).astype(data_type)
    Yinit = np.zeros_like(Xinit)
    

    #plot the collocation points
    plot_pts(Xint, Xbnd)
    
    #define the model 
    tf.keras.backend.set_floatx(data_type)
    l1 = tf.keras.layers.Dense(30, "tanh")