Skip to content

Commit

Permalink
generate MPM from file
Browse files Browse the repository at this point in the history
  • Loading branch information
Yihao-Shi committed Jul 8, 2024
1 parent 7d3d89f commit a880363
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 83 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The performance of GeoTaichi is compared with similar simulator in the field, su
|[shapely](https://pypi.org/project/shapely/)|==1.8.0|Delaunay triangulation|

### Installation

#### Install from source code (recommand)
1. Change the current working directory to the desired location and download the GeoTaichi code:
```
cd /path/to/desired/location/
Expand All @@ -77,7 +77,7 @@ sudo apt-get install python3.8
sudo apt-get install python3-pip
# Install python packages (recommand to add package version)
python3 -m pip install taichi==1.6.0 imageio pybind11 numpy trimesh psutil shapely [optional: -i https://pypi.douban.com/simple]
python3 -m pip install taichi==1.6.0 imageio pybind11 numpy trimesh psutil shapely
# Install Eigen in C++ (if necessary)
sudo apt-get install libeigen3-dev cmake==3.18.2
Expand All @@ -98,6 +98,10 @@ sudo gedit ~/.bashrc
$ export PYTHONPATH="$PYTHONPATH:/path/to/desired/location/GeoTaichi"
source ~/.bashrc
```
#### Install from pip (easy)
```
pip install geotaichi
```

### Working with vtu files

Expand Down
70 changes: 70 additions & 0 deletions example/mpm/ColumnCollapse/bunny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from geotaichi import *

init(device_memory_GB=4)

mpm = MPM()

mpm.set_configuration(
domain=ti.Vector([0.17, 0.37, 0.21]),
background_damping=0.01,
alphaPIC=0.01,
mapping="USL",
shape_function="GIMP",
gravity=ti.Vector([0., -9.8, 0.]))

mpm.set_solver({
"Timestep": 1e-5,
"SimulationTime": 0.4,
"SaveInterval": 0.008,
"SavePath": "Bunny"
})

mpm.memory_allocate(memory={
"max_material_number": 1,
"max_particle_number": 1559361,
"verlet_distance_multiplier": 1.,
"max_constraint_number": {
"max_reflection_constraint": 121914,
"max_friction_constraint": 0,
"max_velocity_constraint": 0
}
})


mpm.add_material(model="LinearElastic",
material={
"MaterialID": 1,
"Density": 2650.,
"YoungModulus": 2e6,
"PossionRatio": 0.3
})

mpm.add_element(element={
"ElementType": "R8N3D",
"ElementSize": ti.Vector([0.002, 0.002, 0.002])
})

mpm.add_body_from_file(body={
"FileType": "OBJ",
"Template": {
"BodyID": 0,
"MaterialID": 1,
"ParticleFile": "/home/eleven/work/GeoTaichi/assets/bunny_sparse.obj",
"nParticlesPerCell": 2,
"Offset": [0.07, 0.1, 0.11]
}
})

mpm.add_boundary_condition(boundary=[
{
"BoundaryType": "ReflectionConstraint",
"Norm": [0., -1., 0.],
"StartPoint": [0., 0.006, 0.],
"EndPoint": [0.17, 0.008, 0.21]
},
])

mpm.select_save_data()

mpm.run()

185 changes: 185 additions & 0 deletions example/mpm/ElementTest/BiaxialCompressionMC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
from geotaichi import *

init(device_memory_GB=4)

mpm = MPM()

mpm.set_configuration(domain=ti.Vector([5., 5., 3.]),
background_damping=0.01,
gravity=ti.Vector([0., 0., 0.]),
alphaPIC=0.1,
mapping="USF",
shape_function="GIMP",
stabilize=None)

mpm.set_solver(solver={
"Timestep": 1e-5,
"SimulationTime": 0.1,
"SaveInterval": 0.01
})

mpm.memory_allocate(memory={
"max_material_number": 1,
"max_particle_number": 3.5e5,
"max_constraint_number": {
"max_velocity_constraint": 51005
}
})

mpm.add_material(model="SoftenMohrCoulomb",
material={
"MaterialID": 1,
"Density": 1530,
"YoungModulus": 3e7,
"PoissionRatio": 0.3,
"Friction": 30.5,
"Cohesion": 8500,
"Dilation": 0,
})

mpm.add_element(element={
"ElementType": "R8N3D",
"ElementSize": ti.Vector([0.04, 0.04, 0.04]),
"Contact": {
"ContactDetection": "MPMContact",
"Friction": 1,
"CutOff": 1.6
}
})

mpm.add_region(region=[{
"Name": "region1",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([2., 2., 0.]),
"BoundingBoxSize": ti.Vector([1., 1., 2.]),
"zdirection": ti.Vector([0., 0., 1.])
},

{
"Name": "region2",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([1.5, 1.5, 2.]),
"BoundingBoxSize": ti.Vector([2., 2., 0.1]),
"zdirection": ti.Vector([0., 0., 1.])
},

{
"Name": "region3",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([2., 2., 0.]),
"BoundingBoxSize": ti.Vector([0.02, 1., 2.]),
"zdirection": ti.Vector([0., 0., 1.])
},

{
"Name": "region4",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([2.98, 2., 0.]),
"BoundingBoxSize": ti.Vector([0.02, 1., 2.]),
"zdirection": ti.Vector([0., 0., 1.])
},

{
"Name": "region5",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([2., 2., 0.]),
"BoundingBoxSize": ti.Vector([1., 0.02, 2.]),
"zdirection": ti.Vector([0., 0., 1.])
},

{
"Name": "region6",
"Type": "Rectangle",
"BoundingBoxPoint": ti.Vector([2., 2.98, 0.]),
"BoundingBoxSize": ti.Vector([1., 0.02, 2.]),
"zdirection": ti.Vector([0., 0., 1.])
}])

mpm.add_body(body={
"Template": [{
"RegionName": "region1",
"nParticlesPerCell": 2,
"BodyID": 0,
"MaterialID": 1,
"ParticleStress": {
"GravityField": False,
"InternalStress": ti.Vector([-100000., -100000., -100000., 0., 0., 0.])
},
"Traction": [{
"Pressure": ti.Vector([100000, 0., 0.]),
"RegionName": "region3"
},

{
"Pressure": ti.Vector([-100000, 0., 0.]),
"RegionName": "region4"
},

{
"Pressure": ti.Vector([0., 100000, 0.]),
"RegionName": "region5"
},

{
"Pressure": ti.Vector([0., -100000, 0.]),
"RegionName": "region6"
}],
"InitialVelocity":ti.Vector([0, 0, 0]),
"FixVelocity": ["Free", "Free", "Free"]

},

{
"RegionName": "region2",
"nParticlesPerCell": 2,
"BodyID": 1,
"RigidBody": True,
"ParticleStress": {
"GravityField": False,
"InternalStress": ti.Vector([-0, -0, -0, 0., 0., 0.])
},
"InitialVelocity":ti.Vector([0, 0, 0]),
"FixVelocity": ["Fix", "Fix", "Fix"]

}]
})

mpm.add_boundary_condition(boundary=[
{
"BoundaryType": "VelocityConstraint",
"Velocity": [0, 0, 0],
"StartPoint": [0., 0., 0.],
"EndPoint": [5., 5., 0.],
"NLevel": 0
},

{
"BoundaryType": "VelocityConstraint",
"Velocity": [None, 0, None],
"StartPoint": [0., 2., 0.],
"EndPoint": [5., 2., 3.],
"NLevel": 0
},

{
"BoundaryType": "VelocityConstraint",
"Velocity": [None, 0, None],
"StartPoint": [0., 3., 0.],
"EndPoint": [5., 3., 3.],
"NLevel": 0
}
])

mpm.select_save_data(grid=True)

mpm.run()

mpm.update_particle_properties(property_name='velocity', value=[0., 0., -0.02], bodyID=1)

mpm.modify_parameters(SimulationTime=15.1, SaveInterval=0.3)

mpm.run()

mpm.postprocessing()


Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
alphaPIC=0.005,
mapping="USF",
shape_function="GIMP",
stabilize=None,
gauss_number=2)
stabilize=None)

mpm.set_solver(solver={
"Timestep": 1e-5,
Expand All @@ -27,16 +26,16 @@
}
})

mpm.add_material(model="ModifiedCamClay",
mpm.add_material(model="DruckerPrager",
material={
"MaterialID": 1,
"Density": 2000,
"PossionRatio": 0.3,
"StressRatio": 1.5,
"lambda": 0.1,
"kappa": 0.008,
"void_ratio_ref": 1.76,
"ConsolidationPressure": 1e5
"MaterialID": 1,
"Density": 2000.,
"YoungModulus": 3e7,
"PossionRatio": 0.3,
"Cohesion": 1000,
"Friction": 24.,
"Dilation": 24.,
"Tensile": 0.
})

mpm.add_element(element={
Expand Down Expand Up @@ -164,10 +163,9 @@

mpm.update_particle_properties(property_name='velocity', value=[0., 0., -0.04], bodyID=1)

mpm.modify_parameters(SimulationTime=15.1, SaveInterval=0.1)
mpm.modify_parameters(SimulationTime=7.6, SaveInterval=0.1)

mpm.run()

mpm.postprocessing()


8 changes: 5 additions & 3 deletions src/mpm/generator/InsertionKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ def kernel_calc_mass_of_center_(coords: ti.types.ndarray()) -> ti.types.vector(3
return position / coords.shape[0]

@ti.kernel
def kernel_position_rotate_(target: ti.types.vector(3, float), offset: ti.types.vector(3, float), body_coords: ti.template(), start_particle_num: int, end_particle_num: int): # type: ignore
def kernel_position_rotate_(target: ti.types.vector(3, float), offset: ti.types.vector(3, float), body_coords: ti.types.ndarray(), start_particle_num: int, end_particle_num: int):
origin =vec3f([0, 0, 1])
R = RodriguesRotationMatrix(origin, target)
for nb in range(start_particle_num, end_particle_num):
coords = body_coords[nb]
coords = vec3f(body_coords[nb, 0], body_coords[nb, 1], body_coords[nb, 2])
coords -= offset
coords = R @ coords
coords += offset
body_coords[nb] = coords
body_coords[nb, 0] = coords[0]
body_coords[nb, 1] = coords[1]
body_coords[nb, 2] = coords[2]

@ti.kernel
def kernel_position_rotate_for_array_(
Expand Down
Loading

0 comments on commit a880363

Please sign in to comment.