Commit 850d8dbe authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Fixed a problem with virtual function in ProblemInstat, rewritten BasisFct::interpol

parent 27106dcf
...@@ -181,7 +181,7 @@ namespace AMDiS { ...@@ -181,7 +181,7 @@ namespace AMDiS {
virtual DimVec<double> *getCoords(int i) const = 0; virtual DimVec<double> *getCoords(int i) const = 0;
/** \brief /** \brief
* Returns a pointer to a const vector with interpolation coefficients of the * Fills a vector with interpolation coefficients of the
* function f; if indices is a pointer to NULL, the coefficient for all * function f; if indices is a pointer to NULL, the coefficient for all
* basis functions are calculated and the i-th entry in the vector is the * basis functions are calculated and the i-th entry in the vector is the
* coefficient of the i-th basis function; if indices is non NULL, only the * coefficient of the i-th basis function; if indices is non NULL, only the
...@@ -197,16 +197,18 @@ namespace AMDiS { ...@@ -197,16 +197,18 @@ namespace AMDiS {
* during mesh traversal. * during mesh traversal.
* Must be implemented by sub classes. * Must be implemented by sub classes.
*/ */
virtual const double* interpol(const ElInfo *el_info, virtual void interpol(const ElInfo *el_info,
int n, const int *indices, int n,
AbstractFunction<double, WorldVector<double> > *f, const int *indices,
double *coeff) = 0; AbstractFunction<double, WorldVector<double> > *f,
mtl::dense_vector<double> &coeff) const = 0;
/// WorldVector<double> valued interpol function. /// WorldVector<double> valued interpol function.
virtual const WorldVector<double>* interpol(const ElInfo *el_info, int no, virtual void interpol(const ElInfo *el_info,
const int *b_no, int no,
AbstractFunction<WorldVector<double>, WorldVector<double> > *f, const int *b_no,
WorldVector<double> *vec) = 0; AbstractFunction<WorldVector<double>, WorldVector<double> > *f,
mtl::dense_vector<WorldVector<double> >& coeff) const = 0;
/// Returns the i-th local basis function /// Returns the i-th local basis function
inline BasFctType *getPhi(int i) const inline BasFctType *getPhi(int i) const
......
...@@ -572,9 +572,6 @@ namespace AMDiS { ...@@ -572,9 +572,6 @@ namespace AMDiS {
/// Returns the average value of the DOFVector. /// Returns the average value of the DOFVector.
T average() const; T average() const;
/// Used by interpol while mesh traversal.
void interpolFct(ElInfo* elinfo);
/// Prints \ref vec to stdout. /// Prints \ref vec to stdout.
void print() const; void print() const;
...@@ -641,12 +638,6 @@ namespace AMDiS { ...@@ -641,12 +638,6 @@ namespace AMDiS {
/// Specifies what operation should be performed after coarsening /// Specifies what operation should be performed after coarsening
CoarsenOperation coarsenOperation; CoarsenOperation coarsenOperation;
/// Used by \ref interpol
AbstractFunction<T, WorldVector<double> > *interFct;
/// Used for mesh traversal
static DOFVector<T> *traverseVector;
}; };
...@@ -795,7 +786,7 @@ namespace AMDiS { ...@@ -795,7 +786,7 @@ namespace AMDiS {
// y = a*x + y // y = a*x + y
template<typename T> template<typename T>
void axpy(double a,const DOFVector<T>& x, DOFVector<T>& y); void axpy(double a, const DOFVector<T>& x, DOFVector<T>& y);
// matrix vector product // matrix vector product
template<typename T> template<typename T>
...@@ -856,6 +847,12 @@ namespace AMDiS { ...@@ -856,6 +847,12 @@ namespace AMDiS {
return vec->getUsedSize(); return vec->getUsedSize();
} }
template<typename T>
inline int size(const DOFVector<T>& vec)
{
return vec.getUsedSize();
}
template<typename T> template<typename T>
inline void checkFeSpace(const FiniteElemSpace* feSpace, const std::vector<T>& vec) inline void checkFeSpace(const FiniteElemSpace* feSpace, const std::vector<T>& vec)
{ {
......
...@@ -132,9 +132,6 @@ namespace AMDiS { ...@@ -132,9 +132,6 @@ namespace AMDiS {
vec.clear(); vec.clear();
} }
template<typename T>
DOFVector<T> * DOFVector<T>::traverseVector = NULL;
template<typename T> template<typename T>
void DOFVectorBase<T>::addElementVector(T factor, void DOFVectorBase<T>::addElementVector(T factor,
const ElementVector &elVec, const ElementVector &elVec,
...@@ -450,8 +447,6 @@ namespace AMDiS { ...@@ -450,8 +447,6 @@ namespace AMDiS {
TEST_EXIT_DBG(fct)("No function to interpolate!\n"); TEST_EXIT_DBG(fct)("No function to interpolate!\n");
interFct = fct;
if (!this->getFeSpace()) { if (!this->getFeSpace()) {
MSG("no dof admin in vec %s, skipping interpolation\n", MSG("no dof admin in vec %s, skipping interpolation\n",
this->getName().c_str()); this->getName().c_str());
...@@ -476,36 +471,27 @@ namespace AMDiS { ...@@ -476,36 +471,27 @@ namespace AMDiS {
return; return;
} }
traverseVector = this; const BasisFunction *basFct = this->getFeSpace()->getBasisFcts();
const DOFAdmin* admin = this->getFeSpace()->getAdmin();
int nBasFcts = basFct->getNumber();
std::vector<DegreeOfFreedom> myLocalIndices(nBasFcts);
mtl::dense_vector<double> fctInterpolValues(nBasFcts);
TraverseStack stack; TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(this->getFeSpace()->getMesh(), -1, ElInfo *elInfo = stack.traverseFirst(this->getFeSpace()->getMesh(), -1,
Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS); Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
while (elInfo) { while (elInfo) {
interpolFct(elInfo); basFct->interpol(elInfo, 0, NULL, fct, fctInterpolValues);
basFct->getLocalIndices(const_cast<Element*>(elInfo->getElement()),
admin, myLocalIndices);
for (int i = 0; i < nBasFcts; i++)
vec[myLocalIndices[i]] = fctInterpolValues[i];
elInfo = stack.traverseNext(elInfo); elInfo = stack.traverseNext(elInfo);
} }
} }
template<typename T>
void DOFVector<T>::interpolFct(ElInfo* elinfo)
{
const BasisFunction *basFct = traverseVector->getFeSpace()->getBasisFcts();
const DOFAdmin* admin = traverseVector->getFeSpace()->getAdmin();
const T *inter_val =
const_cast<BasisFunction*>(basFct)->interpol(elinfo, 0, NULL,
traverseVector->interFct, NULL);
int nBasFcts = basFct->getNumber();
std::vector<DegreeOfFreedom> myLocalIndices(nBasFcts);
basFct->getLocalIndices(const_cast<Element*>(elinfo->getElement()),
admin, myLocalIndices);
for (int i = 0; i < nBasFcts; i++)
(*traverseVector)[myLocalIndices[i]] = inter_val[i];
}
template<typename T> template<typename T>
double DOFVector<T>::Int(Quadrature* q) const double DOFVector<T>::Int(Quadrature* q) const
{ {
...@@ -1047,7 +1033,6 @@ namespace AMDiS { ...@@ -1047,7 +1033,6 @@ namespace AMDiS {
this->nBasFcts = rhs.nBasFcts; this->nBasFcts = rhs.nBasFcts;
vec = rhs.vec; vec = rhs.vec;
this->elementVector.change_dim(this->nBasFcts); this->elementVector.change_dim(this->nBasFcts);
interFct = rhs.interFct;
coarsenOperation = rhs.coarsenOperation; coarsenOperation = rhs.coarsenOperation;
this->operators = rhs.operators; this->operators = rhs.operators;
this->operatorFactor = rhs.operatorFactor; this->operatorFactor = rhs.operatorFactor;
......
...@@ -811,43 +811,21 @@ namespace AMDiS { ...@@ -811,43 +811,21 @@ namespace AMDiS {
} }
const double* Lagrange::interpol(const ElInfo *el_info, void Lagrange::interpol(const ElInfo *el_info,
int no, const int *b_no, int no,
AbstractFunction<double, WorldVector<double> > *f, const int *b_no,
double *vec) AbstractFunction<double, WorldVector<double> > *f,
mtl::dense_vector<double> &rvec) const
{ {
FUNCNAME("Lagrange::interpol()"); FUNCNAME("Lagrange::interpol()");
static double* localVec = NULL;
static int localVecSize = 0;
double *rvec = NULL;
if (vec) {
rvec = vec;
} else {
if (localVec && nBasFcts > localVecSize) {
delete [] localVec;
localVec = new double[nBasFcts];
}
if (!localVec)
localVec = new double[nBasFcts];
localVecSize = nBasFcts;
rvec = localVec;
}
WorldVector<double> x; WorldVector<double> x;
el_info->testFlag(Mesh::FILL_COORDS); el_info->testFlag(Mesh::FILL_COORDS);
if (b_no) { if (b_no) {
if (no <= 0 || no > getNumber()) { TEST_EXIT_DBG(no >= 0 && no < getNumber())("Something is wrong!\n");
ERROR("something is wrong, doing nothing\n");
rvec[0] = 0.0;
return(const_cast<const double *>(rvec));
}
for (int i = 0; i < no; i++) { for (int i = 0; i < no; i++) {
if (b_no[i] < Global::getGeo(VERTEX, dim)) { if (b_no[i] < Global::getGeo(VERTEX, dim)) {
rvec[i] = (*f)(el_info->getCoord(b_no[i])); rvec[i] = (*f)(el_info->getCoord(b_no[i]));
...@@ -865,23 +843,17 @@ namespace AMDiS { ...@@ -865,23 +843,17 @@ namespace AMDiS {
rvec[i] = (*f)(x); rvec[i] = (*f)(x);
} }
} }
return(const_cast<const double *>( rvec));
} }
const WorldVector<double>* void Lagrange::interpol(const ElInfo *el_info,
Lagrange::interpol(const ElInfo *el_info, int no,
int no, const int *b_no,
const int *b_no, AbstractFunction<WorldVector<double>, WorldVector<double> > *f,
AbstractFunction<WorldVector<double>, WorldVector<double> > *f, mtl::dense_vector<WorldVector<double> > &rvec) const
WorldVector<double> *vec)
{ {
FUNCNAME("*Lagrange::interpol_d()"); FUNCNAME("*Lagrange::interpol()");
static WorldVector<double> *inter;
WorldVector<double> *rvec =
vec ? vec : (inter ? inter : inter = new WorldVector<double>[getNumber()]);
WorldVector<double> x; WorldVector<double> x;
el_info->testFlag(Mesh::FILL_COORDS); el_info->testFlag(Mesh::FILL_COORDS);
...@@ -889,12 +861,8 @@ namespace AMDiS { ...@@ -889,12 +861,8 @@ namespace AMDiS {
int vertices = Global::getGeo(VERTEX, dim); int vertices = Global::getGeo(VERTEX, dim);
if (b_no) { if (b_no) {
if (no <= 0 || no > getNumber()) { TEST_EXIT_DBG(no >= 0 && no < getNumber())("Something is wrong!\n");
ERROR("something is wrong, doing nothing\n");
for (int i = 0; i < dow; i++)
rvec[0][i] = 0.0;
return(const_cast<const WorldVector<double> *>( rvec));
}
for (int i = 0; i < no; i++) { for (int i = 0; i < no; i++) {
if (b_no[i] < Global::getGeo(VERTEX, dim)) { if (b_no[i] < Global::getGeo(VERTEX, dim)) {
rvec[i] = (*f)(el_info->getCoord(b_no[i])); rvec[i] = (*f)(el_info->getCoord(b_no[i]));
...@@ -911,8 +879,6 @@ namespace AMDiS { ...@@ -911,8 +879,6 @@ namespace AMDiS {
rvec[i] = (*f)(x); rvec[i] = (*f)(x);
} }
} }
return(const_cast<const WorldVector<double> *>( rvec));
} }
......
...@@ -64,16 +64,15 @@ namespace AMDiS { ...@@ -64,16 +64,15 @@ namespace AMDiS {
static Lagrange* getLagrange(int dim, int degree); static Lagrange* getLagrange(int dim, int degree);
/// Implements BasisFunction::interpol /// Implements BasisFunction::interpol
const double *interpol(const ElInfo *, int, const int *, void interpol(const ElInfo *, int, const int *,
AbstractFunction<double, WorldVector<double> >*, AbstractFunction<double, WorldVector<double> >*,
double *); mtl::dense_vector<double>&) const;
/// Implements BasisFunction::interpol /// Implements BasisFunction::interpol
const WorldVector<double> *interpol(const ElInfo *, int, void interpol(const ElInfo *, int,
const int *b_no, const int *b_no,
AbstractFunction<WorldVector<double>, AbstractFunction<WorldVector<double>, WorldVector<double> >*,
WorldVector<double> >*, mtl::dense_vector<WorldVector<double> >&) const;
WorldVector<double> *);
/// Returns the barycentric coordinates of the i-th basis function. /// Returns the barycentric coordinates of the i-th basis function.
DimVec<double> *getCoords(int i) const; DimVec<double> *getCoords(int i) const;
......
...@@ -164,13 +164,13 @@ namespace AMDiS { ...@@ -164,13 +164,13 @@ namespace AMDiS {
Flag adoptFlag = INIT_NOTHING); Flag adoptFlag = INIT_NOTHING);
/// Used in \ref initialize(). /// Used in \ref initialize().
void createUhOld(); virtual void createUhOld();
/// Implementation of ProblemTimeInterface::initTimestep(). /// Implementation of ProblemTimeInterface::initTimestep().
void initTimestep(AdaptInfo *adaptInfo); virtual void initTimestep(AdaptInfo *adaptInfo);
/// Implementation of ProblemTimeInterface::closeTimestep(). /// Implementation of ProblemTimeInterface::closeTimestep().
void closeTimestep(AdaptInfo *adaptInfo); virtual void closeTimestep(AdaptInfo *adaptInfo);
/// Returns \ref problemStat. /// Returns \ref problemStat.
inline ProblemStatSeq* getStatProblem() inline ProblemStatSeq* getStatProblem()
...@@ -190,11 +190,11 @@ namespace AMDiS { ...@@ -190,11 +190,11 @@ namespace AMDiS {
} }
/// Used by \ref problemInitial /// Used by \ref problemInitial
void transferInitialSolution(AdaptInfo *adaptInfo); virtual void transferInitialSolution(AdaptInfo *adaptInfo);
void serialize(std::ostream &out) {} virtual void serialize(std::ostream &out) {}
void deserialize(std::istream &in) {} virtual void deserialize(std::istream &in) {}
protected: protected:
/// Space problem solved in each timestep. /// Space problem solved in each timestep.
......
...@@ -1065,7 +1065,7 @@ namespace AMDiS { ...@@ -1065,7 +1065,7 @@ namespace AMDiS {
void ProblemStatSeq::dualAssemble(AdaptInfo *adaptInfo, Flag flag, void ProblemStatSeq::dualAssemble(AdaptInfo *adaptInfo, Flag flag,
bool asmMatrix, bool asmVector) bool asmMatrix, bool asmVector)
{ {
FUNCNAME("ProblemStat::dualAssemble()"); FUNCNAME("ProblemStat::dualAssemble()");
...@@ -1631,7 +1631,8 @@ namespace AMDiS { ...@@ -1631,7 +1631,8 @@ namespace AMDiS {
void ProblemStatSeq::assembleOnOneMesh(FiniteElemSpace *feSpace, void ProblemStatSeq::assembleOnOneMesh(FiniteElemSpace *feSpace,
Flag assembleFlag, Flag assembleFlag,
DOFMatrix *matrix, DOFVector<double> *vector) DOFMatrix *matrix,
DOFVector<double> *vector)
{ {
FUNCNAME("ProblemStat::assembleOnOnMesh()"); FUNCNAME("ProblemStat::assembleOnOnMesh()");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment