Skip to content

Commit

Permalink
Merge pull request #108 from EXP-code/outdirTest
Browse files Browse the repository at this point in the history
Check for valid output directory for FieldGenerator methods that write files
  • Loading branch information
The9Cat authored Feb 7, 2025
2 parents 6997a97 + 33179b7 commit a232ebd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
25 changes: 25 additions & 0 deletions expui/FieldGenerator.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <filesystem>
#include <algorithm>
#include <iomanip>
#include <sstream>
Expand Down Expand Up @@ -259,6 +260,14 @@ namespace Field
const std::string prefix,
const std::string outdir)
{
if (myid==0) {
// Verify existence of directory
bool filepathExists = std::filesystem::is_directory(outdir);
if (not filepathExists)
throw std::runtime_error("FieldGenerator::file_lines: directory <" +
outdir + "> does not exist");
}

auto db = lines(basis, coefs, beg, end, num);

if (myid==0) {
Expand Down Expand Up @@ -505,6 +514,14 @@ namespace Field
const std::string prefix,
const std::string outdir)
{
if (myid==0) {
// Verify existence of directory
bool filepathExists = std::filesystem::is_directory(outdir);
if (not filepathExists)
throw std::runtime_error("FieldGenerator::file_slices: directory <" +
outdir + "> does not exist");
}

auto db = slices(basis, coefs);

if (myid==0) {
Expand Down Expand Up @@ -710,6 +727,14 @@ namespace Field
const std::string prefix,
const std::string outdir)
{
if (myid==0) {
// Verify existence of directory
bool filepathExists = std::filesystem::is_directory(outdir);
if (not filepathExists)
throw std::runtime_error("FieldGenerator::file_volumes: directory <" +
outdir + "> does not exist");
}

auto db = volumes(basis, coefs);

int bunch = db.size()/numprocs;
Expand Down
4 changes: 2 additions & 2 deletions exputil/VtkGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ void VtkGrid::Add(const std::vector<double>& data, const std::string& name)
//
int I = 0;

for (int i=0; i<nx; i++) {
for (int k=0; k<nz; k++) {
for (int j=0; j<ny; j++) {
for (int k=0; k<nz; k++) {
for (int i=0; i<nx; i++) {
dataSet[newName][I++] = static_cast<float>(data[(k*ny + j)*nx + i]);
}
}
Expand Down
3 changes: 0 additions & 3 deletions pyEXP/FieldWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,7 @@ void FieldGeneratorClasses(py::module &m) {
See also
--------
<<<<<<< HEAD
=======
points : generate fields at an array of mesh points
>>>>>>> pointMesh
slices : generate fields in a surface slice given by the
initializtion grid
volumes : generate fields in volume given by the initializtion grid
Expand Down

0 comments on commit a232ebd

Please sign in to comment.