This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MPM-MLS in 88 lines of Taichi code, originally created by @yuanming-hu | |
# P2G is parallel in this script. | |
import taichi as ti | |
ti.init(arch=ti.gpu) | |
n_particles = 8192 | |
n_grid = 128 | |
dx = 1 / n_grid | |
dt = 2e-4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define GLFW_INCLUDE_VULKAN | |
#include <GLFW/glfw3.h> | |
#include <iostream> | |
#include <stdexcept> | |
#include <cstdlib> | |
#include <vector> | |
#include <string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
ti.init(arch=ti.cuda) | |
N = 5 | |
NV = (N + 1)**2 | |
NT = 2 * N**2 | |
NE = 2 * N * (N + 1) + N**2 | |
pos = ti.Vector.field(3, ti.f32, shape=NV) | |
tri = ti.field(ti.i32, shape=3 * NT) | |
edge = ti.Vector.field(2, ti.i32, shape=NE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf | |
import argparse | |
import numpy as np | |
import taichi as ti | |
@ti.data_oriented | |
class Cloth: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Loop: | |
Press start button to start random selection | |
Press end to show the selected ID | |
""" | |
import taichi as ti | |
ti.init(arch=ti.cpu,cpu_max_num_threads=1) | |
n = 100 | |
userId = ti.field(ti.i32, shape=n) # userId is an array of 0s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
ti.init(arch=ti.cpu, packed=True) | |
a = ti.field(dtype=ti.i32) | |
ti.root.dense(ti.ij, (2, 3)).dense(ti.ij, (2,3)).place(a) | |
@ti.kernel | |
def fill(): | |
for i, j in a: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf | |
import taichi as ti | |
import numpy as np | |
import argparse | |
@ti.data_oriented | |
class Cloth: | |
def __init__(self, N): | |
self.N = N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
from math import sin, cos, sqrt, pi | |
from random import random | |
@ti.data_oriented | |
class Star: | |
def __init__(self, position, velocity, mass) -> None: | |
assert len(position) == len( | |
velocity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
ti.init(ti.gpu) | |
# global control | |
paused = ti.field(ti.i32, ()) | |
# gravitational constant 6.67408e-11, using 1 for simplicity | |
G = 1 | |
PI = 3.141592653 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
ti.init(arch=ti.gpu) | |
N = 3 #number of object | |
x = ti.Vector.field(2,ti.f32,shape=N) | |
v = ti.Vector.field(2,ti.f32,shape=N) | |
a = ti.Vector.field(2,ti.f32,shape=N) | |
f = ti.Vector.field(2,ti.f32,shape=N) | |
m = ti.field(ti.f32,shape=N) | |
color = ti.Vector.field(3, float, N) | |
@ti.kernel |