Commit 407607e4 authored by Claudia Canevari's avatar Claudia Canevari
Browse files

memory management improvement for data flattening

parent 9a671b9e
......@@ -66,10 +66,6 @@ public:
virtual ~MixedCell()
{
/*if (quadric != NULL)
{
deleteVector<double>(quadric);
}*/
}
};
......@@ -83,8 +79,6 @@ public:
virtual ~Del0Cell()
{
// do nothing, planes are not managed by this class
for (unsigned int i = 0; i < planes.size(); i++)
free(planes[i]);
}
};
......@@ -94,36 +88,36 @@ class Del1Cell : public MixedCell
public:
int ids[2]; // the two atoms generating the del edge
vector<double *> planes; // lateral planes
const double *upper;
const double *lower;
virtual ~Del1Cell()
{
for (unsigned int i = 0; i < planes.size(); i++)
free(planes[i]);
// do nothing, pointers are not managed by this class
}
// #IMPROVE one could build pointers from here to the planes computed in Del2Cell or viceversa
// double upper[4]; // upper plane
// double lower[4]; // upper plane
const double *upper;
const double *lower;
};
// del facet cell
class Del2Cell : public MixedCell
{
public:
int ids[3]; // atom indices
double planes[3][4]; // lateral planes
// double upper[4];
// double lower[4];
int ids[3]; // atom indices
const double *upper;
const double *lower;
double **planes; // lateral planes
int nrows = 3;
Del2Cell()
{
planes = (double **)malloc(sizeof(double *) * nrows);
}
virtual ~Del2Cell()
{
// do nothing, no pointers
free(planes);
}
};
......@@ -133,15 +127,21 @@ class Del3Cell : public MixedCell
public:
int ids[4]; // atom indices
// planes of the reduced tethraedron
double planes[4][4];
int nrows = 4;
double **planes;
double planes_or[4][4];
double points[4][3]; // reduced points in the same order of atom indices
double vor[3]; // Voronoi center
double reduced[4][3]; // reduced points in the same order of atom indices
Del3Cell()
{
planes = (double **)malloc(sizeof(double *) * nrows);
}
virtual ~Del3Cell()
{
// do nothing, no pointers
free(planes);
}
};
......
......@@ -330,6 +330,11 @@ bool SkinBuilder::buildSkinCGAL()
free(_SkinSurf->mixedComplex);
}
if (_SkinSurf->_mixedComplex != NULL)
{
delete _SkinSurf->_mixedComplex;
}
l.reserve(_Surf->delphi->atoms.size() + 6);
time_t start, end;
......@@ -490,6 +495,10 @@ bool SkinBuilder::buildSkinCGAL()
tempMixedComplex.push_back(mc);
////////////////////////// store equation and simplex ////////////////////////////////////////////
mc->planes[0] = new double[4];
mc->planes[1] = new double[4];
mc->planes[2] = new double[4];
mc->planes[3] = new double[4];
plane3points(mc->reduced[2], mc->reduced[1], mc->reduced[0], mc->planes[0], false);
plane3points(mc->reduced[3], mc->reduced[2], mc->reduced[0], mc->planes[1], false);
......@@ -1214,6 +1223,7 @@ bool SkinBuilder::buildSkinCGAL()
_SkinSurf->_mixedComplex->uppers.data.push_back(_upper[3]);
// compute the lateral planes and orient
mc->planes[0] = new double[4];
double *plane;
plane = mc->planes[0];
plane3points(mc->mc_points[0], mc->mc_points[1], mc->mc_points[2], plane);
......@@ -1222,6 +1232,7 @@ bool SkinBuilder::buildSkinCGAL()
if (sign > 0)
ASSIGN4(plane, -plane)
mc->planes[1] = new double[4];
plane = mc->planes[1];
plane3points(mc->mc_points[2], mc->mc_points[3], mc->mc_points[4], plane);
// orient
......@@ -1229,6 +1240,7 @@ bool SkinBuilder::buildSkinCGAL()
if (sign > 0)
ASSIGN4(plane, -plane)
mc->planes[2] = new double[4];
plane = mc->planes[2];
plane3points(mc->mc_points[4], mc->mc_points[5], mc->mc_points[0], plane);
// orient
......@@ -1365,6 +1377,7 @@ bool SkinBuilder::buildSkinCGAL()
{
double *plane = mc0->planes[jt];
_SkinSurf->_mixedComplex->planes.push_back(plane, jt, num - 1);
delete[] mc0->planes[jt];
}
}
......@@ -1379,6 +1392,7 @@ bool SkinBuilder::buildSkinCGAL()
{
double *plane = mc1->planes[jt];
_SkinSurf->_mixedComplex->planes.push_back(plane, jt, num - 1);
delete[] mc1->planes[jt];
}
mc1->upper = _SkinSurf->_mixedComplex->uppers.getdata() + k * 4;
......@@ -1387,14 +1401,15 @@ bool SkinBuilder::buildSkinCGAL()
else if ((*it)->surface_type == DELAUNAY_FACET_CELL)
{
int num = 3;
Del2Cell *mc2 = (Del2Cell *)(*it);
int num = 3;
_SkinSurf->_mixedComplex->num_planes.push_back(num);
for (int jt = 0; jt < num; jt++)
{
double *plane = mc2->planes[jt];
_SkinSurf->_mixedComplex->planes.push_back(plane, jt, num - 1);
delete[] mc2->planes[jt];
}
mc2->upper = _SkinSurf->_mixedComplex->uppers.getdata() + k * 4;
......@@ -1403,8 +1418,8 @@ bool SkinBuilder::buildSkinCGAL()
else if ((*it)->surface_type == DELAUNAY_TETRA_CELL)
{
int num = 4;
Del3Cell *mc3 = (Del3Cell *)(*it);
int num = 4;
_SkinSurf->_mixedComplex->num_planes.push_back(num);
double *tmp_planes = new double(num * 4);
......@@ -1412,6 +1427,8 @@ bool SkinBuilder::buildSkinCGAL()
{
double *plane = mc3->planes[jt];
_SkinSurf->_mixedComplex->planes.push_back(plane, jt, num - 1);
delete[] mc3->planes[jt];
}
}
}
......@@ -1428,32 +1445,35 @@ bool SkinBuilder::buildSkinCGAL()
if (savePovRay)
{
ofstream of;
cout << endl
<< INFO << "Saving surface in Pov-Ray in skin.pov...";
cout.flush();
of.open("skin.pov");
of << "#include \"shapes.inc\" ";
of << "\n#include \"colors.inc\" ";
of << "\nglobal_settings {max_trace_level 3}";
of << "\nbackground { color Black }";
of << "\ncamera {";
of << "\n\tlocation <" << mid_x << "," << max_y << "," << mid_z << ">";
of << "\nlook_at <" << mid_x << "," << mid_y << "," << mid_z << "> translate-<" << mid_x << "," << mid_y << "," << mid_z << ">"
<< " rotate<0,0,clock> "
<< "translate<" << mid_x << "," << mid_y << "," << mid_z << ">}";
of << "\nlight_source {<" << mid_x << "," << max_y << "," << mid_z << ">"
<< " color White "
<< "translate-<" << mid_x << "," << mid_y << "," << mid_z << ">"
<< " rotate<0,0,clock> "
<< "translate<" << mid_x << "," << mid_y << "," << mid_z << ">}";
for (int k = 0; k < _SkinSurf->numMixedCells; k++)
if (delphi->getRank() == 0)
{
MixedCell *mc = _SkinSurf->mixedComplex[k];
saveSkinPatch(of, mc, k, l);
ofstream of;
cout << endl
<< INFO << "Saving surface in Pov-Ray in skin.pov...";
cout.flush();
of.open("skin.pov");
of << "#include \"shapes.inc\" ";
of << "\n#include \"colors.inc\" ";
of << "\nglobal_settings {max_trace_level 3}";
of << "\nbackground { color Black }";
of << "\ncamera {";
of << "\n\tlocation <" << mid_x << "," << max_y << "," << mid_z << ">";
of << "\nlook_at <" << mid_x << "," << mid_y << "," << mid_z << "> translate-<" << mid_x << "," << mid_y << "," << mid_z << ">"
<< " rotate<0,0,clock> "
<< "translate<" << mid_x << "," << mid_y << "," << mid_z << ">}";
of << "\nlight_source {<" << mid_x << "," << max_y << "," << mid_z << ">"
<< " color White "
<< "translate-<" << mid_x << "," << mid_y << "," << mid_z << ">"
<< " rotate<0,0,clock> "
<< "translate<" << mid_x << "," << mid_y << "," << mid_z << ">}";
for (int k = 0; k < _SkinSurf->numMixedCells; k++)
{
MixedCell *mc = _SkinSurf->mixedComplex[k];
saveSkinPatch(of, mc, k, l);
}
cout << "ok!";
of.close();
}
cout << "ok!";
of.close();
}
return true;
......
......@@ -674,7 +674,7 @@ bool Surface::getSurf(bool fillCav, double vol)
}
duration = _time.stop();
// MPI_Waitall(NRequests, sendrequests, MPI_STATUSES_IGNORE);
MPI_Waitall(NRequests, sendrequests, MPI_STATUSES_IGNORE);
}
cout << endl;
......
Supports Markdown
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