From 5f5d792c00b4ac7c77b9a732b4d4507a9f695036 Mon Sep 17 00:00:00 2001 From: Knut Morten Okstad Date: Sun, 17 Jan 2016 13:09:10 +0100 Subject: [PATCH] Fixed: Avoid memory corruption when multi-threaded CGL2 and -principal. Also handle patch index out-of-range in SIMgeneric::evalPoint. --- src/SIM/SIMbase.C | 4 +++- src/SIM/SIMgeneric.C | 17 +++++++++-------- src/SIM/SIMgeneric.h | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/SIM/SIMbase.C b/src/SIM/SIMbase.C index 140020eb..599687fc 100644 --- a/src/SIM/SIMbase.C +++ b/src/SIM/SIMbase.C @@ -2354,7 +2354,9 @@ bool SIMbase::project (Matrix& ssol, const Vector& psol, if (myModel[i]->empty()) continue; // skip empty patches // Extract the primary solution control point values for this patch - extractPatchSolution(myProblem,Vectors(1,psol),i); + myProblem->initResultPoints(time.t); + if (!this->extractPatchSolution(myProblem,Vectors(1,psol),i)) + return false; // Initialize material properties for this patch in case of multiple regions const_cast(this)->setPatchMaterial(i+1); diff --git a/src/SIM/SIMgeneric.C b/src/SIM/SIMgeneric.C index 90fb98b6..ad46015e 100644 --- a/src/SIM/SIMgeneric.C +++ b/src/SIM/SIMgeneric.C @@ -47,13 +47,14 @@ Vector SIMgeneric::getSolution (const Vector& psol, const double* par, return tmpVal.getColumn(1); } -int SIMgeneric::evalPoint(const double* xi, Vec3& X, double* param, int patch) const -{ - ASMbase *pch = getPatch(patch-1); - double dummy[2]; - if(param == nullptr) - return pch->evalPoint(xi, dummy, X); - else - return pch->evalPoint(xi, param, X); +int SIMgeneric::evalPoint (const double* xi, Vec3& X, double* param, + int patch) const +{ + patch = this->getLocalPatchIndex(patch); + if (patch < 1 || (size_t)patch > myModel.size()) + return -1; + + double dummy[3]; + return myModel[patch-1]->evalPoint(xi, param ? param : dummy, X); } diff --git a/src/SIM/SIMgeneric.h b/src/SIM/SIMgeneric.h index ad32b662..f3fbcec4 100644 --- a/src/SIM/SIMgeneric.h +++ b/src/SIM/SIMgeneric.h @@ -50,10 +50,10 @@ public: //! \param[in] xi Dimensionless parameters in range [0,1] of the point //! \param[out] X The Cartesian coordinates of the point //! \param[out] param The parameters of the point in the knot-span domain - //! \param[in] patch The patch to evaluate - //! \return 0 if the evaluation went good - int evalPoint(const double* xi, Vec3& X, - double* param=nullptr, int patch = 1) const; + //! \param[in] patch 1-based patch index contining the evaluation point + //! \return Local node number within the patch that matches the point + int evalPoint(const double* xi, Vec3& X, + double* param = nullptr, int patch = 1) const; }; #endif