num4partialdiff 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 16d60c15e1c6da491e4b8485ecfa5024fcb4a5985ddb05f8b8e65999332ff889
4
+ data.tar.gz: a50c7000c50c87f3471a2e8dbd3a31dadfd45b471fd682b4b13831b48b9073fa
5
+ SHA512:
6
+ metadata.gz: a1498e064591a3865a5500f4fcb69421b72bbcd46f1cba7ba27bdd55082b6da1fed44eb1b9a8cf98659e83bfd222f87b797d42e2733e5b6610dcfda12579b99b
7
+ data.tar.gz: 5658eebcbc846cb902a2a32e1b048b1ae32ed0031df36d0c802cf665894898b8c59f71b204a55a61d144b076a4f61676ab981633e2ceaf08f15c3716c2cae6a1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+
3
+ ## Unreleased
4
+
5
+ ## [0.0.1] - 2023-08-12
6
+
7
+ ### Fixed
8
+ - fix first fixed.
9
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 siranovel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <assert.h>
4
+ #include "CNum4PartialDiff.h"
5
+
6
+ static double* CNum4PartialDiff_doFiniteDiffMethod(int n, double *yi, double h, double *f);
7
+ static CNum4PartialDiff _cNum4PDE = {
8
+ .FP_finiteDiffMethod = CNum4PartialDiff_doFiniteDiffMethod,
9
+ };
10
+ /**************************************/
11
+ /* InterFface部 */
12
+ /**************************************/
13
+ /**************************************/
14
+ /* Class部 */
15
+ /**************************************/
16
+ double* CNum4PartialDiff_finiteDiffMethod(int n, double *yi, double h, double *f)
17
+ {
18
+ assert(f != 0);
19
+ assert(yi != 0);
20
+ assert( n > 0);
21
+
22
+ return _cNum4PDE.FP_finiteDiffMethod(n, yi, h, f);
23
+ }
24
+ /**************************************/
25
+ /* 処理実行部 */
26
+ /**************************************/
27
+ /*
28
+ * 前進差分法
29
+ */
30
+ static double* CNum4PartialDiff_doFiniteDiffMethod(int n, double *yi, double h, double *f)
31
+ {
32
+ int i;
33
+ double *yi_1 = malloc(sizeof(double) * n);
34
+
35
+ assert(yi_1 != 0);
36
+ // yi_1 = yi + h * f(xi, y)
37
+ for (i = 0; i < n; i++) {
38
+ yi_1[i] = yi[i] + h * f[i];
39
+ }
40
+ return yi_1;
41
+ }
42
+
@@ -0,0 +1,20 @@
1
+ #ifndef _CNum4PartialDiff_H_
2
+ #define _CNum4PartialDiff_H_
3
+
4
+ /**************************************/
5
+ /* 構造体宣言 */
6
+ /**************************************/
7
+ typedef struct _CNum4PartialDiff CNum4PartialDiff;
8
+
9
+ struct _CNum4PartialDiff
10
+ {
11
+ double* (*FP_finiteDiffMethod)(int n, double *yi, double h, double *f);
12
+ };
13
+ /**************************************/
14
+ /* define宣言 */
15
+ /**************************************/
16
+ /**************************************/
17
+ /* プロトタイプ宣言 */
18
+ /**************************************/
19
+ double* CNum4PartialDiff_finiteDiffMethod(int n, double *yi, double h, double *f);
20
+ #endif
@@ -0,0 +1,5 @@
1
+ require 'ffi-compiler/compile_task'
2
+
3
+ FFI::Compiler::CompileTask.new('num4partialdiff') do |c|
4
+ c.have_header?('CNum4PartialDiff.h', '.')
5
+ end
@@ -0,0 +1,91 @@
1
+ require 'ffi'
2
+ require 'ffi-compiler/loader'
3
+ require 'fiddle'
4
+
5
+
6
+ #
7
+ # 数値計算によ一次偏微分方程式の解法するライブラリ
8
+ module Num4PartialDiffLib
9
+ extend FFI::Library
10
+
11
+ ffi_lib FFI::Compiler::Loader.find('num4partialdiff')
12
+ attach_function :finiteDiffMethodFFI,
13
+ :CNum4PartialDiff_finiteDiffMethod,[:int, :buffer_in, :double, :buffer_in], :pointer
14
+ class << self
15
+ #
16
+ # @private
17
+ class Counter
18
+ @idx = 0
19
+ def self.getIdx
20
+ return @idx
21
+ end
22
+ def self.countup
23
+ @idx = @idx + 1
24
+ end
25
+ end
26
+ # 有限差分法による数値計算
27
+ #
28
+ # @overload finiteDiffMethod(yi, x0, h, func)
29
+ # @param [double[]] yi 各変数の値
30
+ # @param [double[]] x0 各変数の初期値
31
+ # @param [double] h 刻み幅
32
+ # @param [callback] func xiに対する傾きを計算する関数
33
+ # @return [double[]] x0+nhに対するfi_1の値(配列)
34
+ # @example
35
+ # yi = [0.0, 0.0, 0.0]
36
+ # x0 = [0.0, 0.0, 0.0]
37
+ # h = 0.001
38
+ # func = Proc.new do | n, xi |
39
+ # f = 2 * xi[0] + 3 * xi[1] + 4 * xi[2] + 5
40
+ # next f
41
+ # end
42
+ # yi_1 = Num4PartialDiffLib.finiteDiffMethod(yi, x0, h, func)
43
+ # @note 各変数の刻み幅は、一定です。
44
+ #
45
+ def finiteDiffMethod(yi, x0, h, func)
46
+ n = yi.size
47
+ fi_ptr = calcVectFi(n, x0, h, func)
48
+ yi_ptr = cnvRbAry2pt(n, yi)
49
+ yi_1_ptr = finiteDiffMethodFFI(n, yi_ptr, h, fi_ptr)
50
+ yi_1 = cnvPt2RbAry(n, yi_1_ptr)
51
+ return yi_1
52
+ end
53
+ #
54
+ # @private
55
+ def cnvRbAry2pt(n, ary)
56
+ yi_ptr = FFI::MemoryPointer.new(:double, n)
57
+ n.times.map { |i|
58
+ yi_ptr.put_double(i * Fiddle::SIZEOF_DOUBLE, ary[i].to_f)
59
+ }
60
+ return yi_ptr
61
+ end
62
+ #
63
+ # @private
64
+ def cnvPt2RbAry(n, pt)
65
+ rbAry = n.times.map { |i|
66
+ pt.get_double(i * Fiddle::SIZEOF_DOUBLE)
67
+ }
68
+ return rbAry
69
+ end
70
+ #
71
+ # @private
72
+ def calcVectFi(n, x0, h, func)
73
+ xi = []
74
+ fi_ptr = FFI::MemoryPointer.new(:double, n)
75
+ idx = Counter.getIdx()
76
+ n.times.map { |i|
77
+ xi = x0
78
+ xi[i] = x0[i] + idx * h
79
+ fi_ptr.put_double(i * Fiddle::SIZEOF_DOUBLE, func.call(n, xi))
80
+ }
81
+ Counter.countup
82
+ return fi_ptr
83
+ end
84
+
85
+ private :cnvRbAry2pt
86
+ private :cnvPt2RbAry
87
+ private :calcVectFi
88
+ private :finiteDiffMethodFFI
89
+ end
90
+ end
91
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: num4partialdiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - siranovel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 12.3.3
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '12.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 12.3.3
53
+ description: numerical solution for partial differential equations
54
+ email: siranovel@gmail.com
55
+ executables: []
56
+ extensions:
57
+ - ext/num4partialdiff/Rakefile
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".yardopts"
61
+ - CHANGELOG.md
62
+ - Gemfile
63
+ - LICENSE
64
+ - ext/num4partialdiff/CNum4PartialDiff.c
65
+ - ext/num4partialdiff/CNum4PartialDiff.h
66
+ - ext/num4partialdiff/Rakefile
67
+ - lib/num4partialdiff.rb
68
+ homepage: http://github.com/siranovel/num4partialdifferent
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ changelog_uri: http://github.com/siranovel/num4partialdifferent/blob/main/CHANGELOG.md
73
+ documentation_uri: https://rubydoc.info/gems/num4partialdiff/0.0.1
74
+ homepage_uri: http://github.com/siranovel/num4partialdifferent
75
+ wiki_uri: https://github.com/siranovel/mydocs/tree/main/num4partidifferent
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.3.7
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: num for partial different
95
+ test_files: []