forked from djuber/SciSmalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
153 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
An ExplicitSolverSubscriber implements the minimal behavior to attach to an ODESolver and receive ExplicitSolverAnnouncements. Subclasses should override block to determine appropriate behavior. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Math-ODE.package/ODESolver.class/instance/announceState.time..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
announceState: aState time: aTime | ||
self announcer announce: (ExplicitSolverAnnouncement x: aState t: aTime). |
11 changes: 11 additions & 0 deletions
11
Math-ODE.package/ODESolver.class/instance/lastStepState.endTime..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
solving | ||
lastStepState: aState endTime: endTime | ||
"catch partial or full step at end" | ||
(lastTime equalsTo: endTime ) | ||
ifFalse: | ||
[state := stepper | ||
doStep: state | ||
time: lastTime | ||
stepSize: endTime - lastTime. | ||
self announceState: state time: endTime]. | ||
^ state |
15 changes: 15 additions & 0 deletions
15
Math-ODE.package/ODESolver.class/instance/mainStepsState.startTime.endTime..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
solving | ||
mainStepsState: aState startTime: initialTime endTime: endTime | ||
state := aState. | ||
"don't go to end time to avoid overrunning" | ||
(initialTime to: endTime - self dt by: self dt) do: | ||
[:time | | ||
state := stepper | ||
doStep: state | ||
time: time | ||
stepSize: self dt. | ||
"announce step results" | ||
self announceState: state time: time + self dt. | ||
lastTime := time + self dt]. | ||
|
||
^ state |
24 changes: 14 additions & 10 deletions
24
Math-ODE.package/ODESolver.class/instance/solve.startState.startTime.endTime..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
solving | ||
solve: aSystem startState: initialState startTime: initialTime endTime: endTime | ||
| state | | ||
|
||
self system: aSystem. | ||
stepper ifNil: [ | ||
self stepper: ((self stepperClass) onSystem: self system)]. | ||
state := initialState. | ||
(initialTime to: endTime by: self dt) do: | ||
[:time | | ||
state := stepper | ||
doStep: state | ||
time: time | ||
stepSize: self dt. | ||
"announce step results" | ||
announcer announce: (ExplicitSolverAnnouncement x: state t: time). | ||
]. | ||
|
||
"announce initial conditions" | ||
self announceState: state time: initialTime. | ||
"step until the end" | ||
state := self mainStepsState: state startTime: initialTime endTime: endTime. | ||
|
||
"sanity check" | ||
self assert: [(lastTime between: initialTime and: endTime) | ||
or: [lastTime between: endTime and: initialTime]]. | ||
|
||
"take another step if needed" | ||
state := self lastStepState: state endTime: endTime. | ||
|
||
^ state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
A RK4Solver class is an ODESolver with default stepper type RungeKuttaStepper. | ||
|
||
This is a solver for first order explicit systems (a function of time and state yields the derivative). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class variables | ||
stepperClass | ||
^ RungeKuttaStepper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"category" : "Math-ODE", | ||
"classinstvars" : [ | ||
], | ||
"classtraitcomposition" : "{}", | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "<historical>", | ||
"instvars" : [ | ||
], | ||
"name" : "RK4Solver", | ||
"pools" : [ | ||
], | ||
"super" : "ODESolver", | ||
"traitcomposition" : "{}", | ||
"type" : "normal" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
Math-ODE.package/RungeKuttaStepper.class/instance/doStep.time..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
stepping | ||
doStep: aState time: t | ||
"This method should take one step from inState at time t of size dt, and modify the state, then answer it." | ||
| k1 k2 k3 k4 midPoint endPoint| | ||
self stepSize isNil ifTrue: [self error: 'step size required by stepper']. | ||
aState isNumber | ||
ifTrue: | ||
[^ (self numberDoStep: aState time: t)] | ||
"a collection" | ||
ifFalse: | ||
[^ (self collectionDoStep: aState time: t)] | ||
midPoint := self stepSize / 2 + t. | ||
endPoint := self stepSize + t. | ||
k1 := system x: aState t: t. | ||
k2 := system x: aState + (k1 * self stepSize / 2) t: midPoint. | ||
k3 := system x: aState + (k2 * self stepSize / 2 ) t: midPoint. | ||
k4 := system x: aState + (k3 * self stepSize) t: endPoint. | ||
^ aState + ((k1 + k2 + k2 + k3 + k3 + k4) / 6 * self stepSize). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
A StateRecorder captures each step in an ODESolvers history. | ||
|
||
It stores these as a sorted collection of state,time points, in increasing time order. | ||
It stores these as a sorted collection of StateTime object, in increasing time order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
example | ||
demo | ||
| solver system recorder | | ||
| solver system recorder | | ||
|
||
solver := ODESolver new. | ||
system := ExplicitSystem block: [:x :t | t]. | ||
recorder := self forSolver: solver. | ||
solver solve: system startState: 0 startTime: 0 endTime: 2 stepSize: 0.1. | ||
solver := RK4Solver new. | ||
system := ExplicitSystem block: [:x :t | x collect: [:i | t]]. "exact solution x = 0.5 * t squared + x0" | ||
|
||
recorder unsubscribe. | ||
"these wont be captured" | ||
solver solve: system startState: 0 startTime: 0 endTime: 5 stepSize: 0.1. | ||
recorder states inspect. | ||
recorder := self forSolver: solver. | ||
"an example of moving backward in time with fractional dt" | ||
solver solve: system startState: #(3 1) startTime: 2 endTime: 0 stepSize: (-1 / 10). | ||
|
||
recorder unsubscribe. | ||
|
||
"these wont be captured. an example of moving forward in time with float dt." | ||
solver solve: system startState: #(0) startTime: 0 endTime: 5 stepSize: 0.1. | ||
|
||
recorder states inspect. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
accessing | ||
add: aState at: aTime | ||
states add: aState @ aTime | ||
states add: (StateTime state: aState time: aTime). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
initialize-release | ||
initialize | ||
super initialize. | ||
states := SortedCollection sortBlock: [:x :y | x y < y y]. | ||
states := SortedCollection sortBlock: [:x :y | x time < y time]. | ||
^ self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
A StateTime class is a generalization of point. It holds both a state and a time. | ||
|
||
We don't want to use Point, since state may be a vector quantity, and the behavior of array @ number is a little off (it stores points in an array, what we want is the array itself in state, and the scalar quantity in time). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
instance creation | ||
state: aState time: aTime | ||
^ self new | ||
state: aState; | ||
time: aTime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
accessing | ||
printOn: aStream | ||
"used for inspector. Using the point analogy" | ||
state printOn: aStream. | ||
aStream nextPut: $@. | ||
time printOn: aStream. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
state: anObject | ||
state := anObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
state | ||
^ state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
time: anObject | ||
time := anObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
time | ||
^ time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"category" : "Math-ODE", | ||
"classinstvars" : [ | ||
], | ||
"classtraitcomposition" : "{}", | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "<historical>", | ||
"instvars" : [ | ||
"state", | ||
"time" ], | ||
"name" : "StateTime", | ||
"pools" : [ | ||
], | ||
"super" : "Object", | ||
"traitcomposition" : "{}", | ||
"type" : "normal" } |
Oops, something went wrong.