|
@@ -524,78 +524,73 @@ int main() {
|
|
| 524 |
double rY0 = (((p->pos).y - (iY0 * cellY)) / cellY);
|
| 525 |
int iZ0 = int_of_double(((p->pos).z / cellZ));
|
| 526 |
double rZ0 = (((p->pos).z - (iZ0 * cellZ)) / cellZ);
|
| 527 |
double_nbCorners coeffs;
|
| 528 |
for (int k = 0; (k < nbCorners); k++) {
|
| 529 |
coeffs.v[k] = (((coefX0[k] + (signX0[k] * rX0)) *
|
| 530 |
(coefY0[k] + (signY0[k] * rY0))) *
|
| 531 |
(coefZ0[k] + (signZ0[k] * rZ0)));
|
| 532 |
}
|
| 533 |
vect fieldAtPos = {0., 0., 0.};
|
| 534 |
-
fieldAtPos.x =
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
fieldAtPos.y =
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
fieldAtPos.z =
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
vect accel = {((particleCharge / particleMass) * fieldAtPos.x),
|
| 562 |
((particleCharge / particleMass) * fieldAtPos.y),
|
| 563 |
((particleCharge / particleMass) * fieldAtPos.z)};
|
| 564 |
(p->speed).x = ((p->speed).x + (stepDuration * accel.x));
|
| 565 |
(p->speed).y = ((p->speed).y + (stepDuration * accel.y));
|
| 566 |
(p->speed).z = ((p->speed).z + (stepDuration * accel.z));
|
| 567 |
(p->pos).x = ((p->pos).x + (stepDuration * (p->speed).x));
|
| 568 |
(p->pos).y = ((p->pos).y + (stepDuration * (p->speed).y));
|
| 569 |
(p->pos).z = ((p->pos).z + (stepDuration * (p->speed).z));
|
| 570 |
particle p2 = {(p->pos), (p->speed)};
|
| 571 |
int iX2 = int_of_double(((p->pos).x / cellX));
|
| 572 |
int iY2 = int_of_double(((p->pos).y / cellY));
|
| 573 |
int iZ2 = int_of_double(((p->pos).z / cellZ));
|
| 574 |
int idCell2 = cellOfCoord(iX2, iY2, iZ2);
|
| 575 |
bag_push((&bagsNext[idCell2]), p2);
|
| 576 |
double rX1 = (((p->pos).x - (iX2 * cellX)) / cellX);
|
| 577 |
double rY1 = (((p->pos).y - (iY2 * cellY)) / cellY);
|
| 578 |
double rZ1 = (((p->pos).z - (iZ2 * cellZ)) / cellZ);
|
| 579 |
double_nbCorners coeffs2;
|
| 580 |
-
for (int k = 0; (k < nbCorners); k++) {
|
| 581 |
-
coeffs2.v[k] = (((coefX0[k] + (signX0[k] * rX1)) *
|
| 582 |
-
(coefY0[k] + (signY0[k] * rY1))) *
|
| 583 |
-
(coefZ0[k] + (signZ0[k] * rZ1)));
|
| 584 |
-
}
|
| 585 |
double_nbCorners deltaChargeOnCorners;
|
| 586 |
-
for (int k = 0; (k < nbCorners); k++) {
|
| 587 |
-
deltaChargeOnCorners.v[k] = (particleCharge * (coeffs2.v)[k]);
|
| 588 |
-
}
|
| 589 |
const int_nbCorners indices = indicesOfCorners(idCell2);
|
| 590 |
for (int k = 0; (k < nbCorners); k++) {
|
| 591 |
-
nextCharge[indices.v[k]] +=
|
|
|
|
|
|
|
|
|
|
| 592 |
}
|
| 593 |
}
|
| 594 |
}
|
| 595 |
bag_init_initial(b);
|
| 596 |
}
|
| 597 |
for (int idCell = 0; (idCell < nbCells); idCell++) {
|
| 598 |
bag_swap((&bagsCur[idCell]), (&bagsNext[idCell]));
|
| 599 |
}
|
| 600 |
}
|
| 601 |
}
|
| 524 |
double rY0 = (((p->pos).y - (iY0 * cellY)) / cellY);
|
| 525 |
int iZ0 = int_of_double(((p->pos).z / cellZ));
|
| 526 |
double rZ0 = (((p->pos).z - (iZ0 * cellZ)) / cellZ);
|
| 527 |
double_nbCorners coeffs;
|
| 528 |
for (int k = 0; (k < nbCorners); k++) {
|
| 529 |
coeffs.v[k] = (((coefX0[k] + (signX0[k] * rX0)) *
|
| 530 |
(coefY0[k] + (signY0[k] * rY0))) *
|
| 531 |
(coefZ0[k] + (signZ0[k] * rZ0)));
|
| 532 |
}
|
| 533 |
vect fieldAtPos = {0., 0., 0.};
|
| 534 |
+
fieldAtPos.x =
|
| 535 |
+
(fieldAtPos.x + ((((((((coeffs.v[0] * field_at_corners.v[0].x) +
|
| 536 |
+
(coeffs.v[1] * field_at_corners.v[1].x)) +
|
| 537 |
+
(coeffs.v[2] * field_at_corners.v[2].x)) +
|
| 538 |
+
(coeffs.v[3] * field_at_corners.v[3].x)) +
|
| 539 |
+
(coeffs.v[4] * field_at_corners.v[4].x)) +
|
| 540 |
+
(coeffs.v[5] * field_at_corners.v[5].x)) +
|
| 541 |
+
(coeffs.v[6] * field_at_corners.v[6].x)) +
|
| 542 |
+
(coeffs.v[7] * field_at_corners.v[7].x)));
|
| 543 |
+
fieldAtPos.y =
|
| 544 |
+
(fieldAtPos.y + ((((((((coeffs.v[0] * field_at_corners.v[0].y) +
|
| 545 |
+
(coeffs.v[1] * field_at_corners.v[1].y)) +
|
| 546 |
+
(coeffs.v[2] * field_at_corners.v[2].y)) +
|
| 547 |
+
(coeffs.v[3] * field_at_corners.v[3].y)) +
|
| 548 |
+
(coeffs.v[4] * field_at_corners.v[4].y)) +
|
| 549 |
+
(coeffs.v[5] * field_at_corners.v[5].y)) +
|
| 550 |
+
(coeffs.v[6] * field_at_corners.v[6].y)) +
|
| 551 |
+
(coeffs.v[7] * field_at_corners.v[7].y)));
|
| 552 |
+
fieldAtPos.z =
|
| 553 |
+
(fieldAtPos.z + ((((((((coeffs.v[0] * field_at_corners.v[0].z) +
|
| 554 |
+
(coeffs.v[1] * field_at_corners.v[1].z)) +
|
| 555 |
+
(coeffs.v[2] * field_at_corners.v[2].z)) +
|
| 556 |
+
(coeffs.v[3] * field_at_corners.v[3].z)) +
|
| 557 |
+
(coeffs.v[4] * field_at_corners.v[4].z)) +
|
| 558 |
+
(coeffs.v[5] * field_at_corners.v[5].z)) +
|
| 559 |
+
(coeffs.v[6] * field_at_corners.v[6].z)) +
|
| 560 |
+
(coeffs.v[7] * field_at_corners.v[7].z)));
|
| 561 |
vect accel = {((particleCharge / particleMass) * fieldAtPos.x),
|
| 562 |
((particleCharge / particleMass) * fieldAtPos.y),
|
| 563 |
((particleCharge / particleMass) * fieldAtPos.z)};
|
| 564 |
(p->speed).x = ((p->speed).x + (stepDuration * accel.x));
|
| 565 |
(p->speed).y = ((p->speed).y + (stepDuration * accel.y));
|
| 566 |
(p->speed).z = ((p->speed).z + (stepDuration * accel.z));
|
| 567 |
(p->pos).x = ((p->pos).x + (stepDuration * (p->speed).x));
|
| 568 |
(p->pos).y = ((p->pos).y + (stepDuration * (p->speed).y));
|
| 569 |
(p->pos).z = ((p->pos).z + (stepDuration * (p->speed).z));
|
| 570 |
particle p2 = {(p->pos), (p->speed)};
|
| 571 |
int iX2 = int_of_double(((p->pos).x / cellX));
|
| 572 |
int iY2 = int_of_double(((p->pos).y / cellY));
|
| 573 |
int iZ2 = int_of_double(((p->pos).z / cellZ));
|
| 574 |
int idCell2 = cellOfCoord(iX2, iY2, iZ2);
|
| 575 |
bag_push((&bagsNext[idCell2]), p2);
|
| 576 |
double rX1 = (((p->pos).x - (iX2 * cellX)) / cellX);
|
| 577 |
double rY1 = (((p->pos).y - (iY2 * cellY)) / cellY);
|
| 578 |
double rZ1 = (((p->pos).z - (iZ2 * cellZ)) / cellZ);
|
| 579 |
double_nbCorners coeffs2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
double_nbCorners deltaChargeOnCorners;
|
|
|
|
|
|
|
|
|
|
| 581 |
const int_nbCorners indices = indicesOfCorners(idCell2);
|
| 582 |
for (int k = 0; (k < nbCorners); k++) {
|
| 583 |
+
nextCharge[indices.v[k]] +=
|
| 584 |
+
(particleCharge * (((coefX0[k] + (signX0[k] * rX1)) *
|
| 585 |
+
(coefY0[k] + (signY0[k] * rY1))) *
|
| 586 |
+
(coefZ0[k] + (signZ0[k] * rZ1))));
|
| 587 |
}
|
| 588 |
}
|
| 589 |
}
|
| 590 |
bag_init_initial(b);
|
| 591 |
}
|
| 592 |
for (int idCell = 0; (idCell < nbCells); idCell++) {
|
| 593 |
bag_swap((&bagsCur[idCell]), (&bagsNext[idCell]));
|
| 594 |
}
|
| 595 |
}
|
| 596 |
}
|
#include <stdlib.h>#include "optitrust.h"#include <stdio.h>typedef struct { double x; double y; double z;} vect;typedef struct { vect pos; vect speed;} particle;vect vect_add(vect v1, vect v2) { return {(v1.x + v2.x), (v1.y + v2.y), (v1.z + v2.z)};}vect vect_mul(double d, vect v) { return {(d * v.x), (d * v.y), (d * v.z)}; }const int CHUNK_SIZE = 128;typedef struct chunk { chunk *next; int size; particle items[CHUNK_SIZE];} chunk;typedef struct { chunk *front; chunk *back;} bag;chunk *atomic_read(chunk **p) { chunk *value; value = (*p); return value;}chunk *chunk_alloc() { return (chunk *)malloc(sizeof(chunk)); }void chunk_free(chunk *c) { free(c); }void bag_init(bag *b, int id_bag, int id_cell) { chunk *c = chunk_alloc(); (c->size) = 0;