bibun 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +4 -2
- data/README.md +22 -49
- data/lib/bibun/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 368fa968d06e81e87ca2b1fd0a86a88cd54384d0e04f9c2761f0471862345107
|
|
4
|
+
data.tar.gz: f8dea6d3c5ec670677756ade6887bbff52f67dbe04f18ebf9778fe00844478b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2fe78590c4d0c1c8cb92788e8c9f07c940e6408e2f12f8625440916000dae8572c1ccea8feac860671ace583b1f2a592dd06a88241147269b9dc5c216fb958c6
|
|
7
|
+
data.tar.gz: b2879ade4f8c5f7250c6389ab19f99045333b62e39f570836f1721d81c10c326825eb8b97073a008b7c67091ec13d5de3ca8ef1f6fa52e0b264201e7d8381efe
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
5
|
## [0.0.0] - 2025-10-04
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Initial release.
|
|
7
|
+
## [0.0.1] - 2025-10-04
|
|
8
|
+
- Changed LaTEX expressions and Mermaid diagrams to embedded images so they display well on the documentation and the online repository.
|
|
9
|
+
- Added git repository link to the homepage attribute.
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@ Bibun (微分: differential, derivative). This gem implements Runge-Kutta explic
|
|
|
2
2
|
|
|
3
3
|
# Quick feature overview
|
|
4
4
|
|
|
5
|
-
Instant example for a single differential equation with one variable representing a electrical circuit
|
|
5
|
+
Instant example for a single differential equation with one variable representing a electrical circuit dI / dt = 15 - 3 I
|
|
6
6
|
|
|
7
7
|
```ruby
|
|
8
8
|
require 'bibun'
|
|
@@ -31,10 +31,8 @@ puts ode.current.value
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Quick example of a differential equation system of two variables, the Lotka Volterra equations with specific parameter values (p and d are the prey and predator variables):
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
\frac{dd}{dt}=-0.02d+0.00001pd
|
|
37
|
-
$$
|
|
34
|
+
|
|
35
|
+

|
|
38
36
|
|
|
39
37
|
|
|
40
38
|
```RUby
|
|
@@ -91,16 +89,7 @@ predator_data = lv.logs['predator']
|
|
|
91
89
|
|
|
92
90
|
With the same basics, a more complex system: an salt tank receiving two inlets, one outlet and variable water volume, proportional loss rate. The concentration is calculated and tracked from the salt mass and volume variables and each flow contribution is tracked separatedly:
|
|
93
91
|
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
title: Interface
|
|
97
|
-
---
|
|
98
|
-
flowchart LR
|
|
99
|
-
tan[Container Tank] -- fo --> out[Outlet]
|
|
100
|
-
bri[Brine inlet cs] -- fb --> tan
|
|
101
|
-
spw[Springwater inlet] -- fw --> tan
|
|
102
|
-
tan -- lV --> los[Loss rate]
|
|
103
|
-
```
|
|
92
|
+

|
|
104
93
|
|
|
105
94
|
```Ruby
|
|
106
95
|
tank = Bibun::DifferentialEquationSystem.new
|
|
@@ -153,28 +142,15 @@ The gem uses the `json`, `tomlib` and `csv` libraries for importing and exportin
|
|
|
153
142
|
|
|
154
143
|
`Formatador` is used to display a progress bar while doing the integration and for outputting a DES summary.
|
|
155
144
|
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
This gem has a MIT style license except it forbids its use for AI training purposes (see license file, based on https://github.com/non-ai-licenses/non-ai-licenses).
|
|
148
|
+
|
|
156
149
|
# General Interface and usage
|
|
157
150
|
|
|
158
151
|
The outer `DifferentialEquationSystem` class exposes enough general methods to be able to perform straightforward integration runs, but for a completely control over the integration process it is better to understand and access the inner objects that compose it. Below is the basic interface to a differential equation system object:
|
|
159
152
|
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
title: Interface
|
|
163
|
-
---
|
|
164
|
-
flowchart LR
|
|
165
|
-
sys[System] --shortcut--> vars[variables]
|
|
166
|
-
sys --> syms[syms]
|
|
167
|
-
syms --> vars
|
|
168
|
-
syms --> pars
|
|
169
|
-
sys --shortcut--> pars[parameters]
|
|
170
|
-
vars --> eq[rate_equations]
|
|
171
|
-
vars --shortcut--> rt[terms]
|
|
172
|
-
eq --> rt
|
|
173
|
-
sys --> st[stepper]
|
|
174
|
-
st --> bc[butcher_table]
|
|
175
|
-
sys --> log[logger]
|
|
176
|
-
sys --> tr[tracker]
|
|
177
|
-
```
|
|
153
|
+

|
|
178
154
|
|
|
179
155
|
For easier access there are shortcut methods such as System -> Variables or Variable -> Terms even if the strict relationship lies between adjacent classes.
|
|
180
156
|
|
|
@@ -183,11 +159,10 @@ For easier access there are shortcut methods such as System -> Variables or Vari
|
|
|
183
159
|
The Lotka-Volterra equations will be used as the working example for the documentation.
|
|
184
160
|
|
|
185
161
|
The Lotka-Volterra equations model the change across time in the populations of a prey and a predator species:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
$p$ and $d$ are the variables for the prey and predator populations and $k$, $a$, $r$ and $b$ are constant parameters or coefficients.
|
|
162
|
+
|
|
163
|
+

|
|
164
|
+
|
|
165
|
+
p and d are the variables for the prey and predator populations and k, a, r and b are constant parameters or coefficients.
|
|
191
166
|
|
|
192
167
|
This differential equation system is nonlinear and cyclical, with prey and predator population oscillating around their own maximum and minimum and with a phase shift between them.
|
|
193
168
|
|
|
@@ -290,7 +265,7 @@ lv.add_variable 'predator', 'd', rate_equation: '0.02 * d - 0.00001 * p * d '
|
|
|
290
265
|
lv.predator.rate_equation.rate_function = '-0.02 * d + 0.00001 * p * d'
|
|
291
266
|
```
|
|
292
267
|
|
|
293
|
-
The expression of the rate function must be provided with the form
|
|
268
|
+
The expression of the rate function must be provided with the form dxi/dt = f(X) and using the symbols previously assigned to the variables and parameters.
|
|
294
269
|
|
|
295
270
|
## Adding rate additive terms
|
|
296
271
|
|
|
@@ -343,7 +318,7 @@ lv.integrate starting_values: { 'prey_growth' => 0.08, 'prey_consumption' => 0.0
|
|
|
343
318
|
|
|
344
319
|
## Constant step, non adaptive
|
|
345
320
|
|
|
346
|
-
The method `integrate` is the main method to perform the integration, that is, starts a run where the variable values at each step are calculated numerically using a numerical method. The `starting_values:` parameter allows a last chance to introduce initial values; `step_size:` is used to input the desired step size (
|
|
321
|
+
The method `integrate` is the main method to perform the integration, that is, starts a run where the variable values at each step are calculated numerically using a numerical method. The `starting_values:` parameter allows a last chance to introduce initial values; `step_size:` is used to input the desired step size (h) and the `duration:` parameter determines the lenght of the run. For a non adaptive method, the total number of steps performed will be total_steps = duration / step_size since the step size is held constant.
|
|
347
322
|
|
|
348
323
|
```Ruby
|
|
349
324
|
lv.integrate starting_values: { 'time' => 0, 'prey' => 1000, 'predator' => 50 }, step_size: 1, duration: 100
|
|
@@ -501,7 +476,7 @@ Checking some rows of the generated file:
|
|
|
501
476
|
| 38 | 82.7 | -1.67 | 3.57 | 2137.5 | 170.72 | -178.41 | 25.86 |
|
|
502
477
|
| 39 | 84.6 | -1.71 | 3.63 | 2129.8 | 169.94 | -181.66 | 25.19 |
|
|
503
478
|
|
|
504
|
-
The sums of the terms for each variable equal the value of the variable for the next step. Here at time 37 we can verify that the value for time 38 for the predator population is
|
|
479
|
+
The sums of the terms for each variable equal the value of the variable for the next step. Here at time 37 we can verify that the value for time 38 for the predator population is 80.8 - 1.63 + 3.5 = 82.67, showing the separate contributions due to predation and decay.
|
|
505
480
|
|
|
506
481
|
*NOTE: when the logging interval is not equal to the step size, the term logs account for it in order to always represent the total change between two logging rows, so their logged values will differ if the logging interval change.*
|
|
507
482
|
|
|
@@ -541,15 +516,13 @@ lv.set_global_tolerance 0.1, 0.01 # atol of 0.1 and rtol of 0.01
|
|
|
541
516
|
```
|
|
542
517
|
|
|
543
518
|
The stepper evaluates the error at each iteration and increases the initial step size given if it the overall error is smaller than the aggregate `err` index or decreases the error and repeats the iteration if the error surpasses the aggregate. Because criteria for calculating the error and changing the step size is not set in stone, `Bibun` uses the following formulas[^1] :
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
scale = atol+rtol\times max(x_n,x_{n+1})
|
|
548
|
-
$$
|
|
519
|
+
|
|
520
|
+

|
|
521
|
+
|
|
549
522
|
Where N is the number of variables with nonzero tolerance. Step size is decreased and the step performed again if err < 1 and step size is increased otherwise. The size adjustment is done according to:
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
523
|
+
|
|
524
|
+

|
|
525
|
+
|
|
553
526
|
The 0.9 safety factor is a reccomendation by J.C. Butcher[^2] while the 1/5..10 range is a recommendation by W. H. Press.
|
|
554
527
|
|
|
555
528
|
### Using dense output
|
data/lib/bibun/version.rb
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bibun
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Javier Oswaldo Hernández Batis
|
|
@@ -209,7 +209,7 @@ description: "This gem allows to do simulation runs of systems of ordinary diffe
|
|
|
209
209
|
equations of one independent variable \nusing numerical Runge-Kutta methods for
|
|
210
210
|
approximation. Contains some features like calculation of separate additive\nterms
|
|
211
211
|
of the differential equations, calculation of custom expressions and logging and
|
|
212
|
-
printing runs to
|
|
212
|
+
printing runs to csv files,\nwhich engineers may find convenient.\n"
|
|
213
213
|
email: johernandezbatis@startmail.com
|
|
214
214
|
executables: []
|
|
215
215
|
extensions: []
|
|
@@ -231,7 +231,7 @@ files:
|
|
|
231
231
|
- lib/bibun/symbol_group.rb
|
|
232
232
|
- lib/bibun/version.rb
|
|
233
233
|
- lib/data/butcher_tables.toml
|
|
234
|
-
homepage: https://
|
|
234
|
+
homepage: https://git.sr.ht/~skyfish/bibun
|
|
235
235
|
licenses:
|
|
236
236
|
- Nonstandard
|
|
237
237
|
metadata: {}
|
|
@@ -251,5 +251,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
251
251
|
requirements: []
|
|
252
252
|
rubygems_version: 3.7.2
|
|
253
253
|
specification_version: 4
|
|
254
|
-
summary: A gem to run
|
|
254
|
+
summary: A gem to run simulations of differential equation systems via numerical methods.
|
|
255
255
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|