Commit 4afce1f2 authored by ext-calvo_p's avatar ext-calvo_p

Resolve "Add option to write VTK file"

parent 5b44baf7
This diff is collapsed.
......@@ -32,21 +32,21 @@ public:
virtual ~Option();
/// Make clone.
virtual Option *clone(const std::string &name);
virtual Option* clone(const std::string& name);
/// Execute the command.
virtual void execute();
private:
void handlePsDumpFrame(const std::string &dumpFrame);
void handlePsDumpFrame(const std::string& dumpFrame);
void update(const std::vector<Attribute>&);
// Not implemented.
Option(const Option &);
void operator=(const Option &);
Option(const Option&);
void operator=(const Option&);
// Clone constructor.
Option(const std::string &name, Option *parent);
Option(const std::string& name, Option* parent);
};
#endif // OPAL_Option_HH
\ No newline at end of file
#endif // OPAL_Option_HH
......@@ -18,106 +18,88 @@
//
#include "OptionTypes.h"
#include "Utilities/ClassicRandom.h"
#include <string>
namespace Options {
// The global program options.
bool echo = false;
bool info = true;
int infoLevel = 1;
bool warn = true;
int warnLevel = 1;
bool csrDump = false;
// If true create symmetric distribution
bool cZero = false;
bool asciidump = false;
// If the distance of a particle to bunch mass larger than remotePartDel times of the rms size of the bunch in any dimension,
// the particle will be deleted artifically to hold the accuracy of space charge calculation. The default setting of -1 stands for no deletion.
double remotePartDel = 0.0;
double beamHaloBoundary = 0;
bool writeBendTrajectories = false;
// The global program options.
bool mtrace = false;
bool psDumpEachTurn = false;
DumpFrame psDumpFrame = GLOBAL;
bool rhoDump = false;
bool ebDump = false;
bool enableHDF5 = true;
bool warn = true;
int warnLevel = 1;
// The global random generator.
Random rangen;
// The current random seed.
int seed = 123456789;
// the number of refinements of the search range for the phase with maximum energy
// if eq 0 then no autophase
int autoPhase = 6;
// The frequency to dump the phase space, i.e.dump data when step%psDumpFreq==0
int psDumpFreq = 10;
// // The frequency to dump the phase space, i.e.dump data when step%psDumpFreq==0
// double rDump = 0.0;
// The frequency to dump statistical quantities such as beam RMS properties, i.e. dump
// when step%statDumpFreq == 0.
int statDumpFreq = 10;
// The frequency to dump single particle trajectory of particles with ID = 0 & 1
bool psDumpEachTurn = false;
DumpFrame psDumpFrame = GLOBAL;
int sptDumpFreq = 1;
// The frequency to do particles repartition for better load balance between nodes
int repartFreq = 10;
// The number of bins that have to be emitted before the bin are squashed into a single bin
int minBinEmitted = 10;
// The number of steps into the simulation before the bins are squashed into a single bin
int minStepForRebin = 200;
// The frequency to reset energy bin ID for all particles
int rebinFreq = 100;
/// The frequency to solve space charge fields.
int scSolveFreq = 1;
// How many small timesteps are inside the large timestep used in multiple time stepping (MTS) integrator
int mtsSubsteps = 1;
// The frequency to dump the particle-geometry surface interation data, -1 stands for no dump.
int surfDumpFreq = -1;
double remotePartDel = 0.0;
bool rhoDump = false;
bool ebDump = false;
bool csrDump = false;
int autoPhase = 6;
// Options for the Belos solver
int numBlocks = 0;
int recycleBlocks = 0;
int nLHS = 1;
bool cZero = false;
std::string rngtype = std::string("RANDOM");
bool cloTuneOnly = false;
bool enableHDF5 = true;
bool enableVTK = true;
bool asciidump = false;
// Governs how often boundp_destroy is called to destroy lost particles
// Mainly used in the CyclotronTracker as of now -DW
int boundpDestroyFreq = 10;
// Using hard edge model for calculation of path length
double beamHaloBoundary = 0;
bool cloTuneOnly = false;
bool idealized = false;
// opal version of input file
bool writeBendTrajectories = false;
int version = 10000;
bool amr = false;
/// The frequency to dump AMR grid data and particles into file
int amrYtDumpFreq = 10;
int amrRegridFreq = 10;
bool memoryDump = false;
......@@ -125,4 +107,4 @@ namespace Options {
double haloShift = 0.0;
unsigned int delPartFreq = 1;
}
\ No newline at end of file
}
......@@ -22,6 +22,8 @@
#include "OptionTypes.h"
#include "Utilities/ClassicRandom.h"
#include <string>
namespace Options {
/// Echo flag.
// If true, print an input echo.
......@@ -30,40 +32,17 @@ namespace Options {
/// Info flag.
// If true, print informative messages.
extern bool info;
extern int infoLevel;
/// Trace flag.
// If true, print CPU time before and after each command.
extern bool mtrace;
/// Warn flag.
// If true, print warning messages.
extern bool warn;
extern int warnLevel;
extern bool csrDump;
/// if true create symmetric distribution
extern bool cZero;
/// If true HDF5 files are written
extern bool enableHDF5;
extern bool asciidump;
// If the distance of a particle to bunch mass larger than remotePartDel times of the rms size of the bunch in any dimension,
// the particle will be deleted artifically to hold the accuracy of space charge calculation. The default setting of -1 stands for no deletion.
extern double remotePartDel;
extern double beamHaloBoundary;
extern bool writeBendTrajectories;
extern bool idealized;
/// Trace flag.
// If true, print CPU time before and after each command.
extern bool mtrace;
/// Random generator.
// The global random generator.
extern Random rangen;
......@@ -76,6 +55,16 @@ namespace Options {
/// The frequency to dump statistical values, e.e. dump data when step%statDumpFreq==0
extern int statDumpFreq;
/// phase space dump flag for OPAL-cycl
// if true, dump phase space after each turn
extern bool psDumpEachTurn;
/// flag to decide in which coordinate frame the phase space will be dumped for OPAL-cycl
// - GLOBAL, in Cartesian frame of the global particle
// - BUNCH_MEAN, in Cartesian frame of the bunch mean
// - REFERENCE, in Cartesian frame of the reference (0) particle
extern DumpFrame psDumpFrame;
/// The frequency to dump single particle trajectory of particles with ID = 0 & 1
extern int sptDumpFreq;
......@@ -91,51 +80,63 @@ namespace Options {
/// The frequency to reset energy bin ID for all particles
extern int rebinFreq;
/// phase space dump flag for OPAL-cycl
// if true, dump phase space after each turn
extern bool psDumpEachTurn;
// Governs how often boundp_destroy is called to destroy lost particles
// Mainly used in the CyclotronTracker as of now -DW
extern int boundpDestroyFreq;
/// flag to decide in which coordinate frame the phase space will be dumped for OPAL-cycl
// - GLOBAL, in Cartesian frame of the global particle
// - BUNCH_MEAN, in Cartesian frame of the bunch mean
// - REFERENCE, in Cartesian frame of the reference (0) particle
extern DumpFrame psDumpFrame;
/// The frequency to solve space charge fields.
extern int scSolveFreq;
// How many small timesteps are inside the large timestep used in multiple time stepping (MTS) integrator
extern int mtsSubsteps;
// If the distance of a particle to bunch mass larger than remotePartDel times of the rms size of the bunch in any dimension,
// the particle will be deleted artifically to hold the accuracy of space charge calculation. The default setting of -1 stands for no deletion.
extern double remotePartDel;
extern bool rhoDump;
extern bool ebDump;
extern bool csrDump;
// the number of refinements of the search range for the phase with maximum energy
// if eq 0 then no autophase
// if true opal find the phases in the cavities, such that the energy gain is at maximum
extern int autoPhase;
/// The frequency to dump the particle-geometry surface interation data.
extern int surfDumpFreq;
// Options for the Belos solver
/// RCG: cycle length
extern int numBlocks;
/// RCG: number of recycle blocks
extern int recycleBlocks;
/// number of old left hand sides used to extrapolate a new start vector
extern int nLHS;
/// If true create symmetric distribution
extern bool cZero;
/// random number generator
extern std::string rngtype;
/// If true HDF5 files are written
extern bool enableHDF5;
/// If true VTK files are written
extern bool enableVTK;
extern bool asciidump;
// Governs how often boundp_destroy is called to destroy lost particles
// Mainly used in the CyclotronTracker as of now -DW
extern int boundpDestroyFreq;
extern double beamHaloBoundary;
/// Do closed orbit and tune calculation only.
extern bool cloTuneOnly;
// Using hard edge model for calculation of path length
extern bool idealized;
extern bool writeBendTrajectories;
/// opal version of input file
extern int version;
......@@ -157,4 +158,4 @@ namespace Options {
extern unsigned int delPartFreq;
}
#endif // OPAL_Options_HH
\ No newline at end of file
#endif // OPAL_Options_HH
......@@ -20,10 +20,11 @@
#include "Structure/BoundaryGeometry.h"
#include <algorithm>
#include <cmath>
#include <ctime>
#include <fstream>
#include <string>
#include <algorithm>
#include "H5hut.h"
#include <cfloat>
......@@ -32,8 +33,12 @@
#include "Algorithms/PartBunchBase.h"
#include "Expressions/SRefExpr.h"
#include "Elements/OpalBeamline.h"
#include "Utilities/Options.h"
#include "Physics/Physics.h"
#include "Utilities/OpalException.h"
#include "Utilities/Options.h"
#include <boost/filesystem.hpp>
#include <gsl/gsl_sys.h>
extern Inform* gmsg;
......@@ -328,6 +333,7 @@ Vector_t get_min_extent (std::vector<Vector_t>& coords) {
write legacy VTK file of voxel mesh
*/
static void write_voxel_mesh (
std::string fname,
const std::unordered_map< int, std::unordered_set<int> >& ids,
const Vector_t& hr_m,
const Vektor<int,3>& nr,
......@@ -336,12 +342,10 @@ static void write_voxel_mesh (
/*----------------------------------------------------------------------*/
const size_t numpoints = 8 * ids.size ();
std::ofstream of;
std::string fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
"testBBox.vtk"
});
*gmsg << "* Writing VTK file of voxel mesh." << endl;
of.open (fname);
assert (of.is_open ());
PAssert (of.is_open ());
of.precision (6);
of << "# vtk DataFile Version 2.0" << std::endl;
......@@ -1029,6 +1033,7 @@ BoundaryGeometry::BoundaryGeometry() :
TPartInside_m = IpplTimings::getTimer ("Particle Inside");
h5FileName_m = Attributes::getString (itsAttr[FGEOM]);
try {
defGeometry->update ();
OpalData::getInstance ()->define (defGeometry);
......@@ -1040,7 +1045,6 @@ BoundaryGeometry::BoundaryGeometry() :
if (!h5FileName_m.empty ())
initialize ();
}
BoundaryGeometry::BoundaryGeometry(
......@@ -1608,18 +1612,38 @@ BoundaryGeometry::computeMeshVoxelization (void) {
}
} // for_each triangle
*gmsg << "* Mesh voxelization done." << endl;
if(Ippl::myNode() == 0) {
write_voxel_mesh (voxelMesh_m.ids,
voxelMesh_m.sizeOfVoxel,
voxelMesh_m.nr_m,
voxelMesh_m.minExtent);
// write voxel mesh into VTK file
if (Ippl::myNode() == 0 && Options::enableVTK) {
std::string vtkFileName = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
"testBBox.vtk"
});
bool writeVTK = false;
if (!boost::filesystem::exists(vtkFileName)) {
writeVTK = true;
} else {
std::time_t t_geom = boost::filesystem::last_write_time(h5FileName_m);
std::time_t t_vtk = boost::filesystem::last_write_time(vtkFileName);
if (std::difftime(t_geom,t_vtk) > 0)
writeVTK = true;
}
if (writeVTK) {
write_voxel_mesh (vtkFileName,
voxelMesh_m.ids,
voxelMesh_m.sizeOfVoxel,
voxelMesh_m.nr_m,
voxelMesh_m.minExtent);
}
}
}
void BoundaryGeometry::initialize () {
class Local {
public:
static void computeGeometryInterval (BoundaryGeometry* bg) {
......@@ -1998,6 +2022,12 @@ Change orientation if diff is:
*gmsg << "* Initializing Boundary Geometry..." << endl;
IpplTimings::startTimer (Tinitialize_m);
if (!boost::filesystem::exists(h5FileName_m)) {
throw OpalException("BoundaryGeometry::BoundaryGeometry",
"Failed to open file '" + h5FileName_m +
"', please check if it exists");
}
*gmsg << "* Filename: " << h5FileName_m.c_str() << endl;
double xscale = Attributes::getReal(itsAttr[XSCALE]);
......
......@@ -150,7 +150,7 @@ void DataSink::changeH5Wrapper(H5PartWrapper *h5wrapper) {
void DataSink::writeGeomToVtk(BoundaryGeometry &bg, std::string fn) {
if(Ippl::myNode() == 0) {
if (Ippl::myNode() == 0 && Options::enableVTK) {
bg.writeGeomToVtk (fn);
}
}
......
......@@ -104,7 +104,7 @@ TrackRun::TrackRun():
itsAttr[FIELDSOLVER] = Attributes::makeString
("FIELDSOLVER", "Field solver to be used ", "FIELDSOLVER");
itsAttr[BOUNDARYGEOMETRY] = Attributes::makeString
("BOUNDARYGEOMETRY", "Boundary geometry to be used NONE (default)", "NONE");
("BOUNDARYGEOMETRY", "Boundary geometry to be used NONE (default)", "NONE");
itsAttr[DISTRIBUTION] = Attributes::makeStringArray
("DISTRIBUTION", "List of particle distributions to be used ");
itsAttr[TRACKBACK] = Attributes::makeBool
......@@ -222,8 +222,8 @@ void TrackRun::setupThickTracker()
// Ask the dictionary if BoundaryGeometry is allocated.
// If it is allocated use the allocated BoundaryGeometry
if (!OpalData::getInstance()->hasGlobalGeometry()) {
BoundaryGeometry *bg = BoundaryGeometry::find(Attributes::getString(itsAttr[BOUNDARYGEOMETRY]))->
clone(getOpalName() + std::string("_geometry"));
const std::string geomDescriptor = Attributes::getString(itsAttr[BOUNDARYGEOMETRY]);
BoundaryGeometry* bg = BoundaryGeometry::find(geomDescriptor)->clone(geomDescriptor);
OpalData::getInstance()->setGlobalGeometry(bg);
}
}
......@@ -329,8 +329,8 @@ void TrackRun::setupTTracker(){
// Ask the dictionary if BoundaryGeometry is allocated.
// If it is allocated use the allocated BoundaryGeometry
if (!OpalData::getInstance()->hasGlobalGeometry()) {
BoundaryGeometry *bg = BoundaryGeometry::find(Attributes::getString(itsAttr[BOUNDARYGEOMETRY]))->
clone(getOpalName() + std::string("_geometry"));
const std::string geomDescriptor = Attributes::getString(itsAttr[BOUNDARYGEOMETRY]);
BoundaryGeometry* bg = BoundaryGeometry::find(geomDescriptor)->clone(geomDescriptor);
OpalData::getInstance()->setGlobalGeometry(bg);
}
}
......@@ -432,8 +432,8 @@ void TrackRun::setupCyclotronTracker(){
// Ask the dictionary if BoundaryGeometry is allocated.
// If it is allocated use the allocated BoundaryGeometry
if (!OpalData::getInstance()->hasGlobalGeometry()) {
BoundaryGeometry *bg = BoundaryGeometry::find(Attributes::getString(itsAttr[BOUNDARYGEOMETRY]))->
clone(getOpalName() + std::string("_geometry"));
const std::string geomDescriptor = Attributes::getString(itsAttr[BOUNDARYGEOMETRY]);
BoundaryGeometry* bg = BoundaryGeometry::find(geomDescriptor)->clone(geomDescriptor);
OpalData::getInstance()->setGlobalGeometry(bg);
}
}
......@@ -703,4 +703,4 @@ double TrackRun::setDistributionParallelT(Beam *beam) {
// Return charge per macroparticle.
return beam->getChargePerParticle();
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment