Skip to content

Commit

Permalink
Adding a timer in example001
Browse files Browse the repository at this point in the history
  • Loading branch information
fverdugo committed Feb 6, 2024
1 parent a7ce4bb commit 6ee2ed2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
1 change: 1 addition & 0 deletions extensions/GalerkinToolkitExamples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[extras]
Expand Down
58 changes: 33 additions & 25 deletions extensions/GalerkinToolkitExamples/src/example001.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@ using LinearAlgebra
using SparseArrays
using WriteVTK
using PartitionedArrays: JaggedArray
using TimerOutputs

# This one implements a vanilla sequential iso-parametric Poisson solver by only
# using the mesh interface.

function main(params_in)

timer = TimerOutput()

# Process params
params_default = default_params()
params = add_default_params(params_in,params_default)
results = Dict{Symbol,Any}()

# Setup main data structures
state = setup(params)
@timeit timer "setup" state = setup(params,timer)
add_basic_info(results,params,state)

# Assemble system and solve it
A,b = assemble_system(state)
x = solve_system(A,b,params)
@timeit timer "assemble_system" A,b = assemble_system(state)
@timeit timer "solve_system" x = solve_system(A,b,params,state)

# Post process
uh = setup_uh(x,state)
integrate_error_norms(results,uh,state)
export_results(uh,params,state)
@timeit timer "setup_uh" uh = setup_uh(x,state)
@timeit timer "integrate_error_norms" integrate_error_norms(results,uh,state)
@timeit timer "export_results" export_results(uh,params,state)

display(timer)

results
end
Expand Down Expand Up @@ -165,17 +170,17 @@ function setup_dofs(params,dirichlet_bcs,cell_isomap,face_isomap)
dofs
end

function setup(params)
dirichlet_bcs = setup_dirichlet_bcs(params)
neumann_bcs = setup_neumann_bcs(params)
cell_integration = setup_integration(params,:cells)
face_integration = setup_integration(params,:faces)
cell_isomap = setup_isomap(params,cell_integration)
face_isomap = setup_isomap(params,face_integration)
dofs = setup_dofs(params,dirichlet_bcs,cell_isomap,face_isomap)
user_funs = setup_user_funs(params)
function setup(params,timer)
@timeit timer "dirichlet_bcs" dirichlet_bcs = setup_dirichlet_bcs(params)
@timeit timer "neumann_bcs" neumann_bcs = setup_neumann_bcs(params)
@timeit timer "cell_integration" cell_integration = setup_integration(params,:cells)
@timeit timer "face_integration" face_integration = setup_integration(params,:faces)
@timeit timer "cell_isomap" cell_isomap = setup_isomap(params,cell_integration)
@timeit timer "face_isomap" face_isomap = setup_isomap(params,face_integration)
@timeit timer "dofs" dofs = setup_dofs(params,dirichlet_bcs,cell_isomap,face_isomap)
@timeit timer "user_funs" user_funs = setup_user_funs(params)
solver = params[:solver]
state = (;solver,dirichlet_bcs,neumann_bcs,cell_integration,cell_isomap,face_integration,face_isomap,user_funs,dofs)
state = (;timer,solver,dirichlet_bcs,neumann_bcs,cell_integration,cell_isomap,face_integration,face_isomap,user_funs,dofs)
end

function add_basic_info(results,params,state)
Expand All @@ -192,17 +197,19 @@ function add_basic_info(results,params,state)
end

function assemble_system(state)
args = assemble_sytem_coo(state)
timer = state.timer
@timeit timer "assemble_sytem" args = assemble_sytem_coo(state)
I,J,V,b = args
n_dofs = state.dofs.n_dofs
A = sparse(I,J,V,n_dofs,n_dofs)
@timeit timer "sparse" A = sparse(I,J,V,n_dofs,n_dofs)
A,b
end

function assemble_sytem_coo(state)
args = assemble_sybmolic(state)
assemble_numeric_cells!(args...,state)
assemble_numeric_faces!(args...,state)
timer = state.timer
@timeit timer "assemble_sybmolic" args = assemble_sybmolic(state)
@timeit timer "assemble_numeric_cells!" assemble_numeric_cells!(args...,state)
@timeit timer "assemble_numeric_faces!" assemble_numeric_faces!(args...,state)
args
end

Expand Down Expand Up @@ -398,12 +405,13 @@ function assemble_numeric_faces!(I_coo,J_coo,V_coo,b,state)
end
end

function solve_system(A,b,params)
function solve_system(A,b,params,state)
timer = state.timer
solver = params[:solver]
x = similar(b,axes(A,2))
setup = solver.setup(x,A,b)
solver.solve!(x,setup,b)
solver.finalize!(setup)
@timeit timer "solver.setup" setup = solver.setup(x,A,b)
@timeit timer "solver.solve!" solver.solve!(x,setup,b)
@timeit timer "solver.finalize!" solver.finalize!(setup)
x
end

Expand Down
9 changes: 6 additions & 3 deletions extensions/GalerkinToolkitExamples/src/example002.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ using LinearAlgebra
using SparseArrays
using WriteVTK
using PartitionedArrays
using TimerOutputs

function main(params_in)

timer = TimerOutput()

# Dict to collect results
results = Dict{Symbol,Any}()

Expand All @@ -19,7 +22,7 @@ function main(params_in)
params = add_default_params(params_in,params_default)

# Setup main data structures
state = setup(params)
state = setup(params,timer)
add_basic_info(results,params,state)

# Assemble system and solve it
Expand Down Expand Up @@ -61,12 +64,12 @@ function default_params()
params
end

function setup(params)
function setup(params,timer)
mesh = params[:mesh]
local_states = map(partition(mesh)) do mesh
local_params = copy(params)
local_params[:mesh] = mesh
Example001.setup(local_params)
Example001.setup(local_params,timer)
end

node_partition = gk.node_partition(mesh)
Expand Down
5 changes: 5 additions & 0 deletions extensions/GalerkinToolkitExamples/test/example001_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ results = Example001.main(params)
@test results[:eh1] < tol
@test results[:el2] < tol

params = Dict{Symbol,Any}()
params[:mesh] = gk.cartesian_mesh((0,3,0,2,0,1),(30,30,30))
results = Example001.main(params)
@test results[:eh1] < tol
@test results[:el2] < tol

end # module

0 comments on commit 6ee2ed2

Please sign in to comment.