114{
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());
119
120 std::string line;
121 std::getline(in, line);
122 boost::erase_first(line, "#");
123
124 std::vector<std::string> fieldNames;
126 ASSERTL0(valid,
"Unable to process list of fields from line: " + line);
127
128 int dim = 0;
129 for (auto &it : fieldNames)
130 {
131 if (it == "x" || it == "y" || it == "z")
132 {
133 dim++;
134 }
135 }
136
137 ASSERTL0(dim,
"Failed to find a paramater labelled \"x\",\"y\" or \"z\" "
138 "in file" +
139 inFile + ". Is the coordinated labelled something else?");
140
141 size_t totvars = fieldNames.size();
142 std::vector<std::string> dimNames = {"x", "y", "z"};
143 Array<OneD, int> loc_coord(dim);
144 for (int i = 0; i < dim; ++i)
145 {
146 auto p = std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
147 if (p != fieldNames.end())
148 {
149 auto j = std::distance(fieldNames.begin(), p);
150
151 loc_coord[i] = j;
152 }
153 }
154
155 std::vector<NekDouble> ptsSerial;
156 typedef boost::tokenizer<boost::escaped_list_separator<char>> Tokenizer;
157 Tokenizer tok(line);
158 while (getline(in, line))
159 {
160 tok.assign(line);
161
162 ASSERTL0(std::distance(tok.begin(), tok.end()) ==
163 std::iterator_traits<Tokenizer::iterator>::difference_type(
164 totvars),
165 "wrong number of columns in line: " + line);
166
167 bool ReadValue = true;
168
170 {
171 int cnt = 0;
172 for (auto &it : tok)
173 {
174 for (int j = 0; j < dim; ++j)
175 {
176 if (cnt == loc_coord[j])
177 {
179 std::stod(boost::trim_copy(std::string(it)));
180 switch (j)
181 {
182 case 0:
183 {
184 if ((CoordVal < Range->m_xmin) ||
185 (CoordVal > Range->m_xmax))
186 {
187 ReadValue = false;
188 }
189 }
190 break;
191 case 1:
192 {
193 if ((CoordVal < Range->m_ymin) ||
194 (CoordVal > Range->m_ymax))
195 {
196 ReadValue = false;
197 }
198 }
199 break;
200 case 2:
201 {
202 if ((CoordVal < Range->m_zmin) ||
203 (CoordVal > Range->m_zmax))
204 {
205 ReadValue = false;
206 }
207 }
208 }
209 }
210 }
211 cnt++;
212 }
213 }
214 if (ReadValue)
215 {
216 for (auto &it : tok)
217 {
218 try
219 {
220 ptsSerial.push_back(
221 std::stod(boost::trim_copy(std::string(it))));
222 }
223 catch (...)
224 {
226 "could not convert line: " + line);
227 }
228 }
229 }
230 }
231
232 size_t npts = ptsSerial.size() / totvars;
233
234 Array<OneD, Array<OneD, NekDouble>> pts(totvars);
235 for (size_t i = 0; i < totvars; ++i)
236 {
237 pts[i] = Array<OneD, NekDouble>(npts);
238 }
239
240 for (size_t i = 0; i < npts; ++i)
241 {
242 for (size_t j = 0; j < totvars; ++j)
243 {
244 pts[j][i] = ptsSerial[i * totvars + j];
245 }
246 }
247
248
249 for (int i = 0; i < dim; ++i)
250 {
251 auto p = std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
252 if (p != fieldNames.end())
253 {
254 auto j = std::distance(fieldNames.begin(), p);
255
256 if (i == j)
257 {
258 continue;
259 }
260
261 Array<OneD, NekDouble> tmp = pts[i];
262 pts[i] = pts[j];
263 pts[j] = tmp;
264
265 std::string tmp2 = fieldNames[i];
266 fieldNames[i] = fieldNames[j];
267 fieldNames[j] = tmp2;
268 }
269 }
270 fieldNames.erase(fieldNames.begin(), fieldNames.begin() + dim);
271
273}
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
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.
static DomainRangeShPtr NullDomainRangeShPtr
std::vector< double > p(NPUPPER)