Skip to content

Commit

Permalink
fix #2820
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Li committed Jul 26, 2021
1 parent 325a251 commit c6ea891
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
20 changes: 16 additions & 4 deletions lib/flow/Advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ int Advection::AdvectTillTime(Field *velocity, double startT, double deltaT, dou

bool happened = false;
size_t streamIdx = 0;
size_t maxSteps = 10000;
for (auto &s : _streams) // Process one stream at a time
{
Particle p0 = s.back(); // Start from the last particle in this stream
if (p0.time < startT) // Skip this stream if it didn't advance to startT
continue;

size_t thisStep = 0;

while (p0.time < targetT) {
// Check if the particle is inside of the volume.
// Wrap it along periodic dimensions if applicable.
Expand Down Expand Up @@ -239,20 +242,29 @@ int Advection::AdvectTillTime(Field *velocity, double startT, double deltaT, dou
case ADVECTION_METHOD::EULER: rv = _advectEuler(velocity, p0, dt, p1); break;
case ADVECTION_METHOD::RK4: rv = _advectRK4(velocity, p0, dt, p1); break;
}
if (rv != 0) // Advection wasn't successful for some reason...
{
if (rv != 0) { // Advection wasn't successful for some reason...
break;
} else // Advection successful, keep the new particle.
{
happened = true;
s.push_back(p1);
p0 = std::move(p1);
}
} // Finish the while loop to advect one particle to a time

// Another termination criterion: when advecting at least 10,000 steps and
// more than 10X more than the previous max num of steps.
//
if( ++thisStep == maxSteps ) {
thisStep = maxSteps / 10;
break;
}
} // Finish advecting one particle

maxSteps = std::max(maxSteps, thisStep * 10);

streamIdx++;

} // Finish the for loop to advect all particles to a time
} // Finish advecting all particles

if (happened)
return ADVECT_HAPPENED;
Expand Down
22 changes: 19 additions & 3 deletions lib/render/FlowRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,13 @@ int FlowRenderer::_paintGL(bool fast)
if (params->GetNeedFlowlineOutput()) {
rv = _outputFlowLines();
params->SetNeedFlowlineOutput(false);
_printNonZero(rv, __FILE__, __func__, __LINE__);
if (rv != 0) return rv;
}

if (_updateFlowCacheAndStates(params) != 0) {
rv = _updateFlowCacheAndStates(params);
if( rv != 0) {
_printNonZero(rv, __FILE__, __func__, __LINE__);
MyBase::SetErrMsg("Parameters not ready!");
return flow::PARAMS_ERROR;
}
Expand Down Expand Up @@ -200,6 +203,7 @@ int FlowRenderer::_paintGL(bool fast)
MyBase::SetErrMsg("The velocity field seems to contain only invalid values!");
return flow::PARAMS_ERROR;
} else if (rv != 0) {
_printNonZero(rv, __FILE__, __func__, __LINE__);
MyBase::SetErrMsg("Update deltaT failed!");
return rv;
}
Expand All @@ -216,6 +220,7 @@ int FlowRenderer::_paintGL(bool fast)
rv = _genSeedsFromList(seeds);

if (rv != 0) {
_printNonZero(rv, __FILE__, __func__, __LINE__);
MyBase::SetErrMsg("Generating seeds failed!");
return flow::NO_SEED_PARTICLE_YET;
}
Expand All @@ -226,6 +231,7 @@ int FlowRenderer::_paintGL(bool fast)
_advection.UseSeedParticles(seeds);
rv = _updateAdvectionPeriodicity(&_advection);
if (rv != 0) {
_printNonZero(rv, __FILE__, __func__, __LINE__);
MyBase::SetErrMsg("Update Advection Periodicity failed!");
return flow::GRID_ERROR;
}
Expand All @@ -234,6 +240,7 @@ int FlowRenderer::_paintGL(bool fast)
_2ndAdvection->UseSeedParticles(seeds);
rv = _updateAdvectionPeriodicity(_2ndAdvection.get());
if (rv != 0) {
_printNonZero(rv, __FILE__, __func__, __LINE__);
MyBase::SetErrMsg("Update Advection Periodicity failed!");
return flow::GRID_ERROR;
}
Expand Down Expand Up @@ -288,16 +295,21 @@ int FlowRenderer::_paintGL(bool fast)
// Advection scheme 2: advect to a certain timestamp.
// This scheme is used for unsteady flow
else {
for (int i = 1; i <= _cache_currentTS; i++) { rv = _advection.AdvectTillTime(&_velocityField, _timestamps.at(i - 1), deltaT, _timestamps.at(i)); }
for (int i = 1; i <= _cache_currentTS; i++) {
rv = _advection.AdvectTillTime(&_velocityField, _timestamps.at(i - 1), deltaT, _timestamps.at(i));
_printNonZero(rv, __FILE__, __func__, __LINE__);
}
}

_advectionComplete = true;
}

if (!_coloringComplete) {
rv = _advection.CalculateParticleValues(&_colorField, true);
_printNonZero(rv, __FILE__, __func__, __LINE__);
if (_2ndAdvection) // bi-directional advection
rv = _2ndAdvection->CalculateParticleValues(&_colorField, true);
_printNonZero(rv, __FILE__, __func__, __LINE__);
_coloringComplete = true;
}

Expand All @@ -311,7 +323,9 @@ int FlowRenderer::_paintGL(bool fast)
if (params->GetValueLong("old_render", 0)) {
_renderFromAnAdvectionLegacy(&_advection, params, fast);
/* If the advection is bi-directional */
if (_2ndAdvection) _renderFromAnAdvectionLegacy(_2ndAdvection.get(), params, fast);
if (_2ndAdvection) {
_renderFromAnAdvectionLegacy(_2ndAdvection.get(), params, fast);
}
} else {
// Workaround for how bi-directional was implemented.
// The rendering caches the flow data on the GPU however it
Expand All @@ -321,10 +335,12 @@ int FlowRenderer::_paintGL(bool fast)
if (_2ndAdvection) _renderStatus = FlowStatus::SIMPLE_OUTOFDATE;

rv |= _renderAdvection(&_advection);
_printNonZero(rv, __FILE__, __func__, __LINE__);
/* If the advection is bi-directional */
if (_2ndAdvection) {
_renderStatus = FlowStatus::SIMPLE_OUTOFDATE;
rv |= _renderAdvection(_2ndAdvection.get());
_printNonZero(rv, __FILE__, __func__, __LINE__);
}
}

Expand Down

0 comments on commit c6ea891

Please sign in to comment.