Jump to content

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

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

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

Link to comment
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

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...