You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I delete the plot code because WSL cannot use it.
"""FEniCS tutorial demo program: Incompressible Navier-Stokes equationsfor channel flow (Poisseuille) on the unit square using theIncremental Pressure Correction Scheme (IPCS). u' + u . nabla(u)) - div(sigma(u, p)) = f div(u) = 0"""from __future__ importprint_functionfromdolfinimport*importnumpyasnpT=10.0# final timenum_steps=500# number of time stepsdt=T/num_steps# time step sizemu=1# kinematic viscosityrho=1# density# Create mesh and define function spacesmesh=UnitSquareMesh(16, 16)
V=VectorFunctionSpace(mesh, 'P', 2)
Q=FunctionSpace(mesh, 'P', 1)
# Define boundariesinflow='near(x[0], 0)'outflow='near(x[0], 1)'walls='near(x[1], 0) || near(x[1], 1)'# Define boundary conditionsbcu_noslip=DirichletBC(V, Constant((0, 0)), walls)
bcp_inflow=DirichletBC(Q, Constant(8), inflow)
bcp_outflow=DirichletBC(Q, Constant(0), outflow)
bcu= [bcu_noslip]
bcp= [bcp_inflow, bcp_outflow]
# Define trial and test functionsu=TrialFunction(V)
v=TestFunction(V)
p=TrialFunction(Q)
q=TestFunction(Q)
# Define functions for solutions at previous and current time stepsu_n=Function(V)
u_=Function(V)
p_n=Function(Q)
p_=Function(Q)
# Define expressions used in variational formsU=0.5*(u_n+u)
n=FacetNormal(mesh)
f=Constant((0, 0))
k=Constant(dt)
mu=Constant(mu)
rho=Constant(rho)
# Define strain-rate tensordefepsilon(u):
returnsym(nabla_grad(u))
# Define stress tensordefsigma(u, p):
return2*mu*epsilon(u) -p*Identity(len(u))
# Define variational problem for step 1F1=rho*dot((u-u_n) /k, v)*dx+ \
rho*dot(dot(u_n, nabla_grad(u_n)), v)*dx \
+inner(sigma(U, p_n), epsilon(v))*dx \
+dot(p_n*n, v)*ds-dot(mu*nabla_grad(U)*n, v)*ds \
-dot(f, v)*dxa1=lhs(F1)
L1=rhs(F1)
# Define variational problem for step 2a2=dot(nabla_grad(p), nabla_grad(q))*dxL2=dot(nabla_grad(p_n), nabla_grad(q))*dx- (1/k)*div(u_)*q*dx# Define variational problem for step 3a3=dot(u, v)*dxL3=dot(u_, v)*dx-k*dot(nabla_grad(p_-p_n), v)*dx# Assemble matricesA1=assemble(a1)
A2=assemble(a2)
A3=assemble(a3)
# Apply boundary conditions to matrices
[bc.apply(A1) forbcinbcu]
[bc.apply(A2) forbcinbcp]
# Time-steppingt=0forninrange(num_steps):
# Update current timet+=dt# Step 1: Tentative velocity stepb1=assemble(L1)
[bc.apply(b1) forbcinbcu]
solve(A1, u_.vector(), b1)
# Step 2: Pressure correction stepb2=assemble(L2)
[bc.apply(b2) forbcinbcp]
solve(A2, p_.vector(), b2)
# Step 3: Velocity correction stepb3=assemble(L3)
solve(A3, u_.vector(), b3)
# Plot solution# plot(u_)# Compute erroru_e=Expression(('4*x[1]*(1.0 - x[1])', '0'), degree=2)
u_e=interpolate(u_e, V)
error=np.abs(u_e.vector().get_local() -u_.vector().get_local()).max()
print('t = %.2f: error = %.3g'% (t, error))
print('max u:', u_.vector().get_local().max())
# Update previous solutionu_n.assign(u_)
p_n.assign(p_)
# Hold plot# interactive()
The text was updated successfully, but these errors were encountered:
I am trying to learn FEniCS, and I am confused on the values for a2, L2, a3, and L3. For a1 and L1 we can use lhs and rhs, but how do we know the expressions for them in the second and third steps? Thank you.
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I delete the plot code because WSL cannot use it.
The text was updated successfully, but these errors were encountered: