.. _mhdct_details: MHDCT Details ============= This section gives a detailed account of incorporating MHDCT into your simulation. Please read the overview in :ref:`mhd_methods` first. Also, read the implementation method paper, Collins et al 2010. Parameter Compatibility ----------------------- Due to the consistency requirements of MHDCT, several parameter combinations can and will fail in hilarious ways. Defaults have been selected to give the best performance and the consistent results. The minimum set of parameters to be enabled in your new parameter file are ``NumberOfGhostZones = 5`` ``HydroMethod = 6`` Other parameters must always be set, and sometimes are set differently in other parameter files: ``FluxCorrection = 1`` ``CorrectParentBoundaryFluxes = 1`` Initialization -------------- If you have an initializer that you wish to add ``MHDCT`` to, several things need to be done: 1.) **Set Labels and Units** Define the labels in the primary problem initializer, e. g. ``MHDBlastInitialize.C``. Use the function ``MHDCTSetupFieldLabels();`` 2.) Note: if your main initializer uses a call to ``InitializeUniformGrid``, you can skip steps 2 and 3. In the grid initializer, e.g. ``Grid_MHDBlastInitializeGrid.C``, add ``BaryonField`` pointers for the centered magnetic field. Code should look like .. code-block:: c if( UseMHD ){ FieldType[NumberOfBaryonFields++] = Bfield1; FieldType[NumberOfBaryonFields++] = Bfield2; FieldType[NumberOfBaryonFields++] = Bfield3; } if( HydroMethod == MHD_RK ){ FieldType[NumberOfBaryonFields++] = PhiField; } This is the same as Dedner simulation. Old versions of the code used a variable ``CenteredB``, which was redundant and cumbersome. 3.) **Allocate the appropriate fields** Ensure your code calls ``this->AllocateGrids();`` rather than ``BaryonField[field] = new float[size]``. 4.) **Fill the Fields** This can be either very straight forward, or very difficult depending on your problem. Here we'll present three cases. Note that the very most important thing is that the field is **numerically** divergence free. 4a) **Uniform Magnetic Fields** If you have a uniform magnetic field defined by ``UniformField[3]``, you can initialize them like this: .. code-block:: c for ( int field=0; field < 3; field++ ){ for ( int i=0; iMHD_Curl(GridStartIndex, GridEndIndex, 0) where ``Function`` is anything you like. 5.) **Center the magnetic field** The final step is to fill the centered field, ``BaryonField[B1Num]`` (etc) from ``MagneticField``. Call this function once you've filled ``MagneticField``. .. code-block:: c this->CenterMagneticField(); 6.) **Add to the Energy** Finally you need to add the magnetic energy to the total energy. There are several ways to accomplish this. Something like this is sufficient: .. code-block:: c int DensNum, GENum, Vel1Num, Vel2Num, Vel3Num, TENum, B1Num, B2Num, B3Num; this->IdentifyPhysicalQuantities(DensNum, GENum, Vel1Num, Vel2Num, Vel3Num, TENum, B1Num, B2Num, B3Num); for( i=0; i