@@ -153,8 +153,55 @@ struct Subsystem{T, Eltype, States, Params}
153
153
params:: SubsystemParams{T, Params}
154
154
end
155
155
156
+ """
157
+ get_tag(subsystem::Subsystem{T}) = T
158
+ get_tag(states::SubsystemStates{T}) = T
159
+ get_tag(params::SubsystemParams{T}) = T
160
+ get_tag(::Type{<:Subsystem{T}}) = T
161
+
162
+ Extract the type tag `T` from a subsystem or its components.
163
+
164
+ The tag identifies the subsystem type and is used for dispatch and organization.
165
+
166
+ # Examples
167
+ ```julia
168
+ particle = Subsystem{Particle}(states=(x=1.0, v=0.0), params=(m=2.0,))
169
+ get_tag(particle) # returns Particle
170
+ get_tag(typeof(particle)) # returns Particle
171
+ ```
172
+ """
156
173
function get_tag end
174
+ """
175
+ get_params(subsystem::Subsystem) -> SubsystemParams
176
+
177
+ Extract the parameters from a subsystem.
178
+
179
+ Returns a `SubsystemParams` object containing the non-dynamical parameters
180
+ (constants like mass, charge, spring constants, etc.) of the subsystem.
181
+
182
+ # Example
183
+ ```julia
184
+ sys = Subsystem{Oscillator}(states=(x=1.0, v=0.0), params=(k=2.0, m=1.0))
185
+ params = get_params(sys) # SubsystemParams{Oscillator}(k=2.0, m=1.0)
186
+ params.k # 2.0
187
+ ```
188
+ """
157
189
function get_params end
190
+ """
191
+ get_states(subsystem::Subsystem) -> SubsystemStates
192
+
193
+ Extract the state variables from a subsystem.
194
+
195
+ Returns a `SubsystemStates` object containing the dynamical state variables
196
+ (position, velocity, concentrations, etc.) that evolve over time.
197
+
198
+ # Example
199
+ ```julia
200
+ sys = Subsystem{Oscillator}(states=(x=1.0, v=0.0), params=(k=2.0, m=1.0))
201
+ states = get_states(sys) # SubsystemStates{Oscillator}(x=1.0, v=0.0)
202
+ states.x # 1.0
203
+ ```
204
+ """
158
205
function get_states end
159
206
160
207
"""
@@ -220,6 +267,27 @@ defaults to false, but users may add methods to this function if they have subsy
220
267
subsystem_differential_requires_inputs (:: Type{T} ) where {T} = true
221
268
subsystem_differential_requires_inputs (:: Subsystem{T} ) where {T} = subsystem_differential_requires_inputs (T)
222
269
270
+ """
271
+ apply_subsystem_noise!(vstate, subsystem, t)
272
+
273
+ Apply stochastic noise to a subsystem's state at time `t`.
274
+
275
+ This function modifies the noise terms for a subsystem's stochastic differential equation.
276
+ By default, it does nothing (no noise). Override this for stochastic subsystems.
277
+
278
+ # Arguments
279
+ - `vstate`: A view into the noise vector to be modified
280
+ - `subsystem`: The `Subsystem` instance whose noise is being computed
281
+ - `t`: Current time
282
+
283
+ # Example
284
+ ```julia
285
+ function GraphDynamics.apply_subsystem_noise!(vstate, sys::Subsystem{BrownianParticle}, t)
286
+ # No noise in position, so we don't modify vstate[:x]
287
+ vstate[:v] = sys.σ # White noise in velocity with amplitude σ
288
+ end
289
+ ```
290
+ """
223
291
function apply_subsystem_noise! (vstate, subsystem, t)
224
292
nothing
225
293
end
235
303
function continuous_event_condition end
236
304
function apply_continuous_event! end
237
305
function discrete_event_condition end
306
+ """
307
+ apply_discrete_event!(integrator, sview, pview, subsystem, F[, input])
308
+ apply_discrete_event!(integrator, sview_src, pview_src, sview_dst, pview_dst,
309
+ connection_rule, sys_src, sys_dst[, input_src, input_dst])
310
+
311
+ Apply a discrete event to modify subsystem states or parameters.
312
+
313
+ This function is called when `discrete_event_condition` returns `true`.
314
+
315
+ # Arguments
316
+ - `integrator`: The ODE/SDE integrator
317
+ - `sview`/`pview`: Views into states/params to be modified
318
+ - `subsystem`: The subsystem experiencing the event
319
+ - `F`: `ForeachConnectedSubsystem` for accessing connected subsystems
320
+ - `input`: Optional input from connected subsystems
321
+ - For connection events: views and systems for both source and destination
322
+
323
+ # Example
324
+ ```julia
325
+ function GraphDynamics.apply_discrete_event!(integrator, sview, pview,
326
+ sys::Subsystem{Ball}, F)
327
+ # Bounce: reverse velocity
328
+ sview[:v] = -sys.restitution * sview[:v]
329
+ end
330
+ ```
331
+ """
238
332
function apply_discrete_event! end
239
333
240
334
0 commit comments