@@ -354,211 +354,21 @@ F = FormulationSet(:FEM,
354354 options = opts,
355355);
356356
357- # # Run the FEM solver
358- # @time ws, p = compute!(problem, F);
357+ # Run the FEM solver
358+ @time ws, p = compute! (problem, F);
359359
360- # # Display computation results
361- # per_km(p, 1; mode = :RLCG, tol = 1e-9)
360+ # Display computation results
361+ per_km (p, 1 ; mode = :RLCG , tol = 1e-9 )
362362
363- # # Export ZY matrices to ATPDraw
364- # output_file = fullfile("ZY_export.xml")
365- # export_file = export_data(:atp, p; file_name = output_file, cable_system = cable_system);
363+ # Export ZY matrices to ATPDraw
364+ output_file = fullfile (" ZY_export.xml" )
365+ export_file = export_data (:atp , p; file_name = output_file, cable_system = cable_system);
366366
367- # # Obtain the symmetrical components via Fortescue transformation
368- # Tv, p012 = Fortescue(tol = 1e-5)(p);
367+ # Obtain the symmetrical components via Fortescue transformation
368+ Tv, p012 = Fortescue (tol = 1e-5 )(p);
369369
370- # # Inspect the transformed matrices
371- # per_km(p012, 1; mode = :ZY, tol = 1e-9)
370+ # Inspect the transformed matrices
371+ per_km (p012, 1 ; mode = :ZY , tol = 1e-9 )
372372
373- # # Or the corresponding lumped circuit quantities
374- # per_km(p012, 1; mode = :RLCG, tol = 1e-9)
375-
376- using LineCableModels. Utils: to_nominal
377- using LineCableModels. DataModel: calc_circstrands_coords
378-
379- function collect_layer_geometry (design:: CableDesign ;
380- x_offset:: Real = 0.0 ,
381- y_offset:: Real = 0.0 ,
382- )
383- layer_no = Ref (0 )
384- out = Vector{
385- NamedTuple{(:layer , :type , :element , :x , :y , :radius_out , :rin , :rext ),
386- Tuple{Int, String, Int, Float64, Float64, Float64, Float64, Float64}},
387- }()
388-
389- function push_layer! (layer, x0, y0)
390- if layer isa CircStrands
391- layer_no[] += 1
392- rwire = to_nominal (layer. radius_wire)
393- lay_r = layer. num_wires == 1 ? 0.0 : to_nominal (layer. radius_in)
394- coords = calc_circstrands_coords (layer. num_wires, rwire, lay_r; C = (x0, y0))
395- for (i, (x, y)) in enumerate (coords)
396- push! (out, (layer_no[], " circstrands" , i, x, y, rwire, NaN , NaN ))
397- end
398- elseif layer isa Strip || layer isa Tubular || layer isa Semicon ||
399- layer isa Insulator
400- layer_no[] += 1
401- rin = to_nominal (layer. radius_in);
402- rex = to_nominal (layer. radius_ext)
403- typ = lowercase (string (nameof (typeof (layer))))
404- push! (out, (layer_no[], typ, 1 , x0, y0, rex, rin, rex))
405- elseif layer isa ConductorGroup
406- for sub in layer. layers
407- push_layer! (sub, x0, y0)
408- end
409- else
410- @warn " Skipping layer $(typeof (layer)) in geometry collection"
411- end
412- end
413-
414- for comp in design. components
415- for layer in comp. conductor_group. layers
416- push_layer! (layer, x_offset, y_offset)
417- end
418- for layer in comp. insulator_group. layers
419- push_layer! (layer, x_offset, y_offset)
420- end
421- end
422- return out
423- end
424-
425- function dump_layer_geometry_csv (design:: CableDesign ;
426- x_offset:: Real = 0.0 ,
427- y_offset:: Real = 0.0 ,
428- path:: AbstractString = " layer_dump.csv" ,
429- )
430- layer_no = Ref (0 )
431-
432- function emit! (io, layer, x0, y0)
433- if layer isa CircStrands
434- layer_no[] += 1
435- rwire = to_nominal (layer. radius_wire)
436- lay_r = layer. num_wires == 1 ? 0.0 : to_nominal (layer. radius_in)
437- coords = calc_circstrands_coords (layer. num_wires, rwire, lay_r; C = (x0, y0))
438- for (i, (x, y)) in enumerate (coords)
439- println (io, " $(layer_no[]) ,circstrands,$i ,$x ,$y ,$rwire ,," )
440- end
441- elseif layer isa Strip || layer isa Tubular || layer isa Semicon ||
442- layer isa Insulator
443- layer_no[] += 1
444- rin = to_nominal (layer. radius_in);
445- rex = to_nominal (layer. radius_ext)
446- typ = lowercase (string (nameof (typeof (layer))))
447- println (io, " $(layer_no[]) ,$typ ,1,$x0 ,$y0 ,$rex ,$rin ,$rex " )
448- elseif layer isa ConductorGroup
449- for sub in layer. layers
450- emit! (io, sub, x0, y0)
451- end
452- else
453- @warn " Skipping layer $(typeof (layer)) in CSV dump"
454- end
455- end
456-
457- open (path, " w" ) do io
458- println (io, " layer,type,element,x0,y0,radius_out,rin,rext" )
459- for comp in design. components
460- for layer in comp. conductor_group. layers
461- emit! (io, layer, x_offset, y_offset)
462- end
463- for layer in comp. insulator_group. layers
464- emit! (io, layer, x_offset, y_offset)
465- end
466- end
467- end
468- return path
469- end
470-
471-
472- # dump_layer_geometry_csv(cable_design; path = fullfile("cable_layers.csv"))
473-
474-
475- all_wires = collect_layer_geometry (cable_design)
476-
477- using Gmsh: gmsh
478-
479- gmsh. initialize ()
480-
481- system_id = " test"
482- gmsh. model. add (system_id)
483-
484- gmsh. option. set_number (" General.InitialModule" , 0 )
485- gmsh. option. set_string (" General.DefaultFileName" , system_id * " .geo" )
486-
487- # Define verbosity level
488- gmsh. option. set_number (" General.Verbosity" , 1 )
489-
490- # Set OCC model healing options
491- gmsh. option. set_number (" Geometry.AutoCoherence" , 1 )
492- gmsh. option. set_number (" Geometry.OCCFixDegenerated" , 1 )
493- gmsh. option. set_number (" Geometry.OCCFixSmallEdges" , 1 )
494- gmsh. option. set_number (" Geometry.OCCFixSmallFaces" , 1 )
495- gmsh. option. set_number (" Geometry.OCCSewFaces" , 1 )
496- gmsh. option. set_number (" Geometry.OCCMakeSolids" , 1 )
497-
498- # Log settings based on verbosity
499- @info " Initialized Gmsh model: $system_id "
500-
501- function my_disk! (x, y, r, lcp, wires, llwires)
502- cen = gmsh. model. geo. addPoint (x, y, 0.0 , lcp)
503- p1 = gmsh. model. geo. addPoint (x+ r, y, 0.0 , lcp)
504- p2 = gmsh. model. geo. addPoint (x, y+ r, 0.0 , lcp)
505- p3 = gmsh. model. geo. addPoint (x- r, y, 0 , lcp)
506- p4 = gmsh. model. geo. addPoint (x, y- r, 0 , lcp)
507-
508- c1 = gmsh. model. geo. addCircleArc (p1, cen, p2)
509- c2 = gmsh. model. geo. addCircleArc (p2, cen, p3)
510- c3 = gmsh. model. geo. addCircleArc (p3, cen, p4)
511- c4 = gmsh. model. geo. addCircleArc (p4, cen, p1)
512-
513- ll = gmsh. model. geo. addCurveLoop ([c1, c2, c3, c4])
514- s = gmsh. model. geo. addPlaneSurface ([ll])
515- push! (wires, s)
516- push! (llwires, ll)
517- return s
518- end
519-
520- lc = 0.0
521- z0 = 0.0
522- i= 1
523- wires = []
524- llwires = []
525- for wire in all_wires
526- x = wire. x
527- y = wire. y
528- r = wire. radius_out
529- my_disk! (x, y, r, lc, wires, llwires)
530- end
531-
532- gmsh. model. geo. synchronize ()
533-
534- gmsh. option. set_number (" Geometry.SurfaceLabels" , 0 ) # Show surface labels
535- gmsh. option. set_number (" Geometry.PointNumbers" , 0 )
536- gmsh. option. set_number (" Geometry.CurveNumbers" , 0 )
537- gmsh. option. set_number (" Geometry.SurfaceNumbers" , 0 )
538- gmsh. option. set_number (" Geometry.NumSubEdges" , 160 )
539- gmsh. option. set_number (" Geometry.Points" , 1 )
540- gmsh. option. set_number (" Geometry.Curves" , 1 )
541- gmsh. option. set_number (" Geometry.Surfaces" , 0 )
542- gmsh. option. set_number (" Mesh.ColorCarousel" , 2 ) # Colors by physical group
543- gmsh. option. set_number (" Mesh.LineWidth" , 1 )
544- gmsh. option. set_number (" Mesh.SurfaceFaces" , 1 )
545-
546- gmsh. fltk. initialize ()
547-
548- # Define event check function
549- function check_for_event ()
550- action = gmsh. onelab. get_string (" ONELAB/Action" )
551- if length (action) > 0 && action[1 ] == " check"
552- gmsh. onelab. set_string (" ONELAB/Action" , [" " ])
553- @debug " UI interaction detected"
554- gmsh. graphics. draw ()
555- end
556- return true
557- end
558-
559- # Wait for user to close the window
560- while gmsh. fltk. is_available () == 1 && check_for_event ()
561- gmsh. fltk. wait ()
562- end
563-
564- gmsh. finalize ()
373+ # Or the corresponding lumped circuit quantities
374+ per_km (p012, 1 ; mode = :RLCG , tol = 1e-9 )
0 commit comments