Commit 9fdda5e9 authored by Phillip Lino Rall's avatar Phillip Lino Rall
Browse files

fixed memory leaks in sten_matrix copy assignment operator, variable<T> and MG_array<T>

parent 9bec8af0
......@@ -244,7 +244,7 @@ void Variable<DTyp>::QPrint_VTK(QString DateiName, double (*convert)(DTyp x),dou
}
QTextStream Datei(&file);
Datei.setRealNumberPrecision(10);
// for parallel
double* data_coord;
int size, rank;
......
......@@ -111,17 +111,17 @@ Variable<DTyp>::Variable(Blockgrid& blockgrid_ ) :
data_neighbor_edges = new DTyp**[ug->Give_number_edges() ];
for ( int id=0; id<ug->Give_number_edges(); ++id ) {
num_neighbor = ug->Give_edge ( id )->Give_number_neighbors();
if ( ug->Give_edge ( id )->my_object ( my_rank ) ) {
data_neighbor_edges[id] = new DTyp*[num_neighbor];
for ( int i=0; i<num_neighbor; ++i ) {
num_total = blockgrid->Give_Nx_edge ( id ) +1;
totalNumberData = totalNumberData + num_total;
}
} else data_neighbor_edges[id] = NULL;
}
for ( int id=0; id<ug->Give_number_edges(); ++id ) {
num_neighbor = ug->Give_edge ( id )->Give_number_neighbors();
if ( ug->Give_edge ( id )->my_object ( my_rank ) ) {
//data_neighbor_edges[id] = new DTyp*[num_neighbor];
for ( int i=0; i<num_neighbor; ++i ) {
num_total = blockgrid->Give_Nx_edge ( id ) +1;
totalNumberData = totalNumberData + num_total;
}
}// else data_neighbor_edges[id] = NULL;
}
// points
data_points = new DTyp*[ug->Give_number_points() ];
......@@ -224,7 +224,8 @@ Variable<DTyp>::Variable(Blockgrid& blockgrid_ ) :
if ( ug->Give_edge ( id )->my_object ( my_rank ) ) {
data_neighbor_edges[id] = new DTyp*[num_neighbor];
for ( int i=0; i<num_neighbor; ++i ) {
num_total = blockgrid->Give_Nx_edge ( id ) +1;
num_total = blockgrid->Give_Nx_edge ( id ) +1;
data_neighbor_edges[id][i] = &(dataTotal[indexStart]);
indexStart = indexStart + num_total;
......@@ -251,8 +252,8 @@ Variable<DTyp>::Variable(Blockgrid& blockgrid_ ) :
num_total = ug->Give_point ( id )->Give_number_neighbors();
if ( ug->Give_point ( id )->my_object ( my_rank ) ) {
data_neighbor_points[id] = new DTyp[num_total];
data_neighbor_points[id] = &(dataTotal[indexStart]);
//data_neighbor_points[id] = new DTyp[num_total];
data_neighbor_points[id] = &(dataTotal[indexStart]);
indexStart = indexStart + num_total;
......@@ -391,10 +392,10 @@ void Variable<DTyp>::Delete_data() {
}
data_points = NULL;
if ( data_neighbor_points != NULL ) {
delete [] data_neighbor_points;
}
data_neighbor_points = NULL;
if ( data_neighbor_points != NULL ) {
delete [] data_neighbor_points;
}
data_neighbor_points = NULL;
delete [] ug_edge_number_neighbors;
}
......
......@@ -292,6 +292,8 @@ Blockgrid::~Blockgrid()
if ( number_points!=NULL )
delete [] number_points;
number_points = NULL;
if (bg_coord != NULL)
delete bg_coord;
}
int Blockgrid::Give_Nx_hexahedron ( int id ) const
......
......@@ -141,7 +141,7 @@ class Blockgrid {
// Anzahl der Punkte in Richtung i
// i=0, ..., degree_of_freedom()-1
Blockgrid_coordinates * bg_coord;
Blockgrid_coordinates * bg_coord{};
Unstructured_grid *ug;
private:
......
......@@ -167,10 +167,10 @@ D3vector transform_right_lens_inner_quad ( double t1, double t2, double* pointer
if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
{
//cout << "x " << actualX << " y " << actualY <<endl;
if ( fabs(z) > 1e-8)
{
cout << " stop "<<endl;
}
// if ( fabs(z) > 1e-8)
// {
// cout << " stop "<<endl;
// }
}
......@@ -216,10 +216,10 @@ D3vector transform_left_lens_inner_quad ( double t1, double t2, double* pointer_
if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
{
//cout << "x " << actualX << " y " << actualY <<endl;
if ( fabs(z) > 1e-8)
{
cout << " stop "<<endl;
}
// if ( fabs(z) > 1e-8)
// {
// cout << " stop "<<endl;
// }
}
return D3vector (0 , 0 , z);
......@@ -496,10 +496,10 @@ D3vector transform_diag_inner_faces_NE_quad( double t1, double t2, double* point
double z = zRight * (t1) + zLeft * (1-t1) ;
if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
{
if ( fabs(z) > 1e-8)
{
cout << "stop "<<endl;
}
// if ( fabs(z) > 1e-8)
// {
// cout << "stop "<<endl;
// }
}
return D3vector ( 0 ,0 ,z);
......@@ -564,10 +564,10 @@ D3vector transform_diag_inner_faces_NE_quad_cut( double t1, double t2, double* p
double z = zRight * (t1) + zLeft * (1-t1) ;
if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
{
if ( fabs(z) > 1e-8)
{
cout << "stop "<<endl;
}
// if ( fabs(z) > 1e-8)
// {
// cout << "stop "<<endl;
// }
}
return D3vector ( 0 ,0 ,z);
......@@ -613,10 +613,10 @@ D3vector transform_inner_faces_NE_quad( double t1, double t2, double* pointer_gl
if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
{
if ( fabs(z) > 1e-8)
{
cout << "stop "<<endl;
}
// if ( fabs(z) > 1e-8)
// {
// cout << "stop "<<endl;
// }
}
return D3vector ( 0 ,0 ,z);
......@@ -1301,7 +1301,7 @@ Lens_Geometry::Lens_Geometry (double Radius, double thickness, double curvatureL
double inversFocal = (1.5 - 1.0) * ( (1.0 / curvatureLeft) - ( 1.0 / -curvatureRight ) + ( 1.5 - 1.0) * thickness / ( 1.5 * -curvatureRight * curvatureLeft ));
cout << "Focal length of Lens is " << 1.0 / inversFocal << " (assume n = 1.5 ) ." << endl;
// cout << "Focal length of Lens is " << 1.0 / inversFocal << " (assume n = 1.5 ) ." << endl;
pointer_global_data = new double[size_pointer_global_data];
pointer_global_data[0] = Radius;
pointer_global_data[1] = radius;
......@@ -1505,7 +1505,7 @@ Lens_Geometry_Quad::Lens_Geometry_Quad(double Radius, double thickness, double c
double inversFocal = (1.5 - 1.0) * ( (1.0 / curvatureLeft) - ( 1.0 / -curvatureRight ) + ( 1.5 - 1.0) * thickness / ( 1.5 * -curvatureRight * curvatureLeft ));
focalLength_ = 1.0 / inversFocal;
cout << "Focal length of Lens is " << focalLength_ << " (assume n = 1.5 ) ." << endl;
// cout << "Focal length of Lens is " << focalLength_ << " (assume n = 1.5 ) ." << endl;
thickness_ = thickness;
......@@ -1763,7 +1763,7 @@ Lens_Geometry_cutted_edges::Lens_Geometry_cutted_edges(double RadiusLeft, double
double inversFocal = (1.5 - 1.0) * ( (1.0 / curvatureLeft) - ( 1.0 / -curvatureRight ) + ( 1.5 - 1.0) * thickness / ( 1.5 * -curvatureRight * curvatureLeft ));
focalLength_ = 1.0 / inversFocal;
cout << "Focal length of Lens is " << focalLength_ << " (assume n = 1.5 ) ." << endl;
//cout << "Focal length of Lens is " << focalLength_ << " (assume n = 1.5 ) ." << endl;
thickness_ = thickness;
......
......@@ -44,8 +44,7 @@ class Lens_Geometry_Quad : public Unstructured_grid {
class Lens_Geometry_cutted_edges : public Unstructured_grid {
public:
//Lens_Geometry_cutted_edges(double Radius, double thickness, double curvatureLeft, double curvatureRight, double distForCutLeft, double distForCutRight, double edgeThickness, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched = false, double radius = 0.0);
Lens_Geometry_cutted_edges(double RadiusLeft, double RadiusRight, double MechanicalRadiusLeft,double MechanicalRadiusRight, double thickness, double curvatureLeft, double curvatureRight, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched = false, double radius = 0.0);
Lens_Geometry_cutted_edges(double RadiusLeft, double RadiusRight, double MechanicalRadiusLeft,double MechanicalRadiusRight, double thickness, double curvatureLeft, double curvatureRight, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched = false, double radius = 0.0);
~Lens_Geometry_cutted_edges(){};
double getThickness(){return thickness_;};
......
......@@ -89,6 +89,13 @@ Not_constant_direction_marker::Not_constant_direction_marker(Unstructured_grid*
}
}
Not_constant_direction_marker::~Not_constant_direction_marker()
{
delete[] not_const_x;
delete[] not_const_y;
delete[] not_const_z;
}
void Not_constant_direction_marker::Mark_x_as_not_constant_at(int i, bool bb) {
if(i<0 || i>=num_hexahedra)
cout << " error in Constant_direction_marker::Mark_x_as_const_at" << endl;
......@@ -183,6 +190,8 @@ Unstructured_grid::~Unstructured_grid() {
delete all_points;
delete zordering;
if (my_not_constant_directions != NULL)
delete my_not_constant_directions;
}
void Unstructured_grid::Set_number_points(int num_points_) {
......@@ -231,8 +240,6 @@ void Unstructured_grid::Set_hexahedron(int id,
hexahedra[id].Set_id_corner(ENTdir3D,i_ENT);
std::cout << "id " << id << " " << i_WSD << " " << i_ESD << " " << i_WND << " " << i_END << " "
<< i_WST << " " << i_EST << " " << i_WNT << " " << i_ENT<< std::endl;
hexahedra[id].Set_coord(WSDdir3D,points[i_WSD].Give_coordinate());
hexahedra[id].Set_coord(ESDdir3D,points[i_ESD].Give_coordinate());
......
......@@ -64,7 +64,7 @@ void Calculate_corresponding_corners(dir3D_sons corner, dir3D_sons& SED_corner,
class Not_constant_direction_marker {
public:
Not_constant_direction_marker(Unstructured_grid* grid);
~Not_constant_direction_marker();
int stenIndex(int i, int j, int k, int Nx, int Ny, int id) const {
return ((i-1)*not_const_x[id] + ((Nx-2)*not_const_x[id] + 1)*
((j-1)*not_const_y[id] + ((Ny-2)*not_const_y[id] + 1)*
......@@ -300,7 +300,7 @@ class Unstructured_grid : public Partitioning {
std::vector<double> relativeCoordVector;
std::vector<double> construction_lx, construction_ly, construction_lz;
bool constructionBoolArched;
bool constructionBoolPeriodic;
bool constructionBoolPeriodic{false};
bool transformFromQuadrangle;
......
......@@ -34,6 +34,7 @@
#include "../extemp/co_fu.h"
#include "../extemp/functor.h"
#include "interpol.h"
#include "customtime.h"
#include <iomanip>
#include "assert.h"
......@@ -1343,6 +1344,7 @@ PointInterpolator::~PointInterpolator() {
void Interpolate_direct::init()
{
CustomTime::printTime(std::string("A"));
arrayBoxWSDENT.resize(blockgrid->Give_unstructured_grid()->Give_number_hexahedra());
array_box_boundary.resize(blockgrid->Give_unstructured_grid()->Give_number_hexahedra());
......@@ -1499,7 +1501,6 @@ void Interpolate_direct::init()
indexAllFacesOutside.at(4) = filterCorrectNeighbours(indexAllFacesOutside.at(4));
if (indexAllFacesOutside.at(4).empty())
{
//cout << "no outer neighbours here ! " << endl;
correctRelation.at(4) = emptyVector;
}
else
......@@ -1524,7 +1525,6 @@ void Interpolate_direct::init()
indexAllFacesOutside.at(5) = filterCorrectNeighbours(indexAllFacesOutside.at(5));
if (indexAllFacesOutside.at(5).empty())
{
//cout << "no outer neighbours here ! " << endl;
correctRelation.at(5) = emptyVector;
}
else
......@@ -1689,7 +1689,11 @@ void Interpolate_direct::init()
std::vector<std::vector<int> > Interpolate_direct::calculateNeighbourIndexRelation(std::vector<std::vector<int> > inner, std::vector<std::vector<int> > outer)
{
// 1 : find index which does not change --> not part of the boundary
//cout << "checking ... " << endl;
if (outer.size() != inner.size())
{
cout << "ops " << endl;
}
std::vector<int> diffToAdd(4);
std::vector<int> IndexToInvert(4);
std::vector<int> IndexToSwitch(4);
......@@ -1738,7 +1742,6 @@ std::vector<std::vector<int> > Interpolate_direct::calculateNeighbourIndexRelati
}
diffToAdd.at(indexNotAtBoundaryInner) = outer.front().at(indexNotAtBoundaryOuter) - inner.front().at(indexNotAtBoundaryInner);
retVal.push_back(diffToAdd);
//return std::vector< int >(0);
//check index, which does NOT change and calculate difference
//case 1 :: 0 invert and 0 rotation
......@@ -2546,13 +2549,23 @@ std::vector<int> Interpolate_direct::calculateNeighbourIndex(std::vector<std::ve
std::vector<std::vector <int> > Interpolate_direct::filterCorrectNeighbours(std::vector<std::vector<int> > outer)
{
//filter wrong Neighbours (from other side)
// cout << "outer size " << outer.size() << endl;
// for (int iterInner = 0; iterInner < outer.size(); iterInner++)
// {
// for (int iterI = 0; iterI < outer.at(iterInner).size(); iterI++)
// {
// cout << outer.at(iterInner).at(iterI) << " ";
// }
// cout << "\n";
// }
// cout << endl;
std::vector<int> sumHasToBeFour(blockgrid->Give_unstructured_grid()->Give_number_hexahedra());
std::vector<std::vector<int > > outerCorrect(0);
for (int iterOutside = 0 ; iterOutside < outer.size() ; iterOutside++ )
{
sumHasToBeFour.at(outer.at(iterOutside).at(0))++;
}
int correctNeighbourHex;
int correctNeighbourHex{-1};
for (int iterOutside = 0 ; iterOutside < sumHasToBeFour.size() ; iterOutside++ )
{
if (sumHasToBeFour.at(iterOutside) == 4)
......@@ -2568,6 +2581,10 @@ std::vector<std::vector <int> > Interpolate_direct::filterCorrectNeighbours(std:
outerCorrect.push_back(outer.at(iterOutside));
}
}
if (outerCorrect.size() != 4 && outerCorrect.size() != 0)
{
cout << "size has to be 4 or 0, but isnt"<< endl;
}
return outerCorrect;
}
......
......@@ -342,35 +342,7 @@ private:
***/
class Interpolate_direct {
public:
Interpolate_direct (Blockgrid* bg):blockgrid(bg)
,idHexPrev(-1)
,iPrev(-1)
,jPrev(-1)
,kPrev(-1)
,idHexPrevPrev(-1)
,iPrevPrev(-1)
,jPrevPrev(-1)
,kPrevPrev(-1)
,idHexPrevPrevPrev(-1)
,iPrevPrevPrev(-1)
,jPrevPrevPrev(-1)
,kPrevPrevPrev(-1)
,counterFast(0)
,counterFastest(0)
,counterSamePoint(0)
,counterSecondTry(0)
,counterThirdTry(0)
,counterSlow(0)
,counterHexa(0)
,checkCounter(0)
,counterEdge(0)
,counterCorner(0)
,typCounter0(0)
,typCounter1(0)
,typCounter2(0)
,typCounter3(0)
,typCounter4(0)
,typCounter5(0){}
Interpolate_direct (Blockgrid* bg):blockgrid(bg){}
/**
* preparation for interpolation : calculates the neighbour index for each cell.
......@@ -401,10 +373,10 @@ class Interpolate_direct {
template <class DTyp>
DTyp evaluate(Variable<DTyp>& u);
int counterFast, counterFastest, counterSamePoint, counterSecondTry, counterThirdTry, counterSlow, counterHexa, counterCorner, counterEdge;
int checkCounter;
int boxCounter = 0;
int typCounter0,typCounter1,typCounter2,typCounter3,typCounter4,typCounter5;
int counterFast{}, counterFastest{}, counterSamePoint{}, counterSecondTry{}, counterThirdTry{}, counterSlow{}, counterHexa{}, counterCorner{}, counterEdge{};
int checkCounter{};
int boxCounter{};
int typCounter0{},typCounter1{},typCounter2{},typCounter3{},typCounter4{},typCounter5{};
bool debugTest;
D3vector lambda;
D3vector vNow, vPrev, vPrevPrev, vPrevPrevPrev;
......@@ -413,10 +385,10 @@ class Interpolate_direct {
bool vectorInBox(D3vector vWSD, D3vector vENT, D3vector v, double eps = 1e-10);
int checkBox(int idHex, int i, int j, int k, D3vector v);
private:
int idHexPrev, iPrev, jPrev, kPrev;
int idHexPrevPrevPrev, iPrevPrevPrev, jPrevPrevPrev, kPrevPrevPrev;
int idHexPrevPrev, iPrevPrev, jPrevPrev, kPrevPrev;
int idHexNow, iNow, jNow, kNow;
int idHexPrev{-1}, iPrev{-1}, jPrev{-1}, kPrev{-1};
int idHexPrevPrevPrev{-1}, iPrevPrevPrev{-1}, jPrevPrevPrev{-1}, kPrevPrevPrev{-1};
int idHexPrevPrev{-1}, iPrevPrev{-1}, jPrevPrev{-1}, kPrevPrev{-1};
int idHexNow{-1}, iNow{-1}, jNow{-1}, kNow{-1};
double lamLowerLimit{-0.1};
double lamUpperLimit{1.1};
......
......@@ -32,6 +32,7 @@ template <class T>
class MG_array {
public:
MG_array(int l);
~MG_array();
Set_MG_array<T> operator() (int i);
T& operator[] (int i);
T* &get(int i);
......@@ -67,6 +68,16 @@ MG_array<T>::MG_array(int l) {
}
}
template<class T>
MG_array<T>::~MG_array(){
for(int i=0;i<L;++i)
{
delete this->get(i);
}
delete[] MG_obj;
delete[] set;
}
template <class T>
T* &MG_array<T>::get(int i) {
assert(i>=0 && i<L);
......
......@@ -997,7 +997,7 @@ void Sten_matrix<TYPE2, STENCIL_TYP>::operator= ( const Local_stiffness_matrix<T
if ( ug->Give_point ( id )->my_object ( my_rank ) ) {
N_total = ug->Give_point ( id )->Give_number_neighbors_hex() * 8;
loc_m_neighbor_points[id] = new TYPE2[N_total];
//loc_m_neighbor_points[id] = new TYPE2[N_total];
for(int i = 0;i < N_total;++i )
loc_m_neighbor_points[id][i] = local_stiffness_matrix.Give_loc_m_neighbor_points ( id ) [i];
......
......@@ -180,8 +180,7 @@ Sten_matrix<TYPE2, STENCIL_TYP>::~Sten_matrix()
if (loc_m_neighbor_edges != NULL) {
for (int id=0;id<blockgrid->Give_unstructured_grid()->Give_number_edges();++id)
if (loc_m_neighbor_edges[id] != NULL) {
for (int num=0;num<blockgrid->Give_unstructured_grid()
->Give_edge(id)->Give_number_neighbors_hex();++num)
for (int num=0;num<blockgrid->Give_unstructured_grid()->Give_edge(id)->Give_number_neighbors_hex();++num)
if (loc_m_neighbor_edges[id][num] != NULL)
delete [] loc_m_neighbor_edges[id][num];
delete [] loc_m_neighbor_edges[id];
......
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