Graphics Reference
In-Depth Information
step and a maximum step size constant. This allows the simulation to be applied over rea-
sonable time steps, even if the reference device is being used to perform the calculations.
Finally, a damping factor is used to gradually reduce the amount of flowing inertia in the
system. This will eventually allow the system to return to an equilibrium state after an ap-
propriate period of time.
The recalculated flow values are then written back to the group shared memory, so
they may be used by all of the threads in the simulation to update their current height
values. An important consideration here is that the perimeter threads still calculate their
updated flow values, but only write them into the group shared memory. These flow values
will eventually be discarded, but they will be needed in the next phase of the implemen-
tation to produce the correct height values for the fluid columns that they are in contact
with. After the group shared memory is written to, we perform another memory barrier to
synchronize the thread group's execution.
const float TIME_STEP
= 0.05f;
const float
PIPE_AREA
= 0.0001f;
const float GRAVITATION
= 10.0f;
const float
PIPE_LENGTH
= 0.2f;
const
float FLUID_DENSITY
= 1.0f;
const float
COLUMN_AREA
= 0.05f;
const
float
DAMPING_FACTOR
= 0.9995f;
float fAccelFactor
=
(
min(
TimeFactors.x, TIME_STEP
)
*
PIPE_AREA
*
GRAVITATION
)
/ (
PIPE_LENGTH
*
COLUMN_AREA
);
//
Calculate the
new
flow,
and
add
in
the
previous
flow
value
as
well. The
// damping factor degrades the
amount of inertia in
the
system.
NewFlow
=
(
NewFlow
*
fAccelFactor
+
loadedpoints[GroupIndex].Flow
)
*
DAMPING_FACTOR;
//
Store the updated flow value in
the group
shared
memory for
other
threads
//
to access
loadedpoints[GroupIndex].Flow
=
NewFlow;
//
Synchronize
all threads
before moving
on
GroupMemoryBarrierWithGroupSync()
;
Listing
1
2.5.
Calculating the new flow values based on the delta heights in the current simulation step, as
well as the previous step's flow values.
This is an appropriate time to consider the memory accesses that were required to
perform the new flow calculations. All of the height values and the existing flow values are
read from the GSM, meaning that this phase of the calculation does not touch the device
memory at all. In addition, since we synchronized all of the threads in the thread group after
filling the GSM, we effectively eliminated the need for further low-level synchronization
Search WWH ::
Custom Search