示例#1
0
文件: main.py 项目: magneano/Master-
def main():
	""" The old main  """"


	# Parameters
	n = 40
	w   = 0.3
	show = True 
	
	# Mesh and Functionspaces
	mesh = UnitSquareMesh(n,n)
	Vspace = VectorFunctionSpace(mesh, 'Lagrange', 2) 
	Pspace = FunctionSpace(mesh, 'Lagrange', 1)
	Wspace = MixedFunctionSpace([Vspace, Pspace]) 
		
	ShearStressSpace=FunctionSpace(mesh, 'DG', 1)
	TensorSpace = TensorFunctionSpace(mesh, "DG", 1) # Space for the shearstess,could be named ShearStressSpace			
	DPspace = FunctionSpace(mesh, 'DG', 0)	         # Space for the gradient of the wss 
	
	# Expression for the initial T shape 
	K_1 = Expression('(x[0] > w && x[0] < 1- w && x[1] < 0.5 || x[1] >= 0.5 && x[1] <= 0.7 )? 0.0:1.0', w=w) #K in math.formulation	
	
	# Function calls
	U, P, K_Func = stokes_solver(w=w, mesh=mesh, Vspace=Vspace,Pspace=Pspace, Wspace=Wspace, TensorSpace=TensorSpace, 			DPspace=DPspace, ShearStressSpace=ShearStressSpace , K_array=K_1, n=n)

	#K_Func = domain(mesh = mesh, TensorSpace=TensorSpace, DPspace=DPspace, ShearStressSpace=ShearStressSpace, Pspace=Pspace, U=U, K_Func = K_Func, n=n)

	stokes_solver(w,mesh,Vspace,Pspace,Wspace,TensorSpace,DPspace,ShearStressSpace, K_array=K_Func, n=n)
def time_stepping(K, time):

	print 'time level: ', time 
	

	# Calculating the velocity and the pressure  		
	u, p = stokes_solver(x0=x0, R=R, K=K, mesh=mesh, W=W, speed=speed, mu=mu, dpdy=dpdy)
	

	# Calculating the shear 
	tau_xy_ = tau_xy(u=u)
	tau_xy_proj = project(tau_xy_, DG1) #P)  
	File('shear_N{}_t{}_s{}.xdmf'.format(N, time, speed)) << tau_xy_proj
	

	# Calculating the interface 
	interface_ = interface(K=K) 
	interface_proj = project(interface_, DG1) #P
	
	# Calculating the indicator
	#indicator_ = indicator(space = DG1, interface=interface_proj, tau_xy = tau_xy_proj, interesting_domain = interesting_domain_interpolate, epsilon = epsilon)

	indicator_ = indikator_test(space = DG1, Dirac_delta =interface_proj, tau_xy=tau_xy_proj, interesting_domain= interesting_domain_interpolate)


	# Updating K : K_new = K_old - I  
	K_new = K_update(indikator = indicator_, K=K)
	

	K_cap_ = K_cap(K_new)
	K_cap_proj = project(K_cap_, K.function_space())
	plot(K_cap_proj, interactive = viz, title = 'K cap' )
	#File('Kcap_n{}_t{}_s{}_e{}_alg{}.xdmf'.format(N, time, speed, epsilon, alg)) << K_cap_proj 

	return K_cap_proj  
示例#3
0
def iterative(K_1):
	# step 2: Send it to Stokes solver 
	U, P, K_Func = stokes_solver(w=w, mesh=mesh, Vspace=Vspace, Pspace=Pspace, Wspace=Wspace, K_array=K_1, n=n )

	# step 3: calculate the WSS over it and its bdry 
	wss = WSS(U=U, DG1=DG1)
	#wss_bdry = WSS_bdry(K_Func=K_Func, DPspace=DPspace, WSS=wss)

	# Step 4: This is the diffucult step. we need to create an indicator function now 
	indicator_function(WSS=wss, K_Func=K_Func, DG0=DG0, DG1=DG1)	
def time_stepping(K, time):

	print 'time level: ', time 
	

	# Calculating the velocity and the pressure  		
	u, p = stokes_solver(x0=x0, R=R, K=K, mesh=mesh, W=W, speed=speed, dpdy=dpdy)
	plot(u, interactive = True, title = 'Velocity field')
	#File('u_c105_n{}_t{}_s{}_e{}_alg{}.xdmf'.format( N, time, speed, epsilon, alg)) << u




	# Calculating the shear 
	tau_xy_ = tau_xy(u=u)
	tau_xy_proj = project(tau_xy_, DG1) #P)  
	#plot(tau_xy_proj, interactive = True, title = 'Shear')	
	#dg1_line_plot(tau_xy_proj)	
	File('shear_c105_n{}_t{}_s{}_e{}_alg{}.xdmf'.format(N, time, speed, epsilon, alg)) << tau_xy_proj
	



	# Calculating the interface 
	interface_ = interface(K=K) 
	interface_proj = project(interface_, DG1) #P
	#plot(interface_proj, interactive = viz, title = 'Interface')
	#File('interface_c105_n{}_t{}_s{}_e{}_alg{}.xdmf'.format(N, time, speed, epsilon, alg)) << interface_proj




	# Calculating the indicator
	#indicator_ = indicator(space = DG1, interface=interface_proj, tau_xy = tau_xy_proj, interesting_domain = interesting_domain_interpolate, epsilon = epsilon)

	indicator_ = indicator_tuned(space = DG1, Dirac_delta =interface_proj, tau_xy=tau_xy_proj, interesting_domain= interesting_domain_interpolate)
	plot(indicator_, interactive = viz, title = 'Indicator')
	#File('Indicator_c105_n{}_t{}_s{}__e{}_alg{}.xdmf'.format(N, time, speed,epsilon,alg)) << interface_proj 



	# Updating K : K_new = K_old - I  
	K_new = K_update(indikator = indicator_, K=K)
	#plot(K_new, interactive = viz, title = 'K_ny')
	#File('Knew_c105_n{}_t{}_s{}_e{}_alg{}.xdmf'.format(N, time, speed, epsilon, alg)) << K_new  




	K_cap_ = K_cap(K_new)
	K_cap_proj = project(K_cap_, K.function_space())
	plot(K_cap_proj, interactive = viz, title = 'K cap' )
	#File('Kcap_c105_n{}_t{}_s{}_e{}_alg{}.xdmf'.format(N, time, speed, epsilon, alg)) << K_cap_proj 

	return K_cap_proj  
示例#5
0
def iterative(K_1):

	U, P, K_Func = stokes_solver(w=w, mesh=mesh, Vspace=Vspace, Pspace=Pspace, Wspace=Wspace, DG1=Pspace, K_array=K_1, n=n )


	# Verification: 

	# alternative 1:
	# construct an analytical solution 
	# method of manufactored solutions 
	# first come up with a random slution
	# plut into PDE 
	# doesnt solve original homogeneous PDE exactly 
	# residual is then considered the source term 
	
		
	# alternative 2:
	# really fine mesh , solve a blind model on that mesh 
	# this is reference(considered exact) solution
	
		
		
	# actual convergence test(after alt 1 or 2):
	# mesh refinement test refining the mesh see if rate of convergence goes to 2.
	# mesh.refine() OR refine(mesh)
	# give a mesh, creates new mesh that is finer. 
	# for each mesh solve PDE
	# compute difference of u_e - u
	# in a norm 
	# for each mesh 

	# start with a very coarse one 
	# after halfin 4 times,gives a really fine mesh and solving will get slow. 

	# example:
	# for p2, half the mesh size 
	# error reduction of factor 4 

	# do it at the beginning

	# Magne: 
	# WSS skal naturlig veare i DG1.
	# og det fungerte aa bytte Pspace m DG1 
	
	wss = WSS(U=U, DG1= DG1) #Pspace) #,interesting_domain = interesting_domain_proj)
	bdry_ = bdry(K_Func = K_Func, DG1 = DG1)

	# Simon: 
	# DG1 osgaa inneholder CG1 


	ind_f = ind_func(bdry=bdry_, WSS = project(wss, DG1), DG1 = DG0, interesting_domain = interesting_domain_proj)
	K_new = K_update(ind_func = ind_f, K_Func = K_Func)
	
	#wss_bdry = WSS_bdry(K_Func, DG0, WSS)


	plot(K_new, interactive = True, title = 'K new ')
	K_capped = capping(K_new)
	plot(K_capped, interactive = False, title = 'K capped')
	stokes_solver(w=w, mesh=mesh, Vspace=Vspace, Pspace=Pspace, Wspace=Wspace, K_array=K_capped, n=n )

	return K_capped 
示例#6
0
文件: main3.py 项目: magneano/Master-
# step 4:then we need to calculate an ind function with threshold values for addition domain to it
# step 5:We need to add together the old and the new K functions
# step 6:Then capping the new K function might be necessary
# step 7:finally run stokes solver over the new K funciton

# iterate 50 times
# return the K_func
# store it to xdmf file to open it paraview


# step 1: Take K old
K_1 = Expression("(x[0] > w && x[0] < 1- w && x[1] < 0.5 || x[1] >= 0.5 && x[1] < 0.7 )? 0.0:1.0", w=w)

# step 2: Send it to Stokes solver
U, P, K_Func = stokes_solver(w=w, mesh=mesh, Vspace=Vspace, Pspace=Pspace, Wspace=Wspace, K_array=K_1, n=n)

# step 3: calculate the WSS over it and its bdry
WSS = WSS(U=U, ShearStressSpace=ShearStressSpace)
WSS_bdry = WSS_bdry(K_Func=K_Func, DPspace=DPspace, WSS=WSS)

# Step 4: This is the diffucult step. we need to create an indicator function now
ind_f = ind_func_expr(WSS_bdry=WSS_bdry)
# works!! finally

# step 5: add together old and new K functions
# ind_f is a function in DG0 space and old K function is inPspace
# have to solve this first

K_new = K_update(ind_func=ind_f, K_Func=K_Func)
plot(K_new, interactive=True, title="K new ")