source: src/main/java/agents/anac/y2015/agentBuyogV2/flanagan/physprop/Sucrose.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 23.2 KB
Line 
1/*
2* Sucrose Class
3*
4* Methods for returning the physical properties of
5* aqueous sucrose solutions:
6* viscosity, density, refractive index, solubility, specific volume,
7* diffusion coefficient, mole fraction and molecular weight.
8* Methods for interconverting molar - grams per litre - percent weight by weight.
9*
10* Author: Dr Michael Thomas Flanagan.
11*
12* Created: July 2003
13* Updated: 1 July 2003, May 2004, 29-31 July 2008
14*
15* DOCUMENTATION:
16* See Michael Thomas Flanagan's Java library on-line web page:
17* http://www.ee.ucl.ac.uk/~mflanaga/java/Sucrose.html
18* http://www.ee.ucl.ac.uk/~mflanaga/java/
19*
20* Copyright (c) 2003 - 2008 Michael Thomas Flanagan
21*
22* PERMISSION TO COPY:
23* Permission to use, copy and modify this software and its documentation for
24* NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
25* to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
26*
27* Dr Michael Thomas Flanagan makes no representations about the suitability
28* or fitness of the software for any or for a particular purpose.
29* Michael Thomas Flanagan shall not be liable for any damages suffered
30* as a result of using, modifying or distributing this software or its derivatives.
31*
32***************************************************************************************/
33
34package agents.anac.y2015.agentBuyogV2.flanagan.physprop;
35
36import agents.anac.y2015.agentBuyogV2.flanagan.interpolation.BiCubicSpline;
37import agents.anac.y2015.agentBuyogV2.flanagan.interpolation.CubicSpline;
38import agents.anac.y2015.agentBuyogV2.flanagan.math.ArrayMaths;
39import agents.anac.y2015.agentBuyogV2.flanagan.math.Fmath;
40
41public class Sucrose{
42
43 public static final double MOLWEIGHT = 342.3; // Sucrose molecular weight
44
45 // METHODS
46
47 // Returns the viscosity (Pa s) of sucrose solutions as a function of
48 // the g/l sucrose concentration and temperature.
49 // Interpolation - natural cubic spline and bicubic spline - log of the viscosity
50 // Data - Rubber Handbook
51 public static double viscosity(double gPerL, double temperature){
52
53
54 if(temperature<0.0)throw new IllegalArgumentException("Temperature, " + temperature + ", out of range");
55 if(gPerL<0.0)throw new IllegalArgumentException("Concentration, " + gPerL + " g/l, out of range");
56
57 double[] visc20 = {1.000, 1.013, 1.026, 1.039, 1.053, 1.067, 1.082, 1.097, 1.112, 1.128, 1.144, 1.160, 1.177, 1.195, 1.213, 1.232, 1.251, 1.271, 1.291, 1.312, 1.333, 1.378, 1.426, 1.477, 1.531, 1.589, 1.650, 1.716, 1.786, 1.861, 1.941, 2.120, 2.326, 2.568, 2.849, 3.181, 3.754, 4.044, 4.612, 5.304, 6.150, 7.220, 8.579, 10.28, 12.49, 15.40, 19.30, 24.63, 32.06, 42.69, 58.37, 82.26, 119.9, 181.7, 287.9, 480.6, 853.2, 1628};
58 int viscLength = visc20.length;
59 for(int i=0; i<viscLength; i++)visc20[i] *= 1.005;
60 double[] concnWA = {0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84};
61 double[] concnGA = {0, 5, 10, 15.1, 20.1, 25.2, 30.3, 35.4, 40.6, 45.7, 50.9, 56.1, 61.3, 66.5, 71.8, 77.1, 82.4, 87.7, 93.1, 98.4, 103.8, 114.7, 125.6, 136.6, 147.7, 158.9, 170.2, 181.5, 193, 204.5, 216.2, 239.8, 263.8, 288.1, 312.9, 338.1, 363.7, 389.8, 416.2, 443.2, 470.6, 498.4, 526.8, 555.6, 584.9, 614.8, 645.1, 676, 707.4, 739.3, 771.9, 804.9, 838.6, 872.8, 907.6, 943.1, 979.1, 1015.7, 1053, 1090.9, 1129.4, 1168.5, 1208.2};
62 ArrayMaths amC = new ArrayMaths(concnGA);
63 double[] zero = {1.7921, 1.5188, 1.3077, 1.1404, 1.0050, 0.8937, 0.8007, 0.7225, 0.6560, 0.5988, 0.5454, 0.5064, 0.4688, 0.4355, 0.4061, 0.3799, 0.3565, 0.3355, 0.3165, 0.2994, 0.2838};
64 int length0 = zero.length;
65
66 double[] twenty = {3.804, 3.154, 2.652, 2.267, 1.960, 1.704, 1.504, 1.331, 1.193, 1.070, 0.970, 0.884, 0.808, 0.742, 0.685, 0.635, 0.590, 0.550};
67 int length20 = twenty.length;
68 double[] forty = {14.77, 11.56, 9.794, 7.468, 6.200, 5.187, 4.382, 3.762, 3.249, 2.847, 2.497, 2.219, 1.982, 1.778, 1.608, 1.462, 1.334, 1.221, 1.123, 1.037, 0.960};
69 int length40 = forty.length;
70 double[] sixty = {238, 156, 109.8, 74.6, 56.5, 43.86, 33.78, 26.52, 21.28, 17.18, 14.01, 11.67, 9.83, 8.34, 7.15, 6.20, 5.40, 4.73, 4.15, 3.72, 3.34};
71 int length60 = sixty.length;
72 double[] temp = new double[length0];
73 temp[0] = 0;
74 for(int i=1; i<length60; i++)temp[i] = temp[i-1] + 5.0;
75 ArrayMaths am0 = new ArrayMaths(zero);
76 ArrayMaths am20 = new ArrayMaths(twenty);
77 ArrayMaths am40 = new ArrayMaths(forty);
78 ArrayMaths am60 = new ArrayMaths(sixty);
79 ArrayMaths amT = new ArrayMaths(temp);
80
81 double[] concn85 = {0.0, 216.2, 470.6, 771.9};
82 double[] concn100 = {0.0, 470.6, 771.9};
83
84 double ret = Double.NaN;
85
86 if(gPerL<=771.9){
87 if(temperature<=85){
88
89 int lengthT85 = length20;
90 int lengthC85 = amC.indexOf(771.9);
91 double[] temp85 = amT.subarray_as_double(0, length20-1);
92 double[] conc85 = amC.subarray_as_double(0, lengthC85);
93
94 lengthC85++;
95 double[][] array = new double[lengthT85][lengthC85];
96 for(int i=0; i<lengthT85; i++){
97 double[] lvisc = {Math.log(zero[i]), Math.log(twenty[i]), Math.log(forty[i]), Math.log(sixty[i])};
98 CubicSpline cs = new CubicSpline(concn85, lvisc);
99 for(int j=0; j<lengthC85; j++){
100 array[i][j] = cs.interpolate(conc85[j]);
101 }
102 }
103 BiCubicSpline bcs = new BiCubicSpline(temp85, conc85, array);
104 ret = Math.exp(bcs.interpolate(temperature, gPerL));
105 }
106 else{
107 if(temperature>100.0){
108 throw new IllegalArgumentException("Temperature, " + temperature + ", out of range");
109 }
110 else{
111 int lengthT100 = length60;
112 int lengthC100 = amC.indexOf(771.9);
113 double[] temp100 = amT.subarray_as_double(0, lengthT100-1);
114 double[] conc100 = amC.subarray_as_double(0, lengthC100);
115 lengthC100++;
116
117 double[][] array = new double[lengthT100][lengthC100];
118 for(int i=0; i<lengthT100; i++){
119 double[] lvisc = {Math.log(zero[i]), Math.log(forty[i]), Math.log(sixty[i])};
120 CubicSpline cs = new CubicSpline(concn100, lvisc);
121 for(int j=0; j<lengthC100; j++){
122 array[i][j] = cs.interpolate(conc100[j]);
123
124 }
125 }
126 BiCubicSpline bcs = new BiCubicSpline(temp100, conc100, array);
127 ret = Math.exp(bcs.interpolate(temperature, gPerL));
128 }
129 }
130 }
131 else{
132 if(temperature==20 && gPerL<=1208.2){
133 double[] concM = amC.subarray_as_double(0, viscLength-1);
134 CubicSpline cs = new CubicSpline(concM, visc20);
135 ret = cs.interpolate(gPerL);
136 }
137 else{
138 throw new IllegalArgumentException("Concentration, " + gPerL + " g/l, for this temperature, " + temperature + " C,is out of range");
139 }
140 }
141
142 return ret;
143 }
144
145
146 // Returns the refractive index of sucrose solutions as a function of g/l sucrose concentration
147 // Wavelength - sodium D line 589.3 nm
148 // Interpolation - natural cubic spline
149 // Extrapolation above 1208.2g/l Lorenz-lorenz equation based on
150 // average refraction of sucrose calculated from experimental data
151 // Data - Rubber Handbook
152 // Uses method in class RefrIndex
153 public static double refractIndex(double concentration, double temperature){
154 return RefrIndex.sucrose(concentration, temperature);
155 }
156
157 // Returns the solubility of sucrose in water as g/l solution as a function of temperature
158 // Data - Rubber handbook
159 // interpolation - cubic spline
160 public static double solubility(double temperature){
161
162 double[] tempc = {0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0};
163 double[] solub = {64.18, 64.87, 65.58, 66.53, 67.09, 67.89, 68.8, 69.55, 70.42, 71.32, 72.25, 73.2, 74.18, 75.88, 76.22, 77.27, 78.36, 79.46, 80.61, 81.77, 82.97};
164 double[] deriv = {0, -0.00489357, 0.0243743, -0.0350036, 0.0220399, 0.00444386, -0.0134154, 0.0108176, -0.00105492, 0.000602123, 0.00584643, -0.0191879, 0.078105, -0.120432, 0.0772233, -0.0180611, 0.00462116, 0.00197648, -0.00052706, 0.00253177, 0};
165
166 double solubility;
167
168 int n=tempc.length;
169
170 if(temperature>=tempc[0] && temperature<=tempc[n-1]){
171 solubility = CubicSpline.interpolate(temperature, tempc, solub, deriv);
172 }
173 else{
174 throw new IllegalArgumentException("The temperatue is outside the experimental data limits");
175 }
176 solubility=weightpercentToGperl(solubility, temperature);
177
178 return solubility;
179 }
180
181 // Returns the density (kg/m^3) of sucrose solutions as a function of g/l sucrose concentration
182 // Interpolation - natural cubic spline
183 // Data - Rubber Handbook
184 // concentration g/l concentration of sucrose for which the density is required
185 // temperature temperature (degree Celsius)
186 public static double density(double concentration, double temperature){
187
188 double[] concnG = {0, 5, 10, 15.1, 20.1, 25.2, 30.3, 35.4, 40.6, 45.7, 50.9, 56.1, 61.3, 66.5, 71.8, 77.1, 82.4, 87.7, 93.1, 98.4, 103.8, 114.7, 125.6, 136.6, 147.7, 158.9, 170.2, 181.5, 193, 204.5, 216.2, 239.8, 263.8, 288.1, 312.9, 338.1, 363.7, 389.8, 416.2, 443.2, 470.6, 498.4, 526.8, 555.6, 584.9, 614.8, 645.1, 676, 707.4, 739.3, 771.9, 804.9, 838.6, 872.8, 907.6, 943.1, 979.1, 1015.7, 1053, 1090.9, 1129.4, 1168.5, 1208.2};
189 double[] dens = {998.2, 1000.2, 1002.1, 1004, 1006, 1007.9, 1009.9, 1011.9, 1013.9, 1015.8, 1017.8, 1019.8, 1021.8, 1023.8, 1025.9, 1027.9, 1029.9, 1032, 1034, 1036.1, 1038.1, 1042.3, 1046.5, 1050.7, 1054.9, 1059.2, 1063.5, 1067.8, 1072.2, 1076.6, 1081, 1089.9, 1099, 1108.2, 1117.5, 1127, 1136.6, 1146.4, 1156.2, 1166.3, 1176.5, 1186.8, 1197.2, 1207.9, 1218.6, 1229.5, 1240.6, 1251.8, 1263.2, 1274.7, 1286.4, 1298.3, 1310.3, 1322.4, 1334.8, 1347.2, 1359.9, 1372.6, 1385.5, 1398.6, 1411.7, 1425, 1438.3};
190 double[] deriv = {0, -0.00495764, -0.00416945, 0.0126089, -0.0137458, 0.00978735, -0.00233552, -0.000445268, -0.00464715, 0.00502912, -0.00144255, 0.000741061, -0.0015217, 0.00534573, -0.00654364, -0.0005311, 0.00866803, -0.0127811, 0.0134147, -0.0118716, 0.00515152, -0.0012962, 3.32699e-005, -0.000758744, 0.00112898, -0.000770477, 0.000145246, 0.000189494, 0.000189925, -0.000949193, 0.000223635, 6.85836e-005, 2.005e-005, -0.000287156, 0.000246234, -0.000222108, 0.000174076, -0.000361684, 0.000296689, -0.000183935, 4.13755e-005, -0.000362702, 0.000485174, -0.000459014, 4.51875e-005, 0.000142595, -0.00025712, 0.000125835, -0.000132083, -8.03786e-005, 0.000151752, -0.000212951, -0.000110921, 0.00024994, -0.000447536, 0.00033998, -0.00032882, 2.20206e-005, 5.04017e-005, -0.000253039, 0.000115168, -0.000224291, 0,};
191 double[] concfit = {0, 200, 400, 600, 800, 1000, 1200};
192 double[] coeff0 = {0.000998363, 0.000926078, 0.000864741, 0.000812717, 0.000766724, 0.000727182, 0.000692587};
193 double[] deriv0 = {0, 3.53118e-010, 2.29729e-010, 1.24915e-010, 1.75259e-010, 1.41698e-010, 0};
194 double[] coeff1 = {2.42825e-007, 2.60851e-007, 2.61522e-007, 1.52504e-007, 2.35274e-007, 2.1465e-007, 1.91079e-007};
195 double[] deriv1 = {0, 1.11593e-012, -7.06697e-012, 1.06986e-011, -6.95925e-012, 1.6293e-012, 0};
196 double density, coefficient0, coefficient1;
197 int n=concfit.length;
198 if(concentration>=concfit[0] && concentration<=concfit[n-1] && temperature>=0 && temperature<=50){
199 coefficient0 = CubicSpline.interpolate(concentration, concfit, coeff0, deriv0);
200 coefficient1 = CubicSpline.interpolate(concentration, concfit, coeff1, deriv1);
201
202 density=1.0/(coefficient0+coefficient1*temperature);
203 }
204 else{
205 throw new IllegalArgumentException("Either Temperature or Concentration is outside the experimental data limits");
206 }
207 return density;
208 }
209
210 // Returns the specific volume (m^3/kg) of sucrose in aqueous solution at 20 C
211 // as a function of g/l sucrose concentration
212 // Average value = 0.000621903 sd = 6.16153e-006 This value is used outside the
213 // limits of the experimental concentration and temperature data
214 // Interpolation - natural cubic spline
215 // Data - calculated from density of water and displaced water volume in the Rubber Handbook
216 public static double specificVolume(double concentration){
217
218 double[] concnG = {0, 5, 10, 15.1, 20.1, 25.2, 30.3, 35.4, 40.6, 45.7, 50.9, 56.1, 61.3, 66.5, 71.8, 77.1, 82.4, 87.7, 93.1, 98.4, 103.8, 114.7, 125.6, 136.6, 147.7, 158.9, 170.2, 181.5, 193, 204.5, 216.2, 239.8, 263.8, 288.1, 312.9, 338.1, 363.7, 389.8, 416.2, 443.2, 470.6, 498.4, 526.8, 555.6, 584.9, 614.8, 645.1, 676, 707.4, 739.3, 771.9, 804.9, 838.6, 872.8, 907.6, 943.1, 979.1, 1015.7, 1053, 1090.9, 1129.4, 1168.5, 1208.2};
219 double[] specv = {0.000621118, 0.000621118, 0.000621118, 0.000617005, 0.000618028, 0.000616189, 0.000614968, 0.00061693, 0.000614406, 0.000615988, 0.00061604, 0.000616082, 0.000616117, 0.000616147, 0.000616709, 0.000615895, 0.000616401, 0.000616846, 0.000616577, 0.000616964, 0.000616717, 0.000616629, 0.000617353, 0.00061751, 0.000617225, 0.000617222, 0.000617445, 0.000618193, 0.000618211, 0.000618228, 0.000618597, 0.000618712, 0.000619007, 0.000619651, 0.000619844, 0.000620164, 0.000620584, 0.000620923, 0.000621494, 0.000621832, 0.000622455, 0.000622911, 0.00062337, 0.000623873, 0.000624478, 0.000624905, 0.00062537, 0.000625979, 0.000626516, 0.000627126, 0.000627766, 0.000628414, 0.000628964, 0.000629685, 0.000630377, 0.00063108, 0.000631819, 0.000632624, 0.000633334, 0.000634105, 0.000635019, 0.00063589, 0.000636886};
220 double[] deriv = {0, 9.54239e-008, -3.81696e-007, 4.69472e-007, -2.94053e-007, 3.9486e-008, 2.78669e-007, -4.19907e-007, 3.86217e-007, -1.95897e-007, 5.08841e-008, -9.858e-009, -1.30053e-008, 6.07699e-008, -1.14515e-007, 1.03377e-007, -1.70413e-008, -4.82412e-008, 5.92625e-008, -5.10779e-008, 1.22998e-008, 9.25257e-009, -8.30337e-009, -4.55102e-009, 4.7569e-009, -8.20925e-010, 9.1751e-009, -1.12103e-008, 1.71621e-009, 4.30015e-009, -3.32497e-009, 1.03549e-009, 1.01682e-009, -1.55614e-009, 6.3652e-010, 1.76082e-010, -4.56375e-010, 8.49619e-010, -9.64276e-010, 9.59006e-010, -6.2015e-010, 1.50421e-010, -3.91772e-011, 2.78811e-010, -4.15371e-010, 9.3832e-011, 2.48046e-010, -2.27533e-010, 1.60667e-010, -3.36646e-011, 6.9795e-011, -2.4342e-010, 3.04857e-010, -1.35319e-010, 3.06608e-011, -2.68355e-012, 1.01252e-010, -1.58595e-010, 5.29862e-011, 1.52913e-010, -1.29603e-010, 1.39208e-010, 0};
221 double specvol, average=0.000621903;
222 int n=concnG.length;
223
224 if(concentration>=concnG[0] && concentration<=concnG[n-1]){
225 specvol = CubicSpline.interpolate(concentration, concnG, specv, deriv);
226 }
227 else{
228 specvol=average;
229 }
230 return specvol;
231 }
232
233
234 // Returns the diffusion coefficient (m^2 s^-1) of sucrose in aqueous solution
235 // as a function of the g/l sucrose concentration
236 // concentration g/l concentration of sucrose for which a diffusion coefficient is required
237 // temperature temperature in degree Celsius
238
239 public static double diffCoeff(double concentration, double temperature){
240
241 double diffcoef, f, viscosity, specvol, vol, radius, tempa;
242
243 tempa=temperature - Fmath.T_ABS;
244
245 viscosity=Sucrose.viscosity(concentration, temperature);
246 specvol=Sucrose.specificVolume(concentration);
247 vol=Sucrose.MOLWEIGHT*specvol/(Fmath.N_AVAGADRO*1000);
248 radius=Math.pow(3.0*vol/(4.0*Math.PI),1.0/3.0);
249
250 f=6.0*Math.PI*viscosity*radius;
251
252 diffcoef=Fmath.K_BOLTZMANN*tempa/f;
253
254 return diffcoef;
255 }
256
257 // Returns the mole fraction of sucrose in an aqueous sucrose solution
258 // for a given sucrose concentration (g/l) and temperature
259 public static double moleFraction(double concentration, double temperature){
260 double weightSucrose, totalWeight, molesWater, molesSucrose;
261 weightSucrose=concentration*1000;
262 molesSucrose=weightSucrose/Sucrose.MOLWEIGHT;
263 totalWeight=Sucrose.density(concentration, temperature)*1000.0;
264 molesWater=(totalWeight-weightSucrose)/Water.MOLWEIGHT;
265 return molesSucrose/(molesWater + molesSucrose);
266 }
267
268 // Converts Molar sucrose to g/l sucrose
269 public static double molarToGperl(double molar){
270 return molar*Sucrose.MOLWEIGHT;
271 }
272
273 // Converts Molar sucrose to weight per cent sucrose
274 public static double molarToWeightpercent(double molar, double temperature){
275 double weight;
276 weight = Sucrose.molarToGperl(molar);
277 weight = Sucrose.gperlToWeightpercent(weight, temperature);
278 return weight;
279 }
280
281 // Converts g/l sucrose to Molar sucrose
282 public static double gperlToMolar(double gperl){
283 return gperl/Sucrose.MOLWEIGHT;
284 }
285
286 // Converts a g/l aqueous sucrose concentration to the % weight concentration
287 // (g sucrose / 100g solution)at a gven temperature (Celsius)
288 // Interpolation - cubic spline (20C) and calculation from density
289 // Data - Rubber Handbook
290 public static double gperlToWeightpercent(double concentration, double temperature){
291
292 double[] concnG = {0, 5, 10, 15.1, 20.1, 25.2, 30.3, 35.4, 40.6, 45.7, 50.9, 56.1, 61.3, 66.5, 71.8, 77.1, 82.4, 87.7, 93.1, 98.4, 103.8, 114.7, 125.6, 136.6, 147.7, 158.9, 170.2, 181.5, 193, 204.5, 216.2, 239.8, 263.8, 288.1, 312.9, 338.1, 363.7, 389.8, 416.2, 443.2, 470.6, 498.4, 526.8, 555.6, 584.9, 614.8, 645.1, 676, 707.4, 739.3, 771.9, 804.9, 838.6, 872.8, 907.6, 943.1, 979.1, 1015.7, 1053, 1090.9, 1129.4, 1168.5, 1208.2};
293 double[] concnW = {0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84};
294 double[] deriv = {0, 0.000224325, -0.0008973, 0.00102728, -0.000882025, 0.00017957, 0.000163747, -0.000834558, 0.000970111, -0.000849482, 0.000238375, -0.000104019, 0.000177701, -0.000606786, 0.000176058, -9.74476e-005, 0.000213732, -0.00075748, 0.000850948, -0.000686359, -5.6318e-005, 4.08684e-005, -0.000107156, -6.87474e-005, -6.27622e-005, -0.000112854, 9.20828e-005, -0.000255477, 0.000119556, -0.000222749, 3.59124e-006, -8.44627e-005, -2.16033e-005, -8.47265e-005, -4.4802e-005, -4.36141e-005, -7.34483e-005, -1.02994e-005, -8.43266e-005, -3.04826e-005, -3.26613e-005, -6.69242e-005, -2.42674e-005, -4.13785e-005, -5.47191e-005, -1.76386e-005, -5.07722e-005, -3.04569e-005, -2.61186e-005, -5.41411e-005, -7.97549e-006, -5.00124e-005, -1.83509e-005, -3.00707e-005, -3.65588e-005, -1.72617e-005, -2.57937e-005, -2.9995e-005, -2.0797e-005, -2.23338e-005, -1.90539e-005, -2.47041e-005, 0};
295 double weight;
296
297 weight=concentration*0.1/(Sucrose.density(concentration, temperature)/1000);
298
299 return weight;
300 }
301
302 // Converts weight percent sucrose to Molar sucrose
303 public static double weightpercentToMolar(double weight, double temperature){
304 double molar;
305 molar = weightpercentToGperl(weight, temperature);
306 molar = gperlToMolar(molar);
307 return molar;
308 }
309
310 // Converts the % weight concentration (g sucrose / 100g solution)
311 // to a g/l aqueous sucrose concentration
312 // interpolation - natural cubic spline (20C) and calculation
313 // Data - Rubber Handbook
314 // concentration % weight concentration of sucrose
315 // temperature temperature (degrees Celsius)
316 public static double weightpercentToGperl(double concentration, double temperature){
317 double[] concnW = {0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84};
318 double[] concnG = {0, 5, 10, 15.1, 20.1, 25.2, 30.3, 35.4, 40.6, 45.7, 50.9, 56.1, 61.3, 66.5, 71.8, 77.1, 82.4, 87.7, 93.1, 98.4, 103.8, 114.7, 125.6, 136.6, 147.7, 158.9, 170.2, 181.5, 193, 204.5, 216.2, 239.8, 263.8, 288.1, 312.9, 338.1, 363.7, 389.8, 416.2, 443.2, 470.6, 498.4, 526.8, 555.6, 584.9, 614.8, 645.1, 676, 707.4, 739.3, 771.9, 804.9, 838.6, 872.8, 907.6, 943.1, 979.1, 1015.7, 1053, 1090.9, 1129.4, 1168.5, 1208.2};
319 double[] deriv = {0, -0.230536, 0.922143, -1.05804, 0.909999, -0.181959, -0.182163, 0.910611, -1.06028, 0.930517, -0.261788, 0.116633, -0.204746, 0.702351, -0.204657, 0.116276, -0.260447, 0.925512, -1.0416, 0.840888, 0.078047, -0.0545852, 0.140294, 0.0934103, 0.0860649, 0.16233, -0.135385, 0.37921, -0.181457, 0.346616, -0.00500719, 0.141714, 0.0381529, 0.155675, 0.0891471, 0.0877366, 0.159906, 0.0226375, 0.199544, 0.0791879, 0.0837046, 0.185994, 0.0723209, 0.124723, 0.178788, 0.0601258, 0.180709, 0.117039, 0.101137, 0.228414, 0.0352078, 0.230755, 0.0917725, 0.152155, 0.199608, 0.0994148, 0.152733, 0.189652, 0.138658, 0.155717, 0.138476, 0.190381, 0};
320 double gperl=0.0, f1, f2, f3, g1, g2, g3, tol;
321 int n=concnW.length, j=-1, itermax=1000;
322 boolean test=true;
323
324 if(concentration<concnW[0] || concentration>concnW[n-1]){
325 throw new IllegalArgumentException("concentration is outside the experimental data limits");
326 }
327
328 // obtains g/l by bisection using g/l=weight%*density
329 tol=concentration*1e-4;
330 g1=0.0;
331 g2=1200;
332 f1=g1-concentration*Sucrose.density(g1,temperature)/100;
333 f2=g2-concentration*Sucrose.density(g2,temperature)/100;
334 if ((f1 > 0.0 && f2 > 0.0) || (f1 < 0.0 && f2 < 0.0)){
335 throw new IllegalArgumentException("Root must be bracketed in the bisection");
336 }
337 test=true;
338 while(test){
339 if(f1==0.0){
340 gperl= g1;
341 test=false;
342 }
343 if(f2==0.0){
344 gperl=g2;
345 test=false;
346 }
347 if(test){
348 g3=0.5*(g1+g2);
349 f3=g3-concentration*Sucrose.density(g3,temperature)/100;
350 if(f3==0.0){
351 gperl=g3;
352 test=false;
353 }
354 else{
355 if(f3*f1>0){
356 g1=g3;
357 }
358 else{
359 g2=g3;
360 }
361 f1=g1-concentration*Sucrose.density(g1,temperature)/100;
362 f2=g2-concentration*Sucrose.density(g2,temperature)/100;
363 if(Math.abs(g1-g2)<tol){
364 gperl=0.5*(g1+g2);
365 test=false;
366 }
367 }
368 j++;
369 if(j>itermax){
370 throw new IllegalArgumentException("number of iteractions in bisection exceeded");
371 }
372 }
373 }
374
375 return gperl;
376 }
377}
Note: See TracBrowser for help on using the repository browser.