192 Substitute(sessionFile,
"@TYPE@", expansionType);
197 fs::path sessionPath = scratch.
m_path / fs::path(
"FieldFileRoundTrip" +
198 expansionType +
".xml");
199 fs::path fieldPath = scratch.
m_path / fs::path(
"FieldFileRoundTrip" +
200 expansionType +
".fld");
202 std::ofstream sessionOut(sessionPath.string());
203 sessionOut << sessionFile;
207 std::string exe =
"FieldFileRoundTrip";
208 std::string file = sessionPath.string();
209 char *argv[] = {exe.data(), file.data(),
nullptr};
220 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDefs =
221 expList->GetFieldDefinitions();
222 BOOST_REQUIRE_MESSAGE(fieldDefs.size() > 1,
223 "Expected one field definition per element shape.");
227 const int nCoeffs = expList->GetNcoeffs();
228 std::vector<NekDouble> written(nCoeffs);
229 for (
int i = 0; i < nCoeffs; ++i)
231 written[i] = 1.0 + 0.25 * i;
234 std::vector<std::vector<NekDouble>> fieldData(fieldDefs.size());
235 for (std::size_t i = 0; i < fieldDefs.size(); ++i)
237 fieldDefs[i]->m_fields.push_back(
"u");
238 expList->AppendFieldData(fieldDefs[i], fieldData[i], written);
243 fieldIO->Write(fieldPath.string(), fieldDefs, fieldData);
246 std::vector<LibUtilities::FieldDefinitionsSharedPtr> readDefs;
247 std::vector<std::vector<NekDouble>> readData;
248 fieldIO->Import(fieldPath.string(), readDefs, readData);
250 std::string variable =
"u";
251 std::vector<NekDouble> read(nCoeffs, 0.0);
252 for (std::size_t i = 0; i < readDefs.size(); ++i)
254 expList->ExtractDataToCoeffs(readDefs[i], readData[i], variable, read);
257 for (
int i = 0; i < nCoeffs; ++i)
259 BOOST_CHECK_CLOSE(read[i], written[i], 1.0e-8);
286 auto build = [&expansionType, &scratch](
const std::string &numModes,
287 const std::string &tag) {
292 fs::path path = scratch.
m_path / fs::path(
"FieldOrderChange" +
293 expansionType + tag +
".xml");
294 std::ofstream out(path.string());
300 fs::path lowPath = build(
"4",
"Low");
301 fs::path highPath = build(
"5",
"High");
302 fs::path fieldLow = scratch.
m_path / fs::path(
"FieldOrderChange" +
303 expansionType +
"Low.fld");
304 fs::path fieldHigh = scratch.
m_path / fs::path(
"FieldOrderChange" +
305 expansionType +
"High.fld");
307 std::string exe =
"FieldOrderChange";
308 std::string lowFile = lowPath.string();
309 std::string highFile = highPath.string();
312 char *argvLow[] = {exe.data(), lowFile.data(),
nullptr};
321 char *argvHigh[] = {exe.data(), highFile.data(),
nullptr};
330 BOOST_REQUIRE(expLow->GetNcoeffs() != expHigh->GetNcoeffs());
335 std::vector<NekDouble> &coeffs,
const fs::path &path) {
336 std::vector<LibUtilities::FieldDefinitionsSharedPtr> defs =
337 exp->GetFieldDefinitions();
338 std::vector<std::vector<NekDouble>> data(defs.size());
339 for (std::size_t i = 0; i < defs.size(); ++i)
341 defs[i]->m_fields.push_back(
"u");
342 exp->AppendFieldData(defs[i], data[i], coeffs);
351 const fs::path &path) {
352 std::vector<LibUtilities::FieldDefinitionsSharedPtr> defs;
353 std::vector<std::vector<NekDouble>> data;
356 std::string variable =
"u";
357 std::vector<NekDouble> coeffs(exp->GetNcoeffs(), 0.0);
358 for (std::size_t i = 0; i < defs.size(); ++i)
360 exp->ExtractDataToCoeffs(defs[i], data[i], variable, coeffs);
365 std::vector<NekDouble> written(expLow->GetNcoeffs());
366 for (std::size_t i = 0; i < written.size(); ++i)
368 written[i] = 1.0 + 0.25 *
static_cast<NekDouble>(i);
371 writeField(expLow, sessionLow, written, fieldLow);
374 std::vector<NekDouble> raised = readField(expHigh, sessionHigh, fieldLow);
375 writeField(expHigh, sessionHigh, raised, fieldHigh);
376 std::vector<NekDouble> read = readField(expLow, sessionLow, fieldHigh);
378 BOOST_REQUIRE_EQUAL(read.size(), written.size());
379 for (std::size_t i = 0; i < written.size(); ++i)
381 BOOST_CHECK_CLOSE(read[i], written[i], 1.0e-8);
384 sessionLow->Finalise();
385 sessionHigh->Finalise();