Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pyTurbulence
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Bilocq Amaury
pyTurbulence
Commits
8dd6eb5d
Commit
8dd6eb5d
authored
2 months ago
by
Amaury Bilocq
Browse files
Options
Downloads
Patches
Plain Diff
Refactore dilatational velocity computation
parent
05959851
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#53043
passed
2 months ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyTurbulence/solver.py
+14
-4
14 additions, 4 deletions
pyTurbulence/solver.py
pyTurbulence/spectrum.py
+2
-1
2 additions, 1 deletion
pyTurbulence/spectrum.py
pyTurbulence/syntheticTurbulence.py
+23
-34
23 additions, 34 deletions
pyTurbulence/syntheticTurbulence.py
with
39 additions
and
39 deletions
pyTurbulence/solver.py
+
14
−
4
View file @
8dd6eb5d
...
@@ -60,20 +60,26 @@ def solve(user_params)->dict:
...
@@ -60,20 +60,26 @@ def solve(user_params)->dict:
# Generate the solenoidal velocity field
# Generate the solenoidal velocity field
start
=
time
.
time
()
start
=
time
.
time
()
u
,
v
,
w
,
wmax
=
compute_solenoidal_velocities
(
spectrum
,
nbModes
,
urms
,
k0
,
domain_size
,
domain_resolution
)
u
,
v
,
w
,
wmax
=
compute_solenoidal_velocities
(
spectrum
,
nbModes
,
urms
,
k0
,
domain_size
,
domain_resolution
)
TKE
=
np
.
mean
(
0.5
*
(
u
.
reshape
(
-
1
)
**
2
+
v
.
reshape
(
-
1
)
**
2
+
w
.
reshape
(
-
1
)
**
2
))
TKE
=
np
.
mean
(
0.5
*
(
u
.
reshape
(
-
1
)
**
2
+
v
.
reshape
(
-
1
)
**
2
+
w
.
reshape
(
-
1
)
**
2
))
end
=
time
.
time
()
end
=
time
.
time
()
solenoidal_time
=
end
-
start
solenoidal_time
=
end
-
start
# Generate the incompressible pressure fluctuations
# Generate the incompressible pressure fluctuations
start
=
time
.
time
()
start
=
time
.
time
()
incompressible_pressure_fluctuations
=
compute_solenoidal_pressure
(
u
,
v
,
w
,
domain_resolution
,
domain_size
)
incompressible_pressure_fluctuations
=
compute_solenoidal_pressure
(
u
,
v
,
w
,
domain_resolution
,
domain_size
)
end
=
time
.
time
()
end
=
time
.
time
()
pressure_time
=
end
-
start
pressure_time
=
end
-
start
# Generate the dilatational velocity field
# Generate the dilatational velocity field
start
=
time
.
time
()
start
=
time
.
time
()
ud
,
vd
,
wd
=
compute_dilatational_velocities
(
u
,
v
,
w
,
incompressible_pressure_fluctuations
,
gamma
,
domain_resolution
,
domain_size
)
ud
,
vd
,
wd
=
compute_dilatational_velocities
(
u
,
v
,
w
,
incompressible_pressure_fluctuations
,
gamma
,
domain_resolution
,
domain_size
)
u
+=
ud
*
gamma
*
Mt
**
2
u
+=
ud
*
gamma
*
Mt
**
2
v
+=
vd
*
gamma
*
Mt
**
2
v
+=
vd
*
gamma
*
Mt
**
2
w
+=
wd
*
gamma
*
Mt
**
2
w
+=
wd
*
gamma
*
Mt
**
2
...
@@ -82,7 +88,11 @@ def solve(user_params)->dict:
...
@@ -82,7 +88,11 @@ def solve(user_params)->dict:
# Compute the thermodynamic fields
# Compute the thermodynamic fields
start
=
time
.
time
()
start
=
time
.
time
()
density
,
pressure
,
temperature
=
compute_thermodynamic_fields
(
mean_density
,
mean_pressure
,
mean_temperature
,
incompressible_pressure_fluctuations
,
gamma
,
Mt
,
params
[
"
case
"
])
density
,
pressure
,
temperature
=
compute_thermodynamic_fields
(
mean_density
,
mean_pressure
,
mean_temperature
,
incompressible_pressure_fluctuations
,
gamma
,
Mt
,
params
[
"
case
"
])
end
=
time
.
time
()
end
=
time
.
time
()
thermodynamic_time
=
end
-
start
thermodynamic_time
=
end
-
start
...
...
This diff is collapsed.
Click to expand it.
pyTurbulence/spectrum.py
+
2
−
1
View file @
8dd6eb5d
...
@@ -30,7 +30,8 @@ def energy_spectrum(spectrum: str, k: np.ndarray, urms: float, k0: float) -> np.
...
@@ -30,7 +30,8 @@ def energy_spectrum(spectrum: str, k: np.ndarray, urms: float, k0: float) -> np.
E_k
=
urms
*
k
**
4
*
np
.
exp
(
-
2.
*
k
**
2
/
k0
**
2
)
E_k
=
urms
*
k
**
4
*
np
.
exp
(
-
2.
*
k
**
2
/
k0
**
2
)
return
E_k
return
E_k
def
compute_tke_spectrum
(
u
,
v
,
w
,
lx
,
ly
,
lz
,
smooth
=
True
):
def
compute_tke_spectrum
(
u
:
np
.
ndarray
,
v
:
np
.
ndarray
,
w
:
np
.
ndarray
,
lx
:
float
,
ly
:
float
,
lz
:
float
,
smooth
:
bool
=
True
)
->
tuple
:
"""
"""
Compute the turbulent kinetic energy (TKE) spectrum from the velocity fields.
Compute the turbulent kinetic energy (TKE) spectrum from the velocity fields.
...
...
This diff is collapsed.
Click to expand it.
pyTurbulence/syntheticTurbulence.py
+
23
−
34
View file @
8dd6eb5d
...
@@ -5,7 +5,9 @@ from numba import jit, prange
...
@@ -5,7 +5,9 @@ from numba import jit, prange
from
typing
import
Tuple
from
typing
import
Tuple
@jit
(
nopython
=
True
,
parallel
=
True
)
@jit
(
nopython
=
True
,
parallel
=
True
)
def
_compute_velocity_field
(
u_
,
v_
,
w_
,
nx
,
ny
,
nz
,
kx
,
ky
,
kz
,
xc
,
yc
,
zc
,
um
,
sxm
,
sym
,
szm
,
dx
,
dy
,
dz
,
psi
):
def
_compute_velocity_field
(
u_
,
v_
,
w_
,
nx
,
ny
,
nz
,
kx
,
ky
,
kz
,
xc
,
yc
,
zc
,
um
,
sxm
,
sym
,
szm
,
dx
,
dy
,
dz
,
psi
):
for
k
in
prange
(
nz
):
for
k
in
prange
(
nz
):
for
j
in
prange
(
ny
):
for
j
in
prange
(
ny
):
for
i
in
prange
(
nx
):
for
i
in
prange
(
nx
):
...
@@ -172,7 +174,9 @@ def compute_solenoidal_pressure(u: np.ndarray,v: np.ndarray,w: np.ndarray,
...
@@ -172,7 +174,9 @@ def compute_solenoidal_pressure(u: np.ndarray,v: np.ndarray,w: np.ndarray,
pressure
=
poisson_3d
(
rhs
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
pressure
=
poisson_3d
(
rhs
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
return
pressure
return
pressure
def
compute_thermodynamic_fields
(
mean_density
,
mean_pressure
,
mean_temperature
,
incompressible_pressure_fluctuations
,
gamma
,
Mt
,
case
):
def
compute_thermodynamic_fields
(
mean_density
:
float
,
mean_pressure
:
float
,
mean_temperature
:
float
,
incompressible_pressure_fluctuations
:
np
.
ndarray
,
gamma
:
float
,
Mt
:
float
,
case
:
int
)
->
Tuple
[
np
.
ndarray
,
np
.
ndarray
,
np
.
ndarray
]:
"""
"""
Compute the density, pressure and temperature fields from the incompressible pressure fluctuations.
Compute the density, pressure and temperature fields from the incompressible pressure fluctuations.
Eq (4-5) + ansatz from Ristorcelli and Blaisdell : p
'
= gamma * Mt^2 * p1
Eq (4-5) + ansatz from Ristorcelli and Blaisdell : p
'
= gamma * Mt^2 * p1
...
@@ -259,48 +263,33 @@ def compute_dilatational_velocities(u: np.ndarray,v: np.ndarray,w: np.ndarray,p:
...
@@ -259,48 +263,33 @@ def compute_dilatational_velocities(u: np.ndarray,v: np.ndarray,w: np.ndarray,p:
hy
=
domain_size
[
1
]
/
ny
hy
=
domain_size
[
1
]
/
ny
hz
=
domain_size
[
2
]
/
nz
hz
=
domain_size
[
2
]
/
nz
overGamma
=
1.
/
gamma
velocity
=
np
.
array
([
u
,
v
,
w
])
velocity
=
np
.
array
([
u
,
v
,
w
])
dudx
,
dudy
,
dudz
=
np
.
gradient
(
u
,
hx
,
hy
,
hz
,
edge_order
=
2
)
gradVelocity
=
np
.
array
([
np
.
gradient
(
vel
,
hx
,
hy
,
hz
,
edge_order
=
2
)
for
vel
in
velocity
])
dvdx
,
dvdy
,
dvdz
=
np
.
gradient
(
v
,
hx
,
hy
,
hz
,
edge_order
=
2
)
gradPressure
=
np
.
gradient
(
p
,
hx
,
hy
,
hz
,
edge_order
=
2
)
dwdx
,
dwdy
,
dwdz
=
np
.
gradient
(
w
,
hx
,
hy
,
hz
,
edge_order
=
2
)
gradVelocity
=
np
.
array
([[
dudx
,
dudy
,
dudz
],
[
dvdx
,
dvdy
,
dvdz
],
[
dwdx
,
dwdy
,
dwdz
]])
dpdx
,
dpdy
,
dpdz
=
np
.
gradient
(
p
,
hx
,
hy
,
hz
,
edge_order
=
2
)
gradPressure
=
np
.
array
([
dpdx
,
dpdy
,
dpdz
])
# Compute time derivative of pressure fluctuations (Eq.11)
# Compute time derivative of pressure fluctuations (Eq.11)
#rhs = 2*((u_k * du_i/dx_k + dp/dx_i) * u_j)
#rhs = ((u_k * du_i/dx_k + dp/dx_i) * u_j)
rhs
=
np
.
zeros
([
nx
,
ny
,
nz
])
rhs
=
np
.
einsum
(
'
k...,ik...->i...
'
,
velocity
,
gradVelocity
)
+
gradPressure
for
i
in
range
(
3
):
rhs
=
np
.
einsum
(
'
i...,j...->...
'
,
rhs
,
velocity
)
for
j
in
range
(
3
):
for
k
in
range
(
3
):
rhs
+=
2.
*
(
velocity
[
k
]
*
gradVelocity
[
i
][
k
]
+
gradPressure
[
i
])
*
velocity
[
j
]
# compute second derivative of rhs
# compute second derivative of rhs
# (p,t),jj = (rhs),ij
# (p,t),jj = 2.*(rhs),ij
drhsdx
,
drhsdy
,
drhsdz
=
np
.
gradient
(
rhs
,
hx
,
hy
,
hz
,
edge_order
=
2
)
grad_rhs
=
np
.
gradient
(
rhs
,
hx
,
hy
,
hz
,
edge_order
=
2
)
drhsdxdx
,
drhsdxdy
,
drhsdxdz
=
np
.
gradient
(
drhsdx
,
hx
,
hy
,
hz
,
edge_order
=
2
)
hessian_rhs
=
np
.
array
([
np
.
gradient
(
grad
,
hx
,
hy
,
hz
,
edge_order
=
2
)
for
grad
in
grad_rhs
])
drhsdydx
,
drhsdydy
,
drhsdydz
=
np
.
gradient
(
drhsdy
,
hx
,
hy
,
hz
,
edge_order
=
2
)
rhs_ij
=
np
.
einsum
(
'
ij...->...
'
,
hessian_rhs
)
drhsdzdx
,
drhsdzdy
,
drhsdzdz
=
np
.
gradient
(
drhsdz
,
hx
,
hy
,
hz
,
edge_order
=
2
)
rhs_ij
*=
2.0
hessian_rhs
=
np
.
array
([[
drhsdxdx
,
drhsdxdy
,
drhsdxdz
],
print
(
f
"
mean rhs_ij =
{
np
.
mean
(
rhs_ij
)
}
"
)
[
drhsdydx
,
drhsdydy
,
drhsdydz
],
[
drhsdzdx
,
drhsdzdy
,
drhsdzdz
]])
rhs_ij
=
np
.
zeros
([
nx
,
ny
,
nz
])
for
i
in
range
(
3
):
for
j
in
range
(
3
):
rhs_ij
+=
hessian_rhs
[
i
][
j
]
ddt_p
=
poisson_3d
(
rhs_ij
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
ddt_p
=
poisson_3d
(
rhs_ij
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
# Compute dilatation from Eq.7
# Compute dilatation from Eq.7
# -gamma*dilatation = ddt_p+v_k*dpdxk
# -gamma*dilatation = ddt_p+v_k*dpdxk
dilatation
=
np
.
zeros_like
(
p
)
dilatation
=
-
overGamma
*
(
np
.
sum
(
velocity
*
gradPressure
,
axis
=
0
)
+
ddt_p
)
for
i
in
range
(
3
):
dilatation
+=
velocity
[
i
]
*
gradPressure
[
i
]
print
(
f
"
mean dilatation =
{
np
.
mean
(
dilatation
)
}
"
)
dilatation
+=
ddt_p
dilatation
/=
-
gamma
# Compute dilatational velocity from Eq.12
# Compute dilatational velocity from Eq.12
vd_x
,
vd_y
,
vd_z
=
dilatational_velocities
(
dilatation
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
vd_x
,
vd_y
,
vd_z
=
dilatational_velocities
(
dilatation
,
nx
,
ny
,
nz
,
hx
,
hy
,
hz
)
...
...
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