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
@@ -73,6 +71,67 @@ function namespace_affect(affect::FunctionalAffect, s)
73
71
context(affect))
74
72
end
75
73
74
+
"""
75
+
`MutatingFunctionalAffect` differs from `FunctionalAffect` in two key ways:
76
+
* First, insetad of the `u` vector passed to `f` being a vector of indices into `integ.u` it's instead the result of evaluating `obs` at the current state, named as specified in `obs_syms`. This allows affects to easily access observed states and decouples affect inputs from the system structure.
77
+
* Second, it abstracts the assignment back to system states away. Instead of writing `integ.u[u.myvar] = [whatever]`, you instead declare in `mod_params` that you want to modify `myvar` and then either (out of place) return a named tuple with `myvar` or (in place) modify the associated element in the ComponentArray that's given.
78
+
Initially, we only support "flat" states in `modified`; these states will be marked as irreducible in the overarching system and they will simply be bulk assigned at mutation. In the future, this will be extended to perform a nonlinear solve to further decouple the affect from the system structure.
generate observed function (oop), should save to a component array under obs_syms
822
+
do the same stuff as the normal FA for pars_syms
823
+
call the affect method - test if it's OOP or IP using applicable
824
+
unpack and apply the resulting values
825
+
=#
826
+
obs_exprs =observed(affect)
827
+
for oexpr in obs_exprs
828
+
invalid_vars =invalid_variables(sys, oexpr)
829
+
iflength(invalid_vars) >0
830
+
error("Observed equation $(oexpr) in affect refers to missing variable(s) $(invalid_vars); the variables may not have been added (e.g. if a component is missing).")
831
+
end
832
+
end
833
+
obs_syms =observed_syms(affect)
834
+
obs_size =size.(obs_exprs) # we will generate a work buffer of a ComponentArray that maps obs_syms to arrays of size obs_size
error("Expression $mexpr cannot be assigned to; currently only unknowns and parameters may be updated by an affect.")
840
+
end
841
+
invalid_vars =unassignable_variables(sys, mexpr)
842
+
iflength(invalid_vars) >0
843
+
error("Observed equation $(mexpr) in affect refers to missing variable(s) $(invalid_vars); the variables may not have been added (e.g. if a component is missing) or they may have been reduced away.")
Build the observed function assuming the observed equations are all explicit,
408
-
i.e. there are no cycles.
407
+
Generates a function that computes the observed value(s) `ts` in the system `sys` assuming that there are no cycles in the equations.
408
+
409
+
The return value will be either:
410
+
* a single function if the input is a scalar or if the input is a Vector but `return_inplace` is false
411
+
* the out of place and in-place functions `(ip, oop)` if `return_inplace` is true and the input is a `Vector`
412
+
413
+
The function(s) will be:
414
+
* `RuntimeGeneratedFunction`s by default,
415
+
* A Julia `Expr` if `expression` is true,
416
+
* A directly evaluated Julia function in the module `eval_module` if `eval_expression` is true
417
+
418
+
The signatures will be of the form `g(...)` with arguments:
419
+
* `output` for in-place functions
420
+
* `unknowns` if `params_only` is `false`
421
+
* `inputs` if `inputs` is an array of symbolic inputs that should be available in `ts`
422
+
* `p...` unconditionally; note that in the case of `MTKParameters` more than one parameters argument may be present, so it must be splatted
423
+
* `t` if the system is time-dependent; for example `NonlinearSystem` will not have `t`
424
+
For example, a function `g(op, unknowns, p, inputs, t)` will be the in-place function generated if `return_inplace` is true, `ts` is a vector, an array of inputs `inputs` is given, and `params_only` is false for a time-dependent system.
425
+
426
+
Options not otherwise specified are:
427
+
* `output_type = Array` the type of the array generated by the out-of-place vector-valued function
428
+
* `checkbounds = true` checks bounds if true when destructuring parameters
429
+
* `op = Operator` sets the recursion terminator for the walk done by `vars` to identify the variables that appear in `ts`. See the documentation for `vars` for more detail.
430
+
* `throw = true` if true, throw an error when generating a function for `ts` that reference variables that do not exist
0 commit comments