engineering_calculator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in engineering-calculator.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Thomas Muntaner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ Engineering Calculator provides basic engineering functions for ruby.
2
+
3
+ Gas Dynamics:
4
+ include EngineeringCalculator::GasDynamics
5
+
6
+ Functions:
7
+ fanno(m,gamma)
8
+ isentropic(m,gamma)
9
+ normal_shock(mx,gamma)
10
+ prandtl_compression(mx,gamma,turning_angle)
11
+ prandtl_expansion(mx,gamma,turning_angle)
12
+ rayleigh(m,gamma)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/engineering_calculator/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Thomas Muntaner"]
6
+ gem.email = ["thomas.muntaner@gmail.com"]
7
+ gem.description = %q{Provides engineering functions for ruby}
8
+ gem.summary = %q{Engineering Calculator}
9
+ gem.homepage = "http://www.engineering-calculator.com"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "engineering_calculator"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = EngineeringCalculator::VERSION
17
+ end
@@ -0,0 +1,159 @@
1
+ require "helpers"
2
+
3
+ module EngineeringCalculator
4
+ module GasDynamics
5
+ def fanno(m,gamma)
6
+ p_ratio = 1/m * 1/Math.sqrt((2/(gamma+1)*(1+(gamma-1)/2*pow(m, 2))))
7
+ rho_ratio = 1/m * Math.sqrt((2/(gamma+1)) * (1+(gamma-1)/2*pow(m, 2)))
8
+ t_ratio = 1/(2/(gamma+1)*(1+(gamma-1)/2*pow(m, 2)))
9
+ u_ratio = m * 1/Math.sqrt(2/(gamma+1) * (1 + (gamma-1)/2*pow(m, 2)))
10
+ po_ratio = 1/m * pow(2/(gamma+1) * (1+(gamma-1)/2*pow(m, 2)),(gamma+1)/(gamma-1)/2)
11
+ fanno_param = (1-pow(m, 2))/(gamma*pow(m, 2)) + (gamma+1)/(gamma*2)*Math.log(pow(m, 2)/(2/(gamma+1)*(1+(gamma-1)/2*pow(m, 2))))
12
+ result = {
13
+ :p_ratio => p_ratio,
14
+ :rho_ratio => rho_ratio,
15
+ :t_ratio => t_ratio,
16
+ :u_ratio => u_ratio,
17
+ :po_ratio => po_ratio,
18
+ :fanno_param => fanno_param
19
+ }
20
+ return result
21
+ end
22
+ def isentropic(m,gamma)
23
+ ratio_t = pow(1 + (gamma - 1)/2 * pow(m, 2), -1)
24
+ ratio_p = pow(1 + (gamma - 1)/2 * pow(m, 2), -gamma/(gamma-1))
25
+ ratio_rho = pow(1 + (gamma - 1)/2 * pow(m, 2), -1/(gamma-1))
26
+ ratio_a = pow((gamma + 1)/2, -((gamma + 1)/(gamma - 1)/2))/m * pow(1 + (gamma - 1)/2 * pow(m, 2), ((gamma + 1)/(gamma - 1))/2)
27
+ result = {
28
+ :ratio_t => ratio_t,
29
+ :ratio_p => ratio_p,
30
+ :ratio_rho => ratio_rho,
31
+ :ratio_a => ratio_a
32
+ }
33
+ return result
34
+ end
35
+ def normal_shock(mx,gamma)
36
+ my = Math.sqrt((pow(mx,2)*(gamma-1)+2)/(2*gamma*pow(mx,2)-(gamma-1)))
37
+ py_px = 2*gamma* pow(mx,2) /(gamma+1)-(gamma-1)/(gamma+1)
38
+ rhoy_rhox = (gamma+1)*pow(mx,2)/((gamma-1)*pow(mx,2)+2)
39
+ ty_tx = (1 + (gamma - 1)/2 * pow(mx, 2))*(2*gamma/(gamma - 1) * pow(mx, 2) - 1)/(pow(mx, 2)*(2*gamma/(gamma - 1) + (gamma - 1)/2))
40
+ poy_pox = pow((gamma + 1)/2 * pow(mx, 2)/(1 + (gamma - 1)/2 * pow(mx, 2)), gamma/(gamma - 1)) * pow(1/(2 * gamma/(gamma+1) * pow(mx,2) - (gamma-1)/(gamma+1)), 1/(gamma - 1));
41
+ result = {
42
+ :my => my,
43
+ :py_px => py_px,
44
+ :rhoy_rhox => rhoy_rhox,
45
+ :ty_tx => ty_tx,
46
+ :poy_pox => poy_pox
47
+ }
48
+ return result
49
+ end
50
+ def oblique(mx,gamma,delta)
51
+ pi = Math::PI
52
+ # Initial guess that beta and delta coincide.
53
+ beta = delta*pi/180
54
+ e = 1
55
+ rhs = Math.tan(delta*pi/180)
56
+
57
+ while (e >= 1*10**(-5))
58
+ lhs = 2*(1/Math.tan(beta))*(pow(mx,2)*pow(Math.sin(beta),2)-1)/(pow(mx,2)*(gamma+Math.cos(2*beta))+2)
59
+ e = rhs - lhs
60
+ beta = beta + 0.00001
61
+ end
62
+ ratio_rho = (gamma+1) * pow(mx, 2)*pow(Math.sin(beta), 2) / ((gamma-1)*pow(mx, 2)*pow(Math.sin(beta), 2)+2)
63
+ beta = beta*180/pi;
64
+
65
+ ratio_p = 1+2*gamma/(gamma+1)*(pow(mx,2)*pow(Math.sin(beta*pi/180),2)-1);
66
+ ratio_t = ratio_p*pow((gamma+1)*pow(mx,2)*pow(Math.sin(beta*pi/180),2)/((gamma-1)*pow(mx,2)*pow(Math.sin(beta*pi/180),2)+2),-1);
67
+ my = (1/Math.sin((beta-delta)*pi/180))*pow((1+0.5*(gamma-1)*pow(mx,2)*pow(Math.sin(beta*pi/180),2))/(gamma*pow(mx,2)*pow(Math.sin(beta*pi/180),2)-0.5*(gamma-1)),0.5);
68
+ ratio_px = pow(1 + (gamma - 1)/2 * pow(mx, 2), -gamma/(gamma-1));
69
+ ratio_py = pow(1 + (gamma - 1)/2 * pow(my, 2), -gamma/(gamma-1));
70
+ ratio_po = ratio_px/ratio_py*ratio_p;
71
+ result = {
72
+ :my => my,
73
+ :ratio_rho => ratio_rho,
74
+ :beta => beta,
75
+ :ratio_p => ratio_p,
76
+ :ratio_t => ratio_t,
77
+ :ratio_po => ratio_po
78
+ }
79
+ return result
80
+ end
81
+ def prandtl_compression(mx,gamma,turning_angle)
82
+ pi = Math::PI
83
+ nux = Math.sqrt((gamma+1)/(gamma-1)) * Math.atan(Math.sqrt((gamma-1)/(gamma+1)*(pow(mx, 2)-1))) - Math.atan(Math.sqrt(pow(mx, 2)-1))
84
+ turningAngle = turning_angle*pi/180
85
+ nuy = nux - turningAngle
86
+ my = 1
87
+ e = 1
88
+ while (e >= 0.00001)
89
+ nuy_test = Math.sqrt((gamma+1)/(gamma-1)) * Math.atan(Math.sqrt((gamma-1)/(gamma+1)*(pow(my, 2)-1))) - Math.atan(Math.sqrt(pow(my, 2)-1))
90
+ e = nuy - nuy_test
91
+ my = my+0.00001
92
+ end
93
+ my = my-0.00001
94
+ ty_tx = (1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2))
95
+ py_px = pow((1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2)), gamma/(gamma-1))
96
+ rhoy_rhox = pow((1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2)), 1/(gamma-1))
97
+ mux = Math.asin(1/mx)
98
+ muy = Math.asin(1/my)
99
+ result = {
100
+ :ty_tx => ty_tx,
101
+ :py_px => py_px,
102
+ :rhoy_rhox => rhoy_rhox,
103
+ :my => my,
104
+ :nux => nux*180/pi,
105
+ :nuy => nuy*180/pi,
106
+ :mux => mux*180/pi,
107
+ :muy => muy*180/pi,
108
+ }
109
+ return result
110
+ end
111
+ def prandtl_expansion(mx,gamma,turning_angle)
112
+ pi = Math::PI
113
+ nux = Math.sqrt((gamma+1)/(gamma-1)) * Math.atan(Math.sqrt((gamma-1)/(gamma+1)*(pow(mx, 2)-1))) - Math.atan(Math.sqrt(pow(mx, 2)-1))
114
+ turningAngle = turning_angle*pi/180
115
+ nuy = nux + turningAngle
116
+ my = 1
117
+ e = 1
118
+ while (e >= 0.00001)
119
+ nuy_test = Math.sqrt((gamma+1)/(gamma-1)) * Math.atan(Math.sqrt((gamma-1)/(gamma+1)*(pow(my, 2)-1))) - Math.atan(Math.sqrt(pow(my, 2)-1))
120
+ e = nuy - nuy_test
121
+ my = my+0.00001
122
+ end
123
+ my = my-0.00001
124
+ ty_tx = (1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2))
125
+ py_px = pow((1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2)), gamma/(gamma-1))
126
+ rhoy_rhox = pow((1+(gamma-1)/2*pow(mx, 2))/(1+(gamma-1)/2*pow(my, 2)), 1/(gamma-1))
127
+ mux = Math.asin(1/mx)
128
+ muy = Math.asin(1/my)
129
+ result = {
130
+ :ty_tx => ty_tx,
131
+ :py_px => py_px,
132
+ :rhoy_rhox => rhoy_rhox,
133
+ :my => my,
134
+ :nux => nux*180/pi,
135
+ :nuy => nuy*180/pi,
136
+ :mux => mux*180/pi,
137
+ :muy => muy*180/pi,
138
+ }
139
+ return result
140
+ end
141
+ def rayleigh(m,gamma)
142
+ p_ratio = (gamma+1)/(1+gamma*pow(m, 2));
143
+ rho_ratio = (1+gamma*pow(m,2))/((1+gamma)*pow(m,2));
144
+ t_ratio = pow(gamma+1, 2)*pow(m, 2)/pow(1+gamma*pow(m, 2), 2);
145
+ u_ratio = (gamma+1)*pow(m, 2)/(1+gamma*pow(m, 2));
146
+ po_ratio = (gamma+1)/(1+gamma*pow(m, 2)) * pow(2/(gamma+1)*(1+(gamma-1)/2*pow(m, 2)), gamma/(gamma-1));
147
+ to_ratio= 2*(gamma+1)*pow(m, 2)/pow(1+gamma*pow(m, 2),2) * (1+(gamma-1)/2*pow(m, 2));
148
+ result = {
149
+ :p_ratio => p_ratio,
150
+ :rho_ratio => rho_ratio,
151
+ :t_ratio => t_ratio,
152
+ :u_ratio => u_ratio,
153
+ :po_ratio => po_ratio,
154
+ :to_ratio => to_ratio
155
+ }
156
+ return result
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,3 @@
1
+ module EngineeringCalculator
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "engineering_calculator/version"
2
+ require "engineering_calculator/gas_dynamics"
3
+
4
+ module EngineeringCalculator
5
+
6
+ end
data/lib/helpers.rb ADDED
@@ -0,0 +1,3 @@
1
+ def pow(x,y)
2
+ return x**y
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: engineering_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Muntaner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides engineering functions for ruby
15
+ email:
16
+ - thomas.muntaner@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - engineering-calculator.gemspec
27
+ - lib/engineering_calculator.rb
28
+ - lib/engineering_calculator/gas_dynamics.rb
29
+ - lib/engineering_calculator/version.rb
30
+ - lib/helpers.rb
31
+ homepage: http://www.engineering-calculator.com
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.15
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Engineering Calculator
55
+ test_files: []