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

* int calcMemoryUsage() introduced for some classes

parent 7854212b
......@@ -319,7 +319,7 @@ namespace AMDiS {
feSpace(NULL),
refineInter(false),
coarsenOperation(NO_OPERATION)
{};
{}
/** \brief
* Constructs a DOFVector with name n belonging to FiniteElemSpace f
......@@ -340,7 +340,7 @@ namespace AMDiS {
if (feSpace && feSpace->getAdmin()) {
(dynamic_cast<DOFAdmin*>(feSpace->getAdmin()))->addDOFIndexed(this);
}
};
}
/** \brief
* Destructor
......@@ -373,59 +373,59 @@ namespace AMDiS {
*/
inline void refineInterpol(bool b) {
refineInter = b;
};
}
/** \brief
* Sets \ref coarsenOperation to op
*/
inline void setCoarsenOperation(CoarsenOperation op) {
coarsenOperation = op;
};
}
/** \brief
* Returns \ref coarsenOperation
*/
inline CoarsenOperation getCoarsenOperation() {
return coarsenOperation;
};
}
/** \brief
* Restriction after coarsening. Implemented for DOFVector<double>
*/
inline void coarseRestrict(RCNeighbourList&, int) {};
inline void coarseRestrict(RCNeighbourList&, int) {}
/** \brief
* Returns \ref refineInter
*/
inline bool refineInterpol() {
return refineInter;
};
}
/** \brief
* Interpolation after refinement.
*/
inline void refineInterpol(RCNeighbourList&, int) {};
inline void refineInterpol(RCNeighbourList&, int) {};
/** \brief
* Returns \ref vec
*/
std::vector<T>& getVector() {
return vec;
};
}
/** \brief
* Returns size of \ref vec
*/
inline int getSize() const {
return vec.size();
};
}
/** \brief
* Returns used size of the vector.
*/
inline int getUsedSize() const {
return feSpace->getAdmin()->getUsedSize();
};
}
/** \brief
* Resizes \ref vec to n
......@@ -434,7 +434,7 @@ namespace AMDiS {
FUNCNAME("DOFVector<T>::resize()");
TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n");
vec.resize(n);
};
}
/** \brief
* Resizes \ref vec to n and inits new values with init
......@@ -443,7 +443,7 @@ namespace AMDiS {
FUNCNAME("DOFVector<T>::resize()");
TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n");
vec.resize(n, init);
};
}
/** \brief
* Returns \ref vec[i]
......@@ -453,11 +453,11 @@ namespace AMDiS {
TEST_EXIT_DBG((i>= 0) && (i < static_cast<int>(vec.size())))
("Illegal vector index %d.\n",i);
return vec[i];
};
}
inline int getSize() {
return vec.size();
};
}
/** \brief
* Returns \ref vec[i]
......@@ -467,7 +467,7 @@ namespace AMDiS {
TEST_EXIT_DBG((i >= 0) && (i < static_cast<int>(vec.size())))
("Illegal vector index %d.\n",i);
return vec[i];
};
}
/** \brief
* Calculates Integral of this DOFVector
......@@ -518,7 +518,7 @@ namespace AMDiS {
*/
inline double l2norm() const {
return nrm2();
};
}
/** \brief
* Calculates the absolute sum of this DOFVector
......@@ -530,7 +530,7 @@ namespace AMDiS {
*/
inline double l1norm() const {
return asum();
};
}
/** \brief
* Calculates doublewell of this DOFVector
......@@ -553,7 +553,7 @@ namespace AMDiS {
inline DOFVector<T>& operator=(T d) {
set(d);
return *this;
};
}
/** \brief
* Assignment operator between two vectors
......@@ -590,6 +590,8 @@ namespace AMDiS {
*/
void print() const;
int calcMemoryUsage() const;
/** \brief
* Computes the coefficients of the interpolant of the function fct and
* stores these in the DOFVector
......@@ -604,14 +606,14 @@ namespace AMDiS {
unsigned int size = vec.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
out.write(reinterpret_cast<const char*>(&(vec[0])), size * sizeof(T));
};
}
void deserialize(std::istream &in) {
unsigned int size;
in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
vec.resize(size);
in.read(reinterpret_cast<char*>(&(vec[0])), size * sizeof(T));
};
}
DOFVector<WorldVector<T> > *getGradient(DOFVector<WorldVector<T> >*) const;
......
......@@ -403,15 +403,15 @@ namespace AMDiS {
template<typename T>
void DOFVector<T>::print() const
{
FUNCNAME("DOFVector<T>::print");
int i, j;
FUNCNAME("DOFVector<T>::print()");
const DOFAdmin *admin = NULL;
const char *format;
const char *format;
if (feSpace) admin = feSpace->getAdmin();
if (feSpace)
admin = feSpace->getAdmin();
MSG("Vec `%s':\n", name.c_str());
j = 0;
int j = 0;
if (admin) {
if (admin->getUsedSize() > 100)
format = "%s(%3d,%10.5le)";
......@@ -424,27 +424,25 @@ namespace AMDiS {
for(vecIterator.reset();
!vecIterator.end(); ++vecIterator) {
if ((j % 3) == 0) {
if (j) Msg::print("\n");
if (j)
Msg::print("\n");
MSG(format, "", vecIterator.getDOFIndex(), *vecIterator);
}
else
} else
Msg::print(format, " ", vecIterator.getDOFIndex(), *vecIterator);
j++;
};
}
Msg::print("\n");
}
else
{
} else {
MSG("no DOFAdmin, print whole vector.\n");
for (i = 0; i < static_cast<int>( vec.size()); i++) {
if ((j % 3) == 0)
{
if (j) Msg::print("\n");
MSG("(%d,%10.5e)",i,vec[i]);
}
else
for (int i = 0; i < static_cast<int>( vec.size()); i++) {
if ((j % 3) == 0) {
if (j)
Msg::print("\n");
MSG("(%d,%10.5e)",i,vec[i]);
} else {
Msg::print(" (%d,%10.5e)",i,vec[i]);
}
j++;
}
Msg::print("\n");
......@@ -452,17 +450,25 @@ namespace AMDiS {
return;
}
template<typename T>
int DOFVector<T>::calcMemoryUsage() const
{
int result = 0;
result += sizeof(DOFVector<T>);
result += vec.size() * sizeof(T);
return result;
}
template<typename T>
T DOFVectorBase<T>::evalUh(const DimVec<double>& lambda,
DegreeOfFreedom* dof_indices)
{
int i;
BasisFunction* phi = const_cast<BasisFunction*>(this->getFESpace()->getBasisFcts());
int numberOfBasFcts = phi->getNumber();
T val = 0.0;
for (i = 0; i < numberOfBasFcts; i++)
for (int i = 0; i < numberOfBasFcts; i++)
val += (*this)[dof_indices[i]]*(*phi->getPhi(i))(lambda);
return val;
......
......@@ -255,7 +255,7 @@ namespace AMDiS {
void Element::serialize(std::ostream &out)
{
// write children
if(child[0]) {
if (child[0]) {
out << child[0]->getTypeName() << "\n";
child[0]->serialize(out);
child[1]->serialize(out);
......@@ -420,4 +420,16 @@ namespace AMDiS {
}
}
int Element::calcMemoryUsage()
{
int result = 0;
result += sizeof(Element);
if (child[0]) {
result += child[0]->calcMemoryUsage() + child[1]->calcMemoryUsage();
}
return result;
}
}
......@@ -112,14 +112,14 @@ namespace AMDiS {
*/
inline Element* getFirstChild() const {
return child[0];
};
}
/** \brief
* Returns \ref child[1]
*/
inline Element* getSecondChild() const {
return child[1];
};
}
/** \brief
* Returns \ref child[i], i=0,1
......@@ -127,7 +127,7 @@ namespace AMDiS {
inline Element* getChild(int i) const {
TEST_EXIT_DBG(i==0 || i==1)("i must be 0 or 1\n");
return child[i];
};
}
/** \brief
* Returns true if Element is a leaf element (\ref child[0] == NULL), returns
......@@ -135,35 +135,35 @@ namespace AMDiS {
*/
inline const bool isLeaf() const {
return (child[0] == NULL);
};
}
/** \brief
* Returns \ref dof[i][j] which is the j-th DOF of the i-th node of Element.
*/
const DegreeOfFreedom getDOF(int i, int j) const {
return dof[i][j];
};
}
/** \brief
* Returns \ref dof[i] which is a pointer to the DOFs of the i-th node.
*/
const DegreeOfFreedom* getDOF(int i) const {
return dof[i];
};
}
/** \brief
* Returns a pointer to the DOFs of this Element
*/
const DegreeOfFreedom** getDOF() const {
return const_cast<const DegreeOfFreedom**>(dof);
};
}
/** \brief
* Returns \ref mesh of Element
*/
inline Mesh* getMesh() const {
return mesh;
};
}
/** \brief
* Returns \ref elementData's error estimation, if Element is a leaf element
......@@ -180,7 +180,7 @@ namespace AMDiS {
}
return 0.0;
};
}
/** \brief
* Returns Element's coarsening error estimation, if Element is a leaf
......@@ -196,7 +196,7 @@ namespace AMDiS {
}
return 0.0;
};
}
/** \brief
* Returns region of element if defined, -1 else.
......@@ -236,7 +236,7 @@ namespace AMDiS {
*/
inline const signed char getMark() const {
return mark;
};
}
/** \brief
* Returns \ref newCoord[i]
......@@ -248,14 +248,14 @@ namespace AMDiS {
*/
inline int getIndex() const {
return index;
};
}
/** \brief
* Returns \ref newCoord
*/
inline WorldVector<double>* getNewCoord() const {
return newCoord;
};
}
/** \} */
......@@ -270,21 +270,21 @@ namespace AMDiS {
*/
virtual void setFirstChild(Element *aChild) {
child[0] = aChild;
};
}
/** \brief
* Sets \ref child[1]
*/
virtual void setSecondChild(Element *aChild) {
child[1] = aChild;
};
}
/** \brief
* Sets \ref elementData of Element
*/
void setElementData(ElementData* ed) {
elementData = ed;
};
}
/** \brief
* Sets \ref newCoord of Element. Needed by refinement, if Element has a
......@@ -292,14 +292,14 @@ namespace AMDiS {
*/
inline void setNewCoord(WorldVector<double>* coord) {
newCoord = coord;
};
}
/** \brief
* Sets \ref mesh.
*/
inline void setMesh(Mesh *m) {
mesh = m;
};
}
/** \brief
* Sets the pointer to the DOFs of the i-th node of Element
......@@ -307,7 +307,7 @@ namespace AMDiS {
DegreeOfFreedom* setDOF(int pos, DegreeOfFreedom* p) {
dof[pos] = p;
return dof[pos];
};
}
/** \brief
* Checks whether Element is a leaf element and whether it has leaf data.
......@@ -325,7 +325,7 @@ namespace AMDiS {
} else {
ERROR_EXIT("setEstimation only for leaf elements!\n");
}
};
}
/** \brief
* Sets Element's coarsening error estimation, if Element is a leaf element
......@@ -343,7 +343,7 @@ namespace AMDiS {
} else {
ERROR_EXIT("setEstimation only for leaf elements!\n");
}
};
}
/** \brief
* Sets Elements \ref mark = mark + 1;
......@@ -358,14 +358,14 @@ namespace AMDiS {
inline void decrementMark() {
if (0 < mark)
mark--;
};
}
/** \brief
* Sets Element's \ref mark
*/
inline void setMark(signed char m) {
mark = m;
};
}
/** \} */
......@@ -451,7 +451,7 @@ namespace AMDiS {
elementData = tmp;
}
}
};
}
/** \brief
* Coarsens Element's leaf data
......@@ -470,14 +470,14 @@ namespace AMDiS {
DELETE childData;
child2->setElementData(NULL);
}
};
}
/** \brief
* Returns pointer to \ref elementData
*/
inline ElementData* getElementData() const {
return elementData;
};
}
/** \brief
*
......@@ -487,7 +487,7 @@ namespace AMDiS {
return elementData->getElementData(typeID);
}
return NULL;
};
}
/** \brief
* kills \ref elementData
......@@ -505,7 +505,7 @@ namespace AMDiS {
}
}
return false;
};
}
/** \brief
* Returns whether element is refined at side side
......@@ -521,7 +521,7 @@ namespace AMDiS {
*/
inline bool isNewCoordSet() const {
return (newCoord != NULL);
};
}
/** \brief
* Frees memory for \ref newCoord
......@@ -534,6 +534,8 @@ namespace AMDiS {
void deserialize(std::istream &in);
int calcMemoryUsage();
// ===== protected methods ====================================================
protected:
/** \brief
......@@ -546,7 +548,7 @@ namespace AMDiS {
*/
inline void setIndex(int i) {
index = i;
};
}
/** \brief
* Used by friend class Mesh while dofCompress
......@@ -575,7 +577,7 @@ namespace AMDiS {
* present, then those at the faces, if present, and then those at the
* barycenter, if present.
*/
DegreeOfFreedom **dof;
DegreeOfFreedom **dof;
/** \brief
* Unique global index of the element. these indices are not strictly ordered
......
......@@ -93,14 +93,14 @@ namespace AMDiS {
element->deserialize(in);
// read coords
int i, size;
int size;
in.read(reinterpret_cast<char*>(&size), sizeof(int));
if (coord.getSize()) {
TEST_EXIT(coord.getSize() == size)("invalid size\n");
} else {
coord.initSize(size);
}
for(i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
coord[i].deserialize(in);
}
......@@ -110,13 +110,13 @@ namespace AMDiS {
// read projection
in.read(reinterpret_cast<char*>(&size), sizeof(int));
if(projection.getSize()) {
if (projection.getSize()) {
TEST_EXIT(projection.getSize() == size)("invalid size\n");
} else {
projection.initSize(size);
}
for(i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
int id;
in.read(reinterpret_cast<char*>(&id), sizeof(int));
projection[i] = (id != -1) ? Projection::getProjection(id) : NULL;
......@@ -136,7 +136,7 @@ namespace AMDiS {
neighbour.initSize(size);
}
for(i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
int index;
in.read(reinterpret_cast<char*>(&index), sizeof(int));
......@@ -161,4 +161,18 @@ namespace AMDiS {
in.read(reinterpret_cast<char*>(&elType), sizeof(unsigned char));
}
int MacroElement::calcMemoryUsage()
{
int result = 0;
result += sizeof(MacroElement);
result += coord.getSize() * sizeof(WorldVector<double>);
result += projection.getSize() * sizeof(Projection*);
result += neighbour.getSize() * sizeof(MacroElement*);
result += oppVertex.getSize() * sizeof(char);
result += element->calcMemoryUsage();
return result;
}
}
......@@ -211,7 +211,9 @@ namespace AMDiS {
inline void writeNeighboursTo(std::vector<int> *indices) {
deserializedNeighbourIndices_ = indices;
};
}
int calcMemoryUsage();
protected:
/** \brief
......
......@@ -1101,4 +1101,16 @@ namespace AMDiS {
getNumberOfVertices());
DELETE macroFileInfo_;
}
int Mesh::calcMemoryUsage()
{
int result = 0;
result += sizeof(Mesh);
for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
result += macroElements[i]->calcMemoryUsage();
}