#include "TimestepMHD.h" #include "MHD.h" /***********************************************************************/ /** * @param start_step - First integer timestep in the simulation * @param stop_step - Last integer timestep to simulate * @param dump_interval - frequency of file output (in number of timesteps) * * @note LFM uses variable timesteps, so you're not garaunteed how much simulation time advances over one timestep. To specify exact times to start and stop the simualtion, see UTMHD and search the wiki for INPUT1.xml UTIO support. */ TimestepMHD::TimestepMHD(const int &start_step, const int &stop_step, const int &dump_interval) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::TimestepMHD(...)\n", RTIME.local_proc); #endif startStep = start_step; currentStep = startStep; //currentStep is defined in MHDManager.h stopStep = stop_step; dumpInterval = dump_interval; } /***********************************************************************/ /** * Advance the simulation one timestep * * @returns false if there is no more work to be done. */ bool TimestepMHD::advance(void) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::advance(...)\n", RTIME.local_proc); #endif currentStep++; return (currentStep <= stopStep); } void TimestepMHD::incrementTime(const FLoaT &dt) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::incrementTime(...)\n", RTIME.local_proc); #endif simTime += dt; } /***********************************************************************/ /** * Check if we need to save data. * * @returns true if we should save data to file */ bool TimestepMHD::atDump(void) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::atDump(...)\n", RTIME.local_proc); #endif return (currentStep % dumpInterval == 0); } /***********************************************************************/ /// Standard mhd_dump_step /** * @param base - base filename to pre-pend to each file * @param mhd - mhd object that stores the data in memory * @param innerMag - Inner magnetosphere coupling object. Not used by TimestepMHD since RCM coupling requires UTIO. */ int TimestepMHD::dump_step(char *base, MHD *mhd, IM_Interface const * const innerMag, const Average &avg) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::dump_step(...)\n", RTIME.local_proc); #endif char suffix_1[128]; sprintf(suffix_1, "%07d", currentStep); char suffix_2[128] = "dmp"; double mjd = -999.9; // These functions are defined in the MHDIO Base Class open_write_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjd); // Note: Do not pass innerMag object since LFM-RCM requires UTIO and // is incompatible with timestep I/O. write_data(mhd, avg); close_hdf(); Communication_Manager::Sync(); return 0; } /***********************************************************************/ /// Standard mhd_read_step /** * @param base - base filename to pre-pend to each file * @param mhd - mhd object */ int TimestepMHD::read_step(char *base, MHD *mhd) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in TimestepMHD.C::read_step(...)\n", RTIME.local_proc); #endif char suffix_1[128]; sprintf(suffix_1, "%07d", currentStep); char suffix_2[128] = "hdf"; double mjd = -999.9; // These functions are defined in the MHD Base Class open_read_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjd); read_data(mhd); close_hdf(); Communication_Manager::Sync(); return 0; } /***********************************************************************/ /// Read the accumulate & bleed arrays from file in IM_Interface object used for coupling with RCM. /** * Opens file (UTIO filename), reads accumulate/bleed arrays into * IM_Interface object & closes file handle. * * @param base - base filename to pre-pend to each file * @param mhd - mhd object that stores the data in memory * @param innerMag - Inner Magnetosphere coupling object that will store the accumulate & bleed arrays in memory. */ int TimestepMHD::read_accumulate_and_bleed_step(char *base, MHD *mhd, IM_Interface * const innerMag) { #ifdef DEBUG_MODE_ON cout << "DEBUG: process (" << RTIME.local_proc << ") at " <<__FILE__ << " (Line " << __LINE__ << "): " << __FUNCTION__ << endl; #endif char suffix_1[128]; sprintf(suffix_1, "%07d", currentStep); char suffix_2[128] = "hdf"; double mjd = -999.9; // The following are implemented in the MHDManager Base Class open_read_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjd); read_accumulate_and_bleed_data(mhd, innerMag); close_hdf(); Communication_Manager::Sync(); return 0; }