Skip to content

Commit 9c5a463

Browse files
committed
fix cache update bug 3
1 parent 7a5be26 commit 9c5a463

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

core/base/discreteGradient/DiscreteGradient.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,24 @@ triangulation.
306306
Seed = newSeed;
307307
}
308308

309-
inline bool newSeed() {
310-
return OldSeed != Seed;
309+
inline void
310+
setReturnSaddleConnectors(const bool &returnSaddleConnectors) {
311+
OldReturnSaddleConnectors = ReturnSaddleConnectors;
312+
ReturnSaddleConnectors = returnSaddleConnectors;
311313
}
312314

313-
inline bool newBackend() {
314-
return OldBackEnd != BackEnd;
315+
inline bool newParameters() {
316+
return OldSeed != Seed || OldBackEnd != BackEnd
317+
|| OldReturnSaddleConnectors != ReturnSaddleConnectors;
315318
}
316319

317320
inline void setSaddleConnectorsPersistenceThreshold(double threshold) {
318321
SaddleConnectorsPersistenceThreshold = threshold;
319322
}
320323

321324
/**
322-
* Preprocess all the required connectivity requests on the triangulation.
325+
* Preprocess all the required connectivity requests on the
326+
* triangulation.
323327
*/
324328
inline void preconditionTriangulation(AbstractTriangulation *const data) {
325329
if(data != nullptr) {
@@ -407,8 +411,8 @@ discrete gradient, false otherwise.
407411
bool isCellCritical(const Cell &cell) const;
408412

409413
/**
410-
* Return the identifier of the cell paired to the cell given by the user
411-
in the gradient.
414+
* Return the identifier of the cell paired to the cell given by the
415+
user in the gradient.
412416
*/
413417
template <typename triangulationType>
414418
SimplexId getPairedCell(const Cell &cell,
@@ -461,8 +465,8 @@ in the gradient.
461465
bool *const cycleFound = nullptr) const;
462466

463467
/**
464-
* Detect the presence of a cycle on a edge-triangle path starting from an
465-
* edge.
468+
* Detect the presence of a cycle on a edge-triangle path starting from
469+
* an edge.
466470
*/
467471
template <typename triangulationType>
468472
bool detectGradientCycle(const Cell &cell,
@@ -686,8 +690,8 @@ in the gradient.
686690
std::vector<float> &stencilLength);
687691

688692
/**
689-
* @brief Compute the opposite of numerical gradient at point x with given
690-
* stencil
693+
* @brief Compute the opposite of numerical gradient at point x with
694+
* given stencil
691695
*/
692696
void computeDerivatives(
693697
const SimplexId &x,
@@ -939,7 +943,9 @@ gradient, false otherwise.
939943
BACKEND OldBackEnd{BACKEND::CLASSIC_BACKEND};
940944
unsigned int Seed{};
941945
unsigned int OldSeed{};
942-
946+
bool ReturnSaddleConnectors{};
947+
bool OldReturnSaddleConnectors{};
948+
bool FirstRun{true};
943949
// spare storage (bypass cache) for gradient internal structure
944950
AbstractTriangulation::gradientType localGradient_{};
945951
// cache key (scalar field pointer + timestamp)

core/base/discreteGradient/DiscreteGradient_Template.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ int DiscreteGradient::buildGradient(const triangulationType &triangulation,
7373
this->dimensionality_ = triangulation.getCellVertexNumber(0) - 1;
7474
this->numberOfVertices_ = triangulation.getNumberOfVertices();
7575

76-
bool newParameters = (this->newBackend()) || (this->newSeed());
77-
bool fetchCache = !bypassCache || newParameters;
78-
this->gradient_ = fetchCache ? findGradient() : &this->localGradient_;
79-
80-
if(this->gradient_ == nullptr || bypassCache || newParameters) {
81-
82-
if(!bypassCache && this->gradient_ == nullptr) {
76+
this->gradient_ = !bypassCache ? findGradient() : &this->localGradient_;
77+
this->setReturnSaddleConnectors(bypassCache);
78+
if(this->gradient_ == nullptr || bypassCache || this->newParameters()
79+
|| FirstRun) {
80+
FirstRun = false;
81+
if(this->gradient_ == nullptr && !bypassCache) {
8382
// add new cache entry
8483
cacheHandler.insert(this->inputScalarField_, {});
8584
this->gradient_ = cacheHandler.get(this->inputScalarField_);
@@ -96,7 +95,7 @@ int DiscreteGradient::buildGradient(const triangulationType &triangulation,
9695
} else if(this->BackEnd == BACKEND::STOCHASTIC_BACKEND) {
9796
this->processLowerStarsStochastic<dataType, triangulationType>(
9897
this->inputOffsets_, triangulation);
99-
this->printMsg("Built discrete gradient (Stochastic elgorithm)", 1.0,
98+
this->printMsg("Built discrete gradient (Stochastic algorithm)", 1.0,
10099
tm.getElapsedTime(), this->threadNumber_);
101100

102101
} else if(this->BackEnd == BACKEND::CLASSIC_BACKEND) {

0 commit comments

Comments
 (0)