Skip to content

Commit 33b8002

Browse files
skip ci
1 parent c59046e commit 33b8002

1 file changed

Lines changed: 54 additions & 56 deletions

File tree

src/FEMTools/solver.jl

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,26 @@ end
8383
function define_constants!(problem::GetDP.Problem, fem_formulation::Union{AbstractImpedanceFormulation,AbstractAdmittanceFormulation}, frequency::Float64)
8484
func = GetDP.Function()
8585

86-
DEFAULT_CONSTS = [("I", 1.0), ("V0", 1.0), ("Flag_Degree_a", "1"), ("Flag_Degree_v", "1")]
86+
# DEFAULT_CONSTS = [("I", 1.0), ("V0", 1.0), ("Flag_Degree_a", "1"), ("Flag_Degree_v", "1")]
8787

8888
# Add constants more concisely (because of course it is so much better to jump one fuckton lines to find the damn parameter rather than making readable code)
89-
for (name, value) in [DEFAULT_CONSTS..., ("Freq", frequency)]
90-
add_constant!(func, name, value)
91-
end
89+
# for (name, value) in [DEFAULT_CONSTS..., ("Freq", frequency)]
90+
# add_constant!(func, name, value)
91+
# end
9292

93-
# Add other parameters
94-
add!(func, "Ns", expression="1")
95-
add!(func, "Sc", expression="SurfaceArea[]")
93+
# # Add other parameters
94+
# add!(func, "Ns", expression="1")
95+
# add!(func, "Sc", expression="SurfaceArea[]")
9696

9797
# if fem_formulation isa AbstractImpedanceFormulation
9898
# add_raw_code!(func, "DefineFunction[js0];")
9999
# end
100-
100+
add_constant!(func, "Freq", frequency)
101+
if fem_formulation isa AbstractImpedanceFormulation
102+
add_constant!(func, "I", 1.0)
103+
else
104+
add_constant!(func, "V0", 1.0)
105+
end
101106
push!(problem.function_obj, func)
102107
end
103108

@@ -231,9 +236,9 @@ function define_constraint!(problem::GetDP.Problem, fem_formulation::Union{Abstr
231236
mvp = assign!(constraint, "MagneticVectorPotential_2D")
232237
case!(mvp, "Sur_Dirichlet_Mag", value="0.0")
233238

234-
# # Voltage_2D (placeholder)
235-
# voltage = assign!(constraint, "Voltage_2D")
236-
# case!(voltage, "", comment="UNUSED")
239+
# Voltage_2D (placeholder)
240+
voltage = assign!(constraint, "Voltage_2D")
241+
case!(voltage, "")
237242

238243
# Current_2D
239244
current = assign!(constraint, "Current_2D")
@@ -260,16 +265,16 @@ function define_resolution!(problem::GetDP.Problem, formulation::FEMElectrodynam
260265
functionspace = FunctionSpace()
261266
fs1 = add!(functionspace, "Hgrad_v_Ele", nothing, nothing, Type="Form0")
262267
add_basis_function!(functionspace, "sn", "vn", "BF_Node"; Support="Domain_Ele", Entity="NodesOf[ All ]")
263-
add_basis_function!(functionspace, "sn2", "vn2", "BF_Node_2E";
264-
Support="Domain_Ele",
265-
Entity="EdgesOf[ All ]",
266-
condition="If (Flag_Degree_v == 2)",
267-
endCondition="EndIf")
268+
# add_basis_function!(functionspace, "sn2", "vn2", "BF_Node_2E";
269+
# Support="Domain_Ele",
270+
# Entity="EdgesOf[ All ]",
271+
# condition="If (Flag_Degree_v == 2)",
272+
# endCondition="EndIf")
268273

269274
add_constraint!(functionspace, "vn", "NodesOf", "ElectricScalarPotential")
270-
add_constraint!(functionspace, "vn2", "EdgesOf", "ZeroElectricScalarPotential";
271-
condition="If (Flag_Degree_v == 2)",
272-
endCondition="EndIf")
275+
# add_constraint!(functionspace, "vn2", "EdgesOf", "ZeroElectricScalarPotential";
276+
# condition="If (Flag_Degree_v == 2)",
277+
# endCondition="EndIf")
273278

274279
problem.functionspace = functionspace
275280

@@ -353,14 +358,14 @@ function define_resolution!(problem::GetDP.Problem, formulation::FEMElectrodynam
353358
# Ele_Maps
354359
po1 = add!(postoperation, "Ele_Maps", "EleDyn_v")
355360
op1 = add_operation!(po1)
356-
add_operation!(op1, "Print[ v, OnElementsOf Domain_Ele, File \"$(output_dir)/v.pos\" ];")
357-
add_operation!(op1, "Print[ em, OnElementsOf Cables, Name \"|E| [V/m]\", File \"$(output_dir)/em.pos\" ];")
358-
add_operation!(op1, "Print[ dm, OnElementsOf Cables, Name \"|D| [A/m²]\", File \"$(output_dir)/dm.pos\" ];")
359-
add_operation!(op1, "Print[ e, OnElementsOf Cables, Name \"E [V/m]\", File \"$(output_dir)/e.pos\" ];")
361+
add_operation!(op1, "Print[ v, OnElementsOf Domain_Ele, File \"$(joinpath(output_dir,"v.pos"))\" ];")
362+
add_operation!(op1, "Print[ em, OnElementsOf Cables, Name \"|E| [V/m]\", File \"$(joinpath(output_dir,"em.pos"))\" ];")
363+
add_operation!(op1, "Print[ dm, OnElementsOf Cables, Name \"|D| [A/m²]\", File \"$(joinpath(output_dir,"dm.pos"))\" ];")
364+
add_operation!(op1, "Print[ e, OnElementsOf Cables, Name \"E [V/m]\", File \"$(joinpath(output_dir,"e.pos"))\" ];")
360365
# add_operation!(op1, "Call Change_post_options;")
361-
add_operation!(op1, "Print[ ElectricEnergy[Cable_1], OnGlobal, Format Table, StoreInVariable \$We, SendToServer StrCat[po0,\"0Electric energy\"], File \"$(output_dir)/energy.dat\" ];")
362-
add_operation!(op1, "Print[ V0[Ind_1], OnRegion Ind_1, Format Table, StoreInVariable \$voltage, SendToServer StrCat[po0,\"0U\"], Units \"V\", File \"$(output_dir)/U.dat\" ];")
363-
add_operation!(op1, "Print[ C_from_Energy, OnRegion DomainDummy, Format Table, StoreInVariable \$C1, SendToServer StrCat[po0,\"1C\"], Units \"F/m\", File \"$(output_dir)/C.dat\" ];")
366+
add_operation!(op1, "Print[ ElectricEnergy[Cable_1], OnGlobal, Format Table, StoreInVariable \$We, SendToServer StrCat[po0,\"0Electric energy\"], File \"$(joinpath(output_dir,"energy.dat"))\" ];")
367+
add_operation!(op1, "Print[ V0[Ind_1], OnRegion Ind_1, Format Table, StoreInVariable \$voltage, SendToServer StrCat[po0,\"0U\"], Units \"V\", File \"$(joinpath(output_dir,"U.dat"))\" ];")
368+
add_operation!(op1, "Print[ C_from_Energy, OnRegion DomainDummy, Format Table, StoreInVariable \$C1, SendToServer StrCat[po0,\"1C\"], Units \"F/m\", File \"$(joinpath(output_dir,"C.dat"))\" ];")
364369

365370
problem.postoperation = postoperation
366371

@@ -376,16 +381,16 @@ function define_resolution!(problem::GetDP.Problem, formulation::FEMDarwin, work
376381
# FunctionSpace section
377382
fs1 = add!(functionspace, "Hcurl_a_Mag_2D", nothing, nothing, Type="Form1P")
378383
add_basis_function!(functionspace, "se", "ae", "BF_PerpendicularEdge"; Support="Domain_Mag", Entity="NodesOf[ All ]")
379-
add_basis_function!(functionspace, "se2", "ae2", "BF_PerpendicularEdge_2E";
380-
Support="Domain_Mag",
381-
Entity="EdgesOf[ All ]",
382-
condition="If (Flag_Degree_a == 2)",
383-
endCondition="EndIf")
384+
# add_basis_function!(functionspace, "se2", "ae2", "BF_PerpendicularEdge_2E";
385+
# Support="Domain_Mag",
386+
# Entity="EdgesOf[ All ]",
387+
# condition="If (Flag_Degree_a == 2)",
388+
# endCondition="EndIf")
384389

385390
add_constraint!(functionspace, "ae", "NodesOf", "MagneticVectorPotential_2D")
386-
add_constraint!(functionspace, "ae2", "EdgesOf", "MagneticVectorPotential_2D";
387-
condition="If (Flag_Degree_a == 2)",
388-
endCondition="EndIf")
391+
# add_constraint!(functionspace, "ae2", "EdgesOf", "MagneticVectorPotential_2D";
392+
# condition="If (Flag_Degree_a == 2)",
393+
# endCondition="EndIf")
389394

390395

391396
# fs2 = add!(functionspace, "Hregion_i_2D", nothing, nothing, Type="Vector")
@@ -400,7 +405,7 @@ function define_resolution!(problem::GetDP.Problem, formulation::FEMDarwin, work
400405
add_basis_function!(functionspace, "sr", "ur", "BF_RegionZ"; Support="DomainC_Mag", Entity="DomainC_Mag")
401406
add_global_quantity!(functionspace, "U", "AliasOf"; NameOfCoef="ur")
402407
add_global_quantity!(functionspace, "I", "AssociatedWith"; NameOfCoef="ur")
403-
# add_constraint!(functionspace, "U", "Region", "Voltage_2D")
408+
add_constraint!(functionspace, "U", "Region", "Voltage_2D")
404409
add_constraint!(functionspace, "I", "Region", "Current_2D")
405410

406411
problem.functionspace = functionspace
@@ -549,38 +554,31 @@ function define_resolution!(problem::GetDP.Problem, formulation::FEMDarwin, work
549554
# Add operations for maps
550555
op1 = add_operation!(po1) # Creates a POBase_ for po1
551556

552-
add_operation!(op1, "Print[ az, OnElementsOf Domain_Mag, //Smoothing 1\n Name \"flux lines: Az [T m]\", File \"$(output_dir)/az.pos\" ];")
553-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].NbIso = 25;\",\n \"View[PostProcessing.NbViews-1].IntervalsType = 1;\" // isolines\n ], File \"$(output_dir)/maps.opt\"];")
554-
add_operation!(op1, "Print[ b, OnElementsOf Domain_Mag, //Smoothing 1,\n Name \"B [T]\", File \"$(output_dir)/b.pos\" ];")
555-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
556-
add_operation!(op1, "Print[ bm, OnElementsOf Domain_Mag,\n Name \"|B| [T]\", File \"$(output_dir)/bm.pos\" ];")
557-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
558-
add_operation!(op1, "Print[ jz, OnElementsOf Region[{DomainC_Mag}],\n Name \"jz [A/m^2] Conducting domain\", File \"$(output_dir)/jz_inds.pos\" ];")
559-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
560-
add_operation!(op1, "Print[ rhoj2, OnElementsOf Region[{DomainC_Mag}],\n Name \"Power density\", File \"$(output_dir)/rhoj2.pos\" ];")
561-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
562-
add_operation!(op1, "Print[ jm, OnElementsOf DomainC_Mag,\n Name \"|j| [A/m^2] Conducting domain\", File \"$(output_dir)/jm.pos\" ];")
563-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
564-
add_operation!(op1, "Print[ dm, OnElementsOf DomainC_Mag,\n Name \"|D| [A/m²]\", File \"$(output_dir)/dm.pos\" ];")
565-
add_operation!(op1, "Echo[Str[\"View[PostProcessing.NbViews-1].RangeType = 3;\", // per timestep\n \"View[PostProcessing.NbViews-1].ShowTime = 0;\",\n \"View[PostProcessing.NbViews-1].IntervalsType = 2;\"\n ], File \"$(output_dir)/maps.opt\"];")
557+
add_operation!(op1, "Print[ az, OnElementsOf Domain_Mag, //Smoothing 1\n Name \"flux lines: Az [T m]\", File \"$(joinpath(output_dir,"az.pos"))\" ];")
558+
add_operation!(op1, "Print[ b, OnElementsOf Domain_Mag, //Smoothing 1,\n Name \"B [T]\", File \"$(joinpath(output_dir,"b.pos"))\" ];")
559+
add_operation!(op1, "Print[ bm, OnElementsOf Domain_Mag,\n Name \"|B| [T]\", File \"$(joinpath(output_dir,"bm.pos"))\" ];")
560+
add_operation!(op1, "Print[ jz, OnElementsOf Region[{DomainC_Mag}],\n Name \"jz [A/m^2] Conducting domain\", File \"$(joinpath(output_dir,"jz_inds.pos"))\" ];")
561+
add_operation!(op1, "Print[ rhoj2, OnElementsOf Region[{DomainC_Mag}],\n Name \"Power density\", File \"$(joinpath(output_dir,"rhoj2.pos"))\" ];")
562+
add_operation!(op1, "Print[ jm, OnElementsOf DomainC_Mag,\n Name \"|j| [A/m^2] Conducting domain\", File \"$(joinpath(output_dir,"jm.pos"))\" ];")
563+
add_operation!(op1, "Print[ dm, OnElementsOf DomainC_Mag,\n Name \"|D| [A/m²]\", File \"$(joinpath(output_dir,"dm.pos"))\" ];")
566564

567565
add_raw_code!(po1, "po = \"{01Losses/\";")
568566
add_raw_code!(po1, "po2 = \"{02Pul-parameters/\";")
569567

570568
op2 = add_operation!(po2) # Creates a POBase_ for po2
571-
add_operation!(op2, "Print[ JouleLosses[DomainC_Mag], OnGlobal, Format Table,\n SendToServer StrCat[po,\"0Total conducting domain\"],\n Units \"W/m\", File \"$(output_dir)/losses_total.dat\" ];")
572-
add_operation!(op2, "Print[ JouleLosses[Inds], OnGlobal, Format Table,\n SendToServer StrCat[po,\"3Source\"],\n Units \"W/m\", File \"$(output_dir)/losses_inds.dat\" ];")
573-
add_operation!(op2, "Print[ R, OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"0R\"],\n Units \"Ω\", File \"$(output_dir)/R.dat\" ];")
574-
add_operation!(op2, "Print[ L, OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"1L\"],\n Units \"H\", File \"$(output_dir)/L.dat\" ];")
575-
add_operation!(op2, "Print[ Z[DomainC_Mag], OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"2re(Z)\"] {0},\n Units \"Ω\", File \"$(output_dir)/Z.dat\" ];")
569+
add_operation!(op2, "Print[ JouleLosses[DomainC_Mag], OnGlobal, Format Table,\n SendToServer StrCat[po,\"0Total conducting domain\"],\n Units \"W/m\", File \"$(joinpath(output_dir,"losses_total.dat"))\" ];")
570+
add_operation!(op2, "Print[ JouleLosses[Inds], OnGlobal, Format Table,\n SendToServer StrCat[po,\"3Source\"],\n Units \"W/m\", File \"$(joinpath(output_dir,"losses_inds.dat"))\" ];")
571+
add_operation!(op2, "Print[ R, OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"0R\"],\n Units \"Ω\", File \"$(joinpath(output_dir,"R.dat"))\" ];")
572+
add_operation!(op2, "Print[ L, OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"1L\"],\n Units \"H\", File \"$(joinpath(output_dir,"L.dat"))\" ];")
573+
add_operation!(op2, "Print[ Z[DomainC_Mag], OnRegion Inds, Format Table,\n SendToServer StrCat[po2,\"2re(Z)\"] {0},\n Units \"Ω\", File \"$(joinpath(output_dir,"Z.dat"))\" ];")
576574

577575
# Add the post-operation to the problem
578576
problem.postoperation = postoperation
579577

580578
end
581579

582580
function run_fem_solver(workspace::FEMWorkspace, fem_formulation::AbstractFormulation)
583-
if !(@isdefined(gmsh))
581+
if gmsh.is_initialized() == 0
584582
gmsh.initialize()
585583
end
586584
# Construct solver command
@@ -592,7 +590,7 @@ function run_fem_solver(workspace::FEMWorkspace, fem_formulation::AbstractFormul
592590
@info "Solve successful!"
593591
return true
594592
catch e
595-
@error "Solve failed" exception = e
593+
Base.error("Solver failed: $e")
596594
return false
597595
end
598596
end

0 commit comments

Comments
 (0)