Commit 7ae9f1a2 authored by Thomas Witkowski's avatar Thomas Witkowski

Code refactoring.

parent efd6a256
......@@ -78,10 +78,9 @@ namespace AMDiS {
FUNCNAME("AdaptInstationary::explicitTimeStrategy()");
// estimate before first adaption
if (adaptInfo->getTime() <= adaptInfo->getStartTime()) {
if (adaptInfo->getTime() <= adaptInfo->getStartTime())
problemIteration_->oneIteration(adaptInfo, ESTIMATE);
}
// increment time
adaptInfo->setTime(adaptInfo->getTime() + adaptInfo->getTimestep());
......@@ -136,21 +135,20 @@ namespace AMDiS {
if (problemIteration_->oneIteration(adaptInfo, FULL_ITERATION)) {
if (!fixedTimestep_ &&
!adaptInfo->timeToleranceReached() &&
!(adaptInfo->getTimestep() <= adaptInfo->getMinTimestep()))
{
adaptInfo->setTime(adaptInfo->getTime() - adaptInfo->getTimestep());
adaptInfo->setTimestep(adaptInfo->getTimestep() * time_delta_1);
problemIteration_->endIteration(adaptInfo);
adaptInfo->incSpaceIteration();
break;
}
!(adaptInfo->getTimestep() <= adaptInfo->getMinTimestep())) {
adaptInfo->setTime(adaptInfo->getTime() - adaptInfo->getTimestep());
adaptInfo->setTimestep(adaptInfo->getTimestep() * time_delta_1);
problemIteration_->endIteration(adaptInfo);
adaptInfo->incSpaceIteration();
break;
}
}
adaptInfo->incSpaceIteration();
problemIteration_->endIteration(adaptInfo);
} while(!adaptInfo->spaceToleranceReached() &&
adaptInfo->getSpaceIteration() <= adaptInfo->getMaxSpaceIteration());
} while (!adaptInfo->spaceToleranceReached() &&
adaptInfo->getSpaceIteration() <= adaptInfo->getMaxSpaceIteration());
} else {
problemIteration_->endIteration(adaptInfo);
......@@ -162,7 +160,7 @@ namespace AMDiS {
adaptInfo->getTimestepIteration() <= adaptInfo->getMaxTimestepIteration());
if (!fixedTimestep_ && adaptInfo->timeErrorLow()) {
adaptInfo->setTimestep(adaptInfo->getTimestep() *time_delta_2);
adaptInfo->setTimestep(adaptInfo->getTimestep() * time_delta_2);
if (dbgMode) {
// print information about timestep increase
}
......@@ -170,12 +168,10 @@ namespace AMDiS {
if (dbgMode) {
std::cout << "=== ADAPT INFO DEBUG MODE ===\n";
std::cout << " Do not increase timestep: \n";
if (fixedTimestep_) {
if (fixedTimestep_)
std::cout << " fixedTimestep = true\n";
}
if (!adaptInfo->timeErrorLow()) {
if (!adaptInfo->timeErrorLow())
adaptInfo->printTimeErrorLowInfo();
}
}
}
}
......
......@@ -84,8 +84,8 @@ namespace AMDiS {
D2Phis.resize(omp_get_overall_max_threads());
for (int i = 0; i < omp_get_overall_max_threads(); i++) {
localIndices[i] = GET_MEMORY(DegreeOfFreedom, this->nBasFcts);
localVectors[i] = GET_MEMORY(T, this->nBasFcts);
localIndices[i] = new DegreeOfFreedom[this->nBasFcts];
localVectors[i] = new T[this->nBasFcts];
grdPhis[i] = new DimVec<double>(dim, DEFAULT_VALUE, 0.0);
grdTmp[i] = new DimVec<double>(dim, DEFAULT_VALUE, 0.0);
D2Phis[i] = new DimMat<double>(dim, NO_INIT);
......@@ -96,8 +96,8 @@ namespace AMDiS {
DOFVectorBase<T>::~DOFVectorBase()
{
for (int i = 0; i < static_cast<int>(localIndices.size()); i++) {
FREE_MEMORY(localIndices[i], DegreeOfFreedom, this->nBasFcts);
FREE_MEMORY(localVectors[i], T, this->nBasFcts);
delete [] localIndices[i];
delete [] localVectors[i];
delete grdPhis[i];
delete grdTmp[i];
delete D2Phis[i];
......
......@@ -94,9 +94,8 @@ namespace AMDiS {
GeoIndex position = INDEX_OF_DIM(pos, dim);
int ndof = 0;
for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++)
ndof += mesh->getDOFAdmin(i).getNumberOfDOFs(position);
}
if (ndof > 0) {
for (int i = 0; i < mesh->getGeo(position); i++) {
......@@ -111,7 +110,7 @@ namespace AMDiS {
}
}
FREE_MEMORY(dof, DegreeOfFreedom*, mesh->getNumberOfNodes());
delete [] dof;
if (child[0])
child[0]->deleteElementDOFs();
......
......@@ -286,19 +286,18 @@ namespace AMDiS {
: rows(r), columns(c)
{
TEST_EXIT_DBG(initType == NO_INIT)("wrong initType or wrong initializer\n");
vec = GET_MEMORY(VectorOfFixVecs<FixVecType>*, rows);
for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++) {
vec = new VectorOfFixVecs<FixVecType>*[rows];
for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++)
*i = new VectorOfFixVecs<FixVecType>(dim, columns, NO_INIT);
}
}
/// destructor
virtual ~MatrixOfFixVecs()
{
for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++) {
for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++)
delete *i;
}
FREE_MEMORY(vec, VectorOfFixVecs<FixVecType>*, rows);
delete [] vec;
}
/// assignment operator
......@@ -412,52 +411,38 @@ namespace AMDiS {
class WorldVector : public FixVec<T, WORLD>
{
public:
/** \brief
* Calls the corresponding constructor of AlgoVec
*/
/// Calls the corresponding constructor of AlgoVec
WorldVector()
: FixVec<T, WORLD>(Global::getGeo(WORLD), NO_INIT)
{}
/** \brief
* Calls the corresponding constructor of AlgoVec
*/
/// Calls the corresponding constructor of AlgoVec
WorldVector(InitType initType, T* ini)
: FixVec<T, WORLD>(Global::getGeo(WORLD), initType, ini)
{}
/** \brief
* Calls the corresponding constructor of AlgoVec
*/
/// Calls the corresponding constructor of AlgoVec
WorldVector(InitType initType, const T& ini)
: FixVec<T, WORLD>(Global::getGeo(WORLD), initType, ini)
{}
/** \brief
* Sets all entries to d
*/
/// Sets all entries to d
inline const WorldVector<T>& operator=(const T& d)
{
this->set(d);
return (*this);
}
/** \brief
* Sets the arrays value to the geometric midpoint of the points
* p1 and p2;
*/
/// Sets the arrays value to the geometric midpoint of the points p1 and p2.
inline void setMidpoint(const WorldVector<T> &p1, const WorldVector<T> &p2)
{
int dow = Global::getGeo(WORLD);
for (int i = 0; i < dow; i++) {
for (int i = 0; i < dow; i++)
this->valArray[i] = 0.5 * (p1[i] + p2[i]);
}
}
/** \brief
* Multplication of a matrix with a vector.
*/
/// Multplication of a matrix with a vector.
void multMatrixVec(WorldMatrix<T> &m, WorldVector<T> &v);
};
......
......@@ -26,9 +26,9 @@ namespace AMDiS {
("not for DIM != DIM_OF_WORLD\n");
WorldVector<double> *basis = new WorldVector<double>[dim];
double *lengthBasis = GET_MEMORY(double, dim);
WorldVector<double> *step = new WorldVector<double>[3];
WorldVector<double> *basis = new WorldVector<double>[dim];
double *lengthBasis = new double[dim];
WorldVector<double> *step = new WorldVector<double>[3];
for (int i = 0; i < dim; i++) {
TEST_EXIT(numPoints[i] > 0)("numPoints < 1\n");
......@@ -121,7 +121,7 @@ namespace AMDiS {
}
delete [] basis;
FREE_MEMORY(lengthBasis, double, dim);
delete [] lengthBasis;
delete [] step;
delete outFile;
}
......
......@@ -227,7 +227,7 @@ namespace AMDiS {
TEST_EXIT_DBG((*vertices) == NULL)("vertices != NULL\n");
int dimOfPosition = DIM_OF_INDEX(position, dim);
*vertices = GET_MEMORY(int, dimOfPosition + 1);
*vertices = new int[dimOfPosition + 1];
if ((degree == 4) && (dimOfPosition==1)) {
(*vertices)[(nodeIndex != 2) ? 0 : 1] =
......@@ -667,14 +667,15 @@ namespace AMDiS {
for (int i = 0; i <= dim; i++) { // for all positions
int partsAtPos = Global::getGeo(INDEX_OF_DIM(i, dim), dim);
for (int j = 0; j < partsAtPos; j++) { // for all vertices/edges/faces/...
int *coordInd = GET_MEMORY(int, i + 1); // indices of relevant coords
int *coordInd = new int[i + 1]; // indices of relevant coords
for (int k = 0; k < i + 1; k++) {
coordInd[k] = Global::getReferenceElement(dim)->
getVertexOfPosition(INDEX_OF_DIM(i,dim), j, k);
}
createCoords(coordInd, i + 1, 0, degree);
FREE_MEMORY(coordInd, int, i + 1);
if(static_cast<int>(bary->size()) == nBasFcts) return;
delete [] coordInd;
if (static_cast<int>(bary->size()) == nBasFcts)
return;
}
}
}
......@@ -683,9 +684,9 @@ namespace AMDiS {
int Lagrange::getNumberOfDOFs(int dim, int degree)
{
int result = 0;
for (int i = 0; i <= degree; i++) {
for (int i = 0; i <= degree; i++)
result += fac(dim - 1 + i) / (fac(i) * fac(dim - 1));
}
return result;
}
......@@ -828,8 +829,9 @@ namespace AMDiS {
if (vec) {
rvec = vec;
} else {
if(inter) FREE_MEMORY(inter, double, nBasFcts);
inter = GET_MEMORY(double, nBasFcts);
if (inter)
delete [] inter;
inter = new double[nBasFcts];
inter_size = nBasFcts;
rvec = inter;
}
......@@ -928,8 +930,8 @@ namespace AMDiS {
result = indices;
} else {
if (localVec)
FREE_MEMORY(localVec, DegreeOfFreedom, localVecSize);
localVec = GET_MEMORY(DegreeOfFreedom, nBasFcts);
delete [] localVec;
localVec = new DegreeOfFreedom[nBasFcts];
localVecSize = nBasFcts;
result = localVec;
}
......@@ -946,9 +948,8 @@ namespace AMDiS {
for (int i = 0; i < num; node0++, i++) {
const int *indi = orderOfPositionIndices(el, posIndex, i);
for (int k = 0; k < nrDOFs; k++) {
for (int k = 0; k < nrDOFs; k++)
result[j++] = dof[node0][n0 + indi[k]];
}
}
}
}
......@@ -1005,7 +1006,7 @@ namespace AMDiS {
if ((parametric = mesh->getParametric())) {
ERROR_EXIT("not yet implemented\n");
} else {
wdetf_qp = GET_MEMORY(double, q->getNumPoints());
wdetf_qp = new double[q->getNumPoints()];
}
ElInfo *el_info = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
......@@ -1030,7 +1031,7 @@ namespace AMDiS {
el_info = stack.traverseNext(el_info);
}
FREE_MEMORY(wdetf_qp, double, q->getNumPoints());
delete [] wdetf_qp;
}
......@@ -1272,7 +1273,7 @@ namespace AMDiS {
Element *el = list->getElement(0);
const DOFAdmin *admin = drv->getFESpace()->getAdmin();
DegreeOfFreedom *pdof = GET_MEMORY(DegreeOfFreedom, basFct->getNumber());
DegreeOfFreedom *pdof = new DegreeOfFreedom[basFct->getNumber()];
basFct->getLocalIndices(el, admin, pdof);
/****************************************************************************/
......@@ -1314,7 +1315,7 @@ namespace AMDiS {
+ 0.75 * (*drv)[pdof[9]]);
if (n <= 1) {
FREE_MEMORY(pdof, DegreeOfFreedom, basFct->getNumber());
delete [] pdof;
return;
}
/****************************************************************************/
......@@ -1352,7 +1353,7 @@ namespace AMDiS {
- 0.125 * (*drv)[pdof[6]] + 0.1875 * (-(*drv)[pdof[7]] + (*drv)[pdof[8]])
+ 0.75 *(*drv)[pdof[9]]);
FREE_MEMORY(pdof, DegreeOfFreedom, basFct->getNumber());
delete [] pdof;
}
void Lagrange::refineInter3_2d(DOFIndexed<double> *drv,
......@@ -1681,14 +1682,9 @@ namespace AMDiS {
if (n < 1)
return;
Element *el;
DegreeOfFreedom *pdof = GET_MEMORY(DegreeOfFreedom, basFct->getNumber());
const DegreeOfFreedom *cdof;
const DOFAdmin *admin;
el = list->getElement(0);
admin = drv->getFESpace()->getAdmin();
DegreeOfFreedom *pdof = new DegreeOfFreedom[basFct->getNumber()];
const DOFAdmin *admin = drv->getFESpace()->getAdmin();
Element *el = list->getElement(0);
basFct->getLocalIndices(el, admin, pdof);
......@@ -1696,7 +1692,8 @@ namespace AMDiS {
/* values on child[0] */
/****************************************************************************/
cdof = basFct->getLocalIndices(el->getChild(0), admin, NULL);
const DegreeOfFreedom *cdof =
basFct->getLocalIndices(el->getChild(0), admin, NULL);
(*drv)[cdof[2]] = (*drv)[pdof[10]];
(*drv)[cdof[3]] =
......@@ -1763,7 +1760,7 @@ namespace AMDiS {
(*drv)[cdof[14]] = (*drv)[pdof[13]];
if (n <= 1) {
FREE_MEMORY(pdof, DegreeOfFreedom, basFct->getNumber());
delete [] pdof;
return;
}
/****************************************************************************/
......@@ -1825,7 +1822,7 @@ namespace AMDiS {
- 0.03125*(*drv)[pdof[11]] + 0.75*(*drv)[pdof[14]]);
(*drv)[cdof[14]] = (*drv)[pdof[13]];
FREE_MEMORY(pdof, DegreeOfFreedom, basFct->getNumber());
delete [] pdof;
}
void Lagrange::refineInter4_2d(DOFIndexed<double> *drv,
......
......@@ -49,8 +49,8 @@ namespace AMDiS {
int dim = mesh->getDim();
int el1, el2;
int *verticesEl1 = GET_MEMORY(int, dim);
int *verticesEl2 = GET_MEMORY(int, dim);
int *verticesEl1 = new int[dim];
int *verticesEl2 = new int[dim];
int mode = -1; // 0: drop dofs, 1: associate dofs
int result;
BoundaryType boundaryType;
......@@ -172,8 +172,8 @@ namespace AMDiS {
}
}
FREE_MEMORY(verticesEl1, int, dim);
FREE_MEMORY(verticesEl2, int, dim);
delete [] verticesEl1;
delete [] verticesEl2;
// change periodic vertex dofs
for (int i = 0; i < mesh->getNumberOfVertices(); i++) {
......@@ -362,25 +362,22 @@ namespace AMDiS {
mesh->addMacroElement(mel[i]);
}
dof = GET_MEMORY(DegreeOfFreedom*, nv);
coords = GET_MEMORY(WorldVector<double>, nv);
mel_vertex = GET_MEMORY(int*, ne);
dof = new DegreeOfFreedom*[nv];
coords = new WorldVector<double>[nv];
mel_vertex = new int*[ne];
for (int i = 0; i < ne; i++) {
mel_vertex[i] = GET_MEMORY(int, mesh->getGeo(VERTEX));
}
for (int i = 0; i < ne; i++)
mel_vertex[i] = new int[mesh->getGeo(VERTEX)];
for (int i = 0; i < nv; i++) {
for (int i = 0; i < nv; i++)
dof[i] = mesh->getDOF(VERTEX);
}
for (int i = 0; i < ne; i++) {
mel[i]->element = mesh->createNewElement();
(mel)[i]->index = i;
if (dim == 3) {
if (dim == 3)
(mel)[i]->elType = 0;
}
}
neigh_set = false;
bound_set = false;
......@@ -389,12 +386,12 @@ namespace AMDiS {
void MacroInfo::clear(int ne, int nv)
{
for (int i = 0; i < mesh->getNumberOfMacros(); i++)
FREE_MEMORY(mel_vertex[i], int, mesh->getGeo(VERTEX));
delete [] mel_vertex[i];
FREE_MEMORY(mel_vertex, int*, ne);
FREE_MEMORY(coords, WorldVector<double>, nv);
delete [] mel_vertex;
delete [] coords;
coords = NULL;
FREE_MEMORY(dof, DegreeOfFreedom*, nv);
delete [] dof;
dof = NULL;
mesh = NULL;
......@@ -417,10 +414,9 @@ namespace AMDiS {
{
int dim = mesh->getDim();
for (int i = 0; i <= dim; i++) {
for (int i = 0; i <= dim; i++)
if (fscanf(file, "%d", &id[i]) != 1)
return(false);
}
return(true);
}
......@@ -846,7 +842,7 @@ namespace AMDiS {
std::deque<MacroElement*>::iterator melIt;
BoundaryType *bound = GET_MEMORY(BoundaryType, nv);
BoundaryType *bound = new BoundaryType[nv];
int dim = mesh->getDim();
......@@ -931,7 +927,7 @@ namespace AMDiS {
default: ERROR_EXIT("invalid dim\n");
}
FREE_MEMORY(bound, BoundaryType, nv);
delete [] bound;
}
void MacroReader::computeNeighbours(Mesh *mesh)
......@@ -1147,9 +1143,9 @@ namespace AMDiS {
}
if (3 == dim) {
mesh->setMaxEdgeNeigh(std::max(8, 2*max_n_neigh));
mesh->setMaxEdgeNeigh(std::max(8, 2 * max_n_neigh));
} else {
mesh->setMaxEdgeNeigh(dim-1);
mesh->setMaxEdgeNeigh(dim - 1);
}
}
......@@ -1173,9 +1169,8 @@ namespace AMDiS {
ERROR("Entries in MacroElement structures get reordered\n");
umb(NULL, mesh, umbVkantMacro);
if (nameneu) {
if (nameneu)
ERROR_EXIT("mesh->feSpace\n");
}
}
}
......@@ -1201,12 +1196,11 @@ namespace AMDiS {
int zykstart;
int dim = mesh->getDim();
test = GET_MEMORY(int, mesh->getNumberOfMacros());
zykl = GET_MEMORY(int, mesh->getNumberOfMacros());
test = new int[mesh->getNumberOfMacros()];
zykl = new int[mesh->getNumberOfMacros()];
for (int i = 0; i < mesh->getNumberOfMacros(); i++) {
for (int i = 0; i < mesh->getNumberOfMacros(); i++)
test[i] = 0;
}
zykstart = -1;
macrolfd = mesh->firstMacroElement();
......@@ -1255,8 +1249,8 @@ namespace AMDiS {
}
}
FREE_MEMORY(zykl, int, mesh->getNumberOfMacros());
FREE_MEMORY(test, int, mesh->getNumberOfMacros());
delete [] zykl;
delete [] test;
return zykstart;
}
......@@ -1285,17 +1279,14 @@ namespace AMDiS {
{
FUNCNAME("MacroReader::umb");
int *test;
int i;
test=GET_MEMORY(int, mesh->getNumberOfMacros());
int *test = new int[mesh->getNumberOfMacros()];
for (i=0; i < static_cast<int>(mesh->getNumberOfMacros()); i++)
test[i]=0;
for (int i = 0; i < static_cast<int>(mesh->getNumberOfMacros()); i++)
test[i] = 0;
recumb(mesh, (*mesh->firstMacroElement()), NULL,test,0,0,ele,umbvk);
recumb(mesh, (*mesh->firstMacroElement()), NULL, test, 0, 0, ele, umbvk);
FREE_MEMORY(test, int, mesh->getNumberOfMacros());
delete [] test;
}
bool MacroReader::newEdge(Mesh *mesh, MacroElement *mel,
......@@ -1714,7 +1705,6 @@ namespace AMDiS {
int *test, double lg, int ka, int *ele,
void (*umbvk)(Mesh *mesh, MacroElement*, int k, int *el))
{
int i;
double l[3];
int v[3];
int k = 0;
......@@ -1729,69 +1719,60 @@ namespace AMDiS {
laengstekante(mel->coord,l,v);
if (v[1] == mesh->getGeo(VERTEX)) /*nur eine laengste Kante*/
{
umbvk(mesh,mel,v[0],ele);
if (v[1] == mesh->getGeo(VERTEX)) { /*nur eine laengste Kante*/
umbvk(mesh, mel, v[0], ele);
for (i=0; i < vertices; i++) {
recumb(mesh,
mel->neighbour[i],
mel,
test,
l[0],
0,
ele,
umbvk);
}
return;
for (int i = 0; i < vertices; i++) {
recumb(mesh,
mel->neighbour[i],
mel,
test,
l[0],
0,
ele,
umbvk);
}
else
{
if (ka == 1)
{
if (fabs((l[0]-lg)/lg) < 0.0000001)
{
for (i=0; i < vertices; i++)
{
if (mel->neighbour[i] == macroalt)
{
k=i;
}
}
return;
} else {
if (ka == 1) {
if (fabs((l[0]-lg)/lg) < 0.0000001) {
for (int i = 0; i < vertices; i++)
if (mel->neighbour[i] == macroalt)
k = i;
umbvk(mesh,mel,k,ele);
umbvk(mesh,mel,k,ele);
for (i=0; i < vertices; i++) {
recumb(mesh,
mel->neighbour[i],
mel,
test,
l[0],
0,
ele,
umbvk);
}
return;
}
for (int i = 0; i < vertices; i++) {
recumb(mesh,
mel->neighbour[i],
mel,
test,
l[0],
0,
ele,
umbvk);
}
return;
}
}
n=const_cast<MacroElement*>(mel->getNeighbour(v[0]));
/*Nachbar an fiktiv verlaengerter Kante*/
</