Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86701889
units.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Oct 8, 03:06
Size
4 KB
Mime Type
text/x-c++
Expires
Thu, Oct 10, 03:06 (2 d)
Engine
blob
Format
Raw Data
Handle
21470995
Attached To
rSPECMICP SpecMiCP / ReactMiCP
units.hpp
View Options
/*-------------------------------------------------------
- Module : Physics
- File : units.hpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#ifndef SPECMICP_UNITS_UNITS
#define SPECMICP_UNITS_UNITS
#include "common.hpp"
//! \file units.hpp units conversion
namespace
specmicp
{
namespace
units
{
//! units used for length
enum
class
LengthUnit
{
meter
,
decimeter
,
centimeter
};
//! units used for mass
enum
class
MassUnit
{
kilogram
,
gram
};
//! \brief Simple struct which contains the unit information
struct
UnitsSet
{
MassUnit
mass
;
//!< The unit to use for mass
LengthUnit
length
;
//!< The unit to use for length (also area and volume)
//! \brief Defaults are the SI unit system
UnitsSet
()
:
mass
(
MassUnit
::
kilogram
),
length
(
LengthUnit
::
meter
)
{}
};
//! \brief Base class that handles the units
//!
//! To be inherited by other classes that need units
class
UnitBaseClass
{
public
:
UnitBaseClass
()
{}
UnitBaseClass
(
UnitsSet
units
)
:
m_units
(
units
)
{}
//! \brief Return the units
UnitsSet
get_units
()
{
return
m_units
;}
//! \brief Set the units
void
set_units
(
UnitsSet
units
)
{
m_units
=
units
;}
//! \brief Return the Mass unit
MassUnit
mass_unit
()
const
{
return
m_units
.
mass
;}
//! \brief Return the Length unit
LengthUnit
length_unit
()
const
{
return
m_units
.
length
;}
//! \brief Return the mass unit
MassUnit
&
mass_unit
()
{
return
m_units
.
mass
;}
//! \brief Return the length unit
LengthUnit
&
length_unit
()
{
return
m_units
.
length
;}
private
:
UnitsSet
m_units
;
};
// Temperature
// -----------
//! Convert a temperature from Celsius to Kelvin
inline
scalar_t
celsius
(
scalar_t
tc
)
{
return
tc
+
273.15
;}
//! Convert a temperature from Kelvin to Celsius
inline
scalar_t
to_celsius
(
scalar_t
tk
)
{
return
tk
-
273.15
;}
// Volume
// ------
//! Convert liter to cubic meter
inline
scalar_t
liter
(
scalar_t
vl
)
{
return
1e-3
*
vl
;}
//! convert cubic meter to liter
inline
scalar_t
to_liter
(
scalar_t
vcm
)
{
return
1e3
*
vcm
;}
// Pressure
// --------
inline
scalar_t
convert_pressure
(
scalar_t
pressure_si
,
LengthUnit
length_unit
)
{
switch
(
length_unit
)
{
case
LengthUnit
::
meter:
return
pressure_si
;
break
;
case
LengthUnit
::
decimeter:
return
1e-2
*
pressure_si
;
break
;
case
LengthUnit
::
centimeter:
return
1e-4
*
pressure_si
;
}
}
}
// end namespace units
}
// end namespace specmicp
#endif
// SPECMICP_UNITS_UNITS
Event Timeline
Log In to Comment