Skip to content

Commit 09bdb33

Browse files
committed
Adding Fully Coupled Non-Linear Case
1 parent 8513282 commit 09bdb33

File tree

9 files changed

+232
-4
lines changed

9 files changed

+232
-4
lines changed

examples/TGVNlin.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using PartitionedArrays
2+
using SegregatedVMSSolver
3+
using SegregatedVMSSolver.ParametersDef
4+
using SegregatedVMSSolver.SolverOptions
5+
6+
using MPI
7+
8+
9+
10+
11+
12+
t0 = 0.0
13+
dt = 0.01
14+
tF = 2.5
15+
vortex_diameter = 1.0
16+
N = 16
17+
Re = 1600
18+
D = 2
19+
20+
backend = with_debug
21+
22+
rank_partition = (2,2)
23+
24+
25+
26+
27+
28+
solver_options = options = "-snes_type newtonls -snes_linesearch_type basic -snes_linesearch_damping 1.0 -snes_rtol 1.0e-8 -snes_atol 0 -snes_monitor -snes_max_it 20 \
29+
-pc_type asm -ksp_type fgmres -ksp_converged_reason -ksp_max_it 50 -ksp_rtol 1e-8 -ksp_atol 0.0"
30+
31+
sprob = StabilizedProblem(VMS(1))
32+
timep = TimeParameters(t0=t0, dt=dt, tF=tF)
33+
34+
physicalp = PhysicalParameters(Re=Re, c=vortex_diameter)
35+
solverp = SolverParameters(matrix_freq_update=1, Number_Skip_Expansion=10e6, M=40,
36+
petsc_options=solver_options, linear=false, θ=1.0)
37+
exportp = ExportParameters(printinitial=false, printmodel=false,
38+
vtu_export = ["uh","ph","uh_analytic", "ph_analytic"], extra_export=["VelocityError","PressureError"])
39+
40+
41+
42+
43+
meshp = MeshParameters(rank_partition, D; N=N, L=0.5 * vortex_diameter)
44+
simparams = SimulationParameters(timep, physicalp, solverp, exportp)
45+
bc_tgv = Periodic(meshp, physicalp)
46+
47+
48+
49+
mcase = TaylorGreen(bc_tgv, meshp, simparams, sprob)
50+
51+
52+
53+
# Create folder and file
54+
# mkdir("Log")
55+
# open("Log/PrintSim.txt", "w") do file
56+
# end
57+
58+
59+
60+
SegregatedVMSSolver.solve(mcase, backend)
61+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
function coupled_equations(params::Dict{Symbol,Any},simcase::SimulationCase)
2+
@sunpack skew, ν,dt, θ, D = simcase
3+
4+
sprob = simcase.sprob
5+
@unpack= params
6+
@unpack skew = sprob
7+
8+
#Conservations equations
9+
Rc(u) = u
10+
dRc(du) = du
11+
Rm(t, (u, p)) = ∂t(u) + u (u) + (p) #- ν*Δ(u)
12+
dRm((u, p), (du, dp), (v, q)) = du (u) + u (du) + (dp) #- ν*Δ(du)
13+
stab_coeff = compute_stab_coeff(simcase,params)
14+
15+
Tm(u) = momentum_stabilization(u, stab_coeff, simcase)
16+
Tc(u) = continuity_stabilization(u, stab_coeff, simcase)
17+
18+
19+
θvp = 1.0
20+
21+
#VMS equations
22+
#Function used in VMS terms
23+
TRm(t, (u, p)) = Tm(u.cellfield) * Rm(t, (u, p))
24+
25+
#Variational equations
26+
Bᴳ(t, (u, p), (v, q)) = (∂t(u) v)dΩ + ((u (u)) v)dΩ - ((∇ v) * p)dΩ + ((q * (∇ u)))dΩ + ν * ((v) (u))dΩ
27+
28+
#SUPG terms
29+
B_SUPG(t, (u, p), (v, q)) = ((u (v) + (q)) TRm(t, (u, p)))dΩ + ((∇ v) (Tc(u.cellfield) * Rc(u)))dΩ
30+
31+
#First VMS term
32+
B_VMS1(t, (u, p), (v, q)) = ((u ((v))') TRm(t, (u, p)))dΩ
33+
34+
#Second VMS term
35+
B_VMS2(t, (u, p), (v, q)) = -1 * (((v)) (outer(TRm(t, (u, p)), TRm(t, (u, p)))))dΩ
36+
37+
#Adding all the contributions
38+
Bᴹ(t, (u, p), (v, q)) = Bᴳ(t, (u, p), (v, q)) + B_SUPG(t, (u, p), (v, q)) + B_VMS1(t, (u, p), (v, q)) + B_VMS2(t, (u, p), (v, q))
39+
40+
res(t, (u, p), (v, q)) = Bᴹ(t, (u, p), (v, q))
41+
42+
#VMS Jacobian
43+
#Function used in the VMS terms - derivative
44+
dTRm((u, p), (du, dp), (v, q)) = Tm(u.cellfield)* dRm((u, p), (du, dp), (v, q)) #Derivative of the Function used in the second VMS term
45+
46+
#Variational equations - derivative
47+
dBᴳ(t, (u, p), (du, dp), (v, q)) = (((du (u)) v) + ((u (du)) v) + ((dp) v) + (q * (∇ du)))dΩ + ν * ((v) (du))dΩ
48+
49+
#SUPG terms derivative
50+
dB_SUPG(t, (u, p), (du, dp), (v, q)) = (((du (v)) TRm(t, (u, p))) + ((u (v) + (q)) dTRm((u, p), (du, dp), (v, q))) + ((∇ v) ( Tc(u.cellfield) .* dRc(du))))dΩ
51+
52+
#First VMS term derivative
53+
dB_VMS1(t, (u, p), (du, dp), (v, q)) = (((du (v)') TRm(t, (u, p))) + ((u (v)') dTRm((u, p), (du, dp), (v, q))))dΩ
54+
55+
56+
#Second VMS term derivative
57+
dB_VMS2(t, (u, p), (du, dp), (v, q)) = ((v) (outer(dTRm((u, p), (du, dp), (v, q)), TRm(t, (u, p)))))dΩ + ((v) (outer(TRm(t, (u, p)), dTRm((u, p), (du, dp), (v, q)))))dΩ
58+
59+
60+
#Adding all the contributions
61+
jac(t, (u, p), (du, dp), (v, q)) = dBᴳ(t, (u, p), (du, dp), (v, q)) + dB_SUPG(t, (u, p), (du, dp), (v, q)) + dB_VMS1(t, (u, p), (du, dp), (v, q)) - dB_VMS2(t, (u, p), (du, dp), (v, q))
62+
63+
#VMS time-Jacobian
64+
dtTRm(t, (u, p), (dut, dpt), (v, q)) = ( Tm(u.cellfield)) dut #Derivative of the Function used in the second VMS term
65+
66+
dtBᴳ(t, (u, p), (dut, dpt), (v, q)) = (dut v)dΩ
67+
dtB_SUPG(t, (u, p), (dut, dpt), (v, q)) = ((u (v) + (θvp)*(q)) dtTRm(t, (u, p), (dut, dpt), (v, q)))dΩ
68+
dtB_VMS1(t, (u, p), (dut, dpt), (v, q)) = ((u ((v))') dtTRm(t, (u, p), (dut, dpt), (v, q)))dΩ
69+
dtB_VMS2(t, (u, p), (dut, dpt), (v, q)) = (((v)) (outer(dtTRm(t, (u, p), (dut, dpt), (v, q)), TRm(t, (u, p)))))dΩ + (((v)) (outer(TRm(t, (u, p)), dtTRm(t, (u, p), (dut, dpt), (v, q)))))dΩ
70+
71+
jac_t(t, (u, p), (dut, dpt), (v, q)) = dtBᴳ(t, (u, p), (dut, dpt), (v, q)) + dtB_SUPG(t, (u, p), (dut, dpt), (v, q)) + dtB_VMS1(t, (u, p), (dut, dpt), (v, q)) - dtB_VMS2(t, (u, p), (dut, dpt), (v, q))
72+
73+
res, jac, jac_t
74+
75+
end
76+
77+
78+
79+

src/Commons/Equations/Equations.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ using GridapDistributed: Algebra
1414
using SegregatedVMSSolver.ParametersDef
1515

1616
export segregated_equations
17-
17+
export coupled_equations
1818

1919
include("StabilizationParameters.jl")
2020
include("StabilizationOperations.jl")
2121
include("StabilizedEquations.jl")
22+
include("CoupledEquations.jl")
2223

2324

2425
end

src/Commons/Equations/StabilizationOperations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function momentum_stabilization(uu, stab_coeff::TensorStabilization,simcase::Sim
4545
τ₂ = uu_new G uu_new
4646
return (τ₁ .+ τ₂ .+ τ₃) .^ (-1 / 2)
4747
end
48-
48+
4949
return τm (uu, G, GG)
5050

5151

src/Commons/Equations/StabilizedEquations.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@ function is_VMS(method::SUPG)
6262
return 0
6363
end
6464

65-
6665

src/Commons/ParametersDef/Params.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ end
8181
a_err_threshold::Int64=200 ### threshold to be satisfied:: norm(accelation_initial)/norm(acceleration_final) > a_err_threshold
8282
M::Int64=20 ## maximum number of internal iterations
8383
Number_Skip_Expansion::Int64=100 #number of initial time steps where is not used the Taylor-Expansion to compute the velocity field at the next time step, but simply the velcity field at the previous one.
84+
linear::Bool = true
8485
end
8586

8687

src/Commons/SolveNlin.jl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
module SolveNlin
2+
using Gridap
3+
using GridapDistributed
4+
using GridapPETSc
5+
using SparseArrays
6+
using PartitionedArrays
7+
using Parameters
8+
using Gridap.FESpaces
9+
10+
using SegregatedVMSSolver.ParametersDef
11+
using SegregatedVMSSolver.SolverOptions
12+
using SegregatedVMSSolver.CreateProblem
13+
using SegregatedVMSSolver.MatrixCreation
14+
using SegregatedVMSSolver.VectorsOperations
15+
using SegregatedVMSSolver.ExportUtility
16+
using SegregatedVMSSolver.Interfaces
17+
using SegregatedVMSSolver.Equations
18+
19+
export solve_nlin
20+
21+
function intialize_fields(U,P,V,Q)
22+
Y = MultiFieldFESpace([V, Q])
23+
X = TransientMultiFieldFESpace([U, P])
24+
return X,Y
25+
end
26+
27+
function initialize_solve(simcase::SimulationCase,params::Dict{Symbol,Any})
28+
@unpack trials,tests = params
29+
30+
@sunpack t0,dt,save_sim_dir = simcase
31+
32+
U,P = trials
33+
V,Q = tests
34+
35+
X,Y = intialize_fields(U,P,V,Q)
36+
37+
Ut0 = U(t0)
38+
Pt0 = P(t0)
39+
40+
Ut0_1 = U(t0+dt)
41+
Pt0_1 = P(t0+dt)
42+
43+
merge!(params, Dict(:Utn => Ut0, :Ptn => Pt0, :Utn1 => Ut0_1, :Ptn1 => Pt0_1))
44+
45+
46+
uh0, ph0 = create_initial_conditions(simcase,params)
47+
xh0 = interpolate_everywhere([uh0, ph0], X(t0))
48+
49+
50+
return xh0, X,Y
51+
52+
end
53+
54+
function solve_nlin(simcase::SimulationCase,params::Dict{Symbol,Any})
55+
xh0, X,Y = initialize_solve(simcase,params)
56+
57+
res, jac, jac_t = coupled_equations(params,simcase)
58+
59+
op = TransientFEOperator(res, jac, jac_t,X,Y)
60+
@sunpack t0,dt,tF,petsc_options,θ = simcase
61+
62+
GridapPETSc.with(args=split(petsc_options)) do
63+
64+
nls = PETScNonlinearSolver()
65+
66+
67+
ode_solver = ThetaMethod(nls,dt,θ)
68+
69+
nl_solution = solve(ode_solver, op,xh0, t0, tF)
70+
71+
for ((uh_tn,ph_tn), tn) in nl_solution
72+
println("Solution at time $(tn) computed")
73+
74+
end
75+
76+
end #end GridapPETSc
77+
78+
end
79+
80+
end #end module

src/Main.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using MPI
22
using SegregatedVMSSolver.ParametersDef
33
using SegregatedVMSSolver.CreateProblem
44
using SegregatedVMSSolver.SolveProblem
5+
using SegregatedVMSSolver.SolveNlin
56
using PartitionedArrays, Gridap, GridapDistributed
67

78
function solve(simcase::SimulationCase,backend::Function)
@@ -20,7 +21,12 @@ function solve(simcase::SimulationCase,backend::Function)
2021

2122
printstructure(simcase)
2223
params = setup_case(simcase,distribute)
23-
solve_case(params,simcase)
24+
if simcase.simulationp.solverp.linear
25+
solve_case(params,simcase)
26+
else
27+
solve_nlin(simcase,params)
28+
end
29+
2430
end
2531

2632
return true

src/SegregatedVMSSolver.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include(joinpath("Commons","MatrixCreation.jl"))
1717

1818

1919
include(joinpath("Commons","SolveProblem.jl"))
20+
include(joinpath("Commons","SolveNlin.jl"))
2021

2122
include("Main.jl")
2223

0 commit comments

Comments
 (0)