Skip to main content

wave simulator

Project description

Wave Simulator

中文

This project is for wave simulation.

Please do not use this project for any purpose other than learning, as the author does not guarantee its rigor.

Installation

pip install wave-simulator

Examples

The following is a simple example. You can find more examples here.

from wave_simulator import OneDimensionSimulator, FixedBoundary

def my_initial_wave(x):
    if x < 4:
        return 0.5*x
    return -x + 6

s = OneDimensionSimulator()
s.set_simulation_range(6, 0.01, 16, 0.001)
s.set_initial_wave(my_initial_wave)
s.set_left_boundary(FixedBoundary())
s.set_right_boundary(FixedBoundary())
s.simulate()
s.animate_result_1D(ylim=(-4, 4), down_sampling_rate=20)

Detailed Guide

You can set the simulation's spatial and temporal ranges. This setting should be done before other configurations.

s.set_simulation_range(6, 0.01, 16, 0.001)

Set the initial waveform

def my_initial_wave(x):
    if x < 4:
        return 0.5*x
    return -x + 6

s.set_initial_wave(my_initial_wave)

Set the initial speed of the particles

def my_initial_speed(x):
    if x > 0.1 and x < np.pi/4+0.1:
        return -8*np.cos(8*(x-0.1))
    return 0

s.set_initial_point_speed(my_initial_speed)

Set the wave speed

def my_wave_speed(x):
    if x > 1.5:
        return 0.5
    return 1

s.set_wave_speed(my_wave_speed)

Set boundary conditions

s.set_left_boundary(FixedBoundary())
s.set_right_boundary(FixedBoundary())
s.set_up_boundary(UnlimitedBoundary())
s.set_down_boundary(NeumannBoundary())

To save the simulation result as a video, just add a save_path parameter

s.animate_result_3D(save_path="your_path.mp4")

Correspondence between Mathematical Symbols and Code Variables

Variable Name Meaning
L_x Simulation range for x
dx Spatial step for x
X Discrete values for x
c Wave speed
c2 $c^2$
C $c\frac{dt}{dx}$
C2 $(c\frac{dt}{dx})^2 $
c2_i_sub_1 $c_{i-1}^2$
c2_i $c_i^2$
c2_i_add_1 $c_{i+1}^2$
u_i_sub_1 $u_{i-1}$
u_i $u_{i}$
u_i_add_1 $u_{i+1}$
u_i_j $u_{i,j}$
u_ip1_j $u_{i+1,j}$
u_is1_j $u_{i-1,j}$
u_i_ja1 $u_{i,j+1}$
u_i_js1 $u_{i,j-1}$

Related Formulas

1d reference 2d reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wave_simulator-0.0.2.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wave_simulator-0.0.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file wave_simulator-0.0.2.tar.gz.

File metadata

  • Download URL: wave_simulator-0.0.2.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for wave_simulator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8304b63ab3429d21b4d9a3b04a7aa22b5ac08276a6c98c1afc4b5fd11bfd7343
MD5 0b975fec6d5ce03ebbc072a410a00b1e
BLAKE2b-256 acbb0b4d3b2feadadae245d9a19d1c80a4aecf785ee95d306bfb2b9d705b50ad

See more details on using hashes here.

File details

Details for the file wave_simulator-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: wave_simulator-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for wave_simulator-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69fa9c9979190f51be7c55bd4d5a5c03bbc109b06e07ee6f3195428194e7b13a
MD5 eed3bf5901d2eb319f1faf3dfa3b4ffe
BLAKE2b-256 a989d4fea3ef12b5201ccadb0086b27ce3fb65cc742347706f6ddeb716c54d1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page