rb-daspk 0.0.4-x86-darwin-10 → 0.0.5-x86-darwin-10
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.
- data/lib/rb-daspk.rb +66 -78
- metadata +3 -3
data/lib/rb-daspk.rb
CHANGED
@@ -24,6 +24,9 @@
|
|
24
24
|
#
|
25
25
|
# More information, source code and gems @ http://rubyforge.org/projects/rb-daspk/
|
26
26
|
#
|
27
|
+
#:main:DASPK::Solver
|
28
|
+
#
|
29
|
+
|
27
30
|
|
28
31
|
require 'rubygems'
|
29
32
|
require 'ffi'
|
@@ -49,15 +52,17 @@ module FFI
|
|
49
52
|
end
|
50
53
|
|
51
54
|
|
55
|
+
module DASPKLIB
|
56
|
+
extend FFI::Library
|
57
|
+
ffi_lib File.dirname(__FILE__) + '/libdaspk.dylib'
|
58
|
+
callback :jac, [:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer], :void
|
59
|
+
callback :res, [:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer], :void
|
60
|
+
attach_function 'ddaspk_', [:res, :pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,
|
61
|
+
:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:jac, :pointer], :void
|
62
|
+
attach_function 'd1mach_', [:pointer],:double
|
63
|
+
end
|
64
|
+
|
52
65
|
module DASPK
|
53
|
-
extend FFI::Library
|
54
|
-
ffi_lib File.dirname(__FILE__) + '/libdaspk.dylib'
|
55
|
-
callback :jac, [:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer], :void
|
56
|
-
callback :res, [:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer], :void
|
57
|
-
attach_function 'ddaspk_', [:res, :pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,
|
58
|
-
:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:jac, :pointer], :void
|
59
|
-
attach_function 'd1mach_', [:pointer],:double
|
60
|
-
#
|
61
66
|
#
|
62
67
|
# interface to DASPK
|
63
68
|
#
|
@@ -71,9 +76,8 @@ module DASPK
|
|
71
76
|
#
|
72
77
|
class Solver
|
73
78
|
|
74
|
-
include
|
75
|
-
|
76
|
-
attr_accessor :rtol,:atol,:inter,:jac,:maxstep,:mxnit,:mxnj,:mxnh,:lsoff,:stptol,:epinit
|
79
|
+
include DASPKLIB
|
80
|
+
attr_accessor :rtol,:atol,:inter,:jac,:maxstep
|
77
81
|
#
|
78
82
|
#
|
79
83
|
# * neq = the number of equations. this is always the sum of the number of states and algebraics
|
@@ -84,60 +88,44 @@ module DASPK
|
|
84
88
|
# * res = residual (delta) Proc. must be present. this is responsible for filling of the delta (residual) array.
|
85
89
|
#
|
86
90
|
def initialize (neq, y, yprime, inter=nil, jac=nil, &res)
|
87
|
-
@lwr
|
88
|
-
@lwi
|
89
|
-
@plwr
|
91
|
+
@lwr = 15000
|
92
|
+
@lwi = 15000
|
93
|
+
@plwr = FFI::MemoryPointer.new(:int)
|
90
94
|
@plwr.write_int(@lwr)
|
91
|
-
@plwi
|
95
|
+
@plwi = FFI::MemoryPointer.new(:int)
|
92
96
|
@plwi.write_int(@lwi)
|
93
|
-
@iwork
|
94
|
-
@work
|
95
|
-
@pwork
|
96
|
-
@piwork
|
97
|
-
@info
|
98
|
-
@pinfo
|
99
|
-
@ialgs
|
100
|
-
@res
|
101
|
-
@inter
|
102
|
-
@rtol
|
103
|
-
@atol
|
104
|
-
@jac
|
105
|
-
|
97
|
+
@iwork = [0]*@lwi
|
98
|
+
@work = [0]*@lwr
|
99
|
+
@pwork = FFI::MemoryPointer.new(:double,@lwr)
|
100
|
+
@piwork = FFI::MemoryPointer.new(:int,@lwi)
|
101
|
+
@info = [0]*30
|
102
|
+
@pinfo = FFI::MemoryPointer.new(:int,30)
|
103
|
+
@ialgs = [0]*neq
|
104
|
+
@res = res
|
105
|
+
@inter = inter
|
106
|
+
@rtol = 0.000001
|
107
|
+
@atol = 0.000001
|
108
|
+
@jac = jac
|
109
|
+
@maxstep = 0
|
106
110
|
|
107
|
-
@pmxnit = FFI::MemoryPointer.new(:int)
|
108
|
-
@pmxnj = FFI::MemoryPointer.new(:int)
|
109
|
-
@pmxnh = FFI::MemoryPointer.new(:int)
|
110
|
-
@plsoff = FFI::MemoryPointer.new(:int)
|
111
|
-
@pstptol = FFI::MemoryPointer.new(:double)
|
112
|
-
@pepinit = FFI::MemoryPointer.new(:double)
|
113
|
-
pidum = FFI::MemoryPointer.new(:int)
|
114
|
-
|
115
|
-
@maxstep = 0.0
|
116
|
-
@mxnit = 5
|
117
|
-
@mxnj = 6
|
118
|
-
@mxnh = 5
|
119
|
-
@lsoff = 0
|
120
|
-
@stptol = d1mach_(pidum)**(2.0/3.0)
|
121
|
-
@epinit = 0.01
|
122
|
-
@info[16] = 1
|
123
111
|
|
124
112
|
if (inter) then
|
125
113
|
@info[2]=1
|
126
114
|
end
|
127
115
|
|
128
|
-
@neq
|
129
|
-
@pneq
|
116
|
+
@neq = neq
|
117
|
+
@pneq = FFI::MemoryPointer.new(:int)
|
130
118
|
@pneq.write_int(neq)
|
131
|
-
@y=y
|
132
|
-
@yprime=yprime
|
119
|
+
@y = y
|
120
|
+
@yprime = yprime
|
133
121
|
|
134
|
-
@py
|
122
|
+
@py = FFI::MemoryPointer.new(:double,neq)
|
135
123
|
@py.write_array_of_double(y)
|
136
|
-
@pyprime
|
124
|
+
@pyprime = FFI::MemoryPointer.new(:double,neq)
|
137
125
|
@pyprime.write_array_of_double(yprime)
|
138
126
|
|
139
|
-
@prtol
|
140
|
-
@patol
|
127
|
+
@prtol = FFI::MemoryPointer.new(:double)
|
128
|
+
@patol = FFI::MemoryPointer.new(:double)
|
141
129
|
|
142
130
|
#
|
143
131
|
# residual proc called from the Fortran. Let's pass it onto the user's residual procedure
|
@@ -178,7 +166,7 @@ module DASPK
|
|
178
166
|
# this is only required if the Y's and Y'primes are not
|
179
167
|
# already consistent
|
180
168
|
#
|
181
|
-
# y or yprime will be modified
|
169
|
+
# the contents of y or yprime will be modified
|
182
170
|
#
|
183
171
|
# init=
|
184
172
|
# * 1 compute derivatives and algebraics from states
|
@@ -188,8 +176,16 @@ module DASPK
|
|
188
176
|
# 0 means it is a state (aka has derivative in the equations)
|
189
177
|
# 1 means it is an algebraic
|
190
178
|
#
|
191
|
-
def solveForInitialValues(time,y,yprime,ialgs,init=1)
|
192
|
-
|
179
|
+
def solveForInitialValues(time,y,yprime,ialgs,init=1,mxnit=5,mxnj=6,mxnh=5,lsoff=0,stptol=0,epinit=0.01)
|
180
|
+
|
181
|
+
@mxnit = mxnit
|
182
|
+
@mxnj = mxnj
|
183
|
+
@mxnh = mxnj
|
184
|
+
@lsoff = lsoff
|
185
|
+
pidum = FFI::MemoryPointer.new(:int)
|
186
|
+
@stptol = (stptol==0 ? d1mach_(pidum)**(2.0/3.0) : stptol)
|
187
|
+
@epinit = epinit
|
188
|
+
@info[16] = 1
|
193
189
|
@iwork[31] = @mxnit
|
194
190
|
@iwork[32] = @mxnj
|
195
191
|
@iwork[33] = @mxnh
|
@@ -197,17 +193,18 @@ module DASPK
|
|
197
193
|
@work[13] = @stptol
|
198
194
|
@work[14] = @epinit
|
199
195
|
|
200
|
-
ptime
|
196
|
+
ptime = FFI::MemoryPointer.new(:double)
|
197
|
+
ptout = FFI::MemoryPointer.new(:double)
|
198
|
+
pidid = FFI::MemoryPointer.new(:int)
|
199
|
+
@y = y
|
200
|
+
@yprime = yprime
|
201
|
+
|
201
202
|
ptime.write_double(time)
|
202
|
-
ptout = FFI::MemoryPointer.new(:double)
|
203
203
|
ptout.write_double(time+1)
|
204
|
-
pidid = FFI::MemoryPointer.new(:int)
|
205
|
-
@prtol.write_double(@rtol)
|
206
|
-
@patol.write_double(@atol)
|
207
|
-
@y=y
|
208
|
-
@yprime=yprime
|
209
204
|
@py.write_array_of_double(@y)
|
210
205
|
@pyprime.write_array_of_double(@yprime)
|
206
|
+
@prtol.write_double(@rtol)
|
207
|
+
@patol.write_double(@atol)
|
211
208
|
|
212
209
|
if (init==1) then
|
213
210
|
@info[10]=1
|
@@ -236,24 +233,18 @@ module DASPK
|
|
236
233
|
@yprime.replace @pyprime.read_array_of_double(@neq)
|
237
234
|
idid = pidid.read_int
|
238
235
|
end
|
239
|
-
@info[13]=0
|
240
|
-
@info[10]=0
|
241
|
-
@info[0]=0
|
236
|
+
@info[13] = 0
|
237
|
+
@info[10] = 0
|
238
|
+
@info[0] = 0
|
239
|
+
@info[16] = 0
|
242
240
|
idid
|
243
241
|
|
244
242
|
end
|
245
243
|
|
246
244
|
def solve (time, tout)
|
247
|
-
|
248
245
|
#
|
249
246
|
# solver options
|
250
247
|
#
|
251
|
-
@iwork[31] = @mxnit
|
252
|
-
@iwork[32] = @mxnj
|
253
|
-
@iwork[33] = @mxnh
|
254
|
-
@iwork[34] = @lsoff
|
255
|
-
@work[13] = @stptol
|
256
|
-
@work[14] = @epinit
|
257
248
|
|
258
249
|
@prtol.write_double(@rtol)
|
259
250
|
@patol.write_double(@atol)
|
@@ -292,12 +283,10 @@ module DASPK
|
|
292
283
|
idid=1
|
293
284
|
pidid = FFI::MemoryPointer.new(:int)
|
294
285
|
pidid.write_int(idid)
|
295
|
-
|
296
286
|
@pwork.write_array_of_double(@work)
|
297
287
|
@piwork.write_array_of_int(@iwork)
|
298
288
|
@pinfo.write_array_of_int(@info)
|
299
289
|
|
300
|
-
|
301
290
|
while (idid==1) do
|
302
291
|
ddaspk_(@resproc,@pneq,ptime,@py,@pyprime,ptout,@pinfo,@prtol,@patol,pidid,@pwork,@plwr,@piwork,@plwi,nil,nil,@jacproc,nil)
|
303
292
|
idid = pidid.read_int
|
@@ -310,9 +299,9 @@ module DASPK
|
|
310
299
|
|
311
300
|
end
|
312
301
|
|
313
|
-
@work
|
314
|
-
@iwork
|
315
|
-
@info[0]=1
|
302
|
+
@work = @pwork.read_array_of_double(@lwr) # save the working ram
|
303
|
+
@iwork = @piwork.read_array_of_int(@lwi)
|
304
|
+
@info[0] = 1
|
316
305
|
[ptime.read_double,@py.read_array_of_double(@neq),@pyprime.read_array_of_double(@neq),idid]
|
317
306
|
|
318
307
|
end
|
@@ -323,7 +312,6 @@ module DASPK
|
|
323
312
|
@pyprime.write_array_of_double(@yprime)
|
324
313
|
end
|
325
314
|
|
326
|
-
|
327
315
|
end
|
328
316
|
|
329
317
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-daspk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: x86-darwin-10
|
6
6
|
authors:
|
7
7
|
- Eric Meyers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,7 @@ licenses: []
|
|
40
40
|
|
41
41
|
post_install_message:
|
42
42
|
rdoc_options:
|
43
|
-
-
|
43
|
+
- -S
|
44
44
|
require_paths:
|
45
45
|
- lib
|
46
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|