Skip to content

Commit 118c604

Browse files
authored
Merge pull request #16 from gridapapps/Code_refactoring
Code refactoring
2 parents 03f6af9 + e0343fb commit 118c604

17 files changed

+687
-1052
lines changed

.github/workflows/ci.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
version:
11+
- '1.5'
12+
os:
13+
- ubuntu-latest
14+
arch:
15+
- x64
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: julia-actions/setup-julia@v1
19+
with:
20+
version: ${{ matrix.version }}
21+
arch: ${{ matrix.arch }}
22+
- uses: actions/cache@v1
23+
env:
24+
cache-name: cache-artifacts
25+
with:
26+
path: ~/.julia/artifacts
27+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
28+
restore-keys: |
29+
${{ runner.os }}-test-${{ env.cache-name }}-
30+
${{ runner.os }}-test-
31+
${{ runner.os }}-
32+
- uses: julia-actions/julia-buildpkg@v1
33+
- uses: julia-actions/julia-runtest@v1
34+
- uses: julia-actions/julia-processcoverage@v1
35+
- uses: codecov/codecov-action@v1
36+
with:
37+
file: lcov.info
38+
39+
40+
41+
drivers:
42+
name: Drivers ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
43+
runs-on: ${{ matrix.os }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
version:
48+
- '1.5'
49+
os:
50+
- ubuntu-latest
51+
arch:
52+
- x64
53+
steps:
54+
- uses: actions/checkout@v2
55+
- uses: julia-actions/setup-julia@v1
56+
with:
57+
version: ${{ matrix.version }}
58+
arch: ${{ matrix.arch }}
59+
- uses: actions/cache@v1
60+
env:
61+
cache-name: cache-artifacts
62+
with:
63+
path: ~/.julia/artifacts
64+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
65+
restore-keys: |
66+
${{ runner.os }}-test-${{ env.cache-name }}-
67+
${{ runner.os }}-test-
68+
${{ runner.os }}-
69+
- uses: julia-actions/julia-buildpkg@v1
70+
- run: |
71+
julia --color=yes --project=. --check-bounds=yes --depwarn=error -e '
72+
using Pkg; Pkg.instantiate()'
73+
- run: |
74+
julia --color=yes --project=. --check-bounds=yes --depwarn=error -e '
75+
(1,) .== 1; cd("test"); include("runtests.jl")'
76+
docs:
77+
name: Documentation
78+
runs-on: ubuntu-latest
79+
steps:
80+
- uses: actions/checkout@v2
81+
- uses: julia-actions/setup-julia@v1
82+
with:
83+
version: '1.5'
84+
- run: |
85+
julia --project=docs -e '
86+
using Pkg
87+
Pkg.develop(PackageSpec(path=pwd()))
88+
Pkg.instantiate()'
89+
# - run: |
90+
# julia --project=docs -e '
91+
# using Documenter: doctest
92+
# using Gridap
93+
# doctest(Gridap)'
94+
- run: julia --project=docs docs/make.jl
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

models/elasticFlag.json

+1-1
Large diffs are not rendered by default.

models/elasticFlagFine.json

+1-1
Large diffs are not rendered by default.

models/elasticFlagFine_0.vtu

73 Bytes
Binary file not shown.

models/elasticFlagFine_1.vtu

73 Bytes
Binary file not shown.

models/elasticFlagFine_2.vtu

73 Bytes
Binary file not shown.

models/elasticFlag_coarse.json

+1-1
Large diffs are not rendered by default.

src/Drivers/Analytical.jl

+57-58
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function execute(problem::Problem{:analytical};kwargs...)
101101
d < 1.0e-8
102102
end
103103
oldcell_to_coods = get_cell_coordinates(trian)
104-
oldcell_to_is_in = collect1d(apply(is_in,oldcell_to_coods))
104+
oldcell_to_is_in = collect1d(lazy_map(is_in,oldcell_to_coods))
105105
incell_to_cell = findall(oldcell_to_is_in)
106106
outcell_to_cell = findall(collect(Bool, .! oldcell_to_is_in))
107107
model_solid = DiscreteModel(model,incell_to_cell)
@@ -132,16 +132,15 @@ function execute(problem::Problem{:analytical};kwargs...)
132132
# Quadratures
133133
println("Defining quadratures")
134134
order = _get_kwarg(:order,kwargs,2)
135-
order = _get_kwarg(:order,kwargs,2)
136-
quads = get_FSI_quadratures(Tₕ,order)
135+
dTₕ = get_FSI_measures(Tₕ,order)
137136

138137
# Test FE Spaces
139138
println("Defining FE spaces")
140139
Y_ST, X_ST, Y_FSI, X_FSI = get_FE_spaces(strategy,coupling,models,order,bconds,constraint=:zeromean)
141140

142141
# Stokes problem for initial solution
143142
println("Defining Stokes operator")
144-
op_ST = get_Stokes_operator([X_ST,Y_ST],strategy,Tₕ[:Ωf],quads[:Ωf],μ_f,fv_ST_Ωf(0.0))
143+
op_ST = get_Stokes_operator(X_ST,Y_ST,strategy,dTₕ[:Ωf],μ_f,fv_ST_Ωf(0.0))
145144

146145
# Setup equation parameters
147146
mesh_params = Dict{Symbol,Any}(
@@ -172,7 +171,7 @@ function execute(problem::Problem{:analytical};kwargs...)
172171

173172
# FSI problem
174173
println("Defining FSI operator")
175-
op_FSI = get_FSI_operator([X_FSI,Y_FSI],coupling,strategy,Tₕ,quads,params)
174+
op_FSI = get_FSI_operator(X_FSI,Y_FSI,coupling,strategy,Tₕ,dTₕ,params)
176175

177176
# Setup output files
178177
folderName = "fsi-results"
@@ -184,53 +183,53 @@ function execute(problem::Problem{:analytical};kwargs...)
184183

185184
# Solve Stokes problem
186185
@timeit "ST problem" begin
187-
println("Defining Stokes solver")
188-
xh = solve(op_ST)
189-
if(is_vtk)
190-
writePVD(filePath, Tₕ[:Ωf], [(xh, 0.0)])
186+
println("Defining Stokes solver")
187+
xh = solve(op_ST)
188+
if(is_vtk)
189+
writePVD(filePath, Tₕ[:Ωf], [(xh, 0.0)])
190+
end
191191
end
192-
end
193192

194-
# Compute Stokes solution L2-norm
195-
l2(w) = ww
196-
eu_ST = u(0.0) - restrict(xh[1],Tₕ[:Ωf])
197-
ev_ST = v(0.0) - restrict(xh[2],Tₕ[:Ωf])
198-
ep_ST = p(0.0) - restrict(xh[3],Tₕ[:Ωf])
199-
eul2_ST = sqrt(sum( integrate(l2(eu_ST),Tₕ[:Ωf],quads[:Ωf]) ))
200-
evl2_ST = sqrt(sum( integrate(l2(ev_ST),Tₕ[:Ωf],quads[:Ωf]) ))
201-
epl2_ST = sqrt(sum( integrate(l2(ep_ST),Tₕ[:Ωf],quads[:Ωf]) ))
202-
println("Stokes L2-norm u: ", eul2_ST)
203-
println("Stokes L2-norm v: ", evl2_ST)
204-
println("Stokes L2-norm p: ", epl2_ST)
205-
@test eul2_ST < 1.0e-10
206-
@test evl2_ST < 1.0e-10
207-
@test epl2_ST < 1.0e-10
193+
# Compute Stokes solution L2-norm
194+
l2(w) = ww
195+
eu_ST = u(0.0) - xh[1]
196+
ev_ST = v(0.0) - xh[2]
197+
ep_ST = p(0.0) - xh[3]
198+
eul2_ST = sqrt(( (l2(eu_ST))dTₕ[:Ωf] ))
199+
evl2_ST = sqrt(( (l2(ev_ST))dTₕ[:Ωf] ))
200+
epl2_ST = sqrt(( (l2(ep_ST))dTₕ[:Ωf] ))
201+
println("Stokes L2-norm u: ", eul2_ST)
202+
println("Stokes L2-norm v: ", evl2_ST)
203+
println("Stokes L2-norm p: ", epl2_ST)
204+
@test eul2_ST < 1.0e-10
205+
@test evl2_ST < 1.0e-10
206+
@test epl2_ST < 1.0e-10
208207

209-
# Solve FSI problem
210-
@timeit "FSI problem" begin
211-
println("Defining FSI solver")
212-
xh0 = interpolate_everywhere([u(0.0),v(0.0),p(0.0)],X_FSI(0.0))
213-
nls = NLSolver(
214-
show_trace = true,
215-
method = :newton,
216-
linesearch = BackTracking(),
217-
ftol = 1.0e-10,
218-
iterations = 50
219-
)
220-
odes = ThetaMethod(nls, dt, 0.5)
221-
solver = TransientFESolver(odes)
222-
xht = solve(solver, op_FSI, xh0, t0, tf)
223-
end
208+
# Solve FSI problem
209+
@timeit "FSI problem" begin
210+
println("Defining FSI solver")
211+
xh0 = interpolate_everywhere([u(0.0),v(0.0),p(0.0)],X_FSI(0.0))
212+
nls = NLSolver(
213+
show_trace = true,
214+
method = :newton,
215+
linesearch = BackTracking(),
216+
ftol = 1.0e-10,
217+
iterations = 50
218+
)
219+
odes = ThetaMethod(nls, dt, 0.5)
220+
solver = TransientFESolver(odes)
221+
xht = solve(solver, op_FSI, xh0, t0, tf)
222+
end
224223

225-
# Compute outputs
226-
out_params = Dict(
227-
:u=>u,
228-
:v=>v,
229-
:p=>p,
230-
:filePath=>filePath,
231-
:is_vtk=>is_vtk
232-
)
233-
output = computeOutputs(xht,Tₕ,quads,strategy,out_params)
224+
# Compute outputs
225+
out_params = Dict(
226+
:u=>u,
227+
:v=>v,
228+
:p=>p,
229+
:filePath=>filePath,
230+
:is_vtk=>is_vtk
231+
)
232+
output = computeOutputs(xht,Tₕ,dTₕ,strategy,out_params)
234233

235234
end
236235

@@ -305,7 +304,7 @@ function get_FE_spaces(problem::Problem{:analytical},strategy::WeakForms.MeshStr
305304
)
306305
end
307306

308-
function computeOutputs(xht,Tₕ,quads,strategy,params)
307+
function computeOutputs(xht,Tₕ,dTₕ,strategy,params)
309308

310309
# Unpack parameters
311310
u = params[:u]
@@ -326,18 +325,18 @@ function computeOutputs(xht,Tₕ,quads,strategy,params)
326325
println("============================")
327326

328327
# Compute errors
329-
eu = u(t) - restrict(xh[1],Tₕ[])
330-
ev = v(t) - restrict(xh[2],Tₕ[])
331-
ep = p(t) - restrict(xh[3],Tₕ[])
332-
eul2 = sqrt(sum( integrate(l2(eu),Tₕ[],quads[] )))
333-
evl2 = sqrt(sum( integrate(l2(ev),Tₕ[],quads[] )))
334-
epl2 = sqrt(sum( integrate(l2(ep),Tₕ[],quads[] )))
328+
eu = u(t) - xh[1]
329+
ev = v(t) - xh[2]
330+
ep = p(t) - xh[3]
331+
eul2 = sqrt(( (l2(eu))dTₕ[] ))
332+
evl2 = sqrt(( (l2(ev))dTₕ[] ))
333+
epl2 = sqrt(( (l2(ep))dTₕ[] ))
335334

336335
# Write to PVD
337336
if(is_vtk)
338-
uh = restrict(xh[1],Tₕ[])
339-
vh = restrict(xh[2],Tₕ[])
340-
ph = restrict(xh[3],Tₕ[])
337+
uh = xh[1]
338+
vh = xh[2]
339+
ph = xh[3]
341340
pvd[t] = createvtk(
342341
Tₕ[],
343342
filePath * "_$t.vtu",

src/Drivers/ElasticFlag.jl

+13-30
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function execute(problem::Problem{:elasticFlag}; kwargs...)
8282
println("Defining discrete model")
8383
modelName = _get_kwarg(:model,kwargs,"../models/elasticFlag.json")
8484
model = DiscreteModelFromFile(modelName)
85-
model_solid = DiscreteModel(model,"solid")
86-
model_fluid = DiscreteModel(model,"fluid")
85+
model_solid = DiscreteModel(model,tags="solid")
86+
model_fluid = DiscreteModel(model,tags="fluid")
8787
models = Dict( => model, :Ωf => model_fluid, :Ωs => model_solid)
8888

8989
# Triangulations
@@ -93,15 +93,15 @@ function execute(problem::Problem{:elasticFlag}; kwargs...)
9393
# Quadratures
9494
println("Defining quadratures")
9595
order = _get_kwarg(:order,kwargs,2)
96-
quads = get_FSI_quadratures(Tₕ,order)
96+
dTₕ = get_FSI_measures(Tₕ,order)
9797

9898
# Test FE Spaces
9999
println("Defining FE spaces")
100100
Y_ST, X_ST, Y_FSI, X_FSI = get_FE_spaces(strategy,coupling,models,order,bconds)
101101

102102
# Stokes problem for initial solution
103103
println("Defining Stokes operator")
104-
op_ST = get_Stokes_operator([X_ST,Y_ST],strategy,Tₕ[:Ωf],quads[:Ωf],μ_f,f(0.0))
104+
op_ST = get_Stokes_operator(X_ST,Y_ST,strategy,dTₕ[:Ωf],μ_f,f(0.0))
105105

106106
# Setup equation parameters
107107
mesh_params = Dict{Symbol,Any}(
@@ -132,7 +132,7 @@ function execute(problem::Problem{:elasticFlag}; kwargs...)
132132

133133
# FSI problem
134134
println("Defining FSI operator")
135-
op_FSI = get_FSI_operator([X_FSI,Y_FSI],coupling,strategy,Tₕ,quads,params)
135+
op_FSI = get_FSI_operator(X_FSI,Y_FSI,coupling,strategy,Tₕ,dTₕ,params)
136136

137137
# Setup output files
138138
folderName = "fsi-results"
@@ -178,7 +178,7 @@ out_params = Dict{Symbol,Any}(
178178
:filePath=>filePath,
179179
:is_vtk=>is_vtk,
180180
)
181-
output = computeOutputs(xh0,xht,coupling,strategy,models,Tₕ,quads,out_params)
181+
output = computeOutputs(xh0,xht,coupling,strategy,models,Tₕ,dTₕ,out_params)
182182

183183
end
184184

@@ -248,12 +248,12 @@ function computeOutputs(xh0,xht,coupling::WeakForms.Coupling,strategy::WeakForms
248248
end
249249

250250
## Surface triangulation
251-
trian_Γc = BoundaryTriangulation(models[], "cylinder")
252-
quad_Γc = CellQuadrature(trian_Γc, bdegree)
253-
n_Γc = get_normal_vector(trian_Γc)
251+
Γc = BoundaryTriangulation(models[], tags="cylinder")
252+
dΓc = Measure(Γc, bdegree)
253+
n_Γc = get_normal_vector(Γc)
254254

255255
# Aux function
256-
traction_boundary(n,u,v,p) = n WeakForms.Pf_dev(μ,u,v) + WeakForms.Pf_vol(u,p) * n
256+
traction_boundary(n,u,v,p) = n WeakForms.Pᵥ_Ωf(μ,u,v) + WeakForms.Pₚ_Ωf(u,p) * n
257257
function traction_closure(coupling,n,u,v,p)
258258
if typeof(coupling) == WeakForms.Coupling{:weak}
259259
traction_boundary(n,u,v,p).⁺
@@ -285,30 +285,13 @@ function computeOutputs(xh0,xht,coupling::WeakForms.Coupling,strategy::WeakForms
285285
uh = xh[uvpindex[1]]
286286
vh = xh[uvpindex[2]]
287287
ph = xh[uvpindex[3]]
288-
uh_Γc = restrict(uh, trian_Γc)
289-
vh_Γc = restrict(vh, trian_Γc)
290-
ph_Γc = restrict(ph, trian_Γc)
291-
uhn_Γc = restrict(uhn, trian_Γc)
292-
vhn_Γc = restrict(vhn, trian_Γc)
293-
phn_Γc = restrict(phn, trian_Γc)
294-
uhθ_Γc = θ*uh_Γc + (1.0-θ)*uhn_Γc
295-
vhθ_Γc = θ*vh_Γc + (1.0-θ)*vhn_Γc
296-
phθ_Γc = θ*ph_Γc + (1.0-θ)*phn_Γc
297-
uh_Γi = restrict(uh, Tₕ[:Γi])
298-
vh_Γi = restrict(vh, Tₕ[:Γi])
299-
ph_Γi = restrict(ph, Tₕ[:Γi])
300-
uhn_Γi = restrict(uhn, Tₕ[:Γi])
301-
vhn_Γi = restrict(vhn, Tₕ[:Γi])
302-
phn_Γi = restrict(phn, Tₕ[:Γi])
303-
uhθ_Γi = θ*uh_Γi + (1.0-θ)*uhn_Γi
304-
vhθ_Γi = θ*vh_Γi + (1.0-θ)*vhn_Γi
305-
phθ_Γi = θ*ph_Γi + (1.0-θ)*phn_Γi
288+
(xₙ₊₁,xₙ) = θ*xₙ₊₁ + (1-θ)*xₙ
306289

307290
# Integrate on the cylinder
308-
FDc, FLc = sum(integrate(traction_boundary(n_Γc,uhθ_Γc,vhθ_Γc,phθ_Γc), trian_Γc, quad_Γc))
291+
FDc, FLc = ((traction_boundary(n_Γc,(uh,uhn),(vh,vhn),(ph,phn)) )dΓc )
309292

310293
# Integrate on the interface
311-
FDi, FLi = sum(integrate(traction_interface(n_Γi,uhθ_Γi,vhθ_Γi,phθ_Γi), Tₕ[:Γi], quads[:Γi]))
294+
FDi, FLi = ((traction_boundary(n_Γc,(uh,uhn),(vh,vhn),(ph,phn)) )dΓc )
312295

313296
FD = FDc + FDi
314297
FL = FLc + FLi

0 commit comments

Comments
 (0)