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.3.tar.gz
(8.7 kB
view details)
Built Distribution
pasir-0.0.3-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file pasir-0.0.3.tar.gz
.
File metadata
- Download URL: pasir-0.0.3.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dfb9830232edce3bf1414018dde1b07238d358276bfd184600b97ba4a0c9b17 |
|
MD5 | 2489b547b0772c8c113420592c79d75a |
|
BLAKE2b-256 | 0b5d040bdeb7e3c0fd69887823ee5547a6a7f6e68b8790a3f5edd284ce551a53 |
File details
Details for the file pasir-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pasir-0.0.3-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d40db4fb69da679da431945d5e98d7cc49c8fcdea59bbad344efef72e9754fe0 |
|
MD5 | da423301af6f8378bac337f7bd48b8d1 |
|
BLAKE2b-256 | 64efcb1218797d09df62e49b2c5ed9780601420f4666191aa6cc8c55b9bc71ec |