|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2004-01-24 19:11:17
"Daniel Frey" <d.frey_at_[hidden]> wrote
> On Sat, 24 Jan 2004 23:34:51 +0100, Andy Little wrote:
>
> > "Daniel Frey" <d.frey_at_[hidden]> wrote
> >
> >> I uploaded the new version of the constant library to the files
> >> section. Additionally, I added an example which shows how it can be
> >> used with a unit library, e.g. YANL 2.2. The constant library itself is
> >> independent of the unit library, and I hope that it can be transfered
> >> to the other unit libraries as well. A short appetizer:
> >
> > [example of constant use]
> >
> > I've had a look but am a bit baffled as to how I go about constructing
> > this beast for my pqs library.
>
> This comes to no surprise, as I haven't added documentation for my library
> yet :o)
Thats the bit I dont like either :-)
>
> > pqs is not like YANL !
>
> Of course. This is why I tried to keep the constant library independent of
> a concrete unit library and provide a basic mechanism to support certain
> type-mappings that are needed for all unit libraries.
Yep. If it can be done it will be good... but there are many ways it can
stall.
That is the only concern I have. We shall see...
regards
Andy Little
Getting carried away with my 'bubble' ... :-)
---------------------------------------------
#include "../pqs.hpp"
#include "math_constants.hpp"
#include "gas_constant.hpp"
using namespace physical_quantities;
using physics::ideal_gas_constant;
class Bubble{
private:
q_volume::m3 v;
q_pressure::Pa p;
q_temperature::K t;
q_substance::mol s;
public:
Bubble(
q_length::m const& r_in,
q_temperature::K const& t_in = q_temperature::K(300),
q_pressure::Pa const& p_in = q_pressure::Pa(1.01325e5))
: t(t_in),
p(p_in),
v ((4.0/3.0)
* math::constants<>::pi * power<3>(r_in))
{
s = p * v /(ideal_gas_constant<>::R * t);
}
void set_temperature(q_temperature::K const & t_in)
{
t = t_in;
p = s * ideal_gas_constant<>::R * t / v;
}
void set_pressure(q_pressure::Pa const & p_in)
{
p = p_in;
t = v * p /(s * ideal_gas_constant<>::R ) ;
}
void set_radius_const_temperature(q_length::m const & r_in)
{
v=(4.0/3.0)
* math::constants<>::pi * power<3>(r_in);
p = s * ideal_gas_constant<>::R * t / v;
}
void set_radius_const_pressure(q_length::m const & r_in)
{
v=(4.0/3.0)
* math::constants<>::pi * power<3>(r_in);
t = v * p /(s * ideal_gas_constant<>::R );
}
q_pressure::Pa const& pressure()const
{ return p;}
q_temperature::K const& temperature()const
{ return t;}
q_volume::m3 const& volume()const
{return v;}
q_substance::mol const& substance()const
{ return s;}
};
int main()
{
// a bubble of gas in a resin cure
// radius r
q_length::m r (0.5e-6);
Bubble bubble(r);
std::cout << bubble.pressure() <<'\n';
//the temperature is subsequently reduced
// near to absolute zero
bubble.set_temperature(q_temperature::K(0.001));
std::cout << bubble.pressure() <<'\n';
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk