mypde = LinearPDE(domain) mypde.setValue(A=kro, Y=4. * 3.1415 * G * rho) mypde.setValue(q=q, r=0) mypde.setSymmetryOn() sol = mypde.getSolution() g_field = grad(sol) #The gravitational acceleration g. g_fieldz = g_field * [0, 1] #The vertical component of the g field. gz = length(g_fieldz) #The magnitude of the vertical component. # Save the output to file. saveVTK(os.path.join(save_path,"ex10a.vtu"),\ grav_pot=sol,g_field=g_field,g_fieldz=g_fieldz,gz=gz) ##################################################REGRIDDING & PLOTTING xi, yi, zi = toRegGrid(sol, nx=50, ny=50) pl.matplotlib.pyplot.autumn() pl.contourf(xi, yi, zi, 10) pl.xlabel("Horizontal Displacement (m)") pl.ylabel("Depth (m)") pl.savefig(os.path.join(save_path, "Ucontour.png")) print("Solution has been plotted ...") cut = int(len(xi) // 2) pl.clf() r = np.linspace( 0.0000001, mx / 2, 100 ) # starting point would be 0 but that would cause division by zero later m = 2 * pl.pi * 10 * 10 * 200 * -G / (r * r)
d.setScriptFileName(os.path.join(save_path,"example05.geo")) d.setMeshFileName(os.path.join(save_path,"example05.msh")) domain=MakeDomain(d, optimizeLabeling=True) print("Domain has been generated ...") ##############################################################SOLVE PDE mypde=LinearPDE(domain) mypde.getSolverOptions().setVerbosityOn() mypde.setSymmetryOn() kappa=Scalar(0,Function(domain)) kappa.setTaggedValue("top",2.0*W/m/K) kappa.setTaggedValue("bottom",4.0*W/m/K) mypde.setValue(A=kappa*kronecker(domain)) x=Solution(domain).getX() mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop) qS=Scalar(0,FunctionOnBoundary(domain)) qS.setTaggedValue("linebottom",qin) mypde.setValue(y=qS) print("PDE has been generated ...") ###########################################################GET SOLUTION T=mypde.getSolution() print("PDE has been solved ...") ####################################################################### xi, yi, zi = toRegGrid(T, nx=50, ny=50) pl.matplotlib.pyplot.autumn() pl.contourf(xi,yi,zi,10) pl.xlabel("Horizontal Displacement (m)") pl.ylabel("Depth (m)") pl.savefig(os.path.join(save_path,"Tcontour.png")) print("Solution has been plotted ...")
kappa=Scalar(0,Function(domain)) kappa.setTaggedValue("top",2.0*W/m/K) kappa.setTaggedValue("bottom",4.0*W/m/K) mypde.setValue(A=kappa*kronecker(domain)) x=Solution(domain).getX() mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop) qS=Scalar(0,FunctionOnBoundary(domain)) qS.setTaggedValue("linebottom",qin) mypde.setValue(y=qS) print("PDE has been generated ...") ###########################################################GET SOLUTION T=mypde.getSolution() print("PDE has been solved ...") ##################################################REGRIDDING & PLOTTING xi, yi, zi = toRegGrid(T, nx=50, ny=50) pl.matplotlib.pyplot.autumn() pl.contourf(xi,yi,zi,10) pl.xlabel("Horizontal Displacement (m)") pl.ylabel("Depth (m)") pl.savefig(os.path.join(save_path,"Tcontour.png")) print("Solution has been plotted ...") ##########################################################VISUALISATION # calculate gradient of solution for quiver plot #Projector is used to smooth the data. proj=Projector(domain) #move data to a regular grid for plotting xi,yi,zi = toRegGrid(T,200,200) cut=int(len(xi)//2) pl.clf() pl.plot(zi[:,cut],yi)
# Create a Design which can make the mesh d = Design(dim=2, element_size=200 * m) # Add the subdomains and flux boundaries. d.addItems(rec, PropertySet("linebottom", l12)) d.addItems(l01, l23, l30) # just in case we need them #############################################MAKE THE DOMAIN domain = MakeDomain(d, optimizeLabeling=True) print("Domain has been generated ...") ##############################################################SOLVE PDE mypde = LinearPDE(domain) mypde.getSolverOptions().setVerbosityOn() mypde.setSymmetryOn() mypde.setValue(A=kappa * kronecker(domain)) x = Solution(domain).getX() mypde.setValue(q=whereZero(x[1] - sup(x[1])), r=Ttop) qS = Scalar(0, FunctionOnBoundary(domain)) qS.setTaggedValue("linebottom", qin) mypde.setValue(y=-qS) print("PDE has been generated ...") ###########################################################GET SOLUTION T = mypde.getSolution() print("PDE has been solved ...") ########################################################### xi, yi, zi = toRegGrid(T, nx=50, ny=50) pl.matplotlib.pyplot.autumn() pl.contourf(xi, yi, zi, 10) pl.xlabel("Horizontal Displacement (m)") pl.ylabel("Depth (m)") pl.savefig(os.path.join(save_path, "example04.png")) print("Solution has been plotted ...")
mypde.setValue(A=kro,Y=4.*3.1415*G*rho) mypde.setValue(q=q,r=0) mypde.setSymmetryOn() sol=mypde.getSolution() g_field=grad(sol) #The gravitational acceleration g. g_fieldz=g_field*[0,1] #The vertical component of the g field. gz=length(g_fieldz) #The magnitude of the vertical component. # Save the output to file. saveVTK(os.path.join(save_path,"ex10a.vtu"),\ grav_pot=sol,g_field=g_field,g_fieldz=g_fieldz,gz=gz) ##################################################REGRIDDING & PLOTTING xi, yi, zi = toRegGrid(sol, nx=50, ny=50) pl.matplotlib.pyplot.autumn() pl.contourf(xi,yi,zi,10) pl.xlabel("Horizontal Displacement (m)") pl.ylabel("Depth (m)") pl.savefig(os.path.join(save_path,"Ucontour.png")) print("Solution has been plotted ...") cut=int(len(xi)//2) pl.clf() r=np.linspace(0.0000001,mx/2,100) # starting point would be 0 but that would cause division by zero later m=2*pl.pi*10*10*200*-G/(r*r) pl.plot(xi,zi[:,cut])