Skip to content
Snippets Groups Projects
Commit 0393b61d authored by Jean-François Remacle's avatar Jean-François Remacle
Browse files

use stl::list for a better memory management

parent 6a76fe8d
No related branches found
No related tags found
No related merge requests found
...@@ -61,12 +61,12 @@ static void printInterpLc(const char *name) ...@@ -61,12 +61,12 @@ static void printInterpLc(const char *name)
fclose(f); fclose(f);
} }
static void buildInterpLc(List_T *lcPoints) static void buildInterpLc(const std::vector<IntPoint> &lcPoints)
{ {
IntPoint p; IntPoint p;
interpLc.clear(); interpLc.clear();
for(int i = 0; i < List_Nbr(lcPoints); i++){ for(int i = 0; i < lcPoints.size(); i++){
List_Read(lcPoints, i, &p); p=lcPoints[i];
interpLc.push_back(xi2lc( p.t, p.lc)); interpLc.push_back(xi2lc( p.t, p.lc));
} }
} }
...@@ -197,7 +197,7 @@ static double trapezoidal(IntPoint * P1, IntPoint * P2) ...@@ -197,7 +197,7 @@ static double trapezoidal(IntPoint * P1, IntPoint * P2)
} }
static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to, static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to,
double (*f) (GEdge *e, double X), List_T * pPoints, double (*f) (GEdge *e, double X), std::vector<IntPoint> &Points,
double Prec, int *depth) double Prec, int *depth)
{ {
IntPoint P, p1; IntPoint P, p1;
...@@ -213,17 +213,18 @@ static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to, ...@@ -213,17 +213,18 @@ static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to,
double err = fabs(val1 - val2 - val3); double err = fabs(val1 - val2 - val3);
if(((err < Prec) && (*depth > 1)) || (*depth > 25)) { if(((err < Prec) && (*depth > 1)) || (*depth > 25)) {
List_Read(pPoints, List_Nbr(pPoints) - 1, &p1); p1=Points.back();
P.p = p1.p + val2; P.p = p1.p + val2;
List_Add(pPoints, &P); Points.push_back(P);
List_Read(pPoints, List_Nbr(pPoints) - 1, &p1); //List_Read(pPoints, List_Nbr(pPoints) - 1, &p1);
to->p=P.p+val3;
to->p = p1.p + val3; to->p = p1.p + val3;
List_Add(pPoints, to); Points.push_back(*to);
} }
else { else {
RecursiveIntegration(ge, from, &P, f, pPoints, Prec, depth); RecursiveIntegration(ge, from, &P, f, Points, Prec, depth);
RecursiveIntegration(ge, &P, to, f, pPoints, Prec, depth); RecursiveIntegration(ge, &P, to, f, Points, Prec, depth);
} }
(*depth)--; (*depth)--;
...@@ -231,7 +232,7 @@ static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to, ...@@ -231,7 +232,7 @@ static void RecursiveIntegration(GEdge *ge, IntPoint * from, IntPoint * to,
static double Integration(GEdge *ge, double t1, double t2, static double Integration(GEdge *ge, double t1, double t2,
double (*f) (GEdge *e, double X), double (*f) (GEdge *e, double X),
List_T * pPoints, double Prec) std::vector<IntPoint>&Points, double Prec)
{ {
IntPoint from, to; IntPoint from, to;
...@@ -240,14 +241,13 @@ static double Integration(GEdge *ge, double t1, double t2, ...@@ -240,14 +241,13 @@ static double Integration(GEdge *ge, double t1, double t2,
from.t = t1; from.t = t1;
from.lc = f(ge, from.t); from.lc = f(ge, from.t);
from.p = 0.0; from.p = 0.0;
List_Add(pPoints, &from); Points.push_back(from);
to.t = t2; to.t = t2;
to.lc = f(ge, to.t); to.lc = f(ge, to.t);
RecursiveIntegration(ge, &from, &to, f, pPoints, Prec, &depth); RecursiveIntegration(ge, &from, &to, f, Points, Prec, &depth);
List_Read(pPoints, List_Nbr(pPoints) - 1, &to); return Points.back().p;
return to.p;
} }
void deMeshGEdge::operator() (GEdge *ge) void deMeshGEdge::operator() (GEdge *ge)
...@@ -281,9 +281,7 @@ void meshGEdge::operator() (GEdge *ge) ...@@ -281,9 +281,7 @@ void meshGEdge::operator() (GEdge *ge)
Msg::Info("Meshing curve %d (%s)", ge->tag(), ge->getTypeString().c_str()); Msg::Info("Meshing curve %d (%s)", ge->tag(), ge->getTypeString().c_str());
// Create a list of integration points // Create a list of integration points
List_T *Points = List_Create(10, 10, sizeof(IntPoint)); std::vector<IntPoint> Points,lcPoints;
// Create a list of points for interpolating the LC Field
List_T *lcPoints = List_Create(10, 10, sizeof(IntPoint));
// compute bounds // compute bounds
Range<double> bounds = ge->parBounds(0); Range<double> bounds = ge->parBounds(0);
...@@ -296,8 +294,7 @@ void meshGEdge::operator() (GEdge *ge) ...@@ -296,8 +294,7 @@ void meshGEdge::operator() (GEdge *ge)
if(length == 0.0) if(length == 0.0)
Msg::Debug("Curve %d has a zero length", ge->tag()); Msg::Debug("Curve %d has a zero length", ge->tag());
Points.resize(0);
List_Reset(Points);
// Integrate detJ/lc du // Integrate detJ/lc du
double a; double a;
...@@ -351,8 +348,8 @@ void meshGEdge::operator() (GEdge *ge) ...@@ -351,8 +348,8 @@ void meshGEdge::operator() (GEdge *ge)
IntPoint P1, P2; IntPoint P1, P2;
ge->mesh_vertices.resize(N - 2); ge->mesh_vertices.resize(N - 2);
while(NUMP < N - 1) { while(NUMP < N - 1) {
List_Read(Points, count - 1, &P1); P1=Points[count-1];
List_Read(Points, count, &P2); P2=Points[count];
const double d = (double)NUMP * b; const double d = (double)NUMP * b;
if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) { if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) {
double dt = P2.t - P1.t; double dt = P2.t - P1.t;
...@@ -373,8 +370,6 @@ void meshGEdge::operator() (GEdge *ge) ...@@ -373,8 +370,6 @@ void meshGEdge::operator() (GEdge *ge)
} }
ge->mesh_vertices.resize(NUMP - 1); ge->mesh_vertices.resize(NUMP - 1);
} }
List_Delete(Points);
List_Delete(lcPoints);
for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){ for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){
MVertex *v0 = (i == 0) ? MVertex *v0 = (i == 0) ?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment