#include "UTMHD.h" #include "MHD.h" /***********************************************************************/ /** * @param start_dateTime - Date and time of the first timestep * @param stop_dateTime - Date and time of the last timestep * @param dump_frequency - Frequency of file output (in seconds) */ UTMHD::UTMHD(const DateTime &start_dateTime, const DateTime &stop_dateTime, const double &dump_frequency) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::UTMHD(...)\n", RTIME.local_proc); #endif start = start_dateTime; current = start; //FIXME // set this in the data reader?? // currentStep = startStep; //currentStep is defined in MHDManager.h stop = stop_dateTime; dumpFrequency = dump_frequency; // set the next dump nextDump = start; nextDump.incrementSeconds(dumpFrequency); if (RTIME.local_proc == 0){ std::cout << "--------------------------------------------\n"; std::cout << start; std::cout << "--------------------------------------------\n"; std::cout << stop; std::cout << "--------------------------------------------\n"; } } /***********************************************************************/ /** * Advance the simulation one timestep * * @returns false if there is no more work to be done. */ bool UTMHD::advance(void) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::advance(...)\n", RTIME.local_proc); #endif //FIXME: This is never set or used! currentStep++; if (current > nextDump) nextDump.incrementSeconds(dumpFrequency); return (current <= stop); } /** * Increment the simulation clock by dt seconds. */ void UTMHD::incrementTime(const FLoaT &dt) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::incrementTime(...)\n", RTIME.local_proc); #endif current.incrementSeconds(dt); simTime += dt; } /***********************************************************************/ /** * Check if we need to save data. * * @returns true if we should save data to file */ bool UTMHD::atDump(void) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::atDump(...)\n", RTIME.local_proc); #endif return (current > nextDump); } /***********************************************************************/ /// UT-IO version of mhd_dump_step /** * @param base - base filename to pre-pend to each file * @param mhd - mhd object that holds the data */ int UTMHD::dump_step(char *base, MHD *mhd, IM_Interface const * const innerMag, const Average &avg) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::dump_step(...)\n", RTIME.local_proc); #endif std::string timestr = current.getDateTimeString(); char *suffix_1 = new char [ timestr.size()+1]; strcpy(suffix_1, timestr.c_str()); char suffix_2[128] = "dmp"; double mjdTime = current.getMJD(); // These functions are defined in the MHDIO Base Class open_write_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjdTime); delete [] suffix_1; if (innerMag == NULL){ // stand-alone LFM doesn't define an innerMag. Just do normal I/O. write_data(mhd, avg); } else{ // Is this the time to write inner magnetosphere accumulate/bleed // data to file or just the MHD variables? DateTime accumulate_start = innerMag->getCouplingStart(); accumulate_start.incrementSeconds(-innerMag->getDeltaT()); if (current > accumulate_start){ // write MHD vars along with Accumulate & Bleed arrays write_data(mhd, innerMag, avg); } else{ // Only write the MHD vars. // The accumualte & bleed arrays are meaningless before coupling start time. write_data(mhd, avg); } } close_hdf(); Communication_Manager::Sync(); return 0; } /***********************************************************************/ /// UT-IO version of mhd_read_step /** * @param base - base filename to pre-pend to each file * @param mhd - mhd object that will store the data in memory */ int UTMHD::read_step(char *base, MHD *mhd) { #ifdef DEBUG_MODE_ON printf("DEBUG: process (%d) in UTMHD.C::read_step(...)\n", RTIME.local_proc); #endif std::string timestr = current.getDateTimeString(); char *suffix_1 = new char [ timestr.size()+1]; strcpy(suffix_1, timestr.c_str()); char suffix_2[128] = "hdf"; double mjdTime = current.getMJD(); // These functions are defined in the MHDIO Base Class open_read_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjdTime); delete [] suffix_1; read_data(mhd); close_hdf(); Communication_Manager::Sync(); return 0; } /***********************************************************************/ /// UT-IO version that 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 UTMHD::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 std::string timestr = current.getDateTimeString(); char *suffix_1 = new char [ timestr.size()+1]; strcpy(suffix_1, timestr.c_str()); char suffix_2[128] = "hdf"; double mjdTime = current.getMJD(); // The following are defined in the MHDManager Base Class open_read_hdf(&base[0], &suffix_1[0], &suffix_2[0], &mjdTime); delete [] suffix_1; read_accumulate_and_bleed_data(mhd, innerMag); close_hdf(); Communication_Manager::Sync(); return 0; }