its now possible to define several pre and postprocessors for assemblies with custom arguments; see test/test_mortar_2d_contact.jl for concrete example

This commit is contained in:
Jukka Aho
2016-01-01 20:34:10 +02:00
parent 06a926bd70
commit 42254e73ad
4 changed files with 112 additions and 33 deletions
+6 -8
View File
@@ -64,11 +64,11 @@ function assemble(problem::AllProblems, elrange::UnitRange{Int64}, time::Real, o
end
""" Run preprocess for assembly. """
function preprocess_assembly!
function assemble_preprocess!
end
""" Run postprocess for assembly. """
function postprocess_assembly!
function assemble_postprocess!
end
function assemble(problem::AllProblems, time::Real, nchunks=10)
@@ -77,9 +77,8 @@ function assemble(problem::AllProblems, time::Real, nchunks=10)
slices = [kk[j]+1:kk[j+1] for j=1:nchunks]
assembly = new_assembly(typeof(problem))
args = Tuple{typeof(assembly), typeof(problem), Real}
if method_exists(preprocess_assembly!, args)
preprocess_assembly!(assembly, problem, time)
for (preprocessor, args, kwargs) in problem.preprocessors
assemble_preprocess!(assembly, problem, time, Val{preprocessor}, args...; kwargs...)
end
for (j, elrange) in enumerate(slices)
@@ -90,9 +89,8 @@ function assemble(problem::AllProblems, time::Real, nchunks=10)
end
end
args = Tuple{typeof(assembly), typeof(problem), Real}
if method_exists(postprocess_assembly!, args)
postprocess_assembly!(assembly, problem, time)
for (postprocessor, args, kwargs) in problem.postprocessors
assemble_postprocess!(assembly, problem, time, Val{postprocessor}, args...; kwargs...)
end
return assembly
+6 -2
View File
@@ -34,6 +34,10 @@ function DirectSolver(name="DirectSolver")
)
end
function set_name!(solver::DirectSolver, name::ASCIIString)
solver.name = name
end
function set_linear_system_solver!(solver::DirectSolver, method::Symbol)
solver.linear_system_solvers = Vector{Symbol}([method])
end
@@ -262,7 +266,7 @@ function call(solver::DirectSolver, time::Real=0.0)
last(element["reaction force"]).data = local_sol # <-- replaced
# FIXME: Quick and dirty, updating dirichlet boundary problem
# is causing drifting and convergence issue
if typeof(boundary_problem) <: BoundaryProblem{DirichletProblem{StandardBasis}}
if typeof(boundary_problem) <: BoundaryProblem{DirichletProblem}
# info("skipping dirichlet problem update")
continue
end
@@ -288,7 +292,7 @@ function call(solver::DirectSolver, time::Real=0.0)
if (norm(sol) < solver.nonlinear_convergence_tolerance)
toc(timing, "solver")
info("converged! solver finished in ", time_elapsed(timing, "solver"), " seconds.")
info("converged in $iter iterations! solver finished in ", time_elapsed(timing, "solver"), " seconds.")
return (iter, true)
end
+17 -4
View File
@@ -7,6 +7,8 @@ type FieldProblem{T<:AbstractProblem}
name :: ASCIIString
dim :: Int
elements :: Vector{Element}
preprocessors :: Vector{Tuple{Symbol,Any,Any}}
postprocessors :: Vector{Tuple{Symbol,Any,Any}}
end
type BoundaryProblem{T<:AbstractProblem}
@@ -15,6 +17,8 @@ type BoundaryProblem{T<:AbstractProblem}
parent_field_dim :: Int
dim :: Int
elements :: Vector{Element}
preprocessors :: Vector{Tuple{Symbol,Any,Any}}
postprocessors :: Vector{Tuple{Symbol,Any,Any}}
end
""" Construct new field problem.
@@ -26,8 +30,8 @@ Create vector-valued (dim=3) elasticity problem:
julia> prob = FieldProblem(ElasticityProblem, "this is my problem", 3)
"""
function FieldProblem(problem_type::DataType, name::ASCIIString, dim::Int, elements=[])
FieldProblem{problem_type}(name, dim, elements)
function FieldProblem(problem_type::DataType, name::ASCIIString, dim::Int, elements=[], preprocessors=[], postprocessors=[])
FieldProblem{problem_type}(name, dim, elements, preprocessors, postprocessors)
end
@@ -40,8 +44,17 @@ Create Dirichlet boundary problem for vector-valued (dim=3) elasticity problem.
julia> bc1 = FieldProblem(DirichletProblem, "support dy=0", "displacement", 3)
"""
function BoundaryProblem(problem_type::DataType, name::ASCIIString, parent_field_name::ASCIIString, parent_field_dim::Int, dim::Int=1, elements=[])
BoundaryProblem{problem_type}(name, parent_field_name, parent_field_dim, dim, elements)
function BoundaryProblem(problem_type::DataType, name::ASCIIString, parent_field_name::ASCIIString, parent_field_dim::Int, dim::Int=1, elements=[], preprocessors=[], postprocessors=[])
BoundaryProblem{problem_type}(name, parent_field_name, parent_field_dim, dim, elements, preprocessors, postprocessors)
end
function add_postprocessor!(problem::Union{FieldProblem, BoundaryProblem}, postprocessor_name::Symbol, args...; kwargs...)
push!(problem.postprocessors, (postprocessor_name, args, kwargs))
end
function add_preprocessor!(problem::Union{FieldProblem, BoundaryProblem}, postprocessor_name::Symbol, args...; kwargs...)
push!(problem.preprocessors, (postprocessor_name, args, kwargs))
end
typealias Problem FieldProblem