
Boost::units users, I am trying to perform a flow rate through an orifice calculation (Volume per Time or L^3T^-1) using the following dimensional analysis: Q = Cf * A * sqrt( 2 * abs(P1-P2) ) On paper the dimensional analysis works out correctly. I know we should be receiving a L^3T^-1 consequent to the calculation. If I just take this on one line, it seems to compile: __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d); Where __a_orifice is the area of the orifice, __p_diff is the pressure differential (absolute value), and __d is the mass density. __C_flow (coefficient of flow through orifice) and __two (2.0) are both dimensionless. In terms of units quantities, these are all defined as quantity<si::area>, quantity<si::pressure>, quantity<si::mass_density>, and quantity<si::dimensionless>, to start with. I think my flow-rate dimension and/or unit must be incorrect, but I am failing to see why in order to know what to do to correct the error. typedef boost::units::derived_dimension<boost::units::length_base_dimension,3 ,boost::units::time_base_dimension,-1>::type flow_rate_dimension; typedef boost::units::unit<cs::units::flow_rate_dimension,boost::units::si::system> flow_rate; When I take: si::flow_rate __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d); I am receiving the following compiler error as my clue... Error 1 error C2440: 'initializing' : cannot convert from 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>' c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp 461 CS.Calculations.Managed I'd like to set this up in as base a dimension as possible because later on we'll be introducing unit views, converting from base units to a view unit, or unit system, along these lines, but if we have to specify this in specific unit terms, so be it. We'll worry about unit conversions later on. Best regards, Michael Powell

On Mon, Sep 19, 2011 at 12:10 PM, Michael Powell <mwpowellnm@gmail.com>wrote:
Boost::units users,
I am trying to perform a flow rate through an orifice calculation (Volume per Time or L^3T^-1) using the following dimensional analysis:
Q = Cf * A * sqrt( 2 * abs(P1-P2) )
I should clarify, this should be ... Q = Cf * A * sqrt( 2 * abs(P1-P2) / MD ) Sorry bout that. The dimensional analysis does indeed work out, however, when you include MassDensity...
On paper the dimensional analysis works out correctly. I know we should be receiving a L^3T^-1 consequent to the calculation.
If I just take this on one line, it seems to compile:
__C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
Where __a_orifice is the area of the orifice, __p_diff is the pressure differential (absolute value), and __d is the mass density. __C_flow (coefficient of flow through orifice) and __two (2.0) are both dimensionless.
In terms of units quantities, these are all defined as quantity<si::area>, quantity<si::pressure>, quantity<si::mass_density>, and quantity<si::dimensionless>, to start with.
I think my flow-rate dimension and/or unit must be incorrect, but I am failing to see why in order to know what to do to correct the error.
typedef boost::units::derived_dimension<boost::units::length_base_dimension,3
,boost::units::time_base_dimension,-1>::type flow_rate_dimension;
typedef boost::units::unit<cs::units::flow_rate_dimension,boost::units::si::system> flow_rate;
When I take:
si::flow_rate __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
I am receiving the following compiler error as my clue...
Error 1 error C2440: 'initializing' : cannot convert from 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>' c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp 461 CS.Calculations.Managed
I'd like to set this up in as base a dimension as possible because later on we'll be introducing unit views, converting from base units to a view unit, or unit system, along these lines, but if we have to specify this in specific unit terms, so be it. We'll worry about unit conversions later on.
Best regards,
Michael Powell

On Mon, Sep 19, 2011 at 12:10 PM, Michael Powell <mwpowellnm@gmail.com>wrote:
Boost::units users,
I am trying to perform a flow rate through an orifice calculation (Volume per Time or L^3T^-1) using the following dimensional analysis:
Q = Cf * A * sqrt( 2 * abs(P1-P2) )
On paper the dimensional analysis works out correctly. I know we should be receiving a L^3T^-1 consequent to the calculation.
If I just take this on one line, it seems to compile:
__C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
Where __a_orifice is the area of the orifice, __p_diff is the pressure differential (absolute value), and __d is the mass density. __C_flow (coefficient of flow through orifice) and __two (2.0) are both dimensionless.
In terms of units quantities, these are all defined as quantity<si::area>, quantity<si::pressure>, quantity<si::mass_density>, and quantity<si::dimensionless>, to start with.
I think my flow-rate dimension and/or unit must be incorrect, but I am failing to see why in order to know what to do to correct the error.
typedef boost::units::derived_dimension<boost::units::length_base_dimension,3
,boost::units::time_base_dimension,-1>::type flow_rate_dimension;
typedef boost::units::unit<cs::units::flow_rate_dimension,boost::units::si::system> flow_rate;
When I take:
si::flow_rate __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
The only thing I can figure is that sqrt() is buggering things up. When I do this I get no compiler error: quantity<cs::units::si::flow_rate> __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d); However, when I do this, I do get a compiler error: quantity<cs::units::si::flow_rate, float> __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d); I haven't dug into sqrt() yet to verify its result, but it seems like this is taking some underlying type liberties? Could we do this, boost::units::sqrt<float>(...)? I am receiving the following compiler error as my clue...
Error 1 error C2440: 'initializing' : cannot convert from 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>' c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp 461 CS.Calculations.Managed
I'd like to set this up in as base a dimension as possible because later on we'll be introducing unit views, converting from base units to a view unit, or unit system, along these lines, but if we have to specify this in specific unit terms, so be it. We'll worry about unit conversions later on.
Best regards,
Michael Powell

AMDG On 09/19/2011 11:29 AM, Michael Powell wrote:
On Mon, Sep 19, 2011 at 12:10 PM, Michael Powell <mwpowellnm@gmail.com>wrote:
The only thing I can figure is that sqrt() is buggering things up. When I do this I get no compiler error:
quantity<cs::units::si::flow_rate> __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
However, when I do this, I do get a compiler error:
quantity<cs::units::si::flow_rate, float> __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
I haven't dug into sqrt() yet to verify its result, but it seems like this is taking some underlying type liberties? Could we do this, boost::units::sqrt<float>(...)?
Ah. I see what's going on: The result of sqrt is the same as root<2>(x). The result of root<2>(x) is based on typeof(pow(x.value(), 0.5)). The constant is always a double, thus float gets promoted to double. I'll see what I can do to fix this.
I am receiving the following compiler error as my clue...
Error 1 error C2440: 'initializing' : cannot convert from 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>' c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp 461 CS.Calculations.Managed
In Christ, Steven Watanabe

On Mon, Sep 19, 2011 at 12:57 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On Mon, Sep 19, 2011 at 12:10 PM, Michael Powell <mwpowellnm@gmail.com wrote:
The only thing I can figure is that sqrt() is buggering things up. When I do this I get no compiler error:
quantity<cs::units::si::flow_rate> __fr = __C_flow * __a_orifice * boost::units::sqrt(__two * __p_diff / __d);
However, when I do this, I do get a compiler error:
quantity<cs::units::si::flow_rate, float> __fr = __C_flow * __a_orifice
On 09/19/2011 11:29 AM, Michael Powell wrote: *
boost::units::sqrt(__two * __p_diff / __d);
I haven't dug into sqrt() yet to verify its result, but it seems like this is taking some underlying type liberties? Could we do this, boost::units::sqrt<float>(...)?
Ah. I see what's going on: The result of sqrt is the same as root<2>(x). The result of root<2>(x) is based on typeof(pow(x.value(), 0.5)). The constant is always a double, thus float gets promoted to double. I'll see what I can do to fix this.
If it can be fixed from a library perspective, great. It's easy enough to workaround, however, taking static_cast<float>(x.value()) of the intermediate result, and so that we don't get too far removed from the dimensional analysis.
I am receiving the following compiler error as my clue...
Error 1 error C2440: 'initializing' : cannot convert from 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>' c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp 461 CS.Calculations.Managed
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG On 09/19/2011 12:01 PM, Michael Powell wrote:
On Mon, Sep 19, 2011 at 12:57 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
On 09/19/2011 11:29 AM, Michael Powell wrote:
However, when I do this, I do get a compiler error:
quantity<cs::units::si::flow_rate, float> __fr = __C_flow * __a_orifice
*
boost::units::sqrt(__two * __p_diff / __d);
If it can be fixed from a library perspective, great. It's easy enough to workaround, however, taking static_cast<float>(x.value()) of the intermediate result, and so that we don't get too far removed from the dimensional analysis.
Actually, you can directly convert the quantities. The conversion is just explicit. You're getting an error because the code tries to do an implicit conversion. In Christ, Steven Watanabe

On Mon, Sep 19, 2011 at 1:14 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 09/19/2011 12:01 PM, Michael Powell wrote:
On Mon, Sep 19, 2011 at 12:57 PM, Steven Watanabe <watanabesj@gmail.com wrote:
On 09/19/2011 11:29 AM, Michael Powell wrote:
However, when I do this, I do get a compiler error:
quantity<cs::units::si::flow_rate, float> __fr = __C_flow *
__a_orifice *
boost::units::sqrt(__two * __p_diff / __d);
If it can be fixed from a library perspective, great. It's easy enough to workaround, however, taking static_cast<float>(x.value()) of the intermediate result, and so that we don't get too far removed from the dimensional analysis.
Actually, you can directly convert the quantities. The conversion is just explicit. You're getting an error because the code tries to do an implicit conversion.
Static casting the static_cast<quantity<flow_rate, float>>(...) will work. Thanks, bro.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Michael Powell
-
Steven Watanabe