@@ -18,48 +18,72 @@ Arduino library for mixing water with different temperatures.
18
18
19
19
** Warning: Experimental**
20
20
21
- Experimental library for elementary math of mixing water with different temperatures.
21
+ Experimental library for elementary math of mixing certain amounts of water or other
22
+ (same) liquids with different temperatures.
22
23
23
- The library provides math for mixing a volume of water with temperature T1
24
- with a another volume with temperature temperature T2.
25
- In fact the library will work for any single liquid (TODO: liquidMix class),
26
- although some functions are ** water specific** .
24
+ The library provides math ** add()** for mixing a volume of a liquid with temperature T1
25
+ with another volume of the same liquid with temperature T2.
26
+ The ** WaterMix** class of the library has ** water specific** functions.
27
+ The library does not support mixing different liquids as that would need the density
28
+ function for every liquid involved. Furthermore not all liquids mix well with each other.
27
29
28
- This library is useful e.g. by doing "water math" for aquaria or cooking.
30
+
31
+ The ** add()** function can be called multiple times, e.g. to mix more than two amounts
32
+ of liquids. One can also mix an other LiquidMix object (same liquids).
33
+
34
+ Besides the ** add()** the library supports:
35
+ - ** div()** to "split the liquid in equal amounts" and a
36
+ - ** mul()** to multiply it (magically) and
37
+ - ** sub()** to remove part of the liquid.
38
+
39
+ This library is meant to be useful e.g. by doing "water math" for aquaria or cooking.
29
40
Also the library is well suited for basic educational purposes.
30
41
42
+ Since version 0.1.2, the library has a base class, named ** LiquidMix** which can do
43
+ the basic math. The extended math like in ** WaterMix** needs a ** density()** function
44
+ and cannot be done as the liquid is unknown.
45
+
46
+ For now the library is experimental and refactoring is expected.
47
+ If you have requests, questions or ideas, let me know by opening an issue.
48
+
49
+ By adding the LiquidMix base class the library allows easy derived classes
50
+ like the WaterMix.
31
51
32
52
#### Limitations
33
53
34
- The library uses a generic volume parameter instead of gallons or liters as
54
+ The ** LiquidMix ** uses a generic volume parameter instead of gallons or liters as
35
55
this way any user selected unit can be used.
36
56
However you must use the chosen units consistently as the library cannot handle
37
- different units simultaneously.
38
-
57
+ different units simultaneously.
39
58
To use different units for volume you can convert them with the library named
40
59
** VolumeConverter** .
41
60
42
- The temperature unit can also be chosen by the user and can be Kelvin, Celsius,
43
- Fahrenheit or other.
61
+ For the ** LiquidMix ** the temperature unit can also be chosen by the user and
62
+ can be Kelvin, Celsius, Fahrenheit or other.
44
63
However you must use the chosen units consistently as the library cannot handle
45
64
different units simultaneously. Check ** Temperature** library below for conversion.
46
65
66
+ The ** WaterMix** class must use the ** Celsius** scale as the ** density()** function
67
+ used is defined in degrees Celsius.
68
+
47
69
48
70
#### Accuracy
49
71
50
- The working range for temperature is not tested with real water.
72
+ The working range for temperature is not tested e.g. with real water.
51
73
It is expected to work quite well for water with a range from 5°C to 80°C.
52
74
In the basic math the ** add()** function assumes there is no expansion so
53
- the density is identical for " both volumes of waters" .
75
+ the density is identical for both volumes of waters.
54
76
55
- Of course this is incorrect, therefore it is expected to have a difference
77
+ Of course this assumption is incorrect, therefore there will be a difference
56
78
between the theoretical values and doing the mixing in practice.
57
- However the delta's are expected to be small, less than 1% in many cases.
58
- Given the accuracy of volume measurement and temperature measurement,
59
- this delta is often acceptable.
79
+ However these delta's are expected to be small, less than 1% in many cases.
80
+ Given the accuracy of volume measurement and temperature measurement, this
81
+ delta of 1% will often be acceptable.
60
82
61
- If one wants a more exact answer, one should use the ** addExact()** function
62
- as this compensates for the density of the water at a given temperature.
83
+ If one wants a more exact answer, one could use ** WaterMix** class.
84
+ This class supports the ** addExact()** function which compensates for
85
+ the density of the water at a given temperature.
86
+ This function is much slower but will provide a more exact answer.
63
87
64
88
65
89
#### Related
@@ -75,68 +99,77 @@ as this compensates for the density of the water at a given temperature.
75
99
#include " WaterMix.h"
76
100
```
77
101
78
- #### Constructor
79
-
80
- - ** WaterMix()** constructor, starts with no water of 0°
81
- - ** void begin(float volume = 0, float temperature = 0)**
82
- sets initial values, default no water of 0°.
102
+ #### LiquidMix (base class)
83
103
84
- #### Math
104
+ To be used with any liquid.
85
105
86
- - ** void add(float volume, float temperature)** add an amount of water
87
- with temperature to the "WaterMix".
88
- - ** void addExact(float volume, float temperature)** Water only!
89
- add an amount of water with temperature to the "WaterMix".
90
- The math is calculated including using the density of the water.
91
- This is slower as ** add()** but more exact.
92
- Note the temperature must be in °C.
93
- - ** void sub(float volume)** subtract a volume from the "WaterMix".
106
+ - ** LiquidMix()** constructor, starts with no liquid of 0°
107
+ - ** void begin(float volume = 0, float temperature = 0)**
108
+ sets initial values, default no liquid of 0°.
109
+ - ** void add(float volume, float temperature)** add an amount of liquid
110
+ with temperature to the "LiquidMix".
111
+ - ** void sub(float volume)** subtract a volume from the "LiquidMix".
94
112
Temperature won't change.
95
113
- ** void div(float nr)** divide the amount of liquid, same temperature.
96
114
- ** void mul(float nr)** multiply the amount of liquid, same temperature.
97
-
98
- #### Getters
99
-
100
115
- ** float volume()** get the current volume.
101
116
- ** float temperature()** get the current temperature.
102
- - ** float mass()** get the mass of the current volume. Water only!
103
117
104
- #### Converters
105
118
119
+ #### WaterMix
120
+
121
+ WaterMix is specific for water and has the following additional functions:
122
+
123
+ - ** WaterMix()** constructor, starts with no water of 0°
124
+ - ** void addExact(float volume, float temperature)**
125
+ add an amount of water with temperature to the "WaterMix".
126
+ The math uses the ** density** of the water at the given temperature.
127
+ This is slower as ** add()** but more exact.
128
+ Note the temperature must be in °C.
129
+ - ** float mass()** get the mass of the current volume. Water only!
106
130
- ** float volume2mass(float volume, float temperature)** idem, Water only!
107
- Use volume == 1 to get the density at a certain temperature.
131
+ Use volume == 1 to get the density of water at the given temperature.
132
+ Assumption is no pressure.
108
133
- ** float mass2volume(float mass, float temperature)** idem, Water only!
109
134
110
135
111
136
## Performance
112
137
113
- Most functions are just fast, the only that do the core math are add()
114
- and addExact().
115
- The WaterMix_exact.ino sketch provides some performance figures shown
116
- here.
138
+ Most functions are minimal and fast, the ones that do the core math
139
+ are ** add()** and ** addExact()** .
140
+ The WaterMix_exact.ino sketch provides performance figures shown here.
117
141
Note that the ** addExact()** differs in runtime as it uses a linear lookup
118
142
for the density so the numbers below are indicative.
119
143
120
- | Function | time (us) | Notes |
121
- | :------------:| :-----------:| :--------|
122
- | add() | 72 |
123
- | addExact() | 576 | most accurate |
144
+ Tested on UNO, 16 MHz.
145
+
146
+ | Version | Function | time (us) | Notes |
147
+ | :-----------:| :------------:| :-----------:| :--------|
148
+ | 0.1.1 | add() | 72 |
149
+ | 0.1.1 | addExact() | 576 | most accurate |
124
150
125
- Note it is possible to tune the linear lookup of the density by reducing
126
- the amount of interpolation points in the tables (at your own risk).
127
- This will reduce the accuracy however still be better than the fast ** add()** .
151
+
152
+ Note it is possible to improve the performance of the lookup of the density
153
+ by reducing the amount of interpolation points in the tables (at your own risk).
154
+ This will reduce the accuracy however still be better than the faster ** add()** .
128
155
129
156
Performance of ** addExact()** can be improved by caching the mass of the water.
157
+ As this is needed for every next ** addExact()** . As the volume can be manipulated
158
+ by ** div()** et al, there must be additional code and/or a "dirty" flag.
130
159
To be investigated.
131
160
161
+ Finally the lookup can be improved by a binary search, however previous experience
162
+ indicate that this only improves above a certain number of elements (~ 20).
163
+
132
164
133
165
## Volumetric Coefficient of Expansion
134
166
135
- The VCE is not supported in the library.
167
+ The VCE is related to density and not supported in the library.
168
+ Math needs to be understood / investigated.
136
169
(0.1.1 supports an ** addExact()** for water only, temperature in °C)
137
170
138
- The VCE is useful as background information as the theoretical volumes calculated
139
- in this library will differ from reality due to the VCE effect.
171
+ The VCE is useful as background information as the theoretical volumes
172
+ calculated in this library will differ from reality due to the VCE effect.
140
173
This difference depends on the liquid used and the delta temperature.
141
174
142
175
@@ -204,37 +237,26 @@ Source: - https://www.engineeringtoolbox.com/cubical-expansion-coefficients-d_12
204
237
205
238
- update documentation
206
239
- library can be used for water and salinity and other linear related things.
207
- - investigate linear expansion
208
- - VCE as parameter.
209
240
210
241
211
242
#### Should
212
243
213
- - create base class ** LiquidMix** and derive a specific ** WaterMix** from it.
214
- - code is quite identical, easy to split/strip water specific functions
215
- - ** WaterMix** can include specific heat, density, VCE etc.
216
- - 0.2.0
217
- - ** WaterMixF()** Fahrenheit, as derived class too.
218
- - ** WaterMixK()** Kelvin?
244
+ - investigate linear expansion
245
+ - VCE as parameter.
219
246
- do not make the library too complex (see could below).
220
247
- extend unit tests
221
- - investigate the caching of the mass of the water.
222
- - add Exact only, 4 bytes..
223
248
224
249
225
250
#### Could
226
251
227
- - cool(time) == depends on many factors
252
+ - add ** void cool(time)** == depends on many factors
228
253
- need to configure curve constant (only option).
229
254
- must use defined liquid and temp scale.
230
- - catch temperature below zero?
231
- - must use defined liquid and temp scale.
232
- - user responsibility for now.
233
255
- ** void AddEnergy(float joule)** to raise temperature (joule)
234
256
- must use defined liquid and temp scale.
235
- - specific heat needed. (Water only?)
257
+ - specific heat needed. (WaterMix only?)
236
258
- replace div and mul with operators \* and \/
237
- - use double iso float ?
259
+ - investigate injection of density function to make LiquidMix generic ?
238
260
239
261
240
262
#### Wont (or on special request)
@@ -244,6 +266,16 @@ Source: - https://www.engineeringtoolbox.com/cubical-expansion-coefficients-d_12
244
266
- energy functions to calculate how hot an amount of water
245
267
should be to reach a certain temperature.
246
268
- Think Aquaria or cooking.
269
+ - investigate how to mix different liquids?
270
+ - gives too much params
271
+ - use double instead of float?
272
+ - weight and temperature are not that accurate (assumption)
273
+ - investigate the caching of the mass of the water.
274
+ - ** addExact()** only, 4 bytes only for WaterMix class
275
+ - it is so far no performance issue.
276
+ - catch temperature below zero?
277
+ - must use defined liquid and temp scale.
278
+ - user responsibility for now.
247
279
248
280
249
281
## Support
0 commit comments