You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Blocks/analysis_points.jl
+34-3Lines changed: 34 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ function Base.hash(ap::AnalysisPoint, seed::UInt)
18
18
h3 ⊻ (0xd29cdc51aa6562d4% UInt)
19
19
end
20
20
21
+
function ModelingToolkit.get_unit(ap::AnalysisPoint)
22
+
ModelingToolkit.unitless
23
+
end
24
+
21
25
functionap_var(sys)
22
26
ifhasproperty(sys, :u)
23
27
# collect to turn symbolic arrays into arrays of symbols
@@ -28,6 +32,23 @@ function ap_var(sys)
28
32
error("Could not determine the analysis-point variable in system $(nameof(sys)). To use an analysis point, apply it to a connection between two causal blocks containing connectors of type `RealInput/RealOutput` from ModelingToolkitStandardLibrary.Blocks.")
29
33
end
30
34
35
+
"""
36
+
find_analysis_points(sys)
37
+
38
+
Return a list of all analysis points in `sys`. If none are found, the list is empty.
39
+
"""
40
+
functionfind_analysis_points(sys)
41
+
sys = ModelingToolkit.flatten(sys)
42
+
eqs =equations(sys)
43
+
aps = []
44
+
for eq in eqs
45
+
if eq.rhs isa AnalysisPoint
46
+
push!(aps, eq.rhs)
47
+
end
48
+
end
49
+
aps
50
+
end
51
+
31
52
"""
32
53
AnalysisPoint(in, out, name::Symbol)
33
54
AnalysisPoint(in, out; name::Symbol)
@@ -418,16 +439,26 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys
418
439
ui =get_perturbation_var(ap_var(ap.out), "u")
419
440
push!(multiplicities_u, length(ui)) # one ap may yield several new vars
420
441
append!(u, ui)
421
-
[ap_var(ap.out) .~ap_var(ap.in) + ui;], ui
442
+
if loop_openings !==nothing&& ap.name ∈ loop_openings
443
+
# In thise case, we break the existing connection.
444
+
[ap_var(ap.out) .~ ui;], ui
445
+
else
446
+
[ap_var(ap.out) .~ap_var(ap.in) + ui;], ui
447
+
end
422
448
#input.in.u ~ 0] # We only need to ground one of the ends, hence not including this equation
423
449
elseif output_name isa SymOrVec &&namespaced_ap_match(ap, ns, output_name, nothing)
424
450
push!(namespace_y, ns) # Save the namespace to make it available for renamespace below
425
451
push!(aps_y, ap)
426
452
yi =get_perturbation_var(ap_var(ap.in), "y")
427
453
push!(multiplicities_y, length(yi))
428
454
append!(y, yi)
429
-
[ap_var(ap.in) .~ yi;
430
-
ap_var(ap.out) .~ap_var(ap.in)], yi
455
+
if loop_openings !==nothing&& ap.name ∈ loop_openings
456
+
[ap_var(ap.in) .~ yi;
457
+
ap_var(ap.out) .~0], yi # In thise case, we break the existing connection.
0 commit comments