def u_bound_up_down(x, y):
    return np.zeros_like(x)


#define the input and output data set
xmin = 0
xmax = 2
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] +
Ejemplo n.º 2
0
    nu = model_data["nu"]
    inert = beam_width**3 / 12
    pei = pressure / (6 * E * inert)
    y_temp = y - beam_width / 2  #move (0,0) to below left corner
    x_disp = pei * y_temp * ((6 * beam_length - 3 * x) * x + (2 + nu) *
                             (y_temp**2 - beam_width**2 / 4))
    y_disp = -pei * (3 * nu * y_temp**2 * (beam_length - x) +
                     (4 + 5 * nu) * beam_width**2 * x / 4 +
                     (3 * beam_length - x) * x**2)
    return x_disp, y_disp


print("Testing...")
numPtsUTest = 2 * numElemU * numGauss
numPtsVTest = 2 * numElemV * numGauss
xPhysTest, yPhysTest = geomDomain.getUnifIntPts(numPtsUTest, numPtsVTest,
                                                [1, 1, 1, 1])
XTest = np.concatenate((xPhysTest, yPhysTest), axis=1).astype(data_type)
XTest_tf = tf.convert_to_tensor(XTest)
YTest = pred_model(XTest_tf).numpy()

xPhysTest2D = np.resize(XTest[:, 0], [numPtsVTest, numPtsUTest])
yPhysTest2D = np.resize(XTest[:, 1], [numPtsVTest, numPtsUTest])
YTest2D_x = np.resize(YTest[:, 0], [numPtsVTest, numPtsUTest])
YTest2D_y = np.resize(YTest[:, 1], [numPtsVTest, numPtsUTest])

plt.contourf(xPhysTest2D, yPhysTest2D, YTest2D_x, 255, cmap=plt.cm.jet)
plt.colorbar()
plt.title("Computed x-displacement")
plt.axis('equal')
plt.show()
Ejemplo n.º 3
0
                u[i] = alpha/np.pi * (1-np.cos(np.pi*(t-x/alpha)))
                v[i] = alpha/np.pi * np.pi * np.sin(np.pi*(t-x/alpha))
        return u, v
    
        
    #define the input and output data set
    xmin = 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)
    
Ejemplo n.º 4
0
        v_val = xPhys * v_val + v_left

        return u_val, v_val


#define the input and output data set
beam_length = 8.
beam_width = 2.
domainCorners = np.array([[0., 0.], [0, beam_width], [beam_length, 0.],
                          [beam_length, beam_width]])
geomDomain = Quadrilateral(domainCorners)

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)
results = tfp.optimizer.bfgs_minimize(value_and_gradients_function=loss_func,
                                      initial_position=init_params,
                                      max_iterations=50000,
                                      tolerance=1e-14)

# after training, the final optimized parameters are still in results.position
# so we have to manually put them back to the model
loss_func.assign_new_model_parameters(results.position)
#loss_func.assign_new_model_parameters(results.x)
t2 = time.time()
print("Time taken (LBFGS)", t2 - t1, "seconds")
print("Time taken (all)", t2 - t0, "seconds")
print("Testing...")
numPtsUTest = 2 * numPtsU
numPtsVTest = 2 * numPtsV
xPhysTest, yPhysTest = myQuad.getUnifIntPts(numPtsUTest, numPtsVTest,
                                            [1, 1, 1, 1])
XTest = np.concatenate((xPhysTest, yPhysTest), axis=1).astype(data_type)
XTest_tf = tf.convert_to_tensor(XTest)
YTest = pred_model(XTest_tf).numpy()
YExact = exact_sol(XTest[:, [0]], XTest[:, [1]])

xPhysTest2D = np.resize(XTest[:, 0], [numPtsUTest, numPtsVTest])
yPhysTest2D = np.resize(XTest[:, 1], [numPtsUTest, numPtsVTest])
YExact2D = np.resize(YExact, [numPtsUTest, numPtsVTest])
YTest2D = np.resize(YTest, [numPtsUTest, numPtsVTest])
plt.contourf(xPhysTest2D, yPhysTest2D, YExact2D, 255, cmap=plt.cm.jet)
plt.colorbar()
plt.title("Exact solution")
plt.show()
plt.contourf(xPhysTest2D, yPhysTest2D, YTest2D, 255, cmap=plt.cm.jet)
plt.colorbar()