Commit cd220992 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

ElementMatrix and ElementVector are now MTL4 data structures.

parent 386a66c2
#include <boost/numeric/mtl/mtl.hpp>
#include "CompositeFEMOperator.h"
#include "ElementMatrix.h"
#include "ElementVector.h"
#include "OpenMP.h"
#include "SubElementAssembler.h"
#include "SubElInfo.h"
#include "SubPolytope.h"
void
CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor)
{
FUNCNAME("CompositeFEMOperator::getElementMatrix");
......@@ -18,9 +15,6 @@ CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo,
VectorOfFixVecs<DimVec<double> > *intersecPoints = NULL;
SubPolytope *subPolytope = NULL;
double levelSetSubPolytope;
ElementMatrix *elMat;
ElementMatrix *subPolMat1;
ElementMatrix *subPolMat2;
DimVec<double> subElVertexBarCoords(elInfo->getMesh()->getDim());
/**
......@@ -99,9 +93,9 @@ CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo,
ERROR_EXIT("cannot get position of subpolytope\n");
}
subPolMat1 = NEW ElementMatrix(subElementAssembler->getNRow(),
ElementMatrix subPolMat1(subElementAssembler->getNRow(),
subElementAssembler->getNCol());
subPolMat1->set(0.0);
set_to_zero(subPolMat1);
subElementAssembler->getSubPolytopeMatrix(subPolytope,
subElementAssembler,
elInfo,
......@@ -110,12 +104,12 @@ CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo,
/**
* Integration on second subpolytope produced by the intersection.
*/
elMat = NEW ElementMatrix(subElementAssembler->getNRow(),
ElementMatrix elMat(subElementAssembler->getNRow(),
subElementAssembler->getNCol());
elMat->set(0.0);
subPolMat2 = NEW ElementMatrix(subElementAssembler->getNRow(),
set_to_zero(elMat);
ElementMatrix subPolMat2(subElementAssembler->getNRow(),
subElementAssembler->getNCol());
subPolMat2->set(0.0);
set_to_zero(subPolMat2);
int myRank = omp_get_thread_num();
......@@ -138,28 +132,21 @@ CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo,
elInfo,
subPolMat2);
axpy(-1.0, *subPolMat2, *elMat);
elMat -= subPolMat2;
// Get integral on element as sum of the two integrals on subpolytopes.
axpy(1.0, *subPolMat1, *elMat);
elMat += subPolMat1;
// Add integral to userMat.
axpy(factor, *elMat, *userMat);
/**
* Free data.
*/
DELETE subPolytope;
DELETE elMat;
DELETE subPolMat1;
DELETE subPolMat2;
userMat += factor * elMat;
return;
// Free data
delete subPolytope;
}
void
CompositeFEMOperator::getElementVector(const ElInfo *elInfo,
ElementVector *userVec,
ElementVector& userVec,
double factor)
{
FUNCNAME("CompositeFEMOperator::getElementVector");
......@@ -167,9 +154,6 @@ CompositeFEMOperator::getElementVector(const ElInfo *elInfo,
VectorOfFixVecs<DimVec<double> >*intersecPoints = NULL;
SubPolytope *subPolytope = NULL;
double levelSetSubPolytope;
ElementVector *elVec;
ElementVector *subPolVec1;
ElementVector *subPolVec2;
DimVec<double> subElVertexBarCoords(elInfo->getMesh()->getDim());
/**
......@@ -247,8 +231,8 @@ CompositeFEMOperator::getElementVector(const ElInfo *elInfo,
ERROR_EXIT("cannot get position of subpolytope\n");
}
subPolVec1 = NEW ElementVector(subElementAssembler->getNRow());
subPolVec1->set(0.0);
ElementVector subPolVec1(subElementAssembler->getNRow());
set_to_zero(subPolVec1);
subElementAssembler->getSubPolytopeVector(subPolytope,
subElementAssembler,
elInfo,
......@@ -257,10 +241,10 @@ CompositeFEMOperator::getElementVector(const ElInfo *elInfo,
/**
* Integration on second subpolytope produced by the intersection.
*/
elVec = NEW ElementVector(subElementAssembler->getNRow());
elVec->set(0.0);
subPolVec2 = NEW ElementVector(subElementAssembler->getNRow());
subPolVec2->set(0.0);
ElementVector elVec(subElementAssembler->getNRow());
set_to_zero(elVec);
ElementVector subPolVec2(subElementAssembler->getNRow());
set_to_zero(subPolVec2);
int myRank = omp_get_thread_num();
......@@ -282,21 +266,14 @@ CompositeFEMOperator::getElementVector(const ElInfo *elInfo,
elInfo,
subPolVec2);
axpy(-1.0, *subPolVec2, *elVec);
elVec -= subPolVec2;
// Get integral on element as sum of the two integrals on subpolytopes.
axpy(1.0, *subPolVec1, *elVec);
elVec += subPolVec1;
// Add integral to userVec.
axpy(factor, *elVec, *userVec);
userVec += factor * elVec;
/**
* Free data.
*/
DELETE subPolytope;
DELETE elVec;
DELETE subPolVec1;
DELETE subPolVec2;
return;
// Free data
delete subPolytope;
}
......@@ -6,7 +6,6 @@
#include "FixVec.h"
#include "Flag.h"
#include "ElementLevelSet.h"
#include "MemoryManager.h"
#include "Operator.h"
#include "ElementLevelSet.h"
......@@ -35,10 +34,7 @@ using namespace std;
class CompositeFEMOperator : public Operator
{
public:
MEMORY_MANAGED(CompositeFEMOperator);
/**
* Constructor.
*/
/// Constructor.
CompositeFEMOperator(Flag operatorType_,
ElementLevelSet *elLS_,
const FiniteElemSpace *rowFESpace_,
......@@ -67,7 +63,7 @@ public:
* integration domain.
*/
void getElementMatrix(const ElInfo *elInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor = 1.0);
/**
......@@ -78,7 +74,7 @@ public:
* integration domain.
*/
void getElementVector(const ElInfo *elInfo,
ElementVector *userVec,
ElementVector& userVec,
double factor = 1.0);
protected:
......
#include "PenaltyOperator.h"
#include "SurfaceOperator.h"
double
......@@ -17,7 +16,7 @@ PenaltyOperator::getPenaltyCoeff(const ElInfo *elInfo)
void
PenaltyOperator::getElementMatrix(const ElInfo *elInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor)
{
FUNCNAME("PenaltyOperator::getElementMatrix");
......@@ -135,7 +134,7 @@ PenaltyOperator::getElementMatrix(const ElInfo *elInfo,
void
PenaltyOperator::getElementVector(const ElInfo *elInfo,
ElementVector *userVec,
ElementVector& userVec,
double factor)
{
FUNCNAME("PenaltyOperator::getElementVector");
......@@ -189,12 +188,12 @@ PenaltyOperator::getElementVector(const ElInfo *elInfo,
else {
surfaceOp->adaptSurfaceOperator((*tempCoords));
}
surfaceOp->getElementVector(elInfo, userVec, factor*penaltyCoeff);
surfaceOp->getElementVector(elInfo, userVec, factor * penaltyCoeff);
// Treat second simplex.
(*tempCoords)[0] = (*intersecPoints)[3];
surfaceOp->adaptSurfaceOperator((*tempCoords));
surfaceOp->getElementVector(elInfo, userVec, factor*penaltyCoeff);
surfaceOp->getElementVector(elInfo, userVec, factor * penaltyCoeff);
}
else {
......
......@@ -5,10 +5,8 @@
#include "ElementLevelSet.h"
#include "Flag.h"
#include "MemoryManager.h"
#include "Operator.h"
#include "SurfaceOperator.h"
#include "ElementLevelSet.h"
namespace AMDiS {
......@@ -29,7 +27,6 @@ using namespace std;
class PenaltyOperator : public Operator
{
public:
MEMORY_MANAGED(PenaltyOperator);
/**
* Constructor.
*/
......@@ -76,7 +73,7 @@ public:
* domain.
*/
void getElementMatrix(const ElInfo *elInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor = 1.0);
/**
......@@ -87,7 +84,7 @@ public:
* the integration domain.
*/
void getElementVector(const ElInfo *elInfo,
ElementVector *userVec,
ElementVector& userVec,
double factor = 1.0);
protected:
......
#include <vector>
#include "ElementMatrix.h"
#include "ElementVector.h"
#include <boost/numeric/mtl/mtl.hpp>
#include "SubElementAssembler.h"
#include "ScalableQuadrature.h"
#include "SubPolytope.h"
......@@ -72,7 +71,7 @@ namespace AMDiS {
void SubElementAssembler::getSubElementVector(SubElInfo *subElInfo,
const ElInfo *elInfo,
ElementVector *userVec)
ElementVector& userVec)
{
/**
* Manipulate the quadratures of the SubAssemblers for subelement.
......@@ -87,14 +86,13 @@ namespace AMDiS {
* the result must be corrected with respect to subelement.
*/
double corrFactor = subElInfo->getDet() / fabs(elInfo->getDet());
for (int i = 0; i < nRow; i++) {
(*userVec)[i] *= corrFactor;
}
for (int i = 0; i < nRow; i++)
userVec[i] *= corrFactor;
}
void SubElementAssembler::getSubElementMatrix(SubElInfo *subElInfo,
const ElInfo *elInfo,
ElementMatrix *userMat)
ElementMatrix& userMat)
{
/**
* Manipulate the quadratures of the SubAssemblers for subelement.
......@@ -114,7 +112,7 @@ namespace AMDiS {
double corrFactor = subElInfo->getDet() / fabs(elInfo->getDet());
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
(*userMat)[i][j] *= corrFactor;
userMat[i][j] *= corrFactor;
}
}
}
......@@ -122,44 +120,34 @@ namespace AMDiS {
void SubElementAssembler::getSubPolytopeVector(SubPolytope *subPolytope,
SubElementAssembler *subElementAssembler,
const ElInfo *elInfo,
ElementVector *subPolVec)
ElementVector& subPolVec)
{
/**
* Note: There is no reset of subPolVec.
*/
/// Note: There is no reset of subPolVec.
std::vector<SubElInfo *>::iterator it;
ElementVector *subElVec = NEW ElementVector(nRow);
ElementVector subElVec(nRow);
/**
* Assemble for each subelement of subpolytope.
*/
/// Assemble for each subelement of subpolytope.
for (it = subPolytope->getSubElementsBegin();
it != subPolytope->getSubElementsEnd();
it++) {
subElVec->set(0.0);
set_to_zero(subElVec);
subElementAssembler->getSubElementVector(*it, elInfo, subElVec);
/**
* Add results for subelement to total result for subpolytope.
*/
for (int i = 0; i < nRow; i++) {
(*subPolVec)[i] += (*subElVec)[i];
/// Add results for subelement to total result for subpolytope.
subPolVec += subElVec;
}
}
DELETE subElVec;
}
void SubElementAssembler::getSubPolytopeMatrix(SubPolytope *subPolytope,
SubElementAssembler *subElementAssembler,
const ElInfo *elInfo,
ElementMatrix *subPolMat)
ElementMatrix& subPolMat)
{
/**
* Note: There is no reset of subPolMat.
*/
std::vector<SubElInfo *>::iterator it;
ElementMatrix *subElMat = NEW ElementMatrix(nRow, nCol);
ElementMatrix subElMat(nRow, nCol);
/**
* Assemble for each subelement of subpolytope.
......@@ -167,20 +155,16 @@ namespace AMDiS {
for (it = subPolytope->getSubElementsBegin();
it != subPolytope->getSubElementsEnd();
it++) {
subElMat->set(0.0);
set_to_zero(subElMat);
subElementAssembler->getSubElementMatrix(*it, elInfo, subElMat);
/**
* Add results for subelement to total result for subpolytope.
*/
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
(*subPolMat)[i][j] += (*subElMat)[i][j];
}
for (int i = 0; i < nRow; i++)
for (int j = 0; j < nCol; j++)
subPolMat[i][j] += subElMat[i][j];
}
}
DELETE subElMat;
}
}
......@@ -3,7 +3,6 @@
#ifndef AMDIS_SUBELEMENTASSEMBLER_H
#define AMDIS_SUBELEMENTASSEMBLER_H
#include "MemoryManager.h"
#include "Assembler.h"
#include "SubElInfo.h"
#include "ScalableQuadrature.h"
......@@ -54,8 +53,6 @@ namespace AMDiS {
class SubElementAssembler : public StandardAssembler
{
public:
MEMORY_MANAGED(SubElementAssembler);
SubElementAssembler(Operator *op,
const FiniteElemSpace *rowFESpace,
const FiniteElemSpace *colFESpace = NULL);
......@@ -63,34 +60,34 @@ namespace AMDiS {
virtual ~SubElementAssembler()
{
if (zeroOrderScalableQuadrature)
DELETE zeroOrderScalableQuadrature;
delete zeroOrderScalableQuadrature;
if (firstOrderGrdPsiScalableQuadrature)
DELETE firstOrderGrdPsiScalableQuadrature;
delete firstOrderGrdPsiScalableQuadrature;
if (firstOrderGrdPhiScalableQuadrature)
DELETE firstOrderGrdPhiScalableQuadrature;
delete firstOrderGrdPhiScalableQuadrature;
if (secondOrderScalableQuadrature)
DELETE secondOrderScalableQuadrature;
};
delete secondOrderScalableQuadrature;
}
void scaleQuadratures(const SubElInfo& subElInfo);
void getSubElementVector(SubElInfo *subElInfo,
const ElInfo *elInfo,
ElementVector *userVec);
ElementVector& userVec);
void getSubElementMatrix(SubElInfo *subElInfo,
const ElInfo *elInfo,
ElementMatrix *userMat);
ElementMatrix& userMat);
void getSubPolytopeVector(SubPolytope *subPolytope,
SubElementAssembler *subElementAssembler,
const ElInfo *elInfo,
ElementVector *userVec);
ElementVector& userVec);
void getSubPolytopeMatrix(SubPolytope *subPolytope,
SubElementAssembler *subElementAssembler,
const ElInfo *elInfo,
ElementMatrix *userMat);
ElementMatrix& userMat);
protected:
ScalableQuadrature *zeroOrderScalableQuadrature;
......
......@@ -29,8 +29,6 @@
#include "ElInfo2d.h"
#include "ElInfo3d.h"
#include "Element.h"
#include "ElementMatrix.h"
#include "ElementVector.h"
#include "Error.h"
#include "Estimator.h"
#include "FileWriter.h"
......
......@@ -23,10 +23,13 @@
#ifndef AMDIS_AMDIS_FWD_INCLUDE
#define AMDIS_AMDIS_FWD_INCLUDE
#include <boost/numeric/mtl/mtl.hpp>
namespace AMDiS {
class AdaptInfo;
class AdaptStationary;
class Assembler;
class BasisFunction;
class BoundaryManager;
class CGSolver;
......@@ -37,8 +40,6 @@ namespace AMDiS {
class DOFIndexedBase;
class DOFMatrix;
class Element;
class ElementMatrix;
class ElementVector;
class ElInfo;
class Estimator;
class FastQuadrature;
......@@ -54,6 +55,7 @@ namespace AMDiS {
class Mesh;
class OEMSolver;
class Operator;
class OperatorTerm;
class ProblemInstat;
class ProblemIterationInterface;
class ProblemTimeInterface;
......@@ -83,6 +85,12 @@ namespace AMDiS {
template<typename T> class WorldVector;
template<typename T> class WorldMatrix;
template<typename T> class VectorOfFixVecs;
typedef mtl::dense2D<double> ElementMatrix;
typedef mtl::dense_vector<double> ElementVector;
} // namespace AMDiS
#endif // AMDIS_AMDIS_FWD_INCLUDE
#include <vector>
#include <algorithm>
#include <boost/numeric/mtl/mtl.hpp>
#include "Assembler.h"
#include "Operator.h"
#include "Element.h"
#include "QPsiPhi.h"
#include "ElementMatrix.h"
#include "ElementVector.h"
#include "DOFVector.h"
#include "OpenMP.h"
......@@ -24,28 +21,19 @@ namespace AMDiS {
remember(true),
rememberElMat(false),
rememberElVec(false),
elementMatrix(NULL),
elementVector(NULL),
elementMatrix(nRow, nCol),
elementVector(nRow),
lastMatEl(NULL),
lastVecEl(NULL),
lastTraverseId(-1)
{
elementMatrix = NEW ElementMatrix(nRow, nCol);
elementVector = NEW ElementVector(nRow);
}
{}
Assembler::~Assembler()
{
if (elementMatrix)
DELETE elementMatrix;
if (elementVector)
DELETE elementVector;
}
{}
void Assembler::calculateElementMatrix(const ElInfo *elInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor)
{
FUNCNAME("Assembler::calculateElementMatrix()");
......@@ -61,18 +49,18 @@ namespace AMDiS {
}
if (el != lastMatEl || !operat->isOptimized()) {
if (rememberElMat) {
elementMatrix->set(0.0);
}
if (rememberElMat)
set_to_zero(elementMatrix);
lastMatEl = el;
} else {
if (rememberElMat) {
axpy(factor, *elementMatrix, *userMat);
userMat += factor * elementMatrix;
return;
}
}
ElementMatrix *mat = rememberElMat ? elementMatrix : userMat;
ElementMatrix& mat = rememberElMat ? elementMatrix : userMat;
if (secondOrderAssembler)
secondOrderAssembler->calculateElementMatrix(elInfo, mat);
......@@ -83,17 +71,15 @@ namespace AMDiS {
if (zeroOrderAssembler)
zeroOrderAssembler->calculateElementMatrix(elInfo, mat);
if (rememberElMat && userMat) {
axpy(factor, *elementMatrix, *userMat);
}
if (rememberElMat)
userMat += factor * elementMatrix;
}
void Assembler::calculateElementMatrix(const ElInfo *rowElInfo,
const ElInfo *colElInfo,
const ElInfo *smallElInfo,
const ElInfo *largeElInfo,
ElementMatrix *userMat,
ElementMatrix& userMat,
double factor)
{
FUNCNAME("Assembler::calculateElementMatrix()");
......@@ -110,18 +96,18 @@ namespace AMDiS {
}
if (el != lastMatEl || !operat->isOptimized()) {
if (rememberElMat) {
elementMatrix->set(0.0);
}
if (rememberElMat)
set_to_zero(elementMatrix);
lastMatEl = el;
} else {
if (rememberElMat) {
axpy(factor, *elementMatrix, *userMat);
userMat += factor * elementMatrix;
return;
}
}
ElementMatrix *mat = rememberElMat ? elementMatrix : userMat;
ElementMatrix& mat = rememberElMat ? elementMatrix : userMat;
if (secondOrderAssembler)
secondOrderAssembler->calculateElementMatrix(rowElInfo, colElInfo,
......@@ -136,13 +122,12 @@ namespace AMDiS {