@@ -810,44 +810,45 @@ end
810810    $(TYPEDEF)  
811811
812812A 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. 
813+ Returns the value to use for the `u0` of the problem.  
815814
816815# Fields 
817816
818817$(TYPEDFIELDS) 
819818""" 
820- struct  GetUpdatedU0{GA , GIU}
819+ struct  GetUpdatedU0{GG , GIU}
821820    """ 
822-     Mask with length `length(unknowns(sys))` denoting indices of algebraic variables. 
821+     Mask with length `length(unknowns(sys))` denoting indices of variables which should 
822+     take the guess value from `initializeprob`. 
823823    """  
824-     algevars :: BitVector 
824+     guessvars :: BitVector 
825825    """ 
826-     Function which returns the values of algebraic  variables in `initializeprob`, in the  
827-     order  the algebraic variables  occur in `unknowns(sys)`. 
826+     Function which returns the values of variables in `initializeprob` for which  
827+     `guessvars` is `true`, in  the order they  occur in `unknowns(sys)`. 
828828    """  
829-     get_algevars :: GA 
829+     get_guessvars :: GG 
830830    """ 
831831    Function which returns `Initial.(unknowns(sys))` as a `Vector`. 
832832    """  
833833    get_initial_unknowns:: GIU 
834834end 
835835
836- function  GetUpdatedU0 (sys:: AbstractSystem , initsys:: AbstractSystem )
836+ function  GetUpdatedU0 (sys:: AbstractSystem , initsys:: AbstractSystem , op :: AbstractDict )
837837    dvs =  unknowns (sys)
838838    eqs =  equations (sys)
839-     algevaridxs =  BitVector (is_alg_equation .(eqs))
840-     append! (algevaridxs, falses (length (dvs) -  length (eqs)))
841-     algevars =  dvs[algevaridxs]
842-     get_algevars =  getu (initsys, algevars)
839+     guessvars =  trues (length (dvs))
840+     for  (i, var) in  enumerate (dvs)
841+         guessvars[i] =  ! isequal (get (op, var, nothing ), Initial (var))
842+     end 
843+     get_guessvars =  getu (initsys, dvs[guessvars])
843844    get_initial_unknowns =  getu (sys, Initial .(dvs))
844-     return  GetUpdatedU0 (algevaridxs, get_algevars , get_initial_unknowns)
845+     return  GetUpdatedU0 (guessvars, get_guessvars , get_initial_unknowns)
845846end 
846847
847848function  (guu:: GetUpdatedU0 )(prob, initprob)
848849    buffer =  guu. get_initial_unknowns (prob)
849-     algebuf =  view (buffer, guu. algevars )
850-     copyto! (algebuf, guu. get_algevars (initprob))
850+     algebuf =  view (buffer, guu. guessvars )
851+     copyto! (algebuf, guu. get_guessvars (initprob))
851852    return  buffer
852853end 
853854
@@ -890,7 +891,7 @@ function maybe_build_initialization_problem(
890891    initializeprob =  remake (initializeprob; p =  initp)
891892
892893    get_initial_unknowns =  if  is_time_dependent (sys)
893-         GetUpdatedU0 (sys, initializeprob. f. sys)
894+         GetUpdatedU0 (sys, initializeprob. f. sys, op )
894895    else 
895896        nothing 
896897    end 
0 commit comments