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
float x;
float y;
float z;
Vector3(float x, float y, float z)

Vector3 *m[1000];
Vector3 *B[1000];
Vector3 *F[1000];

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.


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.


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$?

  • 1
    $\begingroup$ 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... $\endgroup$ – Wolfgang Bangerth May 22 at 20:24
  • $\begingroup$ I think each cell has its own U maybe? $\endgroup$ – EMP May 23 at 0:02
  • $\begingroup$ @EMP yes, correct $\endgroup$ – Артур Клочко May 23 at 5:55
  • $\begingroup$ @WolfgangBangerth, someone gave me that formulas. I will ask have I rewrote it correctly $\endgroup$ – Артур Клочко May 23 at 6:02
  • 2
    $\begingroup$ @АртурКлочко 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. $\endgroup$ – Wolfgang Bangerth May 23 at 15:30

I think this question needs more details, but couldn't you just use gauss-divergence theorem to move the gradient inside the integral and transform the volume integral to a surface integral. Maybe you can use a least squares approach to get the gradient in each cell?

| cite | improve this answer | |
  • $\begingroup$ >More details, which exactly? I will add, no problem $\endgroup$ – Артур Клочко May 22 at 17:23
  • $\begingroup$ 1)What is the purpose to use Gauss-divergence theorem? Just for simplification? 2) Least squares to get the gradient, can You give more details or, provide an example? $\endgroup$ – Артур Клочко May 22 at 17:29
  • $\begingroup$ Also as for Gauss theorem, I have gradient, not a divergence operation $\endgroup$ – Артур Клочко May 22 at 17:52
  • $\begingroup$ One approach could be to construct an analytic function matching your data points. Is the domain 2D or 3D? Any symmetries? Is data given on a regular grid? How large are grid dimensions? $\endgroup$ – Maxim Umansky May 22 at 18:36
  • $\begingroup$ @MaximUmansky, wow, I actually thought about getting the analytical equation from points as the last solution to apply. I thought it’s kinda trivial task. 1) What do You mean by symmetries? $\endgroup$ – Артур Клочко May 22 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.