Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NLSolver speed #897

Closed
larsudb opened this issue Apr 4, 2023 · 1 comment
Closed

NLSolver speed #897

larsudb opened this issue Apr 4, 2023 · 1 comment

Comments

@larsudb
Copy link

larsudb commented Apr 4, 2023

I have written a code for a lid-driven square cavity within gridap and am wondering if the solve time can be decreased easily.

using Gridap
using LineSearches: BackTracking
using TickTock
using WriteVTK

n = 100
domain = (0,1,0,1)
partition = (n,n)
model = CartesianDiscreteModel(domain,partition)
labels = get_face_labeling(model)

add_tag_from_tags!(labels,“sides”,[5,7,8])
add_tag_from_tags!(labels,“top”,[6])

D = 2
order = 2
degree = 2*order

Ωₕ = Interior(model)
dΩ = Measure(Ωₕ,degree)
reffeᵤ = ReferenceFE(lagrangian,VectorValue{D,Float64},order)
V = TestFESpace(Ωₕ,reffeᵤ,conformity=:H1,dirichlet_tags=[“top”,“sides”])
reffeₚ = ReferenceFE(lagrangian,Float64,order-1)
Q = TestFESpace(Ωₕ,reffeₚ,conformity=:H1,constraint=:zeromean)

u_wall(x, t) = VectorValue(cos(t),0)
u_wall(t::Real) = x → u_wall(x, t)

u_top(x, t) = VectorValue(1, 0)
u_top(t::Real) = x → u_top(x, t)

U = TransientTrialFESpace(V,[u_top,u_wall])
P = TransientTrialFESpace(Q)

Y = MultiFieldFESpace([V, Q])
X = TransientMultiFieldFESpace([U, P])

res(t,(u,p),(v,q)) = ∫( ∂t(u)⋅v + ∇(u)⊙∇(v) - (∇⋅v)*p + q⋅(∇⋅u))dΩ #- ∫( f(t)⋅v )dΩ - ∫( g(t)*q )dΩ
jac(t,(u,p),(du,dp),(v,q)) = ∫( ∇(du)⊙∇(v) - (∇⋅v)*dp + q⋅(∇⋅du))dΩ
jac_t(t,(u,p),(dut,dpt),(v,q)) = ∫(v⋅dut)dΩ

op = TransientFEOperator(res,jac,jac_t,X,Y)

nls = NLSolver(show_trace = true,method = :newton,linesearch = BackTracking()) #,iterations=5

dt = 0.1
θ = 0.5
ode_solver = ThetaMethod(nls,dt,θ)

u₀ = interpolate_everywhere(VectorValue(0,0),U(0.0))
p₀ = interpolate_everywhere(0,P)
x₀ = interpolate_everywhere([u₀,p₀],X(0.0))

t₀ = 0
T = 10
xₕₜ = solve(ode_solver,op,x₀,t₀,T)

@time createpvd(“transient_stokes_solution”) do pvd
for (xₕ,t) in xₕₜ
(uₕ,pₕ) = xₕ
pvd[t] = createvtk(Ωₕ,“transient_stokes_solution_$t”*“.vtu”,cellfields=[“u”=>uₕ,“p”=>pₕ])
end
end

@JordiManyer
Copy link
Member

@larsudb You are solving 100 steps, and solving a nonlinear problem at each step.... This is costly, no way around it... Either you improve your choice of solvers of you go to parallel, but I don't think anything else can be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants