In this code, I am making a cluster of particles and assigning them x, y and z coordinates. Then, I am evaluating the force due to this cluster at some far away point. The function directSumUnregularized
calculates that force.
I want to see what that force is, but for whatever reason, it is not being printed out.
This is my code:
#include <omp.h>
#include <time.h>
#include <iostream>
#include <cmath>
#include <random>
#include "unitTestFunctions.h"
int main() {
//set up cluster of particles
const int numberOfParticles = 10;
std::random_device rd{};
std::mt19937 gen{rd()};
std::normal_distribution<> d{0,1};
PARTICLE *clusterOfParticles = new PARTICLE [numberOfParticles];
double sumX{}, sumY{}, sumZ{};
for (int ind=0; ind<numberOfParticles; ind++){
clusterOfParticles[ind].x = d(gen);
clusterOfParticles[ind].y = d(gen);
clusterOfParticles[ind].z = d(gen);
}
//test position
double xTest {5}, yTest{6}, zTest {7};
double *exactForceX{nullptr}, *exactForceY{nullptr}, *exactForceZ{nullptr};
*exactForceX = 0;
*exactForceY = 0;
*exactForceZ = 0;
directSumUnregularized(numberOfParticles, exactForceX, exactForceY,
exactForceZ, xTest, yTest, zTest,
clusterOfParticles);
std::cout<<"exactForce X: "<<*exactForceX<<std::endl;
delete [] clusterOfParticles;
return 0;
}
and my function:
#include <omp.h>
#include <time.h>
#include <iostream>
#include <cmath>
#include <random>
#include "unitTestFunctions.h"
void directSumUnregularized(const int numberOfParticles, double *exactForceX,
double *exactForceY, double *exactForceZ, double xTest, double yTest, double zTest,
PARTICLE *clusterOfParticles){
double rSq{};
double r{};
double dx {}, dy {}, dz{};
const double pi = 3.1415926535897;
double inv4pi = 1/(4*pi);
for (int i=0; i<numberOfParticles; i++){
dx = xTest - clusterOfParticles[i].x;
dy = yTest - clusterOfParticles[i].y;
dz = zTest - clusterOfParticles[i].z;
rSq = dx*dx+dy*dy+dz*dz;
r = sqrt(rSq);
*exactForceX -= inv4pi*(dx/(rSq*r));
*exactForceY -= inv4pi*(dy/(rSq*r));
*exactForceZ -= inv4pi*(dz/(rSq*r));
}
return;
}
how should I go about this?