diff --git a/src/interfaces.jl b/src/interfaces.jl index c641a84..e01e362 100644 --- a/src/interfaces.jl +++ b/src/interfaces.jl @@ -5,19 +5,87 @@ using JuliaFEM.Core using JuliaFEM.API: Model """ -This needs this a bit honing ... +Function for creating solver and all the necessary components +for the calculation """ function get_solver(model::Model, case_name::ASCIIString, time::Float64) - element_ids = keys(model.elements) - all_elements = model.elements case = model.load_cases[case_name] - neumann_bcs = case.neumann_boundary_conditions - dirichlet_bcs = case.dirichlet_boundary_conditions - nodes = model.nodes - field_problem = JuliaFEM.Core.(case.problem)() - core_elements = Dict() + + # Create core elements + core_elements = create_core_elements(model) + + # Add Neumann boundary conditions to elements + add_neumann_bcs!(model, case, core_elements) - # luodaan core elementit + # Create Dirichlet boundary conditions + dirichlet_arr = create_dirichlet_bcs(model, case, core_elements) + + # Create solver + solver = create_solver(model, case, + core_elements, dirichlet_arr) + return solver +end + +""" +""" +function create_solver(model, case, core_elements, dirichlet_arr) + field_problem = JuliaFEM.Core.(case.problem)() + all_elsets = model.elsets + + # Pushing all the defined element sets into the calculation + for element_set in case.sets + el_ids = all_elsets[element_set].elements + for each in el_ids + push!(field_problem, core_elements[each]) + end + end + + # Creating the solver and pushing problems and + # boundary conditions + if case.solver == :LinearSolver + solver = JuliaFEM.Core.(case.solver)(field_problem, + dirichlet_arr...) + else + solver = JuliaFEM.Core.(case.solver)() + push!(solver, field_problem) + push!(solver, dirichlet_arr...) + end + solver +end + +""" +""" +function create_dirichlet_bcs(model, case, core_elements) + dirichlet_arr = Any[] + dirichlet_bcs = case.dirichlet_boundary_conditions + elsets = model.elsets + field_problem = JuliaFEM.Core.(case.problem)() + for each in dirichlet_bcs + set_name = each.set_name + value = each.value + problem = JuliaFEM.Core.DirichletProblem( + JuliaFEM.Core.get_unknown_field_name(field_problem), + JuliaFEM.Core.get_unknown_field_dimension(field_problem)) + set_for_bc = each.set_name + set_ids = elsets[set_for_bc] + bc = each.value + for el_id in set_ids.elements + core_element = core_elements[el_id] + core_element[bc[1]] = bc[2] + push!(problem, core_element) + end + push!(dirichlet_arr, problem) + end + dirichlet_arr +end + +""" +""" +function create_core_elements(model) + core_elements = Dict() + nodes = model.nodes + all_elements = model.elements + element_ids = keys(all_elements) for el_id in element_ids element = all_elements[el_id] el_type = element.element_type @@ -32,59 +100,34 @@ function get_solver(model::Model, case_name::ASCIIString, time::Float64) core_elements[el_id] = core_element model.elements[el_id].results = core_element end - - # Add Neumann boundary conditions to elements + core_elements +end + +""" +""" +function add_neumann_bcs!(model, case, core_elements) + neumann_bcs = case.neumann_boundary_conditions + elsets = model.elsets for each in neumann_bcs set_for_bc = each.set_name - set_ids = model.elsets[set_for_bc] + set_ids = elsets[set_for_bc] bc = each.value for el_id in set_ids.elements core_element = core_elements[el_id] core_element[bc[1]] = bc[2] end - end - dirile_arr = Any[] - # Create Dirichlet boundary conditions - for each in dirichlet_bcs - set_name = each.set_name - value = each.value - problem = JuliaFEM.Core.DirichletProblem( - JuliaFEM.Core.get_unknown_field_name(field_problem), - JuliaFEM.Core.get_unknown_field_dimension(field_problem)) - set_for_bc = each.set_name - set_ids = model.elsets[set_for_bc] - bc = each.value - for el_id in set_ids.elements - core_element = core_elements[el_id] - core_element[bc[1]] = bc[2] - push!(problem, core_element) - end - push!(dirile_arr, problem) - end - - # Push all the elements, where the field problem is solved into the field_problem - for element_set in case.sets - el_ids = model.elsets[element_set].elements - for each in el_ids - push!(field_problem, core_elements[each]) + if !(set_for_bc in case.sets) + push!(case.sets, set_for_bc) end end - - # Creating the solver - if case.solver == :LinearSolver - solver = JuliaFEM.Core.(case.solver)(field_problem, dirile_arr...) - else - solver = JuliaFEM.Core.(case.solver)() - push!(solver, field_problem) - for d in dirile_arr - push!(solver, d) - end - end - return solver end +""" +""" function solve!(model::Model, case_name::ASCIIString, time::Float64) + # Create solver solver = get_solver(model, case_name, time) - # Solving + + # Solve problem at given time solver(time) end