Pages

Showing posts with label MHD. Show all posts
Showing posts with label MHD. Show all posts

Sunday, March 20, 2011

Optical Illusion in Visualization

I was recently working on a few basic tests of MHD codes and one of the tests I did was the 2D rotor problem. In this test a circular region of high density initially starts out rotating. There is a magnetic field pointed in the +x direction. As the simulation progresses the magnetic field distorts the spinning high density region and causes magnetic waves to propagate into the surrounding low density region. Thus this test is a good one to show the basic structure of magnetic waves.

This test was done using Athena and the visualization was done in Paraview.  The 2D surface is colored according to the log10 of the density and the vector arrows show velocity and are colored according to the magnitude of the magnetic field.



One thing that came up with this visualization is that at the very beginning there is an optical illusion. Even though the gas is initially spinning in a counter-clock-wise direction because it is slowing down and begins to change direction, it appears as if it is spinning in the opposite direction. Because of the way the velocity vectors change length and direction at the beginning it gives the impression that the gas is spinning in the clock-wise direction. This is an excellent instance of an optical illusion in a visualization. Sometimes when scientists are trying to visualize their data they run the risk of having it create an optical illusion that will mess up their interpretation of the data. The way to fix this is to use a different visualizing method, in this case I could use particle tracers or stream line tracers to fix the problem.

But this is just one of the hazards of trying to use visualization to tell us something about our data. Still, visualization is better than just about any other method in giving a complete picture of what it going on. We just have to be mindful that sometimes our minds will play tricks on us.

Thursday, February 24, 2011

Testing the ∇⋅ B = 0 condition in numeric solvers

When considering magnetic fields in computer simulations using the equations of magnetohydrodynamics (MHD) we have to take into account one of Maxwell's equations, namely:
∇⋅ B = 0
This is the condition that there is no divergence in the magnetic field, which in physical terms means that there are no magnetic charges. That is, we don't have particles floating about that create magnetic field lines. All of the magnetic flux that enters a given volume must leave the volume.

Mathematically this is usually straight forward (well sort of, except for those that have had to suffer through Jackson), but when it comes to computer simulations it turns out that this condition is very hard to preserve. There are several different methods used to preserve this condition and for those that are interested there is an excellent paper by Gábor Tóth that describes many of these methods (Gábor Tóth, Journal of Computational Physics, 161, 2, 2000, Pages 605-652).

While I am not going to discuss how these methods work, I will note that they are all imperfect. Because of the fundamental way simulations and computers work, there will always be some error, which means the divergence condition will never be met. The way of dealing with this usually involves making the error from the numerical solver to be as small as possible. While some ways of solving the MHD equations can make the error very small, it comes at the cost of making the code run slower (for example the projection method may be better than other methods in almost all situations, but it comes at the cost of a 20% increase in the time needed compared to the base method for they hydro equations. For reference, of the seven methods investigated by Tóth the next slowest only added 7% to the time).

But the question is, how do we test the accuracy of these different methods. Well, the easiest way is to have them solve a problem that we already know the answer for analytically and then see how well the code does at getting the correct answer. While many codes will do well with a simple problem, the idea is to get a very difficult problem and see how the code handles it.

One such problem is the Smooth Alfvén Wave test. This test takes a polarized magnetic field and has it propagate across the grid. Using this special set up it will create standing Alfvén waves. Because of the nature of the Alfvén waves and how they interact with the material, for this particular test the density should not change and the wave should not dissipate. That is, after one period the entire system should return to its original state. Any change in the density, energy, velocity or magnetic field is an indication of the errors introduced by the numeric solver. By knowing the initial conditions we can then calculate the change and therefore the error.

So in a real simulation, what would this look like? Well something like this:



This is a video of the Smooth Alfvén Wave test, with a circularly polarized magnetic field. This is a 2D simulation (well, 2.5D but anyway...) with a constant density slab of material with constant pressure. The wave propagates from the top right corner towards the bottom left. The color of the slab indicates the density. The initial density is a grey color and thus any other color you see in the slab indicates an error in the solver (there is a color legend in the video). The arrows indicate the velocity (and the color of the arrows does not mean anything, I just made them pink so that you could see them). The velocity points in the same direction as the magnetic field, so the arrows also show magnetic field. The test runs for five periods.

As I mentioned, any color, red or blue, you see in the slab indicates a numerical error, but while it make look like this was a bad simulation, note that the difference is only 4.3 e -4. This is still small and acceptable for most applications. If I ran it for longer, the errors would grow. If I started adding in other things, again the error would grow. In this case I can compare the result to the analytic solution, but in the case where there is no analytic solution we have to rely of either proven methods, better resolution or in the worst case, just assume that the errors are small (shudder).

This simulation was run in Athena, which uses a constrained transport method to address the ∇⋅ B = 0 problem, and it took about 3 minutes to run on my laptop. I rendered it in Paraview, which after taking a few minutes to set it up, it only took 2 or 3 minuets to render.

Friday, September 18, 2009

Athena Magnetohydrodynamics (MHD) Code

Some of you (one of you) requested a little more information about the hydrodynamics code that I mentioned in a previous post. The code written in C is called Athena after the Greek goddess. The best basic overview of the code comes from the authors themselves:

"Athena is a grid-based code for astrophysical gas dynamics, based on higher-order Godunov methods, with nested and adaptive mesh capabilities. The original development efforts were supported by the NSF Information Technology Research (ITR) program. As part of the project, Athena will be made freely available to the astrophysics community, along with complete documentation and web-based training material.

The current version of the code (v3.1) implements algorithms for:

  • compressible hydrodynamics and ideal MHD in one-, two-, or three-spatial dimensions,
  • ideal gas equation of state with arbitrary γ (including γ = 1, an isothermal EOS).
  • first-, second- or third-order characteristic interpolation in the primitive variables,
  • numerical fluxes computed using a variety of approximate and/or linearized Riemann solvers,
  • source terms due to a static gravitational potential,
  • self-gravity computed using FFTs,
  • an arbitrary number of passive scalars advected with the flow,
  • parallelization using domain decomposition with MPI.
The code is being developed by Jim Stone (Princeton University), Tom Gardiner (Cray Research), Peter Teuben (University of Maryland), and John Hawley (University of Virginia). Code development began in 2000, and is on-going.

The primary motivations for developing Athena are to (1) adapt higher-order Godunov schemes for astrophysical MHD, (2) use a single-step Eulerian update so the solver can be used with adaptive mesh refinement, (3) optimize and parallelize the implementation on modern, distributed memory processors, and (4) distribute the code to the astrophysics community with documentation and web-based training tools. The first three motivations are driven by our own research needs, the last is done in the hope the community will find the resulting code useful for their own research."

So that is how the authors of the code describe the it and now onto my opinion of the code. I found it very easy to pick up and learn how to use. For those who download the code it comes with several preworked examples that demonstrate different aspects of the code. The examples include several standard test problems (spherical blast wave, linear waves and others with more obscure names, usually after the people who first published a paper on that problem). The code comes with a user's guide which contains most of what is needed to get the code up and running. I think that it took me less than a week from when I downloaded the code to when I got the first examples running. Keep in mind that I had also just bought a laptop two days before I downloaded the code and I was in the process of making a Linux partition and making sure that I also had all of the necessary libraries and compilers necessary to run the code. So I was not just dealing with getting the code up and running but also getting my computer up and running for that first week. After that it was a matter of working through some of the examples, changing the inputs and figuring out how it all worked.

On a basic level the code is very simple to run. It only takes three commands to make it run and in some cases it only takes one. For example if I wanted to run my particular problem that I wrote, which I named Starburst, from the command line I would type:

configure --with-problem=starburst --with-gas=hydro

make all

./athena -i ../tst/2D-hydro/starburst.c

The first line sets up the problem and in general has the form: "configure [--enable-feature] [--disable-feature] [--with-package=choice]". The second compiles the code (and does a few more things). The last line actually runs the code and calls the input file "starburst.c". The individual problem files include all of the code needed to make the initial conditions (density, pressure etc.) as well as functions to include a gravitational potential, and functions to update certain cells every cycle (to be used, for example, to inject matter and energy into the center of a galaxy), along with several more useful functions designed for other specific purposes to control output etc.

The code is very versatile and can run on many processors (or just one like my laptop). The individual features available which are used with the configure command are given in the user's manual (snapshot shown below, the bold options are the defaults, click to see a larger and easier to read version):

As you may notice it includes an MHD option which is what makes Athena so powerful, and well known. Most people I have talked to about Athena view it a primarily an MHD code though it is also used for normal hydro stuff. Right now I am using it as a hydro code, but the plan is to eventually use it with MHD.

So overall the code is very easy to learn how to use and to get working. It is another matter (haha) to make it do something different, new and useful (preferably all three), and above all publishable. I would recommend using this code if you are looking into using a standard, ready to run out of the box code for hydrodynamics or MHD. I will now take questions.

Wednesday, June 27, 2007

Relativistic Jets from GRMHD

For some time now it has been known that rotating black holes can produce extremely powerful jets of gamma rays and very high energy particles that shoot out along their axes of rotation. This phenomena is believed to be the power source for active galatic nuclei, pulsars, quasars, a number of other phenomena ending in -sars, and possibly some types of gamma ray bursts. The mechanism for creating these jets, however, remained mysterious. To complicate matters, whatever process is powering these jets appears to be extremely efficient in converting gravitational potential energy from the in-falling material into these high energy streams of photons and particles. So how does a black hole with an accretion disk swirling around it efficiently shoot jets out of its poles?

Nothing like this jumps out of either the linearized magnetohydrodynamics equations or the Einstein equations, so people knew that it had to be some kind of funky non-linear effect, but was it from the MHD equations, the Einstein equations, or some combination of the two? Since the jets were always created by in-falling plasma it seemed safe to say that MHD was involved. And because these jets were only observed around black holes, it seemed pretty reasonable to assume that GR played a role in creating these jets, but the real question was whether it was just the non-linear GR effects that were needed or was this something to do with the event horizon. As Joe mentioned in his post, there is reason to believe that event horizons are trickier than we generally expect, so could these jets be some sort of mechanism for the black hole to deal with matter trying to pass it's event horizon?

Well, the debate now appears to be settled. Researchers at MIT and the University of Wisconsin have published evidence for relativistic jets coming out of a binary star system with an accreting neutron star (pictured on the left). Since neutron stars obviously don't have event horizons the jets must be produced by the non-linearity in the GRMHD (General Relativistic Magnetohydrodynamics) equations alone and not by some trick of the event horizon.

As a side note, they also found that both the overall energy in the jets and the efficiency of the process decreased in the case of the neutron star, perhaps signaling that the effect scales with the gravitational field strength (i.e. curvature). That gives numerical people a good idea of where to look in the non-linear terms for the driving mechanism. GO NUMERICAL METHODS!!!

You can look at the pre-print or read the ScienceDaily summary for more details.