Commit 2359b00a authored by Cassio Kirch's avatar Cassio Kirch
Browse files

Memory freeded if gamma is not calculeted.

parent a4ef49ab
...@@ -65,7 +65,10 @@ initializeBoid (struct Boid* const boid) ...@@ -65,7 +65,10 @@ initializeBoid (struct Boid* const boid)
boid -> next = NULL; boid -> next = NULL;
boid -> previous = NULL; boid -> previous = NULL;
#if defined (ENDO_GAMMA) || defined (ECTO_GAMMA)
boid -> gamma = 0.0; boid -> gamma = 0.0;
#endif
if (boidCount < endoBoids) if (boidCount < endoBoids)
boid -> type = ENDODERM; boid -> type = ENDODERM;
else else
......
...@@ -10,17 +10,20 @@ struct Boid ...@@ -10,17 +10,20 @@ struct Boid
struct Boid* next; /* Considering on the same box... */ struct Boid* next; /* Considering on the same box... */
struct Boid* previous; /* ... (same list). */ struct Boid* previous; /* ... (same list). */
unsigned int boxID; unsigned int boxID;
unsigned int endoNeighbors;
unsigned int ectoNeighbors;
cellType type; /* Endo or ectoderm. */ cellType type; /* Endo or ectoderm. */
double gamma;
double position[2]; double position[2];
double velocity[2]; double velocity[2];
double newVelocity[2]; double newVelocity[2];
#if defined(ENDO_GAMMA) || defined(ECTO_GAMMA) || defined(COUNT_NEIGHBORS)
double gamma;
unsigned int endoNeighbors;
unsigned int ectoNeighbors;
#endif
}; };
#define BOID_STRUCT #define BOID_STRUCT
#endif #endif
unsigned int getBoxID (struct Boid boid); unsigned int getBoxID (struct Boid boid);
void initializeBoid (struct Boid* const boid); void initializeBoid (struct Boid* const boid);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#endif #endif
#endif #endif
#ifdef COUNT_NEIGHBORS
double double
getAverageNeighborsNo(const struct Boid* const boid) getAverageNeighborsNo(const struct Boid* const boid)
{ {
...@@ -30,7 +31,9 @@ getAverageNeighborsNo(const struct Boid* const boid) ...@@ -30,7 +31,9 @@ getAverageNeighborsNo(const struct Boid* const boid)
boid[boidCount].ectoNeighbors) / N; boid[boidCount].ectoNeighbors) / N;
return averageNeighborsNo; return averageNeighborsNo;
} }
#endif
#if defined(ENDO_GAMMA) || defined(ECTO_GAMMA)
double double
getGamma (const struct Boid* const boids) getGamma (const struct Boid* const boids)
{ {
...@@ -86,6 +89,7 @@ for (boidCount = (unsigned)(ENDOPROP*N); boidCount < N; ++boidCount) ...@@ -86,6 +89,7 @@ for (boidCount = (unsigned)(ENDOPROP*N); boidCount < N; ++boidCount)
return gamma; return gamma;
} }
#endif /* #if defined(ENDO_GAMMA) || defined(ECTO_GAMMA) */
void void
one_system () one_system ()
......
...@@ -89,10 +89,12 @@ setNextVelocity (struct Boid* const boid, const struct Box box[]) ...@@ -89,10 +89,12 @@ setNextVelocity (struct Boid* const boid, const struct Box box[])
double sumFX = 0.0, sumFY = 0.0; /* For beta and force sum. */ double sumFX = 0.0, sumFY = 0.0; /* For beta and force sum. */
double sum, sumX, sumY; double sum, sumX, sumY;
struct Boid *conductor; struct Boid *conductor;
#if defined (ENDO_GAMMA) || defined (ECTO_GAMMA)
boid -> endoNeighbors = 0u; boid -> endoNeighbors = 0u;
boid -> ectoNeighbors = 0u; boid -> ectoNeighbors = 0u;
boid -> gamma = 0.0; boid -> gamma = 0.0;
#endif
/* check neighbors in the same box */ /* check neighbors in the same box */
conductor = box[boid -> boxID].first; conductor = box[boid -> boxID].first;
...@@ -141,9 +143,11 @@ setNextVelocity (struct Boid* const boid, const struct Box box[]) ...@@ -141,9 +143,11 @@ setNextVelocity (struct Boid* const boid, const struct Box box[])
boid -> newVelocity[X] = V0 * sumX / sum; boid -> newVelocity[X] = V0 * sumX / sum;
boid -> newVelocity[Y] = V0 * sumY / sum; boid -> newVelocity[Y] = V0 * sumY / sum;
#if defined (ENDO_GAMMA) || defined (ECTO_GAMMA)
if (boid -> ectoNeighbors != 0u || boid -> endoNeighbors != 0u) if (boid -> ectoNeighbors != 0u || boid -> endoNeighbors != 0u)
boid -> gamma = (double)boid -> ectoNeighbors / \ boid -> gamma = (double)boid -> ectoNeighbors / \
(boid -> endoNeighbors + boid -> ectoNeighbors); (boid -> endoNeighbors + boid -> ectoNeighbors);
#endif
} }
void void
......
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