Jump to content
Sign in to follow this  
Hongzhu

Beginner's question: microsolvers run in first frame?

Recommended Posts

I'm learning HDK and fluid sim by swapping out microsolver nodes in Houdini's built in FLIP solver.

I've successfully changed the GasExternalForce node to my simple gravity node. It works okay but there's a small problem that bugs me a lot.

So here's the implementation in the built in solver:

builtin0.png.8f65fc62ca48fe812b040ba9f8dd991c.png

There's a gravity node in the Auto DOP network (looks like the order doesn't really matter. I tried putting the gravity node before the flipsover and nothing changed.) And then in the flipsolver there's a GasExternalForces microsolver that apply forces on the particles.

I deleted the gravity node and changed the GasExternalForces node to my implementation:

bool
SIM_HZExternalForce::solveGasSubclass(SIM_Engine &engine,
			SIM_Object *obj,
			SIM_Time time,
			SIM_Time timestep)
{

	SIM_Geometry* geo = (SIM_Geometry*)obj->getGeometry();
	if (!geo) {
		return false;
	}
	GU_DetailHandle gdh = geo->getOwnGeometry();
	const GU_Detail* gdp_in = gdh.readLock(); // Must unlock later
	GU_Detail* gdp_out = gdh.writeLock();

	GA_RWAttributeRef p_ref_vel = gdp_out->findPointAttribute("v");
	GA_RWHandleT<UT_Vector3F> p_vel(p_ref_vel.getAttribute());

	if (p_vel.isInvalid()) {
		return false;
	}
    
    for (GA_Iterator it(gdp_out->getPointRange()); !it.atEnd(); it.advance()){
        int pid = it.getOffset();
        UT_Vector3F vel = p_vel.get(pid);
        vel[1] -= timestep * 9.80665f;
        p_vel.set(pid, vel);
    }

	gdh.unlock(gdp_out);
	gdh.unlock(gdp_in);
    // Successful cook
    return true;
}

The problem is, the velocities in the first frame are all zero in the official implementation:

builtin.thumb.png.babbe41df950c2f0745bdbf58b222868.png

But in my implementation, the velocities got changed in the first frame:

my.thumb.png.de4ace637e24c4a2a30a7500bb85fa8a.png

I really want to know where this discrepancy comes from. Any suggestions? I've uploaded the source code and scene file if anyone is interested.

GravityTest.zip

Share this post


Link to post
Share on other sites

from what I see, your vel is coming from 

vel[1] -= timestep * 9.80665f;

on first frame its -(1/24) * 9.80665 = -0.40861

timestep will evaluate in first frame too, official might have something else.

Share this post


Link to post
Share on other sites

not knowing anything about HDK, but there is a checkbox on Empty Object and therefore Flip Object too called Solve On Creation Frame, which is off by default

that's why default external forces are not applied on the first frame, so possibly your implementation needs to consider that flag

Share this post


Link to post
Share on other sites

From what I see, you multiply the gravity by the timestep, so at frame 0 you'll have 0 because 0 * 9.80665 = 0, that's what Sumit said. So I guess that even if you cook the first frame it will stay at zero. Try to set it initial and don't multiply it by the timestep

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×