granular-based simulation and related systems
Project description
pasir
granular-based simulation and related systems
install
pip install pasir
instantiation
grain
Syntax
Grain([id[, m[, d[, q[, b]]]]])
id
: identification in string, e.g.0092
, default0000
.m
: mass, e.g.0.5
, default0
.d
: diameter, e.g.1.2
, default0
.q
: charge, e.g.-0.1
, default0
.b
: artificial property, e.g.5.3
, default0
.
Code
g = Grain()
g.r = Vect3(1, 2, 3)
g.color = Color2('#0f0', '#ff0')
print(g)
Output
{
"id": "0000",
"m": 0,
"d": 0,
"q": 0,
"b": 0,
"color": { "stroke": "#0f0", "fill": "#ff0" },
"r": { "x": 1, "y": 2, "z": 3 },
"v": { "x": 0, "y": 0, "z": 0 },
"a": { "x": 0, "y": 0, "z": 0 }
}
gravitational2
Syntax
Gravitational2([constant])
constant
: Gravitational constant.
Code
from pasir.butiran.color2 import Color2
from pasir.butiran.math.vect3 import Vect3
from pasir.butiran.grain import Grain
from pasir.butiran.force.gravitational2 import Gravitational2
if True:
G = 5
gravitational = Gravitational2(constant=G)
print(gravitational)
grain1 = Grain(id="0000", m=5)
grain1.r = Vect3(0, 0, 0)
print(grain1)
grain2 = Grain(id="0034", m=10)
grain2.r = Vect3(3, 4, 0)
print(grain2)
fg12 = gravitational.force(grain1, grain2)
print(fg12)
fg21 = gravitational.force(grain2, grain1)
print(fg21)
Output
{
"constant": "5",
}
{
"id": "0000",
"m": 5,
"d": 0,
"q": 0,
"b": 0,
"color": { "stroke": "#000", "fill": "#fff" },
"r": { "x": 0, "y": 0, "z": 0 },
"v": { "x": 0, "y": 0, "z": 0 },
"a": { "x": 0, "y": 0, "z": 0 }
}
{
"id": "0034",
"m": 10,
"d": 0,
"q": 0,
"b": 0,
"color": { "stroke": "#000", "fill": "#fff" },
"r": { "x": 3, "y": 4, "z": 0 },
"v": { "x": 0, "y": 0, "z": 0 },
"a": { "x": 0, "y": 0, "z": 0 }
}
{ "x": 6.0, "y": 8.0, "z": -0.0 }
{ "x": -6.0, "y": -8.0, "z": -0.0 }
examples
parabolic motion
from pasir.butiran.color2 import Color2
from pasir.butiran.math.vect3 import Vect3
from pasir.butiran.grain import Grain
from pasir.butiran.force.gravitational import Gravitational
# define grain with initial position and velocity
grain = Grain(id="0002", m = 1)
grain.r = Vect3(0, 0, 0)
grain.v = Vect3(30, 40, 0)
# define gravitational field and force
g = Vect3(0, -10, 0)
gravitational = Gravitational(field=g)
import numpy as np
# define iteration
tbeg = 0
tend = 8
N = 100
dt = (tend - tbeg) / N
# define lists
data_t = []
data_x = []
data_y = []
data_vx = []
data_vy = []
# perform iteration
#print("#t x y vx vy")
print("Calculate position and velocity.")
for i in range(N + 1):
t = i
m = grain.m
v = grain.v
r = grain.r
data_t.append(t)
data_x.append(r.x)
data_y.append(r.y)
data_vx.append(v.x)
data_vy.append(v.y)
fg = gravitational.force(grain)
a = fg / m
v += a * dt
r += v * dt
grain.v = v
grain.r = r
#print(t, ' ', end='')
#print(r.x, ' ', r.y, ' ', end='')
#print(v.x, ' ', v.y)
print("Plot data.")
from matplotlib.pyplot import figure
import matplotlib.pyplot as plt
figure(figsize=(5,3.5), dpi=80)
plt.plot(data_x, data_y, c='r')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.xlim([0, 240])
plt.ylim([0, 80])
plt.xticks(np.arange(0, 240+0.01, 40))
plt.yticks(np.arange(0, 80+0.01, 20))
plt.text(60, 39, "$v_x = 30$, $v_y = 40$, $m = 1$", fontsize=12)
plt.text(98, 30, "$g = -10$", fontsize=12)
print("Save figure.")
plt.savefig('parabolic_gravitational_euler.png', bbox_inches='tight')
circular motion
from butiran.color2 import Color2
from butiran.math.vect3 import Vect3
from butiran.grain import Grain
from butiran.force.magnetic import Magnetic
# define grain with initial position and velocity
grain = Grain(id="0001", m = 1, q = 1)
grain.r = Vect3(1, 0, 0)
grain.v = Vect3(0, 1, 0)
# define magnetic field and force
B = Vect3(0, 0, -1)
magnetic = Magnetic(field=B)
import numpy as np
# define iteration
tbeg = 0
tend = 2 * np.pi
N = 10000
dt = (tend - tbeg) / N
# define lists
data_t = []
data_x = []
data_y = []
data_vx = []
data_vy = []
# perform iteration
#print("#t x y vx vy")
print("Calculate position and velocity.")
for i in range(N + 1):
t = i
m = grain.m
v = grain.v
r = grain.r
data_t.append(t)
data_x.append(r.x)
data_y.append(r.y)
data_vx.append(v.x)
data_vy.append(v.y)
fB = magnetic.force(grain)
a = fB / m
v += a * dt
r += v * dt
grain.v = v
grain.r = r
#print(t, ' ', end='')
#print(r.x, ' ', r.y, ' ', end='')
#print(v.x, ' ', v.y)
print("Plot data.")
from matplotlib.pyplot import figure
import matplotlib.pyplot as plt
figure(figsize=(5,5), dpi=80)
plt.plot(data_x, data_y, c='r')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.xlim([-1.5, 1.5])
plt.ylim([-1.5, 1.5])
plt.xticks(np.arange(-1.5, 1.5+0.01, 0.5))
plt.yticks(np.arange(-1.5, 1.5+0.01, 0.5))
plt.text(-0.5, 0.2, "$B = 1, m = 1, q = 1$", fontsize=12)
plt.text(-0.4, -0.05, "$\Delta t = 2 \pi \ / \ 10^4$", fontsize=12)
plt.text(-0.3, -0.3, "$T \in [0, 2\pi]$", fontsize=12)
print("Save figure.")
plt.savefig('circular_magnetic_euler.png', bbox_inches='tight')
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
pasir-0.0.4.tar.gz
(8.6 kB
view details)
Built Distribution
pasir-0.0.4-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file pasir-0.0.4.tar.gz
.
File metadata
- Download URL: pasir-0.0.4.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57409785023e3198a1dd9689e0f09f0a8f7b424c2759a4e491c5d18d72fdb40c |
|
MD5 | 119d41396dd9ba7fc3c260b0f434115d |
|
BLAKE2b-256 | 0913010bf8f64caa3dead1ac766c9b4b5a8db676f4e60db2aaaa71a6be8b9da4 |
File details
Details for the file pasir-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: pasir-0.0.4-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b94bd9549ec835fae33ff2c47923c2304f9bab3e124c035019a0e4286bfef3ce |
|
MD5 | 2cc839a0481b1131dcedbee0fa4a7796 |
|
BLAKE2b-256 | 822fcb1288fc9efaf39d088a504b06cfbdf3437d71ca1c02a0d46ad59af9b0df |