Skip to content

Commit

Permalink
Merge pull request #1 from boutproject/v1.1
Browse files Browse the repository at this point in the history
STORM v1.1
  • Loading branch information
johnomotani authored Feb 10, 2021
2 parents 7838733 + 68b6475 commit 1cd4fa1
Show file tree
Hide file tree
Showing 37 changed files with 2,325 additions and 662 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ BOUT.settings
*.bmp
*.pdf

*filaments
storm3d/storm
*/make.config
data_*
*.txt
storm2d/storm2d
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ https://doi.org/10.1088/0741-3335/58/11/115010

[4] F. Militello, B. Dudson, L. Easy, A. Kirk and P. Naylor, Plasma Physics and
Controlled Fusion 59, 125013 (2017), https://doi.org/10.1088/1361-6587/aa9252

[5] D. Hoare, F. Militello, J.T. Omotani, F. Riva, S. Newton, T. Nicholas, D.
Ryan and N.R. Walkden, Plasma Physics and Controlled Fusion 61, 105013 (2019),
https://doi.org/10.1088/1361-6587/ab34f8
121 changes: 121 additions & 0 deletions shared/fast_output.cxx
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;
}
61 changes: 61 additions & 0 deletions shared/fast_output.hxx
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__
Loading

0 comments on commit 1cd4fa1

Please sign in to comment.