Skip to main content
GameDev.net gamedev.net
🔒 Locked

What is the gradient symbol for

Started by Finalspace Jan 12, 2015 at 7:45 PM 16 replies 12k views
Original Post
Finalspace
Finalspace

Hi am currently breaking down a paper called "Position Based Fluid" and have trouble understanding some symbols.

First off, i dont have any math professional backgrounds at all - i barely understand the basics to break down some formulas but if these gets too complex and i dont have any chance to convert this code.

There is a kernel function for calculation a approximation value based on the difference between two particles - called smoothing function which does some magic math stuff behind, like transforming the distance between two particles into the range of the kernel h with some smoothing...

There are two variants of this formula, one normal and one for gradient:

w-normal.png

w-gradient.png

What are the differerence between those?

I know that delta.png means "Change in" and i also found out that the flipped symbol gradient.png means gradient but i have no clue what this are.

Please help me to break this down.

Thanks and regards,

Final

alvaro
alvaro
The gradient is the vector whose coordinates are the derivatives of the function with respect to each variable. But a quick Google search probably already told you that...
CulDeVu
CulDeVu

It's the Del operator: http://en.wikipedia.org/wiki/Del

Like Alvaro, said, each cooridinate of a gradient vector are the derivatives with respect to it.

For future reference, there's this really nice page that helps me out a lot: http://en.wikipedia.org/wiki/List_of_mathematical_symbols

I'm sorry about any spelling or grammar mistakes or any undue brevity, as I'm most likely typing on my phone   "Hell, there's more evidence that we are just living in a frequency wave that flows in harmonic balance creating the universe and all its existence." ~ GDchat  
jmakitalo
jmakitalo

A more geometrical definition for gradient of a scalar function W is that it is a vector valued function, where the vectors point to the direction where W increasest most rapidly. The length of the vectors indicate how rapidly.

The components of grad(W) are only the coordinate derivatives of W in Cartesian system. Not the case in e.g. spherical coordinates. In most fluid treatments for games, Cartesian coordinates are used, so I don't want to confuse you with this, but it's good to be aware that some definitions are bound to specific coordinate frames while the gradient can be defined in coordinate-free manner.

It may also be useful to know that the "Delta" symbol may refer to the Laplacian, which is a second-order derivative of either scalar or vector function. This may also arise in fluid dynamics.

alvaro
alvaro

A more geometrical definition for gradient of a scalar function W is that it is a vector valued function, where the vectors point to the direction where W increasest most rapidly. The length of the vectors indicate how rapidly.

The components of grad(W) are only the coordinate derivatives of W in Cartesian system. Not the case in e.g. spherical coordinates. In most fluid treatments for games, Cartesian coordinates are used, so I don't want to confuse you with this, but it's good to be aware that some definitions are bound to specific coordinate frames while the gradient can be defined in coordinate-free manner.


Yes, you can define the gradient intrinsically (i.e., without referring to coordinates), but be aware that this definition depends on a metric. The exterior derivative of a function at a point is a covector, and a metric allows you to map that to a vector.

I was going to mention this in my first post, but it's unclear to me how this would help the OP.
Finalspace
Finalspace

I have trouble converting the following formula into its gradient form:

image016.jpg

My code for this:


private float Wspiky (Vec2f r, float kH) {
	float rlen = r.length();
	if (rlen > kH || rlen == 0) {
		return 0;
	}
	final float tmp = kH - rlen;
	final float term = 15.0f / ((float)Math.PI * (float)Math.pow(kH, 6));
	return term * tmp * tmp * tmp;
}

I found a image for a gradient version, but my implementation of this produces wrong results:

46j2joqy.png


private Vec2f gradWspiky (Vec2f r, float kH) {
	float rlen = r.length();
	if (rlen > kH || rlen == 0) {
		return new Vec2f (0f, 0f);
	}
	final float tmp = kH - rlen;
	final float term = 45.0f / ((float)Math.PI * (float)Math.pow(kH, 6) * rlen);
	return r.mult(-term * tmp * tmp);
}

I dont see any mistake.... please help me.

jmakitalo
jmakitalo




I dont see any mistake.... please help me.

Assuming that the math routines do what I think they do, this seems fine. How do you know it is not working? Have you plotted the result to see if it looks like you might expect from the geometric interpretation of the gradient?

A word of warning: I once tried out particle hydrodynamics for some fluid simulations. I never got good results, because there are alot of parameters to play with and it requires a lot of iteration to get things work reasonably. Worst of all, usually the behaviour depends sensitively on the number of included particles and the chosen timestep. Change the timestep and all other parameters may need to be revisited.

Finalspace
Finalspace

I dont see any mistake.... please help me.

Assuming that the math routines do what I think they do, this seems fine. How do you know it is not working? Have you plotted the result to see if it looks like you might expect from the geometric interpretation of the gradient?

A word of warning: I once tried out particle hydrodynamics for some fluid simulations. I never got good results, because there are alot of parameters to play with and it requires a lot of iteration to get things work reasonably. Worst of all, usually the behaviour depends sensitively on the number of included particles and the chosen timestep. Change the timestep and all other parameters may need to be revisited.

Yes i know that tuning SPH parameters are really hard - i made some fluid simulations in the past (Fluid Sandbox) based on physX SDK, but even with an existing physics engine it taked me weeks to figure out some paramter configurations which works - almost. There was over 20 parameters for PxParticleFluid to set... pain .... but fortunatly the paper i am targeting right now, just have a few parameters and support small time steps without doing any sub steps.

alvaro
alvaro
Where did the extra factor of `rlen' come from?
Finalspace
Finalspace

Where did the extra factor of `rlen' come from?

Its the distance vector between two particle positions and rlen is the magnitude of this vector.

alvaro
alvaro


Where did the extra factor of `rlen' come from?


Its the distance vector between two particle positions and rlen is the magnitude of this vector.



What I mean is that
final float term = 45.0f / ((float)Math.PI * (float)Math.pow(kH, 6) * rlen);
should probably be
final float term = 45.0f / ((float)Math.PI * (float)Math.pow(kH, 6));
Unless you can explain where "the extra factor of rlen" came from.
Brother Bob
Brother Bob

Where did the extra factor of `rlen' come from?


Its the distance vector between two particle positions and rlen is the magnitude of this vector.

What I mean is that

final float term = 45.0f / ((float)Math.PI * (float)Math.pow(kH, 6) * rlen);
should probably be

final float term = 45.0f / ((float)Math.PI * (float)Math.pow(kH, 6));
Unless you can explain where "the extra factor of rlen" came from.

Observe the different symbols in his equations: the argument to the function is r (bold and upface) which is presumably a vector, whereas the equations contain r (normal weight and slanted) that is used in a scalar context. His code maps to his equation under the assumption that r=|r|.

alvaro
alvaro
Never mind. The code does seem correct. Using variations of the letter r to mean different things was too subtle for me. smile.png
Finalspace
Finalspace

Never mind. The code does seem correct. Using variations of the letter r to mean different things was too subtle for me. smile.png

That was something which had confused me too, the bold r and the normal r but now i now what they mean :)

HypnotiC
HypnotiC

I think the vector r in your gradient equation needs to be normalized

jmakitalo
jmakitalo

I think the vector r in your gradient equation needs to be normalized

It is normalized by the r in the denominator. In the given formula, the unit vector is given explicitly in the form r/r.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.