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 ASSERTL0(dim,
"Failed to find a paramater labelled \"x\",\"y\" or \"z\" "
137 "in file" + inFile +
". Is the coordinated labelled something else?");
139 size_t totvars = fieldNames.size();
140 std::vector<std::string> dimNames = {
"x",
"y",
"z"};
142 for (
int i = 0; i < dim; ++i)
144 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
145 if (
p != fieldNames.end())
147 auto j = std::distance(fieldNames.begin(),
p);
153 std::vector<NekDouble> ptsSerial;
154 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
156 while (getline(in, line))
160 ASSERTL0(std::distance(tok.begin(), tok.end()) ==
161 std::iterator_traits<Tokenizer::iterator>::difference_type(totvars),
162 "wrong number of columns in line: " + line);
164 bool ReadValue =
true;
171 for(
int j = 0; j < dim; ++j)
173 if(cnt == loc_coord[j])
175 NekDouble CoordVal = boost::lexical_cast<NekDouble>(
176 boost::trim_copy(std::string(it)));
181 if((CoordVal < Range->m_xmin) || (CoordVal > Range->m_xmax))
189 if((CoordVal < Range->m_ymin) || (CoordVal > Range->m_ymax))
197 if((CoordVal < Range->m_zmin) || (CoordVal > Range->m_zmax))
215 boost::lexical_cast<NekDouble>(
216 boost::trim_copy(std::string(it))));
218 catch(
const boost::bad_lexical_cast &)
226 size_t npts = ptsSerial.size() / totvars;
229 for (
size_t i = 0; i < totvars; ++i)
234 for (
size_t i = 0; i < npts; ++i)
236 for (
size_t j = 0; j < totvars; ++j)
238 pts[j][i] = ptsSerial[i * totvars + j];
243 for (
int i = 0; i < dim; ++i)
245 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
246 if (
p != fieldNames.end())
248 auto j = std::distance(fieldNames.begin(),
p);
259 std::string tmp2 = fieldNames[i];
260 fieldNames[i] = fieldNames[j];
261 fieldNames[j] = tmp2;
264 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.
virtual void v_ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField, DomainRangeShPtr &Range)
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)
The above copyright notice and this permission notice shall be included.