@@ -769,7 +769,7 @@ properly.
769
769
770
770
$(TYPEDFIELDS)
771
771
"""
772
- struct InitializationMetadata{R <: ReconstructInitializeprob , GIU , SIU}
772
+ struct InitializationMetadata{R <: ReconstructInitializeprob , GUU , SIU}
773
773
"""
774
774
The `u0map` used to construct the initialization.
775
775
"""
@@ -796,17 +796,58 @@ struct InitializationMetadata{R <: ReconstructInitializeprob, GIU, SIU}
796
796
"""
797
797
oop_reconstruct_u0_p:: R
798
798
"""
799
- A function which takes the parameter object of the problem and returns
800
- `Initial.(unknowns(sys))`.
799
+ A function which takes `(prob, initializeprob)` and return the `u0` to use for the problem.
801
800
"""
802
- get_initial_unknowns :: GIU
801
+ get_updated_u0 :: GUU
803
802
"""
804
803
A function which takes the `u0` of the problem and sets
805
804
`Initial.(unknowns(sys))`.
806
805
"""
807
806
set_initial_unknowns!:: SIU
808
807
end
809
808
809
+ """
810
+ $(TYPEDEF)
811
+
812
+ A callable struct to use as the `get_updated_u0` field of `InitializationMetadata`.
813
+ Returns the value of `Initial.(unknowns(sys))`, except with algebraic variables replaced
814
+ by their guess values in the initialization problem.
815
+
816
+ # Fields
817
+
818
+ $(TYPEDFIELDS)
819
+ """
820
+ struct GetUpdatedU0{GA, GIU}
821
+ """
822
+ Mask with length `length(unknowns(sys))` denoting indices of algebraic variables.
823
+ """
824
+ algevars:: BitVector
825
+ """
826
+ Function which returns the values of algebraic variables in `initializeprob`, in the
827
+ order the algebraic variables occur in `unknowns(sys)`.
828
+ """
829
+ get_algevars:: GA
830
+ """
831
+ Function which returns `Initial.(unknowns(sys))` as a `Vector`.
832
+ """
833
+ get_initial_unknowns:: GIU
834
+ end
835
+
836
+ function GetUpdatedU0 (sys:: AbstractSystem , initsys:: AbstractSystem )
837
+ algevaridxs = BitVector (is_alg_equation .(equations (sys)))
838
+ algevars = unknowns (sys)[algevaridxs]
839
+ get_algevars = getu (initsys, algevars)
840
+ get_initial_unknowns = getu (sys, Initial .(unknowns (sys)))
841
+ return GetUpdatedU0 (algevaridxs, get_algevars, get_initial_unknowns)
842
+ end
843
+
844
+ function (guu:: GetUpdatedU0 )(prob, initprob)
845
+ buffer = guu. get_initial_unknowns (prob)
846
+ algebuf = view (buffer, guu. algevars)
847
+ copyto! (algebuf, guu. get_algevars (initprob))
848
+ return buffer
849
+ end
850
+
810
851
"""
811
852
$(TYPEDSIGNATURES)
812
853
@@ -845,10 +886,15 @@ function maybe_build_initialization_problem(
845
886
end
846
887
initializeprob = remake (initializeprob; p = initp)
847
888
889
+ get_initial_unknowns = if is_time_dependent (sys)
890
+ GetUpdatedU0 (sys, initializeprob. f. sys)
891
+ else
892
+ nothing
893
+ end
848
894
meta = InitializationMetadata (
849
895
u0map, pmap, guesses, Vector {Equation} (initialization_eqs),
850
896
use_scc, ReconstructInitializeprob (sys, initializeprob. f. sys),
851
- getp (sys, Initial .( unknowns (sys))) , setp (sys, Initial .(unknowns (sys))))
897
+ get_initial_unknowns , setp (sys, Initial .(unknowns (sys))))
852
898
853
899
if is_time_dependent (sys)
854
900
all_init_syms = Set (all_symbols (initializeprob))
0 commit comments