Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wave Equation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
gruczela
Wave Equation
Commits
1375a91e
Commit
1375a91e
authored
1 year ago
by
gruczela
Browse files
Options
Downloads
Patches
Plain Diff
Update 1D_wave.py
parent
0e78dbc0
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Update 1D_wave.py
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
1D_wave.py
+0
-51
0 additions, 51 deletions
1D_wave.py
with
0 additions
and
51 deletions
1D_wave.py
+
0
−
51
View file @
1375a91e
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import
matplotlib.pylab
as
plt
import
numpy
as
np
import
time
import
os
from
numba
import
jit
,
njit
,
prange
# In[2]:
def
set_pos
():
xmin
=
0.0
xmax
=
10.0
...
...
@@ -25,10 +15,6 @@ def set_pos():
nx
,
gamma
,
x
,
dx
=
set_pos
()
# In[3]:
def
set_time
():
tmin
=
0.0
tmax
=
10.0
...
...
@@ -39,10 +25,6 @@ def set_time():
nt
,
tgrid
,
dt
=
set_time
()
# In[4]:
def
velocity
():
v
=
np
.
zeros
(
nx
)
dvdt
=
np
.
zeros
(
nx
)
...
...
@@ -50,10 +32,6 @@ def velocity():
v
,
dvdt
=
velocity
()
# In[5]:
y
=
np
.
zeros
(
nx
)
y
=
np
.
exp
(
-
(
np
.
array
(
x
)
-
5.0
)
**
2
)
...
...
@@ -73,10 +51,6 @@ user_time, sys_time, _, _, _ = os.times()
print
(
"
User time: {:.3f} seconds
"
.
format
(
user_time
))
print
(
"
System time: {:.3f} seconds
"
.
format
(
sys_time
))
# In[6]:
plt
.
plot
(
x
,
y
,
label
=
"
Position
"
)
plt
.
plot
(
x
,
v
,
label
=
"
Velocity
"
)
plt
.
plot
(
x
,
dvdt
,
label
=
"
Acceleration
"
)
...
...
@@ -85,10 +59,6 @@ plt.xlabel('Position')
plt
.
ylabel
(
'
Amplitude
'
)
plt
.
legend
()
# In[7]:
@njit
(
parallel
=
True
)
def
fast_pos
():
xmin
=
0.0
...
...
@@ -100,10 +70,6 @@ def fast_pos():
return
nx
,
gamma
,
x
,
dx
nx
,
gamma
,
x
,
dx
=
fast_pos
()
# In[8]:
@njit
(
parallel
=
True
)
def
fast_time
():
tmin
=
0.0
...
...
@@ -115,10 +81,6 @@ def fast_time():
nt
,
tgrid
,
dt
=
fast_time
()
# In[9]:
@njit
(
parallel
=
True
)
def
fast_velocity
():
v
=
np
.
zeros
(
nx
)
...
...
@@ -127,10 +89,6 @@ def fast_velocity():
v
,
dvdt
=
fast_velocity
()
# In[10]:
@njit
(
parallel
=
True
)
def
fast_numerical_sol
():
nx
,
gamma
,
x
,
dx
=
fast_pos
()
...
...
@@ -146,10 +104,6 @@ def fast_numerical_sol():
v
+=
dvdt
*
dt
return
y
,
v
,
dvdt
# In[11]:
start_2
=
time
.
time
()
fast_numerical_sol
()
end_2
=
time
.
time
()
...
...
@@ -162,10 +116,6 @@ end_3 = time.time()
time_3
=
end_3
-
start_3
print
(
"
Seconds elapsed (after compilation) = %s
"
%
(
time_3
))
# In[12]:
x
=
'
Without Using Numba
'
,
'
Using Numba (after compilation)
'
times
=
time_1
,
time_3
y
=
times
...
...
@@ -173,4 +123,3 @@ plt.bar(x, y, width = 0.5)
plt
.
ylabel
(
'
Seconds Elapsed
'
)
plt
.
title
(
'
Timing Results- 1D Wave
'
)
plt
.
show
()
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