Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
d3c7a82e
Commit
d3c7a82e
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
More const-correctness in the unit system.
parent
6eec891e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!143
Gravity particles
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/units.c
+14
-11
14 additions, 11 deletions
src/units.c
src/units.h
+14
-11
14 additions, 11 deletions
src/units.h
with
28 additions
and
22 deletions
src/units.c
+
14
−
11
View file @
d3c7a82e
...
...
@@ -59,7 +59,7 @@ void initUnitSystem(struct UnitSystem* us) {
* @param us The UnitSystem used
* @param baseUnit The base unit
*/
double
getBaseUnit
(
struct
UnitSystem
*
us
,
enum
BaseUnits
baseUnit
)
{
double
getBaseUnit
(
const
struct
UnitSystem
*
us
,
enum
BaseUnits
baseUnit
)
{
switch
(
baseUnit
)
{
case
UNIT_MASS
:
return
us
->
UnitMass_in_cgs
;
...
...
@@ -263,7 +263,8 @@ void getBaseUnitExponantsArray(float baseUnitsExp[5],
* @param us The system of units in use
* @param unit The unit to convert
*/
double
conversionFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
double
conversionFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
baseUnitsExp
[
5
]
=
{
0
.
f
};
getBaseUnitExponantsArray
(
baseUnitsExp
,
unit
);
...
...
@@ -276,7 +277,7 @@ double conversionFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @param us The system of units in use
* @param unit The unit to convert
*/
float
hFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
hFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
baseUnitsExp
[
5
]
=
{
0
.
f
};
getBaseUnitExponantsArray
(
baseUnitsExp
,
unit
);
...
...
@@ -289,7 +290,7 @@ float hFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @param us The system of units in use
* @param unit The unit to convert
*/
float
aFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
aFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
baseUnitsExp
[
5
]
=
{
0
.
f
};
getBaseUnitExponantsArray
(
baseUnitsExp
,
unit
);
...
...
@@ -301,7 +302,7 @@ float aFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors
*/
void
conversionString
(
char
*
buffer
,
struct
UnitSystem
*
us
,
void
conversionString
(
char
*
buffer
,
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
)
{
float
baseUnitsExp
[
5
]
=
{
0
.
f
};
...
...
@@ -317,8 +318,8 @@ void conversionString(char* buffer, struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
double
generalConversionFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
])
{
double
generalConversionFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
])
{
double
factor
=
1
.;
int
i
;
...
...
@@ -335,7 +336,8 @@ double generalConversionFactor(struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float
generalhFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
])
{
float
generalhFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
])
{
float
factor_exp
=
0
.
f
;
factor_exp
+=
-
baseUnitsExponants
[
UNIT_MASS
];
...
...
@@ -352,7 +354,8 @@ float generalhFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float
generalaFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
])
{
float
generalaFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
])
{
float
factor_exp
=
0
.
f
;
factor_exp
+=
baseUnitsExponants
[
UNIT_LENGTH
];
...
...
@@ -369,8 +372,8 @@ float generalaFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
void
generalConversionString
(
char
*
buffer
,
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
])
{
void
generalConversionString
(
char
*
buffer
,
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
])
{
char
temp
[
14
];
double
a_exp
=
generalaFactor
(
us
,
baseUnitsExponants
);
double
h_exp
=
generalhFactor
(
us
,
baseUnitsExponants
);
...
...
This diff is collapsed.
Click to expand it.
src/units.h
+
14
−
11
View file @
d3c7a82e
...
...
@@ -94,7 +94,7 @@ void initUnitSystem(struct UnitSystem*);
/**
* @brief Returns the base unit conversion factor for a given unit system
*/
double
getBaseUnit
(
struct
UnitSystem
*
,
enum
BaseUnits
);
double
getBaseUnit
(
const
struct
UnitSystem
*
,
enum
BaseUnits
);
/**
* @brief Returns the base unit symbol in the cgs system
...
...
@@ -110,49 +110,52 @@ const char* getBaseUnitCGSSymbol(enum BaseUnits);
* @brief Returns the conversion factor for a given unit (expressed in terms of
* the 5 fundamental units) in the chosen unit system
*/
double
generalConversionFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
]);
double
generalConversionFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
]);
/**
* @brief Returns the conversion factor for a given unit in the chosen unit
* system
*/
double
conversionFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
double
conversionFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
/**
* @brief Returns the h factor for a given unit (expressed in terms of the 5
* fundamental units) in the chosen unit system
*/
float
generalhFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
]);
float
generalhFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
]);
/**
* @brief Returns the h factor for a given unit in the chosen unit system
*/
float
hFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
float
hFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
/**
* @brief Returns the scaling factor for a given unit (expressed in terms of the
* 5 fundamental units) in the chosen unit system
*/
float
generalaFactor
(
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
]);
float
generalaFactor
(
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
]);
/**
* @brief Returns the scaling factor for a given unit in the chosen unit system
*/
float
aFactor
(
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
float
aFactor
(
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
/**
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors (expressed in terms of the 5 fundamental units)
*/
void
generalConversionString
(
char
*
buffer
,
struct
UnitSystem
*
us
,
float
baseUnitsExponants
[
5
]);
void
generalConversionString
(
char
*
buffer
,
const
struct
UnitSystem
*
us
,
const
float
baseUnitsExponants
[
5
]);
/**
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors
*/
void
conversionString
(
char
*
buffer
,
struct
UnitSystem
*
us
,
void
conversionString
(
char
*
buffer
,
const
struct
UnitSystem
*
us
,
enum
UnitConversionFactor
unit
);
#endif
/* SWIFT_UNITS_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment