Skip to content

Commit

Permalink
Make number of solver iterations configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekpyron committed Apr 8, 2014
1 parent 2caa06c commit 3f87da3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/SPH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SPH::SPH (const GLuint &_numparticles, const glm::ivec3 &gridsize)
: numparticles (_numparticles), vorticityconfinement (false), radixsort (512, _numparticles >> 9, gridsize),
neighbourcellfinder (_numparticles, gridsize)
neighbourcellfinder (_numparticles, gridsize), num_solveriterations (5)
{
// shader definitions
std::stringstream stream;
Expand Down Expand Up @@ -290,7 +290,7 @@ void SPH::Run (void)

// solver iteration

for (int iteration = 0; iteration < 5; iteration++)
for (int iteration = 0; iteration < num_solveriterations; iteration++)
{
calclambdaprog.Use ();
glDispatchCompute (numparticles >> 8, 1, 1);
Expand Down
21 changes: 21 additions & 0 deletions src/SPH.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ class SPH
return velocitybuffer;
}

/** Get number of solver iterations.
* Returns the number of solver iterations currently used.
* \returns the number of solver iterations.
*/
const GLuint &GetNumSolverIterations (void) const {
return num_solveriterations;
}

/** Set number of solver iterations.
* Specifies the number of solver iterations.
* \param iter the number of solver iterations.
*/
void SetNumSolverIterations (const GLuint &iter) {
num_solveriterations = iter;
}

/** Get highlight buffer.
* Returns a buffer object containing the particle highlighting information.
* \returns the highlight buffer
Expand Down Expand Up @@ -328,6 +344,11 @@ class SPH
*/
Texture highlighttexture;

/** Number of solver iterations.
* Number of solver iterations used for the constraint solver.
*/
GLuint num_solveriterations;

union {
struct {
/** Position buffer.
Expand Down
11 changes: 11 additions & 0 deletions src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ void Simulation::OnKeyUp (int key)
case GUISTATE_TIMESTEP:
sph.SetTimestep (glm::max (sph.GetTimestep () + 0.001 * factor, 0.001));
break;
case GUISTATE_NUM_SOLVER_ITERATIONS:
{
int iters = sph.GetNumSolverIterations ();
iters += factor;
if (iters < 0) iters = 0;
sph.SetNumSolverIterations (iters);
break;
}
case GUISTATE_TENSILE_INSTABILITY_K:
sph.SetTensileInstabilityK (glm::max (sph.GetTensileInstabilityK () + factor * 0.1, 0.1));
break;
Expand Down Expand Up @@ -483,6 +491,9 @@ bool Simulation::Frame (void)
case GUISTATE_TIMESTEP:
stream << "Timestep: " << sph.GetTimestep ();
break;
case GUISTATE_NUM_SOLVER_ITERATIONS:
stream << "Solver iterations: " << sph.GetNumSolverIterations ();
break;
case GUISTATE_TENSILE_INSTABILITY_K:
stream << "Tensile instability k: " << sph.GetTensileInstabilityK ();
break;
Expand Down
1 change: 1 addition & 0 deletions src/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Simulation
GUISTATE_CFM_EPSILON,
GUISTATE_GRAVITY,
GUISTATE_TIMESTEP,
GUISTATE_NUM_SOLVER_ITERATIONS,
GUISTATE_TENSILE_INSTABILITY_K,
GUISTATE_TENSILE_INSTABILITY_SCALE,
GUISTATE_XSPH_VISCOSITY,
Expand Down

0 comments on commit 3f87da3

Please sign in to comment.