1
$\begingroup$

I just wrote a program that computes the potential field inside a Penning-Malmberg trap; my end goal is to simulate plasma inside this trap.

First I need to make sure my potential field across the grid is physically accurate. How can I do this? Which tests would you recommend me to perform on my grid?

I solved the field using a finite difference method; how can I determine what the appropriate grid size would be? Is a linear interpolation between grid points good enough to make good physical sense?

$\endgroup$
  • $\begingroup$ Essentially the same thing as asked here $\endgroup$ – Kyle Kanos Nov 1 at 3:02
  • $\begingroup$ @KyleKanos Could you explain how this is the same as testing a hydrodynamics code? I can't see how I can use the tests quoted on the answer you link. $\endgroup$ – Daniel Duque Nov 1 at 13:51
  • $\begingroup$ Because the answer is the same: you compare your results to analytic solutions and/or other (proven) numerical solutions. $\endgroup$ – Kyle Kanos Nov 1 at 14:07
  • $\begingroup$ See also physics.stackexchange.com/q/311969/25301 $\endgroup$ – Kyle Kanos Nov 1 at 14:08
  • $\begingroup$ @KyleKanos Thank you very much for that second link, I really liked your answer. It is an excellent start for my tests on my simulation. Nevertheless I stil have some questions. What is this $E(N)$ exactly, how can I look more information about minimizing this $E(N)$, and the physical effects on my simulation. How can I know if $E(N)$ is small enough for my purpose. Why is $E(N)/E(N/2)$ approx 2. What is the $y$ in your answer? I don't see what $y$ is or how is it related to $E$. $\endgroup$ – Daniel Duque Nov 2 at 2:23
2
$\begingroup$

How can I do this, which tests would you recommend me to perform on my grid?

When developing new code, the standard thing to do to ensure your code works as expected is to compare it to known solutions. For some mathematical models, there are closed form expressions (i.e., analytic solutions) and you can use these as a basis for testing.

For instance, with the heat equation, you can initialize with a delta function and expect a Gaussian at later times (cf Wikipedia again). If we call the analytic solution $y(x,t)$ and the numerical solution $u(x,t,N)$ where $N$ represents the number of grid points, then the error (how far off your numerical model is from the analytic solution) is then $$ E(t,N)=\left(\frac{1}{N}\sum_i\left[y(x_i,t)-u(x_i,t,N)\right]^2\right)^{1/2}\tag{1} $$ (this is the $\ell^2$ norm, there are other choices). However, if you do not have an analytic solution, then you can compare your model to someone else's to the same effect.

How can I determine what the appropriate grid size would be?

Or, for testing convergences and resolution, you can compare the difference of $N$ grid points versus $N/2$ and $2N$ grid points, as I mention in my answer to this question, using the same error condition in Equation (1). Note that you'll also run into issues of run-times with larger $N$, so the trade-off between convergence and solutions, so only testing can provide an answer to this question.

The ratio of the differences of the errors should be linear in $N$, so $E(N)/E(N/2)\sim N/(N/2)=2$. It could be different, however, for higher-order schemes.

Is a linear interpolation between grid points good enough to make good physical sense?

Finite difference methods assume constant values between grid points (i.e., the value of the potential/density/field/etc is grid-centered & approximately the same throughout). This of course is an approximation and can be mitigated by choosing a larger grid size. However, one can also assume some sort of interpolation (linear and quadratic are often chosen, but there's also "WENO" methods that are popular) of grid values, though this method is often referred to as finite volume, rather than finite difference.
Similar to the above, only testing can give you an answer as to whether something is "good" enough.

$\endgroup$

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.