taichi_houdini icon indicating copy to clipboard operation
taichi_houdini copied to clipboard

Modifying the parameters after materilization

Open Eydcao opened this issue 2 years ago • 0 comments

According to @maajor and @Eydcao , the current implementation requires a materialized MPM_sovler_shell before the importing into the python SOP. The advantage is that no need to redo ti.init() which is unnecessarily time-consuming.

Nonetheless, a materialized shell means many parameters has been determined (such as dx), this limits the flexibility brought by Houdini (i.e. the size of the whole scene always have to be normalized).

A temporal solution proposed by @maajor is directly quoted here

  1. create a class containing all these parameters (with a proper initial value).
# ti_parm.py
import taichi as ti

class TIContext():
    def __init__(self):
        self.device = ti.cpu
        self.last_device = ti.cpu

context = TIContext()
  1. use this global parameter class to init MPM_solver_shell
import taichi as ti
import numpy as np
import ti_parm as tp
from taichi_elements.engine.mpm_solver import MPMSolver

ti.reset()
ti.init(tp.context.device, device_memory_GB=4.0)import importlib

if use_gpu:
    tp.context.device = ti.cuda
else:
    tp.context.device = ti.cpu
    
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device:
    importlib.reload(mpm)
    tp.context.last_device = tp.context.device

# blablabla
  1. finally in the python SOP where 'MPM_solver_shell', by comparing if the current parameter class is the same as an old parameter class, if different, forcefully re-import
import importlib

if use_gpu:
    tp.context.device = ti.cuda
else:
    tp.context.device = ti.cpu
    
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device:
    importlib.reload(mpm)
    tp.context.last_device = tp.context.device

Eydcao avatar Sep 24 '21 04:09 Eydcao