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
Merge requests
!7
leapfrog and stormer_verlet
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
leapfrog and stormer_verlet
jima
into
main
Overview
0
Commits
25
Pipelines
2
Changes
11
Closed
jim92
requested to merge
jima
into
main
1 year ago
Overview
0
Commits
25
Pipelines
2
Changes
1
Expand
implement the leapfrog and stormer_verlet in jobs/src/integrators.py
0
0
Merge request reports
Compare
version 1
version 2
41e489af
1 year ago
version 1
907a611f
1 year ago
main (base)
and
version 2
latest version
41e489af
25 commits,
1 year ago
version 2
41e489af
25 commits,
1 year ago
version 1
907a611f
24 commits,
1 year ago
Show latest version
1 file
+
6
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
jobs/src/integrators.py
+
51
−
0
Options
@@ -20,3 +20,54 @@ 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
=
p
+
dt
/
2
*
F
(
q
)
# 2. Update Position:
q
=
q
+
p
/
m
*
dt
# 3. Update Momentum at Full Step:
p
=
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
=
q
+
p
/
m
*
dt
+
acc
*
(
dt
**
2
*
0.5
)
# 2. Update Momentum:
p
=
p
+
acc
*
(
dt
*
0.5
)
*
m
+
F
(
q
)
*
(
dt
*
0.5
)
return
p
,
q
Loading