@@ -18,48 +18,72 @@ Arduino library for mixing water with different temperatures.
1818
1919** Warning: Experimental**
2020
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.
2223
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.
2729
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.
2940Also the library is well suited for basic educational purposes.
3041
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.
3151
3252#### Limitations
3353
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
3555this way any user selected unit can be used.
3656However you must use the chosen units consistently as the library cannot handle
37- different units simultaneously.
38-
57+ different units simultaneously.
3958To use different units for volume you can convert them with the library named
4059** VolumeConverter** .
4160
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.
4463However you must use the chosen units consistently as the library cannot handle
4564different units simultaneously. Check ** Temperature** library below for conversion.
4665
66+ The ** WaterMix** class must use the ** Celsius** scale as the ** density()** function
67+ used is defined in degrees Celsius.
68+
4769
4870#### Accuracy
4971
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.
5173It is expected to work quite well for water with a range from 5°C to 80°C.
5274In 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.
5476
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
5678between 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.
6082
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.
6387
6488
6589#### Related
@@ -75,68 +99,77 @@ as this compensates for the density of the water at a given temperature.
7599#include " WaterMix.h"
76100```
77101
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)
83103
84- #### Math
104+ To be used with any liquid.
85105
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".
94112Temperature won't change.
95113- ** void div(float nr)** divide the amount of liquid, same temperature.
96114- ** void mul(float nr)** multiply the amount of liquid, same temperature.
97-
98- #### Getters
99-
100115- ** float volume()** get the current volume.
101116- ** float temperature()** get the current temperature.
102- - ** float mass()** get the mass of the current volume. Water only!
103117
104- #### Converters
105118
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!
106130- ** 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.
108133- ** float mass2volume(float mass, float temperature)** idem, Water only!
109134
110135
111136## Performance
112137
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.
117141Note that the ** addExact()** differs in runtime as it uses a linear lookup
118142for the density so the numbers below are indicative.
119143
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 |
124150
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()** .
128155
129156Performance 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.
130159To be investigated.
131160
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+
132164
133165## Volumetric Coefficient of Expansion
134166
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.
136169(0.1.1 supports an ** addExact()** for water only, temperature in °C)
137170
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.
140173This difference depends on the liquid used and the delta temperature.
141174
142175
@@ -204,37 +237,26 @@ Source: - https://www.engineeringtoolbox.com/cubical-expansion-coefficients-d_12
204237
205238- update documentation
206239 - library can be used for water and salinity and other linear related things.
207- - investigate linear expansion
208- - VCE as parameter.
209240
210241
211242#### Should
212243
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.
219246- do not make the library too complex (see could below).
220247- extend unit tests
221- - investigate the caching of the mass of the water.
222- - add Exact only, 4 bytes..
223248
224249
225250#### Could
226251
227- - cool(time) == depends on many factors
252+ - add ** void cool(time)** == depends on many factors
228253 - need to configure curve constant (only option).
229254 - 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.
233255- ** void AddEnergy(float joule)** to raise temperature (joule)
234256 - must use defined liquid and temp scale.
235- - specific heat needed. (Water only?)
257+ - specific heat needed. (WaterMix only?)
236258- replace div and mul with operators \* and \/
237- - use double iso float ?
259+ - investigate injection of density function to make LiquidMix generic ?
238260
239261
240262#### Wont (or on special request)
@@ -244,6 +266,16 @@ Source: - https://www.engineeringtoolbox.com/cubical-expansion-coefficients-d_12
244266- energy functions to calculate how hot an amount of water
245267 should be to reach a certain temperature.
246268 - 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.
247279
248280
249281## Support
0 commit comments