38#include <boost/algorithm/string.hpp>
39#include <boost/tokenizer.hpp>
44#include <boost/format.hpp>
58 :
PtsIO(pComm, sharedFilesystem)
72 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
73 size_t np = ptsField->GetNpoints();
75 std::string filename =
SetUpOutput(outFile,
true, backup);
78 std::ofstream ptsFile;
79 ptsFile.open(filename.c_str());
81 std::vector<std::string> xyz;
85 xyz.resize(ptsField->GetDim());
87 std::string fn = boost::algorithm::join(xyz,
",");
88 ptsFile <<
"# " << fn <<
",";
89 fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
94 ptsField->GetPts(pts);
95 for (
size_t i = 0; i < np; ++i)
98 for (
size_t j = 1; j < nTotvars; ++j)
100 ptsFile <<
"," << pts[j][i];
102 ptsFile << std::endl;
115 std::stringstream errstr;
116 errstr <<
"Unable to load file: " << inFile << std::endl;
117 std::ifstream in(inFile.c_str());
118 ASSERTL0(in.is_open(), errstr.str());
121 std::getline(in, line);
122 boost::erase_first(line,
"#");
124 std::vector<std::string> fieldNames;
126 ASSERTL0(valid,
"Unable to process list of fields from line: " + line);
129 for (
auto &it : fieldNames)
131 if (it ==
"x" || it ==
"y" || it ==
"z")
137 ASSERTL0(dim,
"Failed to find a paramater labelled \"x\",\"y\" or \"z\" "
139 inFile +
". Is the coordinated labelled something else?");
141 size_t totvars = fieldNames.size();
142 std::vector<std::string> dimNames = {
"x",
"y",
"z"};
144 for (
int i = 0; i < dim; ++i)
146 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
147 if (
p != fieldNames.end())
149 auto j = std::distance(fieldNames.begin(),
p);
155 std::vector<NekDouble> ptsSerial;
156 typedef boost::tokenizer<boost::escaped_list_separator<char>> Tokenizer;
158 while (getline(in, line))
162 ASSERTL0(std::distance(tok.begin(), tok.end()) ==
163 std::iterator_traits<Tokenizer::iterator>::difference_type(
165 "wrong number of columns in line: " + line);
167 bool ReadValue =
true;
174 for (
int j = 0; j < dim; ++j)
176 if (cnt == loc_coord[j])
179 std::stod(boost::trim_copy(std::string(it)));
184 if ((CoordVal < Range->m_xmin) ||
185 (CoordVal > Range->m_xmax))
193 if ((CoordVal < Range->m_ymin) ||
194 (CoordVal > Range->m_ymax))
202 if ((CoordVal < Range->m_zmin) ||
203 (CoordVal > Range->m_zmax))
221 std::stod(boost::trim_copy(std::string(it))));
226 "could not convert line: " + line);
232 size_t npts = ptsSerial.size() / totvars;
235 for (
size_t i = 0; i < totvars; ++i)
240 for (
size_t i = 0; i < npts; ++i)
242 for (
size_t j = 0; j < totvars; ++j)
244 pts[j][i] = ptsSerial[i * totvars + j];
249 for (
int i = 0; i < dim; ++i)
251 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
252 if (
p != fieldNames.end())
254 auto j = std::distance(fieldNames.begin(),
p);
265 std::string tmp2 = fieldNames[i];
266 fieldNames[i] = fieldNames[j];
267 fieldNames[j] = tmp2;
270 fieldNames.erase(fieldNames.begin(), fieldNames.begin() + dim);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
std::string v_GetFileEnding() const override
void v_ImportPtsFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField, DomainRangeShPtr &Range) override
CsvIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
std::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
void SetUpFieldMetaData(const std::string outname)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
std::shared_ptr< PtsField > PtsFieldSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
static DomainRangeShPtr NullDomainRangeShPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)