-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from boutproject/v1.1
STORM v1.1
- Loading branch information
Showing
37 changed files
with
2,325 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,8 @@ BOUT.settings | |
*.bmp | ||
|
||
*filaments | ||
storm3d/storm | ||
*/make.config | ||
data_* | ||
*.txt | ||
storm2d/storm2d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
Copyright L. Easy, F. Militello, T. Nicholas, J. Omotani, F. Riva, N. | ||
Walkden, UKAEA, 2017, 2018 | ||
email: [email protected] | ||
This file is part of the STORM module of BOUT++. | ||
STORM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
STORM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with STORM. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <boutcomm.hxx> | ||
#include "fast_output.hxx" | ||
#include <../src/fileio/formatfactory.hxx> | ||
#include <bout/solver.hxx> | ||
#include <string> | ||
|
||
FastOutput::FastOutput() { | ||
// Get options | ||
Options* global_options = Options::getRoot(); | ||
Options* options = global_options->getSection("fast_output"); | ||
std::string type; | ||
OPTION(options, type, "none"); | ||
if (type=="monitor") { | ||
enable_monitor = true; | ||
// Calculate output frequency | ||
BoutReal output_timestep; | ||
global_options->get("timestep", output_timestep, 1.); | ||
int frequency_multiplier; | ||
OPTION(options, frequency_multiplier, 100); // multiple of the output frequency to call fast_output at | ||
setTimestep(output_timestep / double(frequency_multiplier)); | ||
} else if (type == "timestep") { | ||
enable_timestep = true; | ||
// Check that solver:monitor_timestep is true, otherwise type=timestep does nothing | ||
bool monitor_timestep; | ||
OPTION(global_options, monitor_timestep, false); | ||
if (!monitor_timestep) { | ||
throw BoutException("fast_output:type=timestep but solver:monitor_timestep=false, so FastOutput would do nothing. You probably want to set solver:monitor_timestep=true."); | ||
} | ||
} else if (type == "none") { | ||
// don't enable anything | ||
} else { | ||
throw BoutException("Unrecognized option for FastOutput: type=%s", type.c_str()); | ||
} | ||
if (enable_monitor || enable_timestep) { | ||
enabled = true; | ||
// Read more options | ||
std::string prefix; | ||
OPTION(options, prefix, "BOUT.fast"); | ||
std::string dump_ext; | ||
OPTION(options, dump_ext, "nc"); | ||
std::string datadir; | ||
OPTION(global_options, datadir, "data"); | ||
bool append; | ||
OPTION(global_options, append, false); | ||
|
||
std::string filename = "%s/" + prefix + ".%s"; | ||
|
||
// Initialize output_file | ||
output_file = Datafile(options); | ||
if (append) { | ||
output_file.opena(filename.c_str(), datadir.c_str(), dump_ext.c_str()); | ||
} else { | ||
output_file.openw(filename.c_str(), datadir.c_str(), dump_ext.c_str()); | ||
} | ||
|
||
// Add the time to the output | ||
int MYPE; | ||
MPI_Comm_rank(BoutComm::get(), &MYPE); | ||
if (MYPE == 0) | ||
output_file.add(current_time, "time", true); | ||
} | ||
} | ||
|
||
void FastOutput::add(const std::string name, Field3D &f, const int ix_global, const int iy_global, const int iz_global) { | ||
int ix = ix_global - mesh->OffsetX; | ||
int iy = iy_global - mesh->OffsetY; | ||
int iz = iz_global - mesh->OffsetZ; | ||
|
||
if (ix>=mesh->xstart && ix<=mesh->xend && iy>=mesh->ystart && iy<=mesh->yend && iz>=0 && iz<mesh->LocalNz) { | ||
// Store a reference to the field | ||
field3d_list.push_back(&f); | ||
|
||
// Store the indices of the element to output | ||
field3d_inds.push_back({ix, iy, iz}); | ||
|
||
// Extend output_vals | ||
output_vals.push_back(0.); | ||
|
||
// Add to the output_file | ||
output_file.add(output_vals.back(), name.c_str(), true); | ||
// Store the indices as attributes of the variable | ||
output_file.setAttribute(name, "ix", ix_global); | ||
output_file.setAttribute(name, "iy", iy_global); | ||
output_file.setAttribute(name, "iz", iz_global); | ||
} | ||
} | ||
|
||
int FastOutput::monitor_method(BoutReal simtime) { | ||
// Set time | ||
current_time = simtime; | ||
|
||
// Set values to output | ||
for (size_t i=0; i<output_vals.size(); i++) { | ||
output_vals[i] = field3d_list[i]->operator[](field3d_inds[i]); | ||
} | ||
|
||
output_file.write(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright L. Easy, F. Militello, T. Nicholas, J. Omotani, F. Riva, N. | ||
Walkden, UKAEA, 2017, 2018 | ||
email: [email protected] | ||
This file is part of the STORM module of BOUT++. | ||
STORM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
STORM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with STORM. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __FAST_OUTPUT_H__ | ||
#define __FAST_OUTPUT_H__ | ||
|
||
#include <bout/monitor.hxx> | ||
#include <bout/physicsmodel.hxx> | ||
#include <bout/region.hxx> | ||
#include <datafile.hxx> | ||
#include <globals.hxx> | ||
#include <deque> | ||
class Solver; | ||
|
||
// Subclass of BOUT++ Monitor class so we can pass to Solver:: | ||
class FastOutput : public Monitor { | ||
public: | ||
FastOutput(); | ||
FastOutput(FastOutput &f) = delete; | ||
FastOutput &operator=(FastOutput &f) = delete; | ||
|
||
/// Add a point to the output: the element of f with global indices | ||
/// {ix,iy,iz} will be written when monitor_method() is called | ||
void add(const std::string name, Field3D &f, const int ix, const int iy, const int iz); | ||
|
||
/// Writes added points to output_file | ||
int monitor_method(BoutReal simtime); | ||
|
||
bool enabled=false, enable_monitor=false, enable_timestep=false; | ||
|
||
/// provide Monitor::call method which is called by the Solver | ||
int call(Solver* UNUSED(solver), BoutReal time, int UNUSED(iter), int UNUSED(nout)) { | ||
return monitor_method(time); | ||
} | ||
private: | ||
Datafile output_file; | ||
std::deque<Field3D*> field3d_list; | ||
std::deque<Ind3D> field3d_inds; | ||
BoutReal current_time; | ||
std::deque<BoutReal> output_vals; | ||
}; | ||
|
||
#endif //__FAST_OUTPUT_H__ |
Oops, something went wrong.