Abstract

I have the next equation to find a force, for my problem:

$$U=-\int \vec{m}\small{(x)}\times \vec{B}(x)dV$$ $$\vec{F}=-\nabla U$$

Considering 3-dimensional space with x,y,z coordinates, and, hence, $$\vec{m}$$ and $$\vec{B}$$ describe values at a point in the 3D space. Computing via C++. Each values described as:

class Vector3
{
public:
float x;
float y;
float z;
Vector3(float x, float y, float z)
{
this->x=x;
this->y=y;
this->z=z;
}
};

Vector3 *m;
Vector3 *B;
Vector3 *F;


Using: finding F vector literally at every point is impossible, so I will find values with some step. For example, considering some volume 1m*1m*1m, I will find values with step 100mm, so for that volume I need to calculate $$\frac{1m}{100mm}* \frac{1m}{100mm}* \frac{1m}{100mm} =10^3=1000\space points$$.

Fill array, I think should be the next way:

 int count=0;
for(float x=0.0f;x<1.0f;x+=0.1f)
for(float y=0.0f;y<1.0f;y+=0.1f)
for(float Z=0.0f;z<1.0f;z+=0.1f, count++)
F[count]=new Vector3(...)\\here I calculate the formulas above


And I have particles, that move more smoothly, of course, not by 100mm steps, so I will just calculate which point is the nearest, or the average value of the nearest points in that point.

Question

How should I deal with it, if I have literally an array of $$\vec{m}$$ and $$\vec{B}$$ at every point, but not an analytical function, that describes distribution of that values?

As the output I need also array with $$\vec{F}$$ at every point.

Thoughts

I am bad at math, and have, probably wrong assumption. The formulas above wrote for finding field of forces. But in my case in need it to be “dotty”. Here is potential energy at a point.

$$\vec{m}\small{(x)}\times \vec{B}(x) = \frac{J}{T}*T=Joules=Potential\space Energy$$

But it doesn’t have any sense, because I need the difference between two potentials. So what if to calculate $$\vec{F}(x)$$(at a point) as $$\vec{F}(x)=\frac{U(x+k)-U(x)}{k}$$ Taking $$k=step=100mm$$?

• I don't understand what the integral in the first equation extends over. From the $dV$, I presume that it is a volume integral, in which case $U$ is just a number. But then using $\nabla U$ makes no sense in the second equation because $U$ is just a number, not a function that depends on space... – Wolfgang Bangerth May 22 at 20:24
• I think each cell has its own U maybe? – EMP May 23 at 0:02
• @EMP yes, correct – Артур Клочко May 23 at 5:55
• @WolfgangBangerth, someone gave me that formulas. I will ask have I rewrote it correctly – Артур Клочко May 23 at 6:02
• @АртурКлочко But if that is a cellwise quantity, then $\nabla U$ still doesn't make sense for two reasons: First, it is a piecewise constant quantity. So the gradient is either zero or infinite (a distribution); the best one could hope for is a numerical approximation. But second, and more importantly, if it is a cellwise quantity then it is proportional to the volume of the cell. As a consequence, it converges to zero under mesh refinement. It doesn't converge to any physical quantity. For that, you would have to normalize it by the cells' volumes. – Wolfgang Bangerth May 23 at 15:30