コード例 #1
0
def train(epoch):
	startTime=time.time()
	xRes=0
	yRes=0
	mRes=0
	eU=0
	eV=0
	eP=0
	for iteration, batch in enumerate(training_data_loader):
		[JJInv,coord,xi,eta,J,Jinv,dxdxi,dydxi,dxdeta,dydeta]=to4DTensor(batch)
		optimizer.zero_grad()
		output=model(coord)
		output_pad=udfpad(output)
		outputV=output_pad[:,0,:,:].reshape(output_pad.shape[0],1,
			                                output_pad.shape[2],
			                                output_pad.shape[3])
		for j in range(batchSize):
			outputV[j,0,-padSingleSide:,padSingleSide:-padSingleSide]=0 
			outputV[j,0,:padSingleSide,padSingleSide:-padSingleSide]=1					   		
			outputV[j,0,padSingleSide:-padSingleSide,-padSingleSide:]=1 					    			
			outputV[j,0,padSingleSide:-padSingleSide,0:padSingleSide]=1 					    
			outputV[j,0,0,0]=0.5*(outputV[j,0,0,1]+outputV[j,0,1,0])
			outputV[j,0,0,-1]=0.5*(outputV[j,0,0,-2]+outputV[j,0,1,-1])
		dvdx=dfdx(outputV,dydeta,dydxi,Jinv)
		d2vdx2=dfdx(dvdx,dydeta,dydxi,Jinv)
		dvdy=dfdy(outputV,dxdxi,dxdeta,Jinv)
		d2vdy2=dfdy(dvdy,dxdxi,dxdeta,Jinv)
		continuity=(d2vdy2+d2vdx2);
		loss=criterion(continuity,continuity*0)
		loss.backward()
		optimizer.step()
		loss_mass=criterion(continuity, continuity*0)
		mRes+=loss_mass.item()
		CNNVNumpy=outputV[0,0,:,:].cpu().detach().numpy()
		eV=eV+np.sqrt(calMSE(OFV_sb,CNNVNumpy)/calMSE(OFV_sb,OFV_sb*0))
	print('Epoch is ',epoch)
	print("mRes Loss is", (mRes/len(training_data_loader)))
	print("eV Loss is", (eV/len(training_data_loader)))
	if epoch%5000==0 or epoch%nEpochs==0 or np.sqrt(calMSE(OFV_sb,CNNVNumpy)/calMSE(OFV_sb,OFV_sb*0))<0.1:
		torch.save(model, str(epoch)+'.pth')
		fig1=plt.figure()
		ax=plt.subplot(1,2,1)
		visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
			           coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
			           outputV[0,0,1:-1,1:-1].cpu().detach().numpy(),'horizontal',[0,1])
		setAxisLabel(ax,'p')
		ax.set_title('CNN '+r'$T$')
		ax.set_aspect('equal')
		ax=plt.subplot(1,2,2)
		visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
			           coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
			           OFV_sb[1:-1,1:-1],'horizontal',[0,1])
		setAxisLabel(ax,'p')
		ax.set_aspect('equal')
		ax.set_title('FV '+r'$T$')
		fig1.tight_layout(pad=1)
		fig1.savefig(str(epoch)+'T.pdf',bbox_inches='tight')
		plt.close(fig1)		
	return (mRes/len(training_data_loader)),(eV/len(training_data_loader))
コード例 #2
0
def train(epoch):
    startTime = time.time()
    xRes = 0
    yRes = 0
    mRes = 0
    eU = 0
    eV = 0
    eP = 0
    for iteration, batch in enumerate(training_data_loader):
        [Para, coord, xi, eta, J, Jinv, dxdxi, dydxi, dxdeta, dydeta,
         truth] = to4DTensor(batch)
        optimizer.zero_grad()
        output = model(Para)
        output_pad = udfpad(output)
        outputV = output_pad[:, 0, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        for j in range(batchSize):
            #Impose BC
            outputV[j, 0, -padSingleSide:, padSingleSide:-padSingleSide] = (
                outputV[j, 0, 1:2, padSingleSide:-padSingleSide])
            outputV[j, 0, :padSingleSide, padSingleSide:-padSingleSide] = (
                outputV[j, 0, -2:-1, padSingleSide:-padSingleSide])
            outputV[j, 0, :, -padSingleSide:] = 0
            outputV[j, 0, :, 0:padSingleSide] = Para[j, 0, 0, 0]
        dvdx = dfdx(outputV, dydeta, dydxi, Jinv)
        d2vdx2 = dfdx(dvdx, dydeta, dydxi, Jinv)
        dvdy = dfdy(outputV, dxdxi, dxdeta, Jinv)
        d2vdy2 = dfdy(dvdy, dxdxi, dxdeta, Jinv)
        continuity = (d2vdy2 + d2vdx2)
        loss = criterion(continuity, continuity * 0)
        loss.backward()
        optimizer.step()
        loss_mass = criterion(continuity, continuity * 0)
        mRes += loss_mass.item()
        eV = eV + torch.sqrt(
            criterion(truth, outputV) / criterion(truth, truth * 0))
        if epoch % 1000 == 0 or epoch % nEpochs == 0:
            torch.save(model, str(epoch) + '.pth')
            for j in range(batchSize):
                fig1 = plt.figure()
                ax = plt.subplot(1, 2, 1)
                visualize2D(ax, coord[0, 0, :, :].cpu().detach().numpy(),
                            coord[0, 1, :, :].cpu().detach().numpy(),
                            outputV[j, 0, :, :].cpu().detach().numpy())
                ax.set_aspect('equal')
                setAxisLabel(ax, 'p')
                ax.set_title('CNN ' + r'$T$')
                ax = plt.subplot(1, 2, 2)
                visualize2D(ax, coord[0, 0, :, :].cpu().detach().numpy(),
                            coord[0, 1, :, :].cpu().detach().numpy(),
                            truth[j, 0, :, :].cpu().detach().numpy())
                ax.set_aspect('equal')
                setAxisLabel(ax, 'p')
                ax.set_title('FV ' + r'$T$')
                fig1.tight_layout(pad=1)
                fig1.savefig('Epoch' + str(epoch) + 'Para' + str(j) + 'T.pdf',
                             bbox_inches='tight')
                #plt.show()
                plt.close(fig1)
    print('Epoch is ', epoch)
    print("mRes Loss is", (mRes / len(training_data_loader)))
    print("eV Loss is", (eV / len(training_data_loader)))
    return (mRes / len(training_data_loader)), (eV / len(training_data_loader))
コード例 #3
0
ファイル: case4_eval.py プロジェクト: LijieJi6/phygeonet
for i in range(nx):
	for j in range(ny):
		dist=(myMesh.x[j,i]-OFX)**2+(myMesh.y[j,i]-OFY)**2
		idx_min=np.where(dist == dist.min())
		GT[j,i,:]=OFGT[idx_min[0][0],idx_min[1][0],:]
		FI[j,i,:]=OFFI[idx_min[0][0],idx_min[1][0],:]
		KL[j,i,:]=OFKL[idx_min[0][0],idx_min[1][0],:]
Fontsize=20
for i in range(10):
	fig0=plt.figure()
	ax=plt.subplot(1,1,1)
	_,cbar=visualize2D(ax,myMesh.x,
				   myMesh.y,
				   KL[:,:,i],'vertical')
	ax.set_aspect('equal')
	setAxisLabel(ax,'p')
	ax.tick_params(axis='x',labelsize=Fontsize)
	ax.tick_params(axis='y',labelsize=Fontsize)
	cbar.ax.tick_params(labelsize=Fontsize)
	ax.set_title('mode '+str(i+1),fontsize=Fontsize)
	ax.set_xlabel(xlabel=r'$x$',fontsize=Fontsize)
	ax.set_ylabel(ylabel=r'$y$',fontsize=Fontsize)
	fig0.tight_layout(pad=0.5)
	plt.savefig('test/KLMode'+str(i+1)+'.png',bbox_inches='tight')
	plt.close(fig0)
trainSize=1000
batchSize=1
NvarInput=1
NvarOutput=1
nEpochs=1
lr=0.001
コード例 #4
0
def train(epoch):
    startTime = time.time()
    xRes = 0
    yRes = 0
    mRes = 0
    eU = 0
    eV = 0
    eP = 0
    for iteration, batch in enumerate(training_data_loader):
        [JJInv,coord,xi,
        eta,J,Jinv,
        dxdxi,dydxi,
        dxdeta,dydeta,
        Utrue,Vtrue,Ptrue]=\
          to4DTensor(batch)
        solutionTruth = torch.cat([Utrue, Vtrue, Ptrue], axis=1)
        optimizer.zero_grad()
        output = model(coord)
        output_pad = udfpad(output)
        outputU = output_pad[:, 0, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        outputV = output_pad[:, 1, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        outputP = output_pad[:, 2, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        XR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        YR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        MR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        for j in range(batchSize):
            outputU[j, 0, -padSingleSide:,
                    padSingleSide:-padSingleSide] = output[j, 0,
                                                           -1, :].reshape(
                                                               1, nx - 2 *
                                                               padSingleSide)
            outputU[j, 0, :padSingleSide, padSingleSide:-padSingleSide] = 0
            outputU[j, 0, padSingleSide:-padSingleSide, -padSingleSide:] = 0
            outputU[j, 0, padSingleSide:-padSingleSide, 0:padSingleSide] = 0
            outputU[j, 0, 0,
                    0] = 0.5 * (outputU[j, 0, 0, 1] + outputU[j, 0, 1, 0])
            outputU[j, 0, 0,
                    -1] = 0.5 * (outputU[j, 0, 0, -2] + outputU[j, 0, 1, -1])
            outputV[j, 0, -padSingleSide:,
                    padSingleSide:-padSingleSide] = output[j, 1,
                                                           -1, :].reshape(
                                                               1, nx - 2 *
                                                               padSingleSide)
            outputV[j, 0, :padSingleSide, padSingleSide:-padSingleSide] = 0.4
            outputV[j, 0, padSingleSide:-padSingleSide, -padSingleSide:] = 0
            outputV[j, 0, padSingleSide:-padSingleSide, 0:padSingleSide] = 0
            outputV[j, 0, 0,
                    0] = 0.5 * (outputV[j, 0, 0, 1] + outputV[j, 0, 1, 0])
            outputV[j, 0, 0,
                    -1] = 0.5 * (outputV[j, 0, 0, -2] + outputV[j, 0, 1, -1])
            outputP[j, 0, -padSingleSide:, padSingleSide:-padSingleSide] = 0
            outputP[j, 0, :padSingleSide,
                    padSingleSide:-padSingleSide] = output[j, 2, 0, :].reshape(
                        1, nx - 2 * padSingleSide)
            outputP[j, 0, padSingleSide:-padSingleSide,
                    -padSingleSide:] = output[j, 2, :, -1].reshape(
                        ny - 2 * padSingleSide, 1)
            outputP[j, 0, padSingleSide:-padSingleSide,
                    0:padSingleSide] = output[j, 2, :, 0].reshape(
                        ny - 2 * padSingleSide, 1)
            outputP[j, 0, 0,
                    0] = 0.5 * (outputP[j, 0, 0, 1] + outputP[j, 0, 1, 0])
            outputP[j, 0, 0,
                    -1] = 0.5 * (outputP[j, 0, 0, -2] + outputP[j, 0, 1, -1])
        dudx = dfdx(outputU, dydeta, dydxi, Jinv)
        d2udx2 = dfdx(dudx, dydeta, dydxi, Jinv)
        dudy = dfdy(outputU, dxdxi, dxdeta, Jinv)
        d2udy2 = dfdy(dudy, dxdxi, dxdeta, Jinv)
        dvdx = dfdx(outputV, dydeta, dydxi, Jinv)
        d2vdx2 = dfdx(dvdx, dydeta, dydxi, Jinv)
        dvdy = dfdy(outputV, dxdxi, dxdeta, Jinv)
        d2vdy2 = dfdy(dvdy, dxdxi, dxdeta, Jinv)
        dpdx = dfdx(outputP, dydeta, dydxi, Jinv)
        d2pdx2 = dfdx(dpdx, dydeta, dydxi, Jinv)
        dpdy = dfdy(outputP, dxdxi, dxdeta, Jinv)
        d2pdy2 = dfdy(dpdy, dxdxi, dxdeta, Jinv)
        continuity = dudx + dvdy
        momentumX = outputU * dudx + outputV * dudy
        forceX = -dpdx + nu * (d2udx2 + d2udy2)
        Xresidual = momentumX - forceX
        momentumY = outputU * dvdx + outputV * dvdy
        forceY = -dpdy + nu * (d2vdx2 + d2vdy2)
        Yresidual = momentumY - forceY
        loss=(criterion(Xresidual,Xresidual*0)+\
          criterion(Yresidual,Yresidual*0)+\
          criterion(continuity,continuity*0))
        loss.backward()
        optimizer.step()
        loss_xm = criterion(Xresidual, Xresidual * 0)
        loss_ym = criterion(Yresidual, Yresidual * 0)
        loss_mass = criterion(continuity, continuity * 0)
        xRes += loss_xm.item()
        yRes += loss_ym.item()
        mRes += loss_mass.item()
        eU = eU + torch.sqrt(
            criterion(Utrue, output[:, 0:1, :, :]) /
            criterion(Utrue, Utrue * 0))
        eV = eV + torch.sqrt(
            criterion(Vtrue, output[:, 1:2, :, :]) /
            criterion(Vtrue, Vtrue * 0))
        eP = eP + torch.sqrt(
            criterion(Ptrue, output[:, 2:3, :, :]) /
            criterion(Ptrue, Ptrue * 0))
        if epoch % 5000 == 0 or epoch % nEpochs == 0:
            torch.save(model, str(epoch) + '.pth')
            for j in range(batchSize):
                fig1 = plt.figure()
                ax = plt.subplot(2, 3, 1)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            Utrue[j, :, :, :].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('Physics Domain ' + 'U FV')
                ax.set_xticks([-0.25, 0.25])
                ax = plt.subplot(2, 3, 2)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            Vtrue[j, :, :, :].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('Physics Domain ' + 'V FV')
                ax.set_xticks([-0.25, 0.25])
                ax = plt.subplot(2, 3, 3)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            Ptrue[j, :, :, :].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('Physics Domain ' + 'P FV')
                ax.set_xticks([-0.25, 0.25])
                ax = plt.subplot(2, 3, 4)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            outputU[j, 0, 1:-1, 1:-1].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('U CNN')
                ax.set_xticks([-0.25, 0.25])
                ax = plt.subplot(2, 3, 5)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            outputV[j, 0, 1:-1, 1:-1].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('V CNN')
                ax.set_xticks([-0.25, 0.25])
                ax = plt.subplot(2, 3, 6)
                visualize2D(ax, coord[j, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                            coord[j, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                            outputP[j, 0, 1:-1, 1:-1].cpu().detach().numpy())
                setAxisLabel(ax, 'p')
                ax.set_title('P CNN')
                ax.set_xticks([-0.25, 0.25])
                fig1.tight_layout(pad=1)
                fig1.savefig('epoch' + str(epoch) + 'Para' + str(j) +
                             'UVPCFD.pdf',
                             bbox_inches='tight')
                plt.close(fig1)
    print('Epoch is ', epoch)
    print("xRes Loss is", (xRes / len(training_data_loader)))
    print("yRes Loss is", (yRes / len(training_data_loader)))
    print("mRes Loss is", (mRes / len(training_data_loader)))
    print("eU Loss is", (eU / len(training_data_loader)))
    print("eV Loss is", (eV / len(training_data_loader)))
    print("eP Loss is", (eP / len(training_data_loader)))
    return (xRes/len(training_data_loader)), (yRes/len(training_data_loader)),\
        (mRes/len(training_data_loader)), (eU.item()/len(training_data_loader)),\
        (eV.item()/len(training_data_loader)), (eP.item()/len(training_data_loader))
コード例 #5
0
ファイル: case1_main.py プロジェクト: LijieJi6/phygeonet
def train(epoch):
    startTime = time.time()
    xRes = 0
    yRes = 0
    mRes = 0
    eU = 0
    eV = 0
    eP = 0
    for iteration, batch in enumerate(training_data_loader):
        [JJInv, coord, xi, eta, J, Jinv, dxdxi, dydxi, dxdeta,
         dydeta] = to4DTensor(batch)
        optimizer.zero_grad()
        output = model(coord)
        output_pad = udfpad(output)
        outputU = output_pad[:, 0, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        outputV = output_pad[:, 1, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        outputP = output_pad[:, 2, :, :].reshape(output_pad.shape[0], 1,
                                                 output_pad.shape[2],
                                                 output_pad.shape[3])
        XR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        YR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        MR = torch.zeros([batchSize, 1, ny, nx]).to('cuda')
        for j in range(batchSize):
            outputU[j, 0, -padSingleSide:,
                    padSingleSide:-padSingleSide] = output[j, 0,
                                                           -1, :].reshape(
                                                               1, nx - 2 *
                                                               padSingleSide)
            outputU[j, 0, :padSingleSide, padSingleSide:-padSingleSide] = 0
            outputU[j, 0, padSingleSide:-padSingleSide, -padSingleSide:] = 0
            outputU[j, 0, padSingleSide:-padSingleSide, 0:padSingleSide] = 0
            outputU[j, 0, 0, 0] = 1 * (outputU[j, 0, 0, 1])
            outputU[j, 0, 0, -1] = 1 * (outputU[j, 0, 0, -2])
            outputV[j, 0, -padSingleSide:,
                    padSingleSide:-padSingleSide] = output[j, 1,
                                                           -1, :].reshape(
                                                               1, nx - 2 *
                                                               padSingleSide)
            outputV[j, 0, :padSingleSide, padSingleSide:-padSingleSide] = 1
            outputV[j, 0, padSingleSide:-padSingleSide, -padSingleSide:] = 0
            outputV[j, 0, padSingleSide:-padSingleSide, 0:padSingleSide] = 0
            outputV[j, 0, 0, 0] = 1 * (outputV[j, 0, 0, 1])
            outputV[j, 0, 0, -1] = 1 * (outputV[j, 0, 0, -2])
            outputP[j, 0, -padSingleSide:, padSingleSide:-padSingleSide] = 0
            outputP[j, 0, :padSingleSide,
                    padSingleSide:-padSingleSide] = output[j, 2, 0, :].reshape(
                        1, nx - 2 * padSingleSide)
            outputP[j, 0, padSingleSide:-padSingleSide,
                    -padSingleSide:] = output[j, 2, :, -1].reshape(
                        ny - 2 * padSingleSide, 1)
            outputP[j, 0, padSingleSide:-padSingleSide,
                    0:padSingleSide] = output[j, 2, :, 0].reshape(
                        ny - 2 * padSingleSide, 1)
            outputP[j, 0, 0, 0] = 1 * (outputP[j, 0, 0, 1])
            outputP[j, 0, 0, -1] = 1 * (outputP[j, 0, 0, -2])
        dudx = dfdx(outputU, dydeta, dydxi, Jinv)
        d2udx2 = dfdx(dudx, dydeta, dydxi, Jinv)
        dudy = dfdy(outputU, dxdxi, dxdeta, Jinv)
        d2udy2 = dfdy(dudy, dxdxi, dxdeta, Jinv)
        dvdx = dfdx(outputV, dydeta, dydxi, Jinv)
        d2vdx2 = dfdx(dvdx, dydeta, dydxi, Jinv)
        dvdy = dfdy(outputV, dxdxi, dxdeta, Jinv)
        d2vdy2 = dfdy(dvdy, dxdxi, dxdeta, Jinv)
        dpdx = dfdx(outputP, dydeta, dydxi, Jinv)
        d2pdx2 = dfdx(dpdx, dydeta, dydxi, Jinv)
        dpdy = dfdy(outputP, dxdxi, dxdeta, Jinv)
        d2pdy2 = dfdy(dpdy, dxdxi, dxdeta, Jinv)
        continuity = dudx + dvdy
        momentumX = outputU * dudx + outputV * dudy
        forceX = -dpdx + nu * (d2udx2 + d2udy2)
        Xresidual = momentumX - forceX
        momentumY = outputU * dvdx + outputV * dvdy
        forceY = -dpdy + nu * (d2vdx2 + d2vdy2)
        Yresidual = momentumY - forceY
        loss=(criterion(Xresidual,Xresidual*0)+\
          criterion(Yresidual,Yresidual*0)+\
          criterion(continuity,continuity*0))
        #loss.backward()
        optimizer.step()
        loss_xm = criterion(Xresidual, Xresidual * 0)
        loss_ym = criterion(Yresidual, Yresidual * 0)
        loss_mass = criterion(continuity, continuity * 0)
        xRes += loss_xm.item()
        yRes += loss_ym.item()
        mRes += loss_mass.item()
        CNNUNumpy = outputU[0, 0, :, :].cpu().detach().numpy()
        CNNVNumpy = outputV[0, 0, :, :].cpu().detach().numpy()
        CNNPNumpy = outputP[0, 0, :, :].cpu().detach().numpy()
        eU = eU + np.sqrt(
            calMSE(OFU_sb, CNNUNumpy) / calMSE(OFU_sb, OFU_sb * 0))
        eV = eV + np.sqrt(
            calMSE(OFV_sb, CNNVNumpy) / calMSE(OFV_sb, OFV_sb * 0))
        eP = eP + np.sqrt(
            calMSE(OFP_sb, CNNPNumpy) / calMSE(OFP_sb, OFP_sb * 0))
        eVmag = np.sqrt(
            calMSE(np.sqrt(OFU_sb**2 + OFV_sb**2),
                   np.sqrt(CNNUNumpy**2 + CNNVNumpy**2)) /
            calMSE(np.sqrt(OFU_sb**2 + OFV_sb**2),
                   np.sqrt(OFU_sb**2 + OFV_sb**2) * 0))
        eVmag_FCNN = np.sqrt(
            calMSE(np.sqrt(OFU_sb**2 + OFV_sb**2),
                   np.sqrt(fcnn_U**2 + fcnn_V**2)) /
            calMSE(np.sqrt(OFU_sb**2 + OFV_sb**2),
                   np.sqrt(OFU_sb**2 + OFV_sb**2) * 0))
        print('VelMagError_CNN=', eVmag)
        print('VelMagError_FCNN=', eVmag_FCNN)
        print('P_err_CNN=',
              np.sqrt(calMSE(OFP_sb, CNNPNumpy) / calMSE(OFP_sb, OFP_sb * 0)))
        print('P_err_FCNN=',
              np.sqrt(calMSE(OFP_sb, fcnn_P) / calMSE(OFP_sb, OFP_sb * 0)))
    print('Epoch is ', epoch)
    print("xRes Loss is", (xRes / len(training_data_loader)))
    print("yRes Loss is", (yRes / len(training_data_loader)))
    print("mRes Loss is", (mRes / len(training_data_loader)))
    print("eU Loss is", (eU / len(training_data_loader)))
    print("eV Loss is", (eV / len(training_data_loader)))
    print("eP Loss is", (eP / len(training_data_loader)))
    if epoch % 5000 == 0 or epoch % nEpochs == 0:
        torch.save(model, str(epoch) + '.pth')
        fig0 = plt.figure()
        ax = plt.subplot(2, 3, 1)
        _,cbar=visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
                    coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
                    np.sqrt(fcnn_U[1:-1,1:-1]**2+\
                         fcnn_V[1:-1,1:-1]**2),'vertical',[0,1.3])
        cbar.set_ticks([0, 0.3, 0.6, 0.9, 1.3])
        setAxisLabel(ax, 'p')
        ax.set_title('FCNN ' + 'Velocity')

        ax = plt.subplot(2, 3, 2)
        _,cbar=visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
                    coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
                    np.sqrt(outputU[0,0,1:-1,1:-1].cpu().detach().numpy()**2+\
                         outputV[0,0,1:-1,1:-1].cpu().detach().numpy()**2),'vertical',[0,1.3])
        setAxisLabel(ax, 'p')
        ax.set_title('PhyGeoNet ' + 'Velocity')
        cbar.set_ticks([0, 0.3, 0.6, 0.9, 1.3])

        ax = plt.subplot(2, 3, 3)
        _,cbar=visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
                    coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
                    np.sqrt(OFU_sb[1:-1,1:-1]**2+\
                         OFV_sb[1:-1,1:-1]**2),'vertical',[0,1.3])
        cbar.set_ticks([0, 0.3, 0.6, 0.9, 1.3])
        setAxisLabel(ax, 'p')
        ax.set_title('CFD ' + 'Velocity')

        ax = plt.subplot(2, 3, 4)
        visualize2D(ax, coord[0, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                    coord[0, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                    fcnn_P[1:-1, 1:-1], 'vertical', [0, 1.5])
        setAxisLabel(ax, 'p')
        ax.set_title('FCNN ' + 'Pressure')

        ax = plt.subplot(2, 3, 5)
        visualize2D(ax, coord[0, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                    coord[0, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                    outputP[0, 0, 1:-1,
                            1:-1].cpu().detach().numpy(), 'vertical', [0, 1.5])
        setAxisLabel(ax, 'p')
        ax.set_title('PhyGeoNet ' + 'Pressure')

        ax = plt.subplot(2, 3, 6)
        visualize2D(ax, coord[0, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                    coord[0, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                    OFP_sb[1:-1, 1:-1], 'vertical', [0, 1.5])
        setAxisLabel(ax, 'p')
        ax.set_title('CFD ' + 'Pressure')
        fig0.tight_layout(pad=1)
        fig0.savefig(str(epoch) + 'VelMagAndPressureFCNN.pdf',
                     bbox_inches='tight')
        plt.close(fig0)

        fig0 = plt.figure()
        ax = plt.subplot(2, 2, 1)
        _,cbar=visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
                    coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
                    np.sqrt(outputU[0,0,1:-1,1:-1].cpu().detach().numpy()**2+\
                         outputV[0,0,1:-1,1:-1].cpu().detach().numpy()**2),'vertical',[0,1.3])
        setAxisLabel(ax, 'p')
        ax.set_title('PhyGeoNet ' + 'Velocity')
        ax.set_aspect(1.3)
        cbar.set_ticks([0, 0.3, 0.6, 0.9, 1.3])
        ax = plt.subplot(2, 2, 2)
        visualize2D(ax, coord[0, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                    coord[0, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                    outputP[0, 0, 1:-1,
                            1:-1].cpu().detach().numpy(), 'vertical', [0, 1.5])
        setAxisLabel(ax, 'p')
        ax.set_title('PhyGeoNet ' + 'Pressure')
        ax.set_aspect(1.3)
        ax = plt.subplot(2, 2, 3)
        _,cbar=visualize2D(ax,coord[0,0,1:-1,1:-1].cpu().detach().numpy(),
                    coord[0,1,1:-1,1:-1].cpu().detach().numpy(),
                    np.sqrt(OFU_sb[1:-1,1:-1]**2+\
                         OFV_sb[1:-1,1:-1]**2),'vertical',[0,1.3])
        setAxisLabel(ax, 'p')
        ax.set_title('CFD ' + 'Velocity')
        ax.set_aspect(1.3)
        cbar.set_ticks([0, 0.3, 0.6, 0.9, 1.3])
        ax = plt.subplot(2, 2, 4)
        visualize2D(ax, coord[0, 0, 1:-1, 1:-1].cpu().detach().numpy(),
                    coord[0, 1, 1:-1, 1:-1].cpu().detach().numpy(),
                    OFP_sb[1:-1, 1:-1], 'vertical', [0, 1.5])
        setAxisLabel(ax, 'p')
        ax.set_title('CFD ' + 'Pressure')
        ax.set_aspect(1.3)
        fig0.tight_layout(pad=1)
        fig0.savefig(str(epoch) + 'VelMagAndPressureCNN.pdf',
                     bbox_inches='tight')
        plt.close(fig0)
    return (xRes/len(training_data_loader)), (yRes/len(training_data_loader)),\
        (mRes/len(training_data_loader)), (eU/len(training_data_loader)),\
        (eV/len(training_data_loader)), (eP/len(training_data_loader))