Commit 29b6099b authored by Thomas Witkowski's avatar Thomas Witkowski

Not a bug fix, a feature fix.

parent ec1e26c5
......@@ -38,15 +38,13 @@ namespace AMDiS {
{
FUNCNAME("Assembler::calculateElementMatrix()");
if (remember && (factor != 1.0 || operat->uhOld)) {
if (remember && (factor != 1.0 || operat->uhOld))
rememberElMat = true;
}
Element *el = elInfo->getElement();
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized()) {
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized())
initElement(elInfo);
}
if (el != lastMatEl || !operat->isOptimized()) {
if (rememberElMat)
......@@ -84,16 +82,14 @@ namespace AMDiS {
{
FUNCNAME("Assembler::calculateElementMatrix()");
if (remember && ((factor != 1.0) || (operat->uhOld))) {
if (remember && ((factor != 1.0) || (operat->uhOld)))
rememberElMat = true;
}
Element *el = smallElInfo->getElement();
lastVecEl = lastMatEl = NULL;
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized()) {
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized())
initElement(smallElInfo, largeElInfo);
}
if (el != lastMatEl || !operat->isOptimized()) {
if (rememberElMat)
......@@ -149,15 +145,13 @@ namespace AMDiS {
{
FUNCNAME("Assembler::calculateElementVector()");
if (remember && factor != 1.0) {
if (remember && factor != 1.0)
rememberElVec = true;
}
Element *el = elInfo->getElement();
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized()) {
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized())
initElement(elInfo);
}
if (el != lastVecEl || !operat->isOptimized()) {
if (rememberElVec)
......@@ -174,9 +168,9 @@ namespace AMDiS {
ElementVector& vec = rememberElVec ? elementVector : userVec;
if (operat->uhOld && remember) {
matVecAssemble(elInfo, vec);
if (rememberElVec) {
if (rememberElVec)
userVec += factor * elementVector;
}
return;
}
......@@ -184,6 +178,7 @@ namespace AMDiS {
firstOrderAssemblerGrdPsi->calculateElementVector(elInfo, vec);
if (zeroOrderAssembler)
zeroOrderAssembler->calculateElementVector(elInfo, vec);
if (rememberElVec)
userVec += factor * elementVector;
}
......@@ -197,15 +192,13 @@ namespace AMDiS {
{
FUNCNAME("Assembler::calculateElementVector()");
if (remember && factor != 1.0) {
if (remember && factor != 1.0)
rememberElVec = true;
}
Element *el = mainElInfo->getElement();
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized()) {
if ((el != lastMatEl && el != lastVecEl) || !operat->isOptimized())
initElement(auxElInfo);
}
if (el != lastVecEl || !operat->isOptimized()) {
if (rememberElVec)
......@@ -228,9 +221,8 @@ namespace AMDiS {
matVecAssemble(mainElInfo, auxElInfo, smallElInfo, largeElInfo, vec);
}
if (rememberElVec) {
if (rememberElVec)
userVec += factor * elementVector;
}
return;
}
......
......@@ -32,7 +32,7 @@ namespace AMDiS {
grdTmpVec1[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
grdTmpVec2[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
}
};
}
BasisFunction::~BasisFunction()
{
......
......@@ -40,30 +40,27 @@ namespace AMDiS {
Element *el = el_info->getElement();
signed char mark;
if (el->getChild(0))
{
/****************************************************************************/
/* interior node of the tree */
/****************************************************************************/
mark = max(el->getChild(0)->getMark(), el->getChild(1)->getMark());
el->setMark(std::min(mark + 1, 0));
}
else
{
/****************************************************************************/
/* leaf node of the tree */
/****************************************************************************/
if (el->getMark() < 0) el->setMark(el->getMark() - 1);
}
if (el->getChild(0)) {
/****************************************************************************/
/* interior node of the tree */
/****************************************************************************/
mark = max(el->getChild(0)->getMark(), el->getChild(1)->getMark());
el->setMark(std::min(mark + 1, 0));
} else {
/****************************************************************************/
/* leaf node of the tree */
/****************************************************************************/
if (el->getMark() < 0)
el->setMark(el->getMark() - 1);
}
return 0;
}
void CoarseningManager::spreadCoarsenMark()
{
traversePtr = this;
mesh->traverse(-1,
Mesh::CALL_EVERY_EL_POSTORDER,
spreadCoarsenMarkFunction);
mesh->traverse(-1, Mesh::CALL_EVERY_EL_POSTORDER, spreadCoarsenMarkFunction);
}
......@@ -93,7 +90,6 @@ namespace AMDiS {
Flag CoarseningManager::coarsenMesh(Mesh *aMesh)
{
int n_elements;
Flag flag = Mesh::CALL_EVERY_EL_POSTORDER | Mesh::FILL_NEIGH;
ElInfo *el_info;
mesh = aMesh;
......@@ -102,18 +98,23 @@ namespace AMDiS {
spreadCoarsenMark();
stack = NEW TraverseStack;
stack = new TraverseStack;
do {
doMore = false;
el_info = stack->traverseFirst(mesh, -1, flag);
el_info = stack->traverseFirst(mesh, -1,
Mesh::CALL_EVERY_EL_POSTORDER | Mesh::FILL_NEIGH);
while (el_info) {
coarsenFunction(el_info);
int idx = el_info->getElement()->getIndex();
// if (idx != 2288 && idx != 2283)
coarsenFunction(el_info);
el_info = stack->traverseNext(el_info);
}
} while (doMore);
DELETE stack;
delete stack;
cleanUpAfterCoarsen();
......
......@@ -87,15 +87,15 @@ namespace AMDiS {
/****************************************************************************/
/* get new dof on el at the midpoint of the coarsening edge */
/****************************************************************************/
if (!el->getDOF(node+2)) {
el->setDOF(node+2, mesh->getDOF(EDGE));
if (!el->getDOF(node + 2)) {
el->setDOF(node + 2, mesh->getDOF(EDGE));
if (neigh) {
neigh->setDOF(node+2, const_cast<int*>( el->getDOF(node+2)));
neigh->setDOF(node + 2, const_cast<int*>(el->getDOF(node+2)));
}
}
}
if (mesh->getNumberOfDOFs(EDGE) || mesh->getNumberOfDOFs(CENTER)) {
if (mesh->getNumberOfDOFs(EDGE) || mesh->getNumberOfDOFs(CENTER)) {
coarsenList->addDOFParents(n_neigh);
}
......@@ -132,7 +132,7 @@ namespace AMDiS {
int CoarseningManager2d::coarsenFunction(ElInfo *el_info)
{
Triangle *el = dynamic_cast<Triangle*>(const_cast<Element*>( el_info->getElement()));
Triangle *el = dynamic_cast<Triangle*>(const_cast<Element*>(el_info->getElement()));
DegreeOfFreedom *edge[2];
int n_neigh, bound = 0;
RCNeighbourList coarse_list(2);
......@@ -165,11 +165,11 @@ namespace AMDiS {
/****************************************************************************/
if (el->getDOF(0,0) < el->getDOF(1,0)) {
edge[0] = const_cast<int*>( el->getDOF(0));
edge[1] = const_cast<int*>( el->getDOF(1));
edge[0] = const_cast<int*>(el->getDOF(0));
edge[1] = const_cast<int*>(el->getDOF(1));
} else {
edge[1] = const_cast<int*>( el->getDOF(0));
edge[0] = const_cast<int*>( el->getDOF(1));
edge[1] = const_cast<int*>(el->getDOF(0));
edge[0] = const_cast<int*>(el->getDOF(1));
}
coarse_list.setElement(0, el, true);
......
......@@ -89,7 +89,7 @@ namespace AMDiS {
ERROR_EXIT("TODO\n");
}
void DOFAdmin::freeDOFIndex(int dof) {
void DOFAdmin::freeDOFIndex(int dof) {
FUNCNAME("DOFAdmin::freeDOFIndex()");
TEST_EXIT_DBG(usedCount > 0)("no dofs in use\n");
......@@ -98,19 +98,17 @@ namespace AMDiS {
std::list<DOFIndexedBase*>::iterator di;
std::list<DOFIndexedBase*>::iterator end = dofIndexedList.end();
for (di = dofIndexedList.begin(); di != end; ++di) {
for (di = dofIndexedList.begin(); di != end; ++di)
(*di)->freeDOFContent(dof);
}
std::list<DOFContainer*>::iterator dc;
std::list<DOFContainer*>::iterator dcend = dofContainerList.end();
for (dc = dofContainerList.begin(); dc != dcend; ++dc) {
for (dc = dofContainerList.begin(); dc != dcend; ++dc)
(*dc)->freeDOFIndex(dof);
}
dofFree[dof] = true;
if (static_cast<int>(firstHole) > dof)
firstHole = dof;
......@@ -118,8 +116,6 @@ namespace AMDiS {
holeCount++;
}
/****************************************************************************/
int DOFAdmin::getDOFIndex()
{
FUNCNAME("DOFAdmin::getDOFIndex()");
......@@ -160,9 +156,6 @@ namespace AMDiS {
return(dof);
}
/****************************************************************************/
void DOFAdmin::enlargeDOFLists(int minsize)
{
FUNCNAME("DOFAdmin::enlargeDOFLists()");
......@@ -256,9 +249,6 @@ namespace AMDiS {
ERROR("container not in list\n");
}
/****************************************************************************/
void DOFAdmin::compress(std::vector<DegreeOfFreedom> &new_dof)
{
FUNCNAME("DOFAdmin::compress()");
......@@ -269,16 +259,14 @@ namespace AMDiS {
if (holeCount < 1) return;
// vector to mark used dofs
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
new_dof[i] = -1;
}
// mark used dofs
DOFIteratorBase it(this, USED_DOFS);
for (it.reset(); !it.end(); ++it) {
for (it.reset(); !it.end(); ++it)
new_dof[it.getDOFIndex()] = 1;
}
int n = 0, last = 0;
for (int i = 0; i < size; i++) { /* create a MONOTONE compress */
if (new_dof[i] == 1) {
......@@ -290,13 +278,12 @@ namespace AMDiS {
TEST_EXIT_DBG(n == usedCount)("count %d != usedCount %d\n", n, usedCount);
// mark used dofs in compressed dofFree
for (int i = 0; i < n; i++) {
for (int i = 0; i < n; i++)
dofFree[i] = false;
}
// mark unused dofs in compressed dofFree
for (int i = n; i < size; i++) {
for (int i = n; i < size; i++)
dofFree[i] = true;
}
firstHole = n;
holeCount = 0;
......@@ -313,18 +300,14 @@ namespace AMDiS {
std::list<DOFIndexedBase*>::iterator di;
std::list<DOFIndexedBase*>::iterator end = dofIndexedList.end();
for (di = dofIndexedList.begin(); di != end; ++di) {
for (di = dofIndexedList.begin(); di != end; ++di)
(*di)->compressDOFIndexed(first, last, new_dof);
};
std::list<DOFContainer*>::iterator dc;
std::list<DOFContainer*>::iterator endc = dofContainerList.end();
for (dc = dofContainerList.begin(); dc != endc; dc++) {
for (dc = dofContainerList.begin(); dc != endc; dc++)
(*dc)->compressDOFContainer(n, new_dof);
};
return;
}
void DOFAdmin::setNumberOfDOFs(int i,int v) {
......
......@@ -98,12 +98,11 @@ namespace AMDiS {
typedef traits::range_generator<major, Matrix>::type cursor_type;
typedef traits::range_generator<nz, cursor_type>::type icursor_type;
for (cursor_type cursor = begin<major>(matrix), cend = end<major>(matrix); cursor != cend; ++cursor) {
std::cout.precision(10);
for (cursor_type cursor = begin<major>(matrix), cend = end<major>(matrix); cursor != cend; ++cursor)
for (icursor_type icursor = begin<nz>(cursor), icend = end<nz>(cursor); icursor != icend; ++icursor)
Msg::print(" (%3d,%3d,%20.17lf)", row(*icursor), col(*icursor), value(*icursor));
Msg::print("\n");
}
std::cout << row(*icursor) << " " << col(*icursor) << " " << value(*icursor) << "\n";
}
bool DOFMatrix::symmetric()
......@@ -201,7 +200,6 @@ namespace AMDiS {
}
}
// === Add element matrix to the global matrix using the indices mapping. ===
DegreeOfFreedom row, col;
......@@ -219,6 +217,7 @@ namespace AMDiS {
for (int j = 0; j < nCol; j++) { // for all columns
col = colIndices[j];
entry = elMat[i][j];
if (add)
ins[row][col]+= sign * entry;
else
......@@ -233,33 +232,8 @@ namespace AMDiS {
}
void DOFMatrix::freeDOFContent(int index)
{
if (matrix.nnz() == 0) return;
using mtl::tag::major; using mtl::tag::nz; using mtl::begin; using mtl::end;
namespace traits= mtl::traits;
typedef base_matrix_type Matrix;
traits::row<Matrix>::type row(matrix);
traits::col<Matrix>::type col(matrix);
typedef traits::range_generator<major, Matrix>::type cursor_type;
typedef traits::range_generator<nz, cursor_type>::type icursor_type;
cursor_type cursor = begin<major>(matrix);
// Jump directly to corresponding row or column
cursor+= index;
// Requires structural symmetry !!!
for (icursor_type icursor = begin<nz>(cursor), icend = end<nz>(cursor); icursor != icend; ++icursor) {
int my_row= row(*icursor), my_col= col(*icursor);
// Not very efficient (but general)
matrix.lvalue(my_row, my_col) = 0.0; // Need to call crop somewhere !!!! Peter
matrix.lvalue(my_col, my_row) = 0.0;
}
}
{}
// Should work as before
void DOFMatrix::assemble(double factor, ElInfo *elInfo, const BoundaryType *bound)
{
FUNCNAME("DOFMatrix::assemble()");
......@@ -268,13 +242,9 @@ namespace AMDiS {
std::vector<Operator*>::iterator it = operators.begin();
std::vector<double*>::iterator factorIt = operatorFactor.begin();
for (; it != operators.end(); ++it, ++factorIt) {
if ((*it)->getNeedDualTraverse() == false) {
(*it)->getElementMatrix(elInfo,
elementMatrix,
*factorIt ? **factorIt : 1.0);
}
}
for (; it != operators.end(); ++it, ++factorIt)
if ((*it)->getNeedDualTraverse() == false)
(*it)->getElementMatrix(elInfo, elementMatrix, *factorIt ? **factorIt : 1.0);
addElementMatrix(factor, elementMatrix, bound, elInfo, NULL);
}
......
......@@ -290,8 +290,6 @@ namespace AMDiS {
/// Resizes \ref matrix to n rows
inline void resize(int n) {
TEST_EXIT_DBG(n >= 0)("Can't resize DOFMatrix to negative size\n");
// matrix.change_dim(n, n);
//WARNING("Obsolete function without effect -- Peter\n");
}
/// Returns value at logical indices a,b
......
......@@ -65,8 +65,8 @@ namespace AMDiS {
result = grad;
} else {
if(result && result->getFESpace() != feSpace) {
DELETE result;
result = NEW DOFVector<WorldVector<double> >(feSpace, "gradient");
delete result;
result = new DOFVector<WorldVector<double> >(feSpace, "gradient");
}
}
......@@ -157,11 +157,11 @@ namespace AMDiS {
if (!result) {
if (vec && vec->getFESpace() != feSpace) {
DELETE vec;
delete vec;
vec = NULL;
}
if (!vec) {
vec = NEW DOFVector<WorldVector<double> >(feSpace, "gradient");
vec = new DOFVector<WorldVector<double> >(feSpace, "gradient");
}
result = vec;
}
......@@ -257,48 +257,42 @@ namespace AMDiS {
if (quadFast) {
for (int i = 0; i < nPoints; i++) {
for (int j = 0; j < dim + 1; j++) {
for (int j = 0; j < dim + 1; j++)
grd1[j] = 0.0;
}
for (int j = 0; j < nBasFcts; j++) {
for (int k = 0; k < parts; k++) {
for (int j = 0; j < nBasFcts; j++)
for (int k = 0; k < parts; k++)
grd1[k] += quadFast->getGradient(i, j, k) * localVec[j];
}
}
for (int l=0; l < dow; l++) {
result[i][l] = 0.0;
for (int k = 0; k < parts; k++) {
for (int k = 0; k < parts; k++)
result[i][l] += grdLambda[k][l] * grd1[k];
}
}
}
} else {
} else {
const BasisFunction *basFcts = feSpace->getBasisFcts();
DimVec<double>* grdPhi = grdPhis[myRank];
for (int i = 0; i < nPoints; i++) {
for (int j = 0; j < dim + 1; j++) {
for (int j = 0; j < dim + 1; j++)
grd1[j] = 0.0;
}
for (int j = 0; j < nBasFcts; j++) {
(*(basFcts->getGrdPhi(j)))(quad->getLambda(i), *grdPhi);
for (int k = 0; k < parts; k++) {
for (int k = 0; k < parts; k++)
grd1[k] += (*grdPhi)[k] * localVec[j];
}
}
for (int l = 0; l < dow; l++) {
result[i][l] = 0.0;
for (int k = 0; k < parts; k++) {
for (int k = 0; k < parts; k++)
result[i][l] += grdLambda[k][l] * grd1[k];
}
}
}
}
return const_cast<const WorldVector<double>*>(result);
}
......@@ -585,7 +579,7 @@ namespace AMDiS {
if (feSpace->getMesh() == vFESpace->getMesh()) {
DegreeOfFreedom *myLocalIndices = localIndices[omp_get_thread_num()];
WorldVector<double> *vLocalCoeffs = NEW WorldVector<double>[vNumBasFcts];
WorldVector<double> *vLocalCoeffs = new WorldVector<double>[vNumBasFcts];
Mesh *mesh = feSpace->getMesh();
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(mesh, -1,
......@@ -608,7 +602,7 @@ namespace AMDiS {
elInfo = stack.traverseNext(elInfo);
}
DELETE [] vLocalCoeffs;
delete [] vLocalCoeffs;
} else {
ERROR_EXIT("not yet for dual traverse\n");
}
......@@ -635,14 +629,14 @@ namespace AMDiS {
result = grad;
} else {
if (!result) {
result = NEW WorldVector<DOFVector<double>*>;
result = new WorldVector<DOFVector<double>*>;
result->set(NULL);
}
for (int i = 0; i < dow; i++) {
if ((*result)[i] && (*result)[i]->getFESpace() != feSpace) {
DELETE (*result)[i];
(*result)[i] = NEW DOFVector<double>(feSpace, "gradient");
delete (*result)[i];
(*result)[i] = new DOFVector<double>(feSpace, "gradient");
}
}
}
......@@ -720,17 +714,15 @@ namespace AMDiS {
DOFVector<DegreeOfFreedom>()
{}
void DOFVectorDOF::freeDOFContent(DegreeOfFreedom dof) {
void DOFVectorDOF::freeDOFContent(DegreeOfFreedom dof)
{
std::vector<DegreeOfFreedom>::iterator it;
std::vector<DegreeOfFreedom>::iterator end = vec.end();
DegreeOfFreedom pos = 0;
for (it = vec.begin(); it != end; ++it, ++pos) {
for (it = vec.begin(); it != end; ++it, ++pos)
if (*it == dof) *it = pos;
}
}
WorldVector<DOFVector<double>*> *transform(DOFVector<WorldVector<double> > *vec,
WorldVector<DOFVector<double>*> *res)
{
......@@ -742,20 +734,17 @@ namespace AMDiS {
static WorldVector<DOFVector<double>*> *result = NULL;
if (!res && !result) {
result = NEW WorldVector<DOFVector<double>*>;
for (int i = 0; i < dow; i++) {
(*result)[i] = NEW DOFVector<double>(vec->getFESpace(), "transform");
}
result = new WorldVector<DOFVector<double>*>;
for (int i = 0; i < dow; i++)
(*result)[i] = new DOFVector<double>(vec->getFESpace(), "transform");
}
WorldVector<DOFVector<double>*> *r = res ? res : result;
int vecSize = vec->getSize();
for (int i = 0; i < vecSize; i++) {
for (int j = 0; j < dow; j++) {