Commit 880c8d64 authored by Praetorius, Simon's avatar Praetorius, Simon

Helpers

parent 9c22c3a2
......@@ -2,59 +2,9 @@
using namespace AMDiS;
namespace Helpers {
void Helpers::copyDOF(std::vector<DOFVector<double>*> dof1, std::vector<DOFVector<double>*> dof2, WorldVector<double> shift, double fillValue)
{ FUNCNAME("Helpers::copyDOF()");
TEST_EXIT(dof1.size() == dof2.size())("number of components to copy must be the same!\n");
TEST_EXIT(dof1.size() > 0)("Minimum 1 DOFVector to copy\n");
const FiniteElemSpace* feSpace1 = dof1[0]->getFeSpace();
const FiniteElemSpace* feSpace2 = dof2[0]->getFeSpace();
Mesh* mesh1 = feSpace1->getMesh();
Mesh* mesh2 = feSpace2->getMesh();
DOFVector<WorldVector<double> > coords(feSpace2, "coords");
mesh2->getDofIndexCoords(feSpace2, coords);
ElInfo *elInfo = mesh1->createNewElInfo();
MacroElement *oldMacro = NULL;
DimVec<double> lambda(mesh1->getDim(), NO_INIT);
std::vector<DegreeOfFreedom> localIndices; // DOF-indices of all DOFs in trinangle
mtl::dense_vector<double> uh; // evaluation of DOFVectors at QPs
localIndices.resize(feSpace1->getBasisFcts()->getNumber());
uh.change_dim(mesh1->getDim()+1);
MSG("map source-DOFVectors to target mesh...\n");
for (DegreeOfFreedom i = 0; i < coords.getSize(); i++) {
WorldVector<double> x = coords[i]+shift;;
bool inMesh;
if (oldMacro == NULL)
inMesh = mesh1->findElInfoAtPoint(x, elInfo, lambda, NULL, NULL, NULL);
else
inMesh = mesh1->findElInfoAtPoint(x, elInfo, lambda, oldMacro, NULL, NULL);
// calculate values!
for (int j = 0; j < dof1.size(); j++) {
double value = fillValue;
if (inMesh) {
feSpace1->getBasisFcts()->getLocalIndices(elInfo->getElement(), feSpace1->getAdmin(), localIndices);
for (int l = 0; l < lambda.size(); l++)
uh[l] = (*dof1[j])[localIndices[l]];
value = feSpace1->getBasisFcts()->evalUh(lambda, uh);
}
(*dof2[j])[i] = value;
}
oldMacro = elInfo->getMacroElement();
}
};
void Helpers::calcMaxOnXAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima)
void calcMaxOnXAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima)
{ FUNCNAME("Helpers::calcMaxOnXAxis()");
std::vector<WorldVector<double> > x;
......@@ -77,7 +27,7 @@ void Helpers::calcMaxOnXAxis(DOFVector<double> *rho, std::vector<std::pair<World
}
};
void Helpers::calcMaxOnYAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima)
void calcMaxOnYAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima)
{ FUNCNAME("Helpers::calcMaxOnYAxis()");
std::vector<WorldVector<double> > x;
......@@ -102,7 +52,7 @@ void Helpers::calcMaxOnYAxis(DOFVector<double> *rho, std::vector<std::pair<World
};
void Helpers::transformMesh(Mesh *mesh, WorldVector<double> scale, WorldVector<double> shift, WorldVector<double> rotate)
void transformMesh(Mesh *mesh, WorldVector<double> scale, WorldVector<double> shift, WorldVector<double> rotate)
{ FUNCNAME("Helpers::scaleMesh()");
int dow = Global::getGeo(WORLD);
......@@ -153,7 +103,7 @@ void Helpers::transformMesh(Mesh *mesh, WorldVector<double> scale, WorldVector<d
}
};
void Helpers::scaleMesh(Mesh *mesh, WorldVector<double> shift, WorldVector<double> scale)
void scaleMesh(Mesh *mesh, WorldVector<double> shift, WorldVector<double> scale)
{ FUNCNAME("Helpers::scaleMesh()");
deque<MacroElement*>::iterator macro;
......@@ -170,7 +120,7 @@ void Helpers::scaleMesh(Mesh *mesh, WorldVector<double> shift, WorldVector<doubl
};
// scale by different values in all directions
void Helpers::scaleMesh(Mesh *mesh, WorldVector<double> scale)
void scaleMesh(Mesh *mesh, WorldVector<double> scale)
{ FUNCNAME("Helpers::scaleMesh()");
WorldVector<double> shift; shift.set(0.0);
......@@ -178,7 +128,7 @@ void Helpers::scaleMesh(Mesh *mesh, WorldVector<double> scale)
}
// scale by different values in all directions
void Helpers::scaleMesh(std::vector<Mesh*> meshes, WorldVector<double> scale)
void scaleMesh(std::vector<Mesh*> meshes, WorldVector<double> scale)
{ FUNCNAME("Helpers::scaleMesh()");
WorldVector<double> shift; shift.set(0.0);
......@@ -187,7 +137,7 @@ void Helpers::scaleMesh(std::vector<Mesh*> meshes, WorldVector<double> scale)
}
// scale and shift by the same values in all directions
void Helpers::scaleMesh(Mesh *mesh, double shift, double scale)
void scaleMesh(Mesh *mesh, double shift, double scale)
{ FUNCNAME("Helpers::scaleMesh()");
WorldVector<double> wShift, wScale;
......@@ -196,7 +146,7 @@ void Helpers::scaleMesh(Mesh *mesh, double shift, double scale)
scaleMesh(mesh,wShift,wScale);
}
void Helpers::read_dof_vector(const std::string file, DOFVector<double> *dofvec, long size)
void read_dof_vector(const std::string file, DOFVector<double> *dofvec, long size)
{ FUNCNAME("Helpers::read_dof_vector()");
ifstream in;
......@@ -221,7 +171,7 @@ void Helpers::read_dof_vector(const std::string file, DOFVector<double> *dofvec,
throw(std::runtime_error("#vertices != dofIter.size()"));
}
WorldVector<double> Helpers::getMeshDimension(Mesh *mesh)
WorldVector<double> getMeshDimension(Mesh *mesh)
{ FUNCNAME("Helpers::getMeshDimension()");
WorldVector<double> dimension; dimension.set(-1.e10);
......@@ -240,7 +190,7 @@ WorldVector<double> Helpers::getMeshDimension(Mesh *mesh)
return dimension;
}
void Helpers::getMeshDimension(Mesh *mesh, WorldVector<double> &min_corner, WorldVector<double> &max_corner)
void getMeshDimension(Mesh *mesh, WorldVector<double> &min_corner, WorldVector<double> &max_corner)
{ FUNCNAME("Helpers::getMeshDimension()");
max_corner.set(-1.e10);
......@@ -260,7 +210,7 @@ void Helpers::getMeshDimension(Mesh *mesh, WorldVector<double> &min_corner, Worl
}
}
void Helpers::getNormalsWeighted(FiniteElemSpace *feSpace, DOFVector<WorldVector<double> > *normals)
void getNormalsWeighted(FiniteElemSpace *feSpace, DOFVector<WorldVector<double> > *normals)
{
Mesh *mesh = feSpace->getMesh();
const BasisFunction *basisFcts = feSpace->getBasisFcts();
......@@ -301,7 +251,7 @@ void Helpers::getNormalsWeighted(FiniteElemSpace *feSpace, DOFVector<WorldVector
}
}
void Helpers::getNormals(FiniteElemSpace *feSpace, DOFVector<WorldVector<double> > *normals, DOFVector<WorldMatrix<double> > *gradNormals)
void getNormals(FiniteElemSpace *feSpace, DOFVector<WorldVector<double> > *normals, DOFVector<WorldMatrix<double> > *gradNormals)
{
using namespace mtl;
using namespace itl;
......@@ -419,7 +369,7 @@ void Helpers::getNormals(FiniteElemSpace *feSpace, DOFVector<WorldVector<double>
// delete grdDOF;
}
void Helpers::getCurvature(DOFVector<WorldVector<double> >* normals,DOFVector<double>* curvature)
void getCurvature(DOFVector<WorldVector<double> >* normals,DOFVector<double>* curvature)
{
int dim = normals->getFeSpace()->getMesh()->getDim();
int dow = Global::getGeo(WORLD);
......@@ -450,7 +400,7 @@ void Helpers::getCurvature(DOFVector<WorldVector<double> >* normals,DOFVector<do
}
}
void Helpers::process_mem_usage(double& vm_usage, double& resident_set)
void process_mem_usage(double& vm_usage, double& resident_set)
{
using std::ios_base;
using std::ifstream;
......@@ -486,7 +436,7 @@ void Helpers::process_mem_usage(double& vm_usage, double& resident_set)
}
// plots a vector with ascii-code
void Helpers::plot(std::vector<double> &values, int numRows, int numCols, std::string symbol)
void plot(std::vector<double> &values, int numRows, int numCols, std::string symbol)
{
unsigned num=values.size();
unsigned cols=std::min(numCols,(int)num), rows=std::min(numRows,(int)num);
......@@ -522,3 +472,5 @@ void Helpers::plot(std::vector<double> &values, int numRows, int numCols, std::s
for(unsigned i=0;i<lines.size(); ++i)
std::cout<<lines[i]<<std::endl;
}
} // end namespace Helpers
\ No newline at end of file
......@@ -33,8 +33,8 @@ static long random_seed_initial_value = 0;
namespace Helpers {
/// math routines
/// ==============
// math routines
// ==============
inline double cint(double x) {
double intpart;
......@@ -58,8 +58,8 @@ namespace Helpers {
inline bool isPositiv(double val, double tol = DBL_TOL) { return val > -tol; }
inline bool isStrictPositiv(double val, double tol = DBL_TOL) { return val > tol; }
/// routines for conversion to string
/// =================================
// routines for conversion to string
// =================================
template<typename T>
inline std::string toString(const T &value,
......@@ -142,7 +142,7 @@ namespace Helpers {
return std::string(len, c);
}
// process printable string of memory
/// produce printable string of memory
inline std::string memoryToString(double mem, int startIdx = 0) {
int idx = startIdx;
double mem_ = mem;
......@@ -155,29 +155,41 @@ namespace Helpers {
}
/// some mesh routines
/// ===========================
// some mesh routines
// ===========================
/// rotate scale and shift the mesh coordinates
void transformMesh(Mesh *mesh, WorldVector<double> scale, WorldVector<double> shift, WorldVector<double> rotate);
/// scale a vector of meshes by different values in all directions
void scaleMesh(std::vector<Mesh*> meshes, WorldVector<double> scale);
// scale and shift by different values in all directions
/// scale and shift by different values in all directions
void scaleMesh(Mesh *mesh, WorldVector<double> shift, WorldVector<double> scale);
// scale by different values in all directions
/// scale by different values in all directions
void scaleMesh(Mesh *mesh, WorldVector<double> scale);
// scale and shift by the same values in all directions
/// scale and shift by the same values in all directions
void scaleMesh(Mesh *mesh, double shift=0.0, double scale=1.0);
/// calculate the dimension of a mesh
/**
* calculate the dimension of a mesh, by mesh traversal.
* The mthod determines the maximal mesh coordinates and assumes symmetry of the
* mesh around the origin, i.e. mesh = [-rsult, result]
**/
WorldVector<double> getMeshDimension(Mesh *mesh);
/// calculate the dimension of a mesh, by mesh traversal.
void getMeshDimension(Mesh *mesh, WorldVector<double> &min_corner, WorldVector<double> &max_corner);
/// read DOFVector from AMDiS .dat-files
void read_dof_vector(const std::string file, DOFVector<double> *dofvec, long size);
/// some linear algebra methods
/// ===========================
// some linear algebra methods
// ===========================
/// calculate the determant of a 3x3 matrix of type dense2D
inline double determinant(mtl::dense2D<double> &A) // only for 3x3 - matrices
{
if(num_rows(A)==3 && num_cols(A)==3) {
......@@ -187,6 +199,7 @@ namespace Helpers {
return 1.0;
}
/// calculate the determant of a 3x3 matrix of type WorldMatrix
inline double determinant(WorldMatrix<double> &A) // only for 3x3 - matrices
{
if(A.getNumRows()==3 && A.getNumCols()==3) {
......@@ -270,8 +283,10 @@ namespace Helpers {
}
}
/// calculate maxima of DOFVector along line, using interpolOverLine
/// calculate maxima of DOFVector along x-axis, using interpolOverLine
static void calcMaxOnXAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima);
/// calculate maxima of DOFVector along y-axis, using interpolOverLine
static void calcMaxOnYAxis(DOFVector<double> *rho, std::vector<std::pair<WorldVector<double>, double> > &maxima);
/// calc normal vectors of surface from element normals by averaging
......@@ -283,8 +298,8 @@ namespace Helpers {
/// calc curvature from given normal vectors
static void getCurvature(DOFVector<WorldVector<double> >* normals, DOFVector<double>* curvature);
/// misc routines
/// =============
// misc routines
// =============
void plot(std::vector<double> &values, int numRows = 7, int numCols = 20, std::string symbol = "*");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment