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
6ac915e5
Commit
6ac915e5
authored
3 months ago
by
Amaury Bilocq
Browse files
Options
Downloads
Patches
Plain Diff
Split interface and solver script
parent
0bcf5c1b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#52468
passed
3 months ago
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
example.py
+62
-74
62 additions, 74 deletions
example.py
pyTurbulence/solver.py
+70
-0
70 additions, 0 deletions
pyTurbulence/solver.py
pyTurbulence/spectrum.py
+15
-6
15 additions, 6 deletions
pyTurbulence/spectrum.py
pyproject.toml
+2
-1
2 additions, 1 deletion
pyproject.toml
with
150 additions
and
81 deletions
.gitignore
+
1
−
0
View file @
6ac915e5
...
@@ -3,6 +3,7 @@ __pycache__/
...
@@ -3,6 +3,7 @@ __pycache__/
*.pkl
*.pkl
dist/
dist/
build/
build/
results/
*.dat
*.dat
*.egg-info/
*.egg-info/
*.egg
*.egg
...
...
This diff is collapsed.
Click to expand it.
example.py
+
62
−
74
View file @
6ac915e5
import
numpy
as
np
import
numpy
as
np
from
pyTurbulence.syntheticTurbulence
import
*
from
pyTurbulence.solver
import
solve
from
pyTurbulence.plot3D
import
*
from
datetime
import
datetime
from
pyTurbulence.spectrum
import
*
import
os
import
time
params
=
{
def
main
():
"
nbModes
"
:
512
,
# Metadata
"
Mt
"
:
0.23
,
code_name
=
"
~~~ pyTurbulence: Synthetic Turbulence Generator ~~~
"
"
Pressure
"
:
1.0
,
author
=
"
Amaury Bilocq
"
"
Temperature
"
:
1.0
,
date
=
datetime
.
now
().
strftime
(
"
%Y-%m-%d %H:%M:%S
"
)
"
k0
"
:
8.0
,
"
domain_size
"
:
(
2.
*
np
.
pi
,
2.
*
np
.
pi
,
2.
*
np
.
pi
),
"
domain_resolution
"
:
(
256
,
256
,
256
),
"
seed
"
:
42
,
"
gamma
"
:
1.4
,
"
case
"
:
1
,
"
Spectrum
"
:
"
PassotPouquet
"
}
# read the params dictionnary
# Parameters
nbModes
=
params
[
"
nbModes
"
]
params
=
{
Mt
=
params
[
"
Mt
"
]
"
nbModes
"
:
256
,
mean_pressure
=
params
[
"
Pressure
"
]
"
Mt
"
:
0.23
,
mean_temperature
=
params
[
"
Temperature
"
]
"
Pressure
"
:
1.0
,
mean_density
=
mean_pressure
/
mean_temperature
"
Temperature
"
:
1.0
,
gamma
=
params
[
"
gamma
"
]
"
k0
"
:
8.0
,
celerity
=
np
.
sqrt
(
gamma
*
mean_pressure
/
mean_density
)
"
domain_size
"
:
(
2.
*
np
.
pi
,
2.
*
np
.
pi
,
2.
*
np
.
pi
),
Ek
=
0.5
*
(
Mt
*
celerity
)
**
2
"
domain_resolution
"
:
(
64
,
64
,
64
),
urms
=
np
.
sqrt
(
2.
*
Ek
/
3.
)
"
seed
"
:
42
,
k0
=
params
[
"
k0
"
]
"
gamma
"
:
1.4
,
domain_size
=
params
[
"
domain_size
"
]
"
case
"
:
1
,
domain_resolution
=
params
[
"
domain_resolution
"
]
"
Spectrum
"
:
"
PassotPouquet
"
xi
=
gamma
*
Mt
**
2
}
# xi = 0.0
spectrum
=
params
[
"
Spectrum
"
]
# Generate the solenoidal velocity field
# Create results directory
start
=
time
.
time
()
results_dir
=
"
results
"
u
,
v
,
w
,
wmax
=
compute_solenoidal_velocities
(
spectrum
,
nbModes
,
urms
,
k0
,
domain_size
,
domain_resolution
,
seed
=
42
)
if
not
os
.
path
.
exists
(
results_dir
):
TKE
=
np
.
mean
(
0.5
*
(
u
.
reshape
(
-
1
)
**
2
+
v
.
reshape
(
-
1
)
**
2
+
w
.
reshape
(
-
1
)
**
2
))
os
.
makedirs
(
results_dir
)
end
=
time
.
time
()
print
(
f
"
done computing the solenoidal velocity field with TKE =
{
TKE
}
, expected TKE =
{
Ek
}
in
{
end
-
start
}
seconds
"
)
# Generate the incompressible pressure fluctuations
# Run the solver
start
=
time
.
time
()
results
=
solve
(
params
,
results_dir
)
incompressible_pressure_fluctuations
=
compute_solenoidal_pressure
(
u
,
v
,
w
,
domain_resolution
,
domain_size
)
end
=
time
.
time
()
print
(
f
"
done computing the incompressible pressure fluctuations in
{
end
-
start
}
seconds
"
)
# Compute the thermodynamic fields
# Log file
start
=
time
.
time
()
log_file
=
os
.
path
.
join
(
results_dir
,
"
log.txt
"
)
density
,
pressure
,
temperature
=
compute_thermodynamic_fields
(
mean_density
,
with
open
(
log_file
,
"
w
"
)
as
f
:
mean_pressure
,
# Display metadata
mean_temperature
,
f
.
write
(
f
"
{
'
=
'
*
70
}
\n
"
)
incompressible_pressure_fluctuations
,
f
.
write
(
f
"
{
code_name
:
^
70
}
\n
"
)
gamma
,
Mt
,
params
[
"
case
"
])
f
.
write
(
f
"
{
'
=
'
*
70
}
\n
"
)
end
=
time
.
time
()
f
.
write
(
f
"
{
'
Author
:
'
:
<
20
}
{
author
}
\n
"
)
print
(
f
"
done computing the thermodynamic fields in
{
end
-
start
}
seconds
"
)
f
.
write
(
f
"
{
'
Date
:
'
:
<
20
}
{
date
}
\n
"
)
f
.
write
(
f
"
{
'
=
'
*
70
}
\n
"
)
# Plot the spectrum
# Display parameters
start
=
time
.
time
()
f
.
write
(
f
"
{
'
Parameters
'
:
<
20
}
\n
"
)
knyquist
,
wave_numbers
,
tke_spectrum
=
compute_tke_spectrum
(
u
,
v
,
w
,
f
.
write
(
f
"
{
'
-
'
*
70
}
\n
"
)
domain_size
[
0
],
for
key
,
value
in
params
.
items
():
domain_size
[
1
],
f
.
write
(
f
"
{
key
:
<
20
}
:
{
value
}
\n
"
)
domain_size
[
2
])
f
.
write
(
f
"
{
'
=
'
*
70
}
\n
"
)
plot_spectrum
(
wmax
,
wave_numbers
,
tke_spectrum
)
end
=
time
.
time
()
print
(
f
"
done plotting the spectrum in
{
end
-
start
}
seconds
"
)
# Generate the visualisation
# Display results
# plot3D(u, domain_size, domain_resolution, "U")
f
.
write
(
f
"
{
'
Task
'
:
<
50
}
{
'
Time (seconds)
'
:
>
20
}
\n
"
)
# plot3D(pressure, domain_size, domain_resolution, "Pressure")
f
.
write
(
f
"
{
'
-
'
*
70
}
\n
"
)
f
.
write
(
f
"
{
'
Computing the solenoidal velocity field
'
:
<
50
}
{
results
[
'
solenoidal_time
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
Computing the incompressible pressure fluctuations
'
:
<
50
}
{
results
[
'
pressure_time
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
Computing the thermodynamic fields
'
:
<
50
}
{
results
[
'
thermodynamic_time
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
Plotting the spectrum
'
:
<
50
}
{
results
[
'
spectrum_time
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
Saving the data
'
:
<
50
}
{
results
[
'
save_time
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
-
'
*
70
}
\n
"
)
f
.
write
(
f
"
{
'
Total TKE
'
:
<
50
}
{
results
[
'
TKE
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
Expected TKE
'
:
<
50
}
{
results
[
'
Ek
'
]
:
>
20.4
f
}
\n
"
)
f
.
write
(
f
"
{
'
=
'
*
70
}
\n
"
)
# Save the data
# Print log to console
start
=
time
.
time
()
with
open
(
log_file
,
"
r
"
)
as
f
:
u
.
tofile
(
"
u.dat
"
)
print
(
f
.
read
())
v
.
tofile
(
"
v.dat
"
)
w
.
tofile
(
"
w.dat
"
)
if
__name__
==
"
__main__
"
:
pressure
.
tofile
(
"
p.dat
"
)
main
()
temperature
.
tofile
(
"
T.dat
"
)
\ No newline at end of file
end
=
time
.
time
()
print
(
f
"
done saving the data in
{
end
-
start
}
seconds
"
)
This diff is collapsed.
Click to expand it.
pyTurbulence/solver.py
0 → 100644
+
70
−
0
View file @
6ac915e5
import
numpy
as
np
from
pyTurbulence.syntheticTurbulence
import
compute_solenoidal_velocities
,
compute_solenoidal_pressure
,
compute_thermodynamic_fields
from
pyTurbulence.spectrum
import
compute_tke_spectrum
,
plot_spectrum
,
energy_spectrum
import
time
import
os
def
solve
(
params
,
results_dir
):
# Read the params dictionary
nbModes
=
params
[
"
nbModes
"
]
Mt
=
params
[
"
Mt
"
]
mean_pressure
=
params
[
"
Pressure
"
]
mean_temperature
=
params
[
"
Temperature
"
]
mean_density
=
mean_pressure
/
mean_temperature
gamma
=
params
[
"
gamma
"
]
celerity
=
np
.
sqrt
(
gamma
*
mean_pressure
/
mean_density
)
Ek
=
0.5
*
(
Mt
*
celerity
)
**
2
urms
=
np
.
sqrt
(
2.
*
Ek
/
3.
)
k0
=
params
[
"
k0
"
]
domain_size
=
params
[
"
domain_size
"
]
domain_resolution
=
params
[
"
domain_resolution
"
]
xi
=
gamma
*
Mt
**
2
spectrum
=
params
[
"
Spectrum
"
]
# Generate the solenoidal velocity field
start
=
time
.
time
()
u
,
v
,
w
,
wmax
=
compute_solenoidal_velocities
(
spectrum
,
nbModes
,
urms
,
k0
,
domain_size
,
domain_resolution
,
seed
=
params
[
"
seed
"
])
TKE
=
np
.
mean
(
0.5
*
(
u
.
reshape
(
-
1
)
**
2
+
v
.
reshape
(
-
1
)
**
2
+
w
.
reshape
(
-
1
)
**
2
))
end
=
time
.
time
()
solenoidal_time
=
end
-
start
# Generate the incompressible pressure fluctuations
start
=
time
.
time
()
incompressible_pressure_fluctuations
=
compute_solenoidal_pressure
(
u
,
v
,
w
,
domain_resolution
,
domain_size
)
end
=
time
.
time
()
pressure_time
=
end
-
start
# Compute the thermodynamic fields
start
=
time
.
time
()
density
,
pressure
,
temperature
=
compute_thermodynamic_fields
(
mean_density
,
mean_pressure
,
mean_temperature
,
incompressible_pressure_fluctuations
,
gamma
,
Mt
,
params
[
"
case
"
])
end
=
time
.
time
()
thermodynamic_time
=
end
-
start
# Plot the spectrum
start
=
time
.
time
()
knyquist
,
wave_numbers
,
tke_spectrum
=
compute_tke_spectrum
(
u
,
v
,
w
,
domain_size
[
0
],
domain_size
[
1
],
domain_size
[
2
])
real_spectrum
=
energy_spectrum
(
spectrum
,
wave_numbers
,
urms
,
k0
)
spectrum_path
=
os
.
path
.
join
(
results_dir
,
"
spectrum.png
"
)
plot_spectrum
(
wmax
,
wave_numbers
,
tke_spectrum
,
real_spectrum
=
real_spectrum
,
save_path
=
spectrum_path
)
end
=
time
.
time
()
spectrum_time
=
end
-
start
# Save the data
start
=
time
.
time
()
u
.
tofile
(
os
.
path
.
join
(
results_dir
,
"
u.dat
"
))
v
.
tofile
(
os
.
path
.
join
(
results_dir
,
"
v.dat
"
))
w
.
tofile
(
os
.
path
.
join
(
results_dir
,
"
w.dat
"
))
pressure
.
tofile
(
os
.
path
.
join
(
results_dir
,
"
p.dat
"
))
temperature
.
tofile
(
os
.
path
.
join
(
results_dir
,
"
T.dat
"
))
end
=
time
.
time
()
save_time
=
end
-
start
return
{
"
TKE
"
:
TKE
,
"
Ek
"
:
Ek
,
"
solenoidal_time
"
:
solenoidal_time
,
"
pressure_time
"
:
pressure_time
,
"
thermodynamic_time
"
:
thermodynamic_time
,
"
spectrum_time
"
:
spectrum_time
,
"
save_time
"
:
save_time
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pyTurbulence/spectrum.py
+
15
−
6
View file @
6ac915e5
...
@@ -92,11 +92,20 @@ def compute_tke_spectrum(u,v,w,lx,ly,lz):
...
@@ -92,11 +92,20 @@ def compute_tke_spectrum(u,v,w,lx,ly,lz):
return
knyquist
,
kvals
,
Abins
/
(
kbins
[
1
:]
-
kbins
[:
-
1
])
return
knyquist
,
kvals
,
Abins
/
(
kbins
[
1
:]
-
kbins
[:
-
1
])
def
plot_spectrum
(
knyquist
,
wave_numbers
,
tke_spectrum
):
def
plot_spectrum
(
wmax
,
wave_numbers
,
tke_spectrum
,
real_spectrum
=
None
,
save_path
=
None
):
plt
.
figure
()
plt
.
figure
()
plt
.
loglog
(
wave_numbers
,
tke_spectrum
,
'
o-
'
)
plt
.
loglog
(
wave_numbers
,
tke_spectrum
,
'
o-
'
,
label
=
'
Computed Spectrum
'
)
plt
.
axvline
(
x
=
knyquist
,
color
=
'
r
'
,
linestyle
=
'
--
'
)
plt
.
axvline
(
x
=
wmax
,
color
=
'
r
'
,
linestyle
=
'
--
'
,
label
=
'
Cut-off Wavenumber
'
)
plt
.
xlabel
(
'
k
'
)
plt
.
ylabel
(
'
E(k)
'
)
if
real_spectrum
is
not
None
:
plt
.
loglog
(
wave_numbers
,
real_spectrum
,
'
k
'
,
label
=
'
Real Spectrum
'
)
plt
.
xlabel
(
'
Wavenumber (k)
'
)
plt
.
ylabel
(
'
Energy Spectrum (E(k))
'
)
plt
.
legend
()
plt
.
grid
()
plt
.
grid
()
plt
.
show
()
if
save_path
:
plt
.
savefig
(
save_path
)
else
:
plt
.
show
()
This diff is collapsed.
Click to expand it.
pyproject.toml
+
2
−
1
View file @
6ac915e5
...
@@ -18,7 +18,8 @@ dependencies = [
...
@@ -18,7 +18,8 @@ dependencies = [
"numba>
=
0.56
", # For JIT optimization
"numba>
=
0.56
", # For JIT optimization
"pytest>
=
7.0
", # For testing
"pytest>
=
7.0
", # For testing
"matplotlib>
=
3.4
", # For plotting
"matplotlib>
=
3.4
", # For plotting
"scipy>
=
1.7
" # For scientific computations
"scipy>
=
1.7
", # For scientific computations
"typing-extensions>
=
3.10
" # For type hints and compatibility
]
]
[project.optional-dependencies]
[project.optional-dependencies]
...
...
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