Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/electrodynamic_formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ add_constraint!(functionspace, "vn2", "EdgesOf", "ZeroElectricScalarPotential";
condition="If (Flag_Degree_v == 2)",
endCondition="EndIf")

problem.functionspace = functionspace
# problem.functionspace = functionspace
push!(problem.functionspace, functionspace)

# Formulation section
formulation = Formulation()
Expand All @@ -36,7 +37,8 @@ eq = add_equation!(form)
add!(eq, "Galerkin", "[ sigma[] * Dof{d v} , {d v} ]", In="Domain_Ele", Jacobian="Vol", Integration="I1")
add!(eq, "Galerkin", "DtDof[ epsilon[] * Dof{d v} , {d v} ]", In="Domain_Ele", Jacobian="Vol", Integration="I1")

problem.formulation = formulation
# problem.formulation = formulation
push!(problem.formulation, formulation)

# Resolution section
resolution = Resolution()
Expand All @@ -53,7 +55,8 @@ add!(resolution, "Electrodynamics", "Sys_Ele",
"PostOperation[Ele_Cuts]"
])

problem.resolution = resolution
# problem.resolution = resolution
push!(problem.resolution, resolution)

## PostProcessing section
postprocessing = PostProcessing()
Expand Down Expand Up @@ -97,7 +100,8 @@ add!(q, "Term", "V0 * F_Cos_wt_p[]{2*Pi*Freq, Pc}"; Type="Global", In="Ind_3")
q = add!(pp, "C_from_Energy")
add!(q, "Term", "2*\$We/SquNorm[\$voltage]"; Type="Global", In="DomainDummy")

problem.postprocessing = postprocessing
# problem.postprocessing = postprocessing
push!(problem.postprocessing, postprocessing)

# PostOperation section
postoperation = PostOperation()
Expand Down Expand Up @@ -133,7 +137,8 @@ op2 = add_operation!(po2)
add_operation!(op2, "Print[ em, OnLine { {x2,y2,0} {x2+dc/2+ti+txlpe+to+tapl,y2,0} } {100}, Name \"|E| [V/m] cut in phase 2\", File \"res/em_cut.pos\" ]")
add_operation!(op2, "Echo[Str[\"View[PostProcessing.NbViews-1].Type = 4;\",\n \"View[PostProcessing.NbViews-1].Axes = 3;\",\n \"View[PostProcessing.NbViews-1].AutoPosition = 3;\",\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].LineWidth = 3;\",\n \"View[PostProcessing.NbViews-1].NbIso = 5;\"],\n File \"res/em_cut.opt\" ]")

problem.postoperation = postoperation
# problem.postoperation = postoperation
push!(problem.postoperation, postoperation)

# Generate and write the .pro file
make_file!(problem)
Expand Down
11 changes: 6 additions & 5 deletions examples/problem_definition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ add!(group, "DomainDummy", [12345], "Region")
# add_space!(group)

# Assign Group to Problem
problem.group = group
push!(problem.group, group)

# Add the second Function definition
func2 = GetDP.Function() # Use qualified name as established previously
Expand Down Expand Up @@ -389,8 +389,9 @@ add_constant!(func2, "Flag_Degree_v", "1")

add_space!(func2)

problem.function_obj = [func1, func2]

# problem.function_obj = [func1, func2]
push!(problem.function_obj, func1)
push!(problem.function_obj, func2)
# Add the Constraint definition
constraint = GetDP.Constraint()

Expand Down Expand Up @@ -428,8 +429,8 @@ case!(current, "Ind_2", value="I", time_function="F_Cos_wt_p[]{2*Pi*Freq, Pb}")
case!(current, "Ind_3", value="I", time_function="F_Cos_wt_p[]{2*Pi*Freq, Pc}")

# Assign Constraint to Problem
problem.constraint = constraint

# problem.constraint = constraint
push!(problem.constraint, constraint)
# Generate and write the .pro file
make_file!(problem)

Expand Down
121 changes: 65 additions & 56 deletions src/problem_definition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ using Dates
"""
Problem

The main problem definition class that brings together all the components.
A classe principal de definição de problema que reúne todos os componentes.
"""
mutable struct Problem
_GETDP_CODE::Vector{String}
filename::Union{String,Nothing}
group::Group
group::Vector{Group}
function_obj::Vector{Function}
constraint::Constraint
functionspace::FunctionSpace
jacobian::Jacobian
integration::Integration
formulation::Formulation
resolution::Resolution
postprocessing::PostProcessing
postoperation::PostOperation
constraint::Vector{Constraint}
functionspace::Vector{FunctionSpace}
jacobian::Vector{Jacobian}
integration::Vector{Integration}
formulation::Vector{Formulation}
resolution::Vector{Resolution}
postprocessing::Vector{PostProcessing}
postoperation::Vector{PostOperation}
objects::Vector{String}

function Problem(; gmsh_major_version=nothing)
version = GetDP.VERSION
_GETDP_CODE = ["// This code was created by GetDP.jl v$(version).\n"]

group = Group()
function_obj = Function[] # Initialize as empty vector
constraint = Constraint()
functionspace = FunctionSpace()
jacobian = Jacobian()
integration = Integration()
formulation = Formulation()
resolution = Resolution()
postprocessing = PostProcessing()
postoperation = PostOperation()
group = Group[]
function_obj = Function[]
constraint = Constraint[]
functionspace = FunctionSpace[]
jacobian = Jacobian[]
integration = Integration[]
formulation = Formulation[]
resolution = Resolution[]
postprocessing = PostProcessing[]
postoperation = PostOperation[]

objects = [
"group",
Expand Down Expand Up @@ -74,7 +74,7 @@ end
"""
get_code(problem::Problem)

Returns properly formatted GetDP code.
Retorna o código GetDP formatado adequadamente.
"""
function get_code(problem::Problem)
return join(problem._GETDP_CODE, "")
Expand All @@ -83,7 +83,7 @@ end
"""
add_raw_code!(problem::Problem, raw_code, newline=true)

Add raw code to the Problem object.
Adiciona código bruto ao objeto Problem.
"""
function add_raw_code!(problem::Problem, raw_code, newline=true)
problem._GETDP_CODE = [add_raw_code(get_code(problem), raw_code, newline)]
Expand All @@ -92,7 +92,7 @@ end
"""
add_comment!(problem::Problem, comment_text, newline=true)

Add a comment to the Problem object.
Adiciona um comentário ao objeto Problem.
"""
function add_comment!(problem::Problem, comment_text, newline=true)
add_raw_code!(problem, comment(comment_text; newline=false), newline)
Expand All @@ -101,60 +101,70 @@ end
"""
make_file!(problem::Problem)

Generate the GetDP code for all objects in the Problem, including only non-empty components.
Gera o código GetDP para todos os objetos no Problem, incluindo apenas componentes não vazios.
"""
function make_file!(problem::Problem)
for attr in problem.objects
components = getfield(problem, Symbol(attr))
if attr == "function_obj"
for func in problem.function_obj # Iterate over all Function objects
if !isempty(func.content) # Check if functions are defined
for func in components
if !isempty(func.content)
push!(problem._GETDP_CODE, code(func))
end
end
elseif attr == "group"
p = getfield(problem, :group)
if !isempty(p.content) # Check if groups are defined
push!(problem._GETDP_CODE, code(p))
for grp in components
if !isempty(grp.content)
push!(problem._GETDP_CODE, code(grp))
end
end
elseif attr == "constraint"
p = getfield(problem, :constraint)
if !isempty(p.constraints) # Check if constraints are defined
push!(problem._GETDP_CODE, code(p))
for constr in components
if !isempty(constr.constraints)
push!(problem._GETDP_CODE, code(constr))
end
end
elseif attr == "functionspace"
p = getfield(problem, :functionspace)
if !isempty(p.content) # Check if items are defined
push!(problem._GETDP_CODE, code(p))
for fs in components
if !isempty(fs.content)
push!(problem._GETDP_CODE, code(fs))
end
end
elseif attr == "jacobian"
p = getfield(problem, :jacobian)
if !isempty(p.content) # Check if jacobians are defined
push!(problem._GETDP_CODE, code(p))
for jac in components
if !isempty(jac.content)
push!(problem._GETDP_CODE, code(jac))
end
end
elseif attr == "integration"
p = getfield(problem, :integration)
if !isempty(p.content) # Check if integrations are defined
push!(problem._GETDP_CODE, code(p))
for integ in components
if !isempty(integ.content)
push!(problem._GETDP_CODE, code(integ))
end
end
elseif attr == "formulation"
p = getfield(problem, :formulation)
if !isempty(p.items) # Check if formulations are defined
push!(problem._GETDP_CODE, code(p))
for form in components
if !isempty(form.items)
push!(problem._GETDP_CODE, code(form))
end
end
elseif attr == "resolution"
p = getfield(problem, :resolution)
if !isempty(p.content) # Check if resolutions are defined
push!(problem._GETDP_CODE, code(p))
for res in components
if !isempty(res.content)
push!(problem._GETDP_CODE, code(res))
end
end
elseif attr == "postprocessing"
p = getfield(problem, :postprocessing)
if !isempty(p.content) # Check if postprocessings are defined
push!(problem._GETDP_CODE, code(p))
for pp in components
if !isempty(pp.content)
push!(problem._GETDP_CODE, code(pp))
end
end
elseif attr == "postoperation"
p = getfield(problem, :postoperation)
if !isempty(p.content) # Check if postoperations are defined
push!(problem._GETDP_CODE, code(p))
for po in components
if !isempty(po.content)
push!(problem._GETDP_CODE, code(po))
end
end
end
end
Expand All @@ -163,7 +173,7 @@ end
"""
write_file!(problem::Problem)

Write the GetDP code to a file.
Escreve o código GetDP em um arquivo.
"""
function write_file!(problem::Problem)
if problem.filename === nothing
Expand All @@ -178,13 +188,12 @@ end
"""
include!(problem::Problem, incl_file)

Include another GetDP file.
Inclui outro arquivo GetDP.
"""
function include!(problem::Problem, incl_file)
push!(problem._GETDP_CODE, "\nInclude \"$(incl_file)\";")
end


"""
write_multiple_problems(problems::Vector{Problem}, filename::String)

Expand Down
15 changes: 10 additions & 5 deletions test/test_problem_formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ include("../test/normalized.jl")
condition="If (Flag_Degree_v == 2)",
endCondition="EndIf")

problem.functionspace = functionspace
# problem.functionspace = functionspace
push!(problem.functionspace, functionspace)

# Formulation section
formulation = Formulation()
Expand All @@ -35,7 +36,8 @@ include("../test/normalized.jl")
add!(eq, "Galerkin", "[ sigma[] * Dof{d v} , {d v} ]", In="Domain_Ele", Jacobian="Vol", Integration="I1")
add!(eq, "Galerkin", "DtDof[ epsilon[] * Dof{d v} , {d v} ]", In="Domain_Ele", Jacobian="Vol", Integration="I1")

problem.formulation = formulation
# problem.formulation = formulation
push!(problem.formulation, formulation)

# Resolution section
resolution = Resolution()
Expand All @@ -52,7 +54,8 @@ include("../test/normalized.jl")
"PostOperation[Ele_Cuts]"
])

problem.resolution = resolution
# problem.resolution = resolution
push!(problem.resolution, resolution)

## PostProcessing section
postprocessing = PostProcessing()
Expand Down Expand Up @@ -96,7 +99,8 @@ include("../test/normalized.jl")
q = add!(pp, "C_from_Energy")
add!(q, "Term", "2*\$We/SquNorm[\$voltage]"; Type="Global", In="DomainDummy")

problem.postprocessing = postprocessing
# problem.postprocessing = postprocessing
push!(problem.postprocessing, postprocessing)

# PostOperation section
postoperation = PostOperation()
Expand Down Expand Up @@ -132,7 +136,8 @@ include("../test/normalized.jl")
add_operation!(op2, "Print[ em, OnLine { {x2,y2,0} {x2+dc/2+ti+txlpe+to+tapl,y2,0} } {100}, Name \"|E| [V/m] cut in phase 2\", File \"res/em_cut.pos\" ]")
add_operation!(op2, "Echo[Str[\"View[PostProcessing.NbViews-1].Type = 4;\",\n \"View[PostProcessing.NbViews-1].Axes = 3;\",\n \"View[PostProcessing.NbViews-1].AutoPosition = 3;\",\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].LineWidth = 3;\",\n \"View[PostProcessing.NbViews-1].NbIso = 5;\"],\n File \"res/em_cut.opt\" ]")

problem.postoperation = postoperation
# problem.postoperation = postoperation
push!(problem.postoperation, postoperation)

# Generate and write the .pro file
make_file!(problem)
Expand Down
Loading