Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
comp-sci-project
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
nguyed99
comp-sci-project
Commits
907a611f
Commit
907a611f
authored
1 year ago
by
JayM0826
Browse files
Options
Downloads
Patches
Plain Diff
implement the leapfrog and stormer_verlet in jobs/src/integrators.py
parent
1feb464c
Branches
Branches containing commit
No related tags found
1 merge request
!7
leapfrog and stormer_verlet
Pipeline
#59211
passed
1 year ago
Stage: test-jobs
Stage: test-tasks
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jobs/src/integrators.py
+50
-0
50 additions, 0 deletions
jobs/src/integrators.py
with
50 additions
and
0 deletions
jobs/src/integrators.py
+
50
−
0
View file @
907a611f
...
...
@@ -20,3 +20,53 @@ def verlet(F: Callable, q0: np.ndarray, p0: np.ndarray, m: np.ndarray, dt: float
p
=
p
+
1
/
2
*
F
(
q
)
*
dt
return
p
,
q
def
leapfrog
(
F
:
Callable
,
q0
:
np
.
ndarray
,
p0
:
np
.
ndarray
,
m
:
np
.
ndarray
,
dt
:
float
):
'''
# using leapfrog integration. https://en.wikipedia.org/wiki/Leapfrog_integration
The basic idea of the Leapfrog method is to update the position
and momentum of a particle or system at half-integer time steps.
The algorithm proceeds in discrete steps, and the update scheme looks like this:
1. Update Velocity at Half Step:
2. Update Position:
3. Update Velocity at Full Step:
'''
p
=
p0
q
=
q0
# 1. Update Momentum at Half Step:
p
+=
dt
/
2
*
F
(
q
)
# 2. Update Position:
q
+=
p
/
m
*
dt
# 3. Update Momentum at Full Step:
p
+=
dt
/
2
*
F
(
q
)
# print("-------------------")
# print(f'accelerations={accelerations}')
# print(f'velocity={velocity}')
return
p
,
q
def
stormer_verlet
(
F
:
Callable
,
q0
:
np
.
ndarray
,
p0
:
np
.
ndarray
,
m
:
np
.
ndarray
,
dt
:
float
):
"""
stormer_verlet integrator for one time step
# https://www.physics.udel.edu/~bnikolic/teaching/phys660/numerical_ode/node5.html
# https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet
# https://www.algorithm-archive.org/contents/verlet_integration/verlet_integration.html
"""
p
=
p0
q
=
q0
# 1. Update Position at Half Step:
acc
=
F
(
q
)
/
m
q
+=
p
/
m
*
dt
+
acc
*
(
dt
**
2
*
0.5
)
# 2. Update Momentum:
p
+=
acc
*
(
dt
*
0.5
)
*
m
+
F
(
q
)
*
(
dt
*
0.5
)
return
p
,
q
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