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
5c357a87
Commit
5c357a87
authored
9 years ago
by
Bert Vandenbroucke
Browse files
Options
Downloads
Patches
Plain Diff
Added extra adiabatic index power functions for use in Riemann solvers.
parent
7fc4cc73
No related branches found
No related tags found
1 merge request
!223
Merge Gizmo-SPH into the master branch
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/adiabatic_index.h
+102
-0
102 additions, 0 deletions
src/adiabatic_index.h
tests/testRiemann.c
+20
-1
20 additions, 1 deletion
tests/testRiemann.c
with
122 additions
and
1 deletion
src/adiabatic_index.h
+
102
−
0
View file @
5c357a87
/*******************************************************************************
/*******************************************************************************
* This file is part of SWIFT.
* This file is part of SWIFT.
* Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
* Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
* Bert Vandenbroucke (bert.vandenbroucke@gmail.com).
*
*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* it under the terms of the GNU Lesser General Public License as published
...
@@ -167,4 +168,105 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
...
@@ -167,4 +168,105 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
#endif
#endif
}
}
/**
* @brief Returns one over the argument to the power given by the adiabatic
* index
*
* Computes \f$x^{-\gamma}\f$.
*
* @param x Argument
* @return One over the argument to the power given by the adiabatic index
*/
__attribute__
((
always_inline
))
INLINE
static
float
pow_minus_gamma
(
float
x
)
{
#if defined(HYDRO_GAMMA_5_3)
const
float
cbrt_inv
=
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
const
float
cbrt_inv2
=
cbrt_inv
*
cbrt_inv
;
/* x^(-2/3) */
return
cbrt_inv
*
cbrt_inv2
*
cbrt_inv2
;
/* x^(-5/3) */
#elif defined(HYDRO_GAMMA_4_3)
const
float
cbrt_inv
=
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
const
float
cbrt_inv2
=
cbrt_inv
*
cbrt_inv
;
/* x^(-2/3) */
return
cbrt_inv2
*
cbrt_inv2
;
/* x^(-4/3) */
#elif defined(HYDRO_GAMMA_2_1)
const
float
inv
=
1
.
f
/
x
;
return
inv
*
inv
;
#else
error
(
"The adiabatic index is not defined !"
);
return
0
.
f
;
#endif
}
/**
* @brief Return the argument to the power given by two divided by the adiabatic
* index minus one
*
* Computes \f$x^{\frac{2}{\gamma - 1}}\f$.
*
* @param x Argument
* @return Argument to the power two divided by the adiabatic index minus one
*/
__attribute__
((
always_inline
))
INLINE
static
float
pow_two_over_gamma_minus_one
(
float
x
)
{
#if defined(HYDRO_GAMMA_5_3)
return
x
*
x
*
x
;
/* x^3 */
#elif defined(HYDRO_GAMMA_4_3)
return
x
*
x
*
x
*
x
*
x
*
x
;
/* x^6 */
#elif defined(HYDRO_GAMMA_2_1)
return
x
*
x
;
/* x^2 */
#else
error
(
"The adiabatic index is not defined !"
);
return
0
.
f
;
#endif
}
/**
* @brief Return the argument to the power given by two times the adiabatic
* index divided by the adiabatic index minus one
*
* Computes \f$x^{\frac{2\gamma}{\gamma - 1}}\f$.
*
* @param x Argument
* @return Argument to the power two times the adiabatic index divided by the
* adiabatic index minus one
*/
__attribute__
((
always_inline
))
INLINE
static
float
pow_two_gamma_over_gamma_minus_one
(
float
x
)
{
#if defined(HYDRO_GAMMA_5_3)
return
x
*
x
*
x
*
x
*
x
;
/* x^5 */
#elif defined(HYDRO_GAMMA_4_3)
return
x
*
x
*
x
*
x
*
x
*
x
*
x
*
x
;
/* x^8 */
#elif defined(HYDRO_GAMMA_2_1)
return
x
*
x
*
x
*
x
;
/* x^4 */
#else
error
(
"The adiabatic index is not defined !"
);
return
0
.
f
;
#endif
}
#endif
/* SWIFT_ADIABATIC_INDEX_H */
#endif
/* SWIFT_ADIABATIC_INDEX_H */
This diff is collapsed.
Click to expand it.
tests/testRiemann.c
+
20
−
1
View file @
5c357a87
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include
"error.h"
#include
"error.h"
void
check_value
(
float
a
,
float
b
,
const
char
*
s
)
{
void
check_value
(
float
a
,
float
b
,
const
char
*
s
)
{
if
(
fabsf
(
a
-
b
)
>
1.e-
6
f
)
{
if
(
fabsf
(
a
-
b
)
>
1.e-
5
f
)
{
error
(
"Values are inconsistent: %g %g (%s)!"
,
a
,
b
,
s
);
error
(
"Values are inconsistent: %g %g (%s)!"
,
a
,
b
,
s
);
}
else
{
}
else
{
message
(
"Values are consistent: %g %g (%s)."
,
a
,
b
,
s
);
message
(
"Values are consistent: %g %g (%s)."
,
a
,
b
,
s
);
...
@@ -57,9 +57,28 @@ void check_constants() {
...
@@ -57,9 +57,28 @@ void check_constants() {
check_value
(
val
,
hydro_one_over_gamma
,
"1/gamma"
);
check_value
(
val
,
hydro_one_over_gamma
,
"1/gamma"
);
}
}
void
check_functions
()
{
float
val_a
,
val_b
;
const
float
x
=
0
.
4
;
val_a
=
pow
(
x
,
-
hydro_gamma
);
val_b
=
pow_minus_gamma
(
x
);
check_value
(
val_a
,
val_b
,
"x^(-gamma)"
);
val_a
=
pow
(
x
,
2
.
0
f
/
(
hydro_gamma
-
1
.
0
f
));
val_b
=
pow_two_over_gamma_minus_one
(
x
);
check_value
(
val_a
,
val_b
,
"x^(2/(gamma-1))"
);
val_a
=
pow
(
x
,
2
.
0
f
*
hydro_gamma
/
(
hydro_gamma
-
1
.
0
f
));
val_b
=
pow_two_gamma_over_gamma_minus_one
(
x
);
check_value
(
val_a
,
val_b
,
"x^((2 gamma)/(gamma-1))"
);
}
int
main
()
{
int
main
()
{
check_constants
();
check_constants
();
check_functions
();
return
0
;
return
0
;
}
}
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