Commit 639f286f authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Global::getGeo optimized by precalculation

* added ifdef OPENMP to delete warning during compilation
parent b8cd3cef
...@@ -680,8 +680,6 @@ namespace AMDiS { ...@@ -680,8 +680,6 @@ namespace AMDiS {
void Pre0::calculateElementMatrix(const ElInfo *elInfo, ElementMatrix *mat) void Pre0::calculateElementMatrix(const ElInfo *elInfo, ElementMatrix *mat)
{ {
double *c = GET_MEMORY(double, 1);
if (firstCall) { if (firstCall) {
q00 = Q00PsiPhi::provideQ00PsiPhi(owner->getRowFESpace()->getBasisFcts(), q00 = Q00PsiPhi::provideQ00PsiPhi(owner->getRowFESpace()->getBasisFcts(),
owner->getColFESpace()->getBasisFcts(), owner->getColFESpace()->getBasisFcts(),
...@@ -691,20 +689,22 @@ namespace AMDiS { ...@@ -691,20 +689,22 @@ namespace AMDiS {
firstCall = false; firstCall = false;
} }
c[0] = 0.0; // c[0] = 0.0;
double c = 0.0;
int myRank = omp_get_thread_num(); int myRank = omp_get_thread_num();
int size = static_cast<int>(terms[myRank].size());
for (int i = 0; i < static_cast<int>( terms[myRank].size()); i++) { for (int i = 0; i < size; i++) {
(static_cast<ZeroOrderTerm*>((terms[myRank][i])))->getC(elInfo, 1, c); (static_cast<ZeroOrderTerm*>((terms[myRank][i])))->getC(elInfo, 1, &c);
} }
c[0] *= elInfo->getDet(); c *= elInfo->getDet();
if (symmetric) { if (symmetric) {
for (int i = 0; i < nRow; i++) { for (int i = 0; i < nRow; i++) {
(*mat)[i][i] += c[0] * q00->getValue(i,i); (*mat)[i][i] += c * q00->getValue(i,i);
for (int j = i + 1; j < nCol; j++) { for (int j = i + 1; j < nCol; j++) {
double val = c[0] * q00->getValue(i, j); double val = c * q00->getValue(i, j);
(*mat)[i][j] += val; (*mat)[i][j] += val;
(*mat)[j][i] += val; (*mat)[j][i] += val;
} }
...@@ -712,16 +712,12 @@ namespace AMDiS { ...@@ -712,16 +712,12 @@ namespace AMDiS {
} else { } else {
for (int i = 0; i < nRow; i++) for (int i = 0; i < nRow; i++)
for (int j = 0; j < nCol; j++) for (int j = 0; j < nCol; j++)
(*mat)[i][j] += c[0]*q00->getValue(i,j); (*mat)[i][j] += c * q00->getValue(i, j);
} }
FREE_MEMORY(c, double, 1);
} }
void Pre0::calculateElementVector(const ElInfo *elInfo, ElementVector *vec) void Pre0::calculateElementVector(const ElInfo *elInfo, ElementVector *vec)
{ {
double *c = GET_MEMORY(double, 1);
if (firstCall) { if (firstCall) {
q00 = Q00PsiPhi::provideQ00PsiPhi(owner->getRowFESpace()->getBasisFcts(), q00 = Q00PsiPhi::provideQ00PsiPhi(owner->getRowFESpace()->getBasisFcts(),
owner->getColFESpace()->getBasisFcts(), owner->getColFESpace()->getBasisFcts(),
...@@ -734,17 +730,15 @@ namespace AMDiS { ...@@ -734,17 +730,15 @@ namespace AMDiS {
::std::vector<OperatorTerm*>::iterator termIt; ::std::vector<OperatorTerm*>::iterator termIt;
int myRank = omp_get_thread_num(); int myRank = omp_get_thread_num();
c[0] = 0.0; double c = 0.0;
for (termIt = terms[myRank].begin(); termIt != terms[myRank].end(); ++termIt) { for (termIt = terms[myRank].begin(); termIt != terms[myRank].end(); ++termIt) {
(static_cast<ZeroOrderTerm*>( *termIt))->getC(elInfo, 1, c); (static_cast<ZeroOrderTerm*>( *termIt))->getC(elInfo, 1, &c);
} }
c[0] *= elInfo->getDet(); c *= elInfo->getDet();
for (int i = 0; i < nRow; i++) for (int i = 0; i < nRow; i++)
(*vec)[i] += c[0] * q0->getValue(i); (*vec)[i] += c * q0->getValue(i);
FREE_MEMORY(c, double, 1);
} }
Stand10::Stand10(Operator *op, Assembler *assembler, Quadrature *quad) Stand10::Stand10(Operator *op, Assembler *assembler, Quadrature *quad)
......
...@@ -35,7 +35,7 @@ namespace AMDiS { ...@@ -35,7 +35,7 @@ namespace AMDiS {
{ {
TEST_EXIT(rowFESpace)("no rowFESpace\n"); TEST_EXIT(rowFESpace)("no rowFESpace\n");
if(!colFESpace) { if (!colFESpace) {
colFESpace = rowFESpace; colFESpace = rowFESpace;
} }
...@@ -57,7 +57,7 @@ namespace AMDiS { ...@@ -57,7 +57,7 @@ namespace AMDiS {
{ {
FUNCNAME("DOFMatrix::~DOFMatrix()"); FUNCNAME("DOFMatrix::~DOFMatrix()");
if(rowFESpace && rowFESpace->getAdmin()) { if (rowFESpace && rowFESpace->getAdmin()) {
(const_cast<DOFAdmin*>(rowFESpace->getAdmin()))->removeDOFIndexed(this); (const_cast<DOFAdmin*>(rowFESpace->getAdmin()))->removeDOFIndexed(this);
} }
} }
......
...@@ -33,11 +33,7 @@ namespace AMDiS { ...@@ -33,11 +33,7 @@ namespace AMDiS {
for (int i = 0; i < vertices; i++) { for (int i = 0; i < vertices; i++) {
coord_[i] = mel->coord[i]; coord_[i] = mel->coord[i];
} }
} }
// if(fillFlag_.isSet(Mesh::FILL_DET) || fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
// det = elGrdLambda(*Lambda);
// }
if (fillFlag_.isSet(Mesh::FILL_NEIGH) || fillFlag_.isSet(Mesh::FILL_OPP_COORDS)) { if (fillFlag_.isSet(Mesh::FILL_NEIGH) || fillFlag_.isSet(Mesh::FILL_OPP_COORDS)) {
WorldVector<double> oppC; WorldVector<double> oppC;
...@@ -221,10 +217,6 @@ namespace AMDiS { ...@@ -221,10 +217,6 @@ namespace AMDiS {
} }
} }
// if(fillFlag_.isSet(Mesh::FILL_DET) || fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
// det = calcGrdLambda(*Lambda);
// }
if (fillFlag_.isSet(Mesh::FILL_NEIGH) || fillFlag_.isSet(Mesh::FILL_OPP_COORDS)) { if (fillFlag_.isSet(Mesh::FILL_NEIGH) || fillFlag_.isSet(Mesh::FILL_OPP_COORDS)) {
WorldVector<double> oppC; WorldVector<double> oppC;
......
...@@ -348,7 +348,6 @@ namespace AMDiS { ...@@ -348,7 +348,6 @@ namespace AMDiS {
{ {
FUNCNAME("ElInfo3d::fillElInfo()"); FUNCNAME("ElInfo3d::fillElInfo()");
int el_type_local = 0; /* el_type in {0,1,2} */
int ochild = 0; /* index of other child = 1-ichild */ int ochild = 0; /* index of other child = 1-ichild */
int *cv = NULL; /* cv = child_vertex[el_type][ichild] */ int *cv = NULL; /* cv = child_vertex[el_type][ichild] */
const int (*cvg)[4] = NULL; /* cvg = child_vertex[el_type] */ const int (*cvg)[4] = NULL; /* cvg = child_vertex[el_type] */
...@@ -370,12 +369,12 @@ namespace AMDiS { ...@@ -370,12 +369,12 @@ namespace AMDiS {
fillFlag_ = fillFlag__local; fillFlag_ = fillFlag__local;
parent_ = el_old; parent_ = el_old;
level_ = elinfo_old->level_ + 1; level_ = elinfo_old->level_ + 1;
el_type = (( dynamic_cast<ElInfo3d*>(const_cast<ElInfo*>( elinfo_old)))->el_type + 1) % 3; int el_type_local = ( dynamic_cast<ElInfo3d*>(const_cast<ElInfo*>( elinfo_old)))->getType();
el_type = (el_type_local + 1) % 3;
TEST_EXIT_DBG(element_)("missing child %d?\n", ichild); TEST_EXIT_DBG(element_)("missing child %d?\n", ichild);
if (fillFlag__local.isAnySet()) { if (fillFlag__local.isAnySet()) {
el_type_local = ( dynamic_cast<ElInfo3d*>(const_cast<ElInfo*>( elinfo_old)))->getType();
cvg = Tetrahedron::childVertex[el_type_local]; cvg = Tetrahedron::childVertex[el_type_local];
cv = const_cast<int*>( cvg[ichild]); cv = const_cast<int*>( cvg[ichild]);
ochild = 1 - ichild; ochild = 1 - ichild;
......
...@@ -81,13 +81,6 @@ namespace AMDiS { ...@@ -81,13 +81,6 @@ namespace AMDiS {
*/ */
double getNormal(int side, WorldVector<double> &normal) const; double getNormal(int side, WorldVector<double> &normal) const;
/** \brief
* 3-dimensional realisation of ElInfo's getElementNormal method.
*/
//double getElementNormal( WorldVector<double> &normal) const;
/** \brief /** \brief
* update ElInfo after refinement (of some neighbours). Only in 3d! * update ElInfo after refinement (of some neighbours). Only in 3d!
*/ */
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "Flag.h" #include "Flag.h"
#include "ElInfo.h" #include "ElInfo.h"
#include "Mesh.h" #include "Mesh.h"
#include "OpenMP.h"
namespace AMDiS { namespace AMDiS {
...@@ -150,6 +151,10 @@ namespace AMDiS { ...@@ -150,6 +151,10 @@ namespace AMDiS {
GET_PARAMETER(0, name + "->index decimals", "%d", &indexDecimals); GET_PARAMETER(0, name + "->index decimals", "%d", &indexDecimals);
GET_PARAMETER(0, name + "->write every i-th timestep", "%d", &tsModulo); GET_PARAMETER(0, name + "->write every i-th timestep", "%d", &tsModulo);
GET_PARAMETER(0, name + "->delay", "%d", &delayWriting_); GET_PARAMETER(0, name + "->delay", "%d", &delayWriting_);
TEST_EXIT(!delayWriting_ || amdisHaveOpenMP)
("Delayed writing only possible with OpenMP support!\n");
} }
void FileWriter::writeFiles(AdaptInfo *adaptInfo, void FileWriter::writeFiles(AdaptInfo *adaptInfo,
......
...@@ -13,14 +13,18 @@ namespace AMDiS { ...@@ -13,14 +13,18 @@ namespace AMDiS {
const char *funcName = NULL; const char *funcName = NULL;
const char *Msg::oldFuncName = NULL; const char *Msg::oldFuncName = NULL;
::std::ostream* Msg::out=NULL; ::std::ostream* Msg::out = NULL;
::std::ostream* Msg::error=NULL; ::std::ostream* Msg::error = NULL;
int Global::dimOfWorld = 0; int Global::dimOfWorld = 0;
::std::vector< ::std::vector< int > > Global::geoIndexTable;
int Msg::msgInfo = 10; int Msg::msgInfo = 10;
bool Msg::msgWait = true; bool Msg::msgWait = true;
Element *Global::referenceElement[4] = Element *Global::referenceElement[4] =
{ NULL, NEW Line(NULL), NEW Triangle(NULL), NEW Tetrahedron(NULL) }; { NULL,
NEW Line(NULL),
NEW Triangle(NULL),
NEW Tetrahedron(NULL) };
void Msg::wait(bool w) void Msg::wait(bool w)
{ {
...@@ -55,99 +59,87 @@ namespace AMDiS { ...@@ -55,99 +59,87 @@ namespace AMDiS {
void Msg::open_file(const char *filename, OPENMODE type) void Msg::open_file(const char *filename, OPENMODE type)
{ {
FUNCNAME("Msg::open_file"); FUNCNAME("Msg::open_file()");
::std::ofstream *fp; ::std::ofstream *fp;
if (filename && (fp = new ::std::ofstream(filename, type))) if (filename && (fp = new ::std::ofstream(filename, type))) {
{ if (out && *out != ::std::cout && *out != ::std::cerr) {
if (out && *out != ::std::cout && *out != ::std::cerr) dynamic_cast< ::std::ofstream*>(out)->close();
{ delete out;
dynamic_cast< ::std::ofstream*>(out)->close();
delete out;
}
out = fp;
}
else
{
if (filename)
ERROR("can not open %s;\n", filename);
else
ERROR("no filename specified;\n");
ERROR("use previous stream for messages furthermore\n");
} }
out = fp;
} else {
if (filename)
ERROR("can not open %s;\n", filename);
else
ERROR("no filename specified;\n");
ERROR("use previous stream for messages furthermore\n");
}
return; return;
} }
void Msg::change_error_out(::std::ofstream *fp) void Msg::change_error_out(::std::ofstream *fp)
{ {
FUNCNAME("Msg::change_error_out"); FUNCNAME("Msg::change_error_out()");
if (fp)
{ if (fp) {
if (error && *error != ::std::cout && *error != ::std::cerr) if (error && *error != ::std::cout && *error != ::std::cerr) {
{ dynamic_cast< ::std::ofstream*>(error)->close();
dynamic_cast< ::std::ofstream*>(error)->close(); delete error;
delete error;
}
error = fp;
}
else
{
ERROR("file pointer is pointer to nil;\n");
ERROR("use previous stream for errors furthermore\n");
} }
error = fp;
} else {
ERROR("file pointer is pointer to nil;\n");
ERROR("use previous stream for errors furthermore\n");
}
return; return;
} }
void Msg::open_error_file(const char *filename, OPENMODE type) void Msg::open_error_file(const char *filename, OPENMODE type)
{ {
FUNCNAME("Msg::open_error_file"); FUNCNAME("Msg::open_error_file()");
::std::ofstream *fp; ::std::ofstream *fp;
if (filename && (fp = new ::std::ofstream(filename, type))) if (filename && (fp = new ::std::ofstream(filename, type))) {
{ if (error && *error != ::std::cout && *error != ::std::cerr) {
if (error && *error != ::std::cout && *error != ::std::cerr) dynamic_cast< ::std::ofstream*>(error)->close();
{ delete error;
dynamic_cast< ::std::ofstream*>(error)->close();
delete error;
}
error = fp;
}
else
{
if (filename)
ERROR("can not open %s;\n", filename);
else
ERROR("no filename specified;\n");
ERROR("use previous stream for errors furthermore\n");
} }
error = fp;
} else {
if (filename)
ERROR("can not open %s;\n", filename);
else
ERROR("no filename specified;\n");
ERROR("use previous stream for errors furthermore\n");
}
return; return;
} }
const char *generate_filename(const char * path, const char * fn, int ntime) const char *generate_filename(const char * path, const char * fn, int ntime)
{ {
static char name[256]; static char name[256];
char *cp; char *cp;
if (path == NULL || path[0] == '\0') if (path == NULL || path[0] == '\0') {
{ sprintf(name, "./%s", fn);
sprintf(name, "./%s", fn); } else {
} const char* ccp = path;
else while (*ccp)
{ ccp++;
const char* ccp = path; ccp--;
while (*ccp) if (*ccp == '/')
ccp++; sprintf(name, "%s%s", path, fn);
ccp--; else
if (*ccp == '/') sprintf(name, "%s/%s", path, fn);
sprintf(name, "%s%s", path, fn); }
else
sprintf(name, "%s/%s", path, fn);
}
cp = name; cp = name;
while (*cp) while (*cp)
cp++; cp++;
...@@ -159,7 +151,8 @@ namespace AMDiS { ...@@ -159,7 +151,8 @@ namespace AMDiS {
void Msg::print_funcname(const char *funcName) void Msg::print_funcname(const char *funcName)
{ {
if (!out) out = &::std::cout; if (!out)
out = &::std::cout;
if (funcName && oldFuncName != funcName) { if (funcName && oldFuncName != funcName) {
(*out)<< funcName << ":" << ::std::endl; (*out)<< funcName << ":" << ::std::endl;
...@@ -176,29 +169,32 @@ namespace AMDiS { ...@@ -176,29 +169,32 @@ namespace AMDiS {
{ {
static int old_line = -1; static int old_line = -1;
if (!error) error = &::std::cerr; if (!error)
error = &::std::cerr;
if (funcName && oldFuncName != funcName) { if (funcName && oldFuncName != funcName) {
(*error)<<funcName<< ": "; (*error)<<funcName<< ": ";
} }
else if (!funcName) { else if (!funcName) {
if (line-old_line > 5) (*error)<< "*unknown function*"; if (line-old_line > 5)
(*error) << "*unknown function*";
} }
if (oldFuncName != funcName) { if (oldFuncName != funcName) {
(*error)<<"ERROR in "<<file<<", line "<<line<<"\n"; (*error) << "ERROR in " << file << ", line " << line << "\n";
oldFuncName = funcName; oldFuncName = funcName;
} else if (line - old_line > 5) } else if (line - old_line > 5)
(*error)<< "ERROR in "<<file<<", line "<<line<<"\n"; (*error) << "ERROR in " << file << ", line " << line << "\n";
old_line = line; old_line = line;
} }
void Msg::print_error_exit(const char *format, ...) void Msg::print_error_exit(const char *format, ...)
{ {
va_list arg; va_list arg;
char buff[255]; char buff[255];
if (!error) error = &::std::cerr; if (!error)
error = &::std::cerr;
va_start(arg, format); va_start(arg, format);
vsprintf(buff, format, arg); vsprintf(buff, format, arg);
...@@ -210,11 +206,12 @@ namespace AMDiS { ...@@ -210,11 +206,12 @@ namespace AMDiS {
void Msg::print_error(const char *format, ...) void Msg::print_error(const char *format, ...)
{ {
va_list arg; va_list arg;
char buff[255]; char buff[255];
if (!error) error = &::std::cerr; if (!error)
error = &::std::cerr;
va_start(arg, format); va_start(arg, format);
vsprintf(buff, format, arg); vsprintf(buff, format, arg);
...@@ -228,31 +225,33 @@ namespace AMDiS { ...@@ -228,31 +225,33 @@ namespace AMDiS {
const char *file, const char *file,
int line) int line)
{ {
static int old_line = -1; static int old_line = -1;
if (!out) out = &::std::cout; if (!out)
out = &::std::cout;
if (funcName && oldFuncName != funcName) { if (funcName && oldFuncName != funcName) {
(*out)<<funcName<<": "; (*out) << funcName << ": ";
} }
else if (!funcName){ else if (!funcName){
(*out)<< "*unknown function*"; (*out) << "*unknown function*";
} }
if (oldFuncName != funcName) { if (oldFuncName != funcName) {
(*out)<<"WARNING in "<<file<<", line "<<line<<"\n"; (*out) << "WARNING in " << file << ", line " << line << "\n";
oldFuncName = funcName; oldFuncName = funcName;
} else if (line - old_line > 5) } else if (line - old_line > 5)
(*out)<<"WARNING in "<<file<<", line "<<line<<"\n"; (*out) << "WARNING in " << file << ", line " << line << "\n";
old_line = line; old_line = line;
} }
void Msg::print_warn(const char *format, ...) void Msg::print_warn(const char *format, ...)
{ {
va_list arg; va_list arg;
char buff[255]; char buff[255];
if (!out) out = &::std::cout; if (!out)
out = &::std::cout;
va_start(arg, format); va_start(arg, format);
vsprintf(buff, format, arg); vsprintf(buff, format, arg);
...@@ -265,15 +264,15 @@ namespace AMDiS { ...@@ -265,15 +264,15 @@ namespace AMDiS {