38 #include <boost/algorithm/string.hpp> 39 #include <boost/tokenizer.hpp> 44 #include <boost/format.hpp> 56 namespace LibUtilities
61 :
PtsIO(pComm, sharedFilesystem)
75 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
76 size_t np = ptsField->GetNpoints();
78 std::string filename =
SetUpOutput(outFile,
true, backup);
81 std::ofstream ptsFile;
82 ptsFile.open(filename.c_str());
84 std::vector<std::string> xyz;
88 xyz.resize(ptsField->GetDim());
90 std::string fn = boost::algorithm::join(xyz,
",");
91 ptsFile <<
"# " << fn <<
",";
92 fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
97 ptsField->GetPts(pts);
98 for (
size_t i = 0; i < np; ++i)
100 ptsFile << pts[0][i];
101 for (
size_t j = 1; j < nTotvars; ++j)
103 ptsFile <<
"," << pts[j][i];
105 ptsFile << std::endl;
114 std::stringstream errstr;
115 errstr <<
"Unable to load file: " << inFile << std::endl;
116 std::ifstream in(inFile.c_str());
117 ASSERTL0(in.is_open(), errstr.str());
120 std::getline(in, line);
121 boost::erase_first(line,
"#");
123 std::vector<std::string> fieldNames;
125 ASSERTL0(valid,
"Unable to process list of fields from line: " + line);
128 for (
auto &it : fieldNames)
130 if (it ==
"x" || it ==
"y" || it ==
"z")
136 size_t totvars = fieldNames.size();
138 std::vector<NekDouble> ptsSerial;
139 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
141 while (getline(in, line))
145 ASSERTL0(std::distance(tok.begin(), tok.end()) ==
146 std::iterator_traits<Tokenizer::iterator>::difference_type(totvars),
147 "wrong number of columns in line: " + line);
154 boost::lexical_cast<NekDouble>(
155 boost::trim_copy(std::string(it))));
157 catch(
const boost::bad_lexical_cast &)
164 size_t npts = ptsSerial.size() / totvars;
167 for (
size_t i = 0; i < totvars; ++i)
172 for (
size_t i = 0; i < npts; ++i)
174 for (
size_t j = 0; j < totvars; ++j)
176 pts[j][i] = ptsSerial[i * totvars + j];
181 std::vector<std::string> dimNames = {
"x",
"y",
"z"};
182 for (
int i = 0; i < dim; ++i)
184 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
185 if (
p != fieldNames.end())
187 auto j = std::distance(fieldNames.begin(),
p);
198 std::string tmp2 = fieldNames[i];
199 fieldNames[i] = fieldNames[j];
200 fieldNames[j] = tmp2;
203 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 mod...
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
virtual void v_ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField)
std::shared_ptr< PtsField > PtsFieldSharedPtr
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::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
void SetUpFieldMetaData(const std::string outname)
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
CsvIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)