Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Nektar::SolverUtils::FilterHistoryPoints Class Reference

#include <FilterHistoryPoints.h>

Inheritance diagram for Nektar::SolverUtils::FilterHistoryPoints:
[legend]

Public Member Functions

SOLVER_UTILS_EXPORT FilterHistoryPoints (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
 
SOLVER_UTILS_EXPORT ~FilterHistoryPoints () override=default
 
- Public Member Functions inherited from Nektar::SolverUtils::Filter
SOLVER_UTILS_EXPORT Filter (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation)
 
virtual SOLVER_UTILS_EXPORT ~Filter ()=default
 
SOLVER_UTILS_EXPORT void Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT void Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT void Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT bool IsTimeDependent ()
 
SOLVER_UTILS_EXPORT std::string SetupOutput (const std::string ext, const ParamMap &pParams)
 
SOLVER_UTILS_EXPORT std::string SetupOutput (const std::string ext, const std::string inname)
 
SOLVER_UTILS_EXPORT void SetUpdateOnInitialise (bool flag)
 

Static Public Member Functions

static FilterSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
 Creates an instance of this class.
 

Static Public Attributes

static std::string cmdSetStartFilterFileNum
 
static std::string className
 Name of the class.
 

Protected Member Functions

SOLVER_UTILS_EXPORT void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT bool v_IsTimeDependent () override
 
bool GetPoint (Array< OneD, NekDouble > gloCoord, int I)
 
SOLVER_UTILS_EXPORT void v_WriteData (const int &rank, const Array< OneD, NekDouble > &data, const int &numFields, const NekDouble &time)
 
- Protected Member Functions inherited from Nektar::SolverUtils::Filter
virtual SOLVER_UTILS_EXPORT std::string v_SetupOutput (const std::string ext, const ParamMap &pParams)
 
virtual SOLVER_UTILS_EXPORT std::string v_SetupOutput (const std::string ext, const std::string inname)
 

Protected Attributes

Array< OneD, Array< OneD, const NekDouble > > m_historyPoints
 
size_t m_historyPointsSize = 0
 
unsigned int m_index = 0
 
unsigned int m_outputFrequency
 
int m_outputPlane
 plane to take history point from if using a homogeneous1D expansion
 
std::vector< int > m_planeIDs
 
bool m_isHomogeneous1D
 
bool m_waveSpace
 
std::string m_outputFile
 
std::ofstream m_outputStream
 
std::stringstream m_historyPointStream
 
std::list< std::tuple< Array< OneD, const NekDouble >, Array< OneD, const NekDouble >, int, int > > m_historyList
 
std::map< LibUtilities::PtsType, Array< OneD, NekDouble > > m_pointDatMap
 
std::map< LibUtilities::PtsType, Array< OneD, int > > m_pointNumMap
 
unsigned int m_outputIndex = 0
 
bool m_outputOneFile
 
bool m_adaptive
 
- Protected Attributes inherited from Nektar::SolverUtils::Filter
LibUtilities::SessionReaderSharedPtr m_session
 
const std::weak_ptr< EquationSystemm_equ
 
bool m_updateOnInitialise = true
 

Friends

class MemoryManager< FilterHistoryPoints >
 

Additional Inherited Members

- Public Types inherited from Nektar::SolverUtils::Filter
typedef std::map< std::string, std::string > ParamMap
 

Detailed Description

Definition at line 45 of file FilterHistoryPoints.h.

Constructor & Destructor Documentation

◆ FilterHistoryPoints()

Nektar::SolverUtils::FilterHistoryPoints::FilterHistoryPoints ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::shared_ptr< EquationSystem > &  pEquation,
const ParamMap pParams 
)

Definition at line 58 of file FilterHistoryPoints.cpp.

61 : Filter(pSession, pEquation)
62{
63 // OutputFile
64 std::string ext = ".his";
65 m_outputFile = Filter::SetupOutput(ext, pParams);
66
67 // OutputFrequency
68 auto it = pParams.find("OutputFrequency");
69 if (it == pParams.end())
70 {
72 }
73 else
74 {
75 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
76 m_outputFrequency = round(equ.Evaluate());
77 }
78
79 // output all data into one file
80 it = pParams.find("OutputOneFile");
81 if (it == pParams.end())
82 {
83 m_outputOneFile = true;
84 }
85 else
86 {
87 std::string sOption = it->second.c_str();
88 m_outputOneFile = (boost::iequals(sOption, "true")) ||
89 (boost::iequals(sOption, "yes"));
90 }
91
92 // OutputPlane
93 m_session->MatchSolverInfo("Homogeneous", "1D", m_isHomogeneous1D, false);
95 {
96 it = pParams.find("OutputPlane");
97 if (it == pParams.end())
98 {
99 m_outputPlane = -1;
100 }
101 else
102 {
103 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
104 m_outputPlane = round(equ.Evaluate());
105 }
106
107 it = pParams.find("WaveSpace");
108 if (it == pParams.end())
109 {
110 m_waveSpace = false;
111 }
112 else
113 {
114 std::string sOption = it->second.c_str();
115 m_waveSpace = (boost::iequals(sOption, "true")) ||
116 (boost::iequals(sOption, "yes"));
117 }
118 }
119
120 // Points
121 if (pParams.end() != (it = pParams.find("Points")))
122 {
123 m_pointNumMap[LibUtilities::ePtsFile] = Array<OneD, int>(1, 0);
124 m_historyPointStream.str(it->second);
125 }
126 else if (pParams.end() != (it = pParams.find("line")))
127 {
128 vector<NekDouble> values;
129 ASSERTL0(ParseUtils::GenerateVector(it->second, values),
130 "Failed to interpret line string");
131
132 ASSERTL0(values.size() > 2, "line string should contain 2*Dim+1 values "
133 "N,x0,y0,z0,x1,y1,z1");
134
135 double tmp;
136 ASSERTL0(std::modf(values[0], &tmp) == 0.0, "N is not an integer");
137 ASSERTL0(values[0] > 1, "N is not a valid number");
138
139 int dim = (values.size() - 1) / 2;
140 int npts = values[0];
141
142 Array<OneD, int> num(1, npts);
143 Array<OneD, NekDouble> delta(6, 0.);
144 for (int i = 0; i < dim; ++i)
145 {
146 delta[i + 0] = values[i + 1];
147 delta[i + 3] = (values[dim + i + 1] - values[i + 1]) / (npts - 1);
148 }
151 }
152 else if (pParams.end() != (it = pParams.find("plane")))
153 {
154 vector<NekDouble> values;
155 ASSERTL0(ParseUtils::GenerateVector(it->second, values),
156 "Failed to interpret plane string");
157
158 ASSERTL0(values.size() > 9,
159 "plane string should contain 4 Dim+2 values "
160 "N1,N2,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3");
161
162 double tmp;
163 ASSERTL0(std::modf(values[0], &tmp) == 0.0, "N1 is not an integer");
164 ASSERTL0(std::modf(values[1], &tmp) == 0.0, "N2 is not an integer");
165
166 ASSERTL0(values[0] > 1, "N1 is not a valid number");
167 ASSERTL0(values[1] > 1, "N2 is not a valid number");
168
169 int dim = (values.size() - 2) / 4;
170
171 Array<OneD, int> npts(3);
172 npts[0] = values[0];
173 npts[1] = values[0] * values[1];
174 npts[2] = values[1];
175
176 Array<OneD, NekDouble> delta(12, 0.);
177 for (int i = 0; i < dim; ++i)
178 {
179 delta[i + 0] = values[2 + i];
180 delta[i + 3] = values[2 + 3 * dim + i];
181 delta[i + 6] = (values[2 + 1 * dim + i] - values[2 + 0 * dim + i]) /
182 (values[0] - 1);
183 delta[i + 9] = (values[2 + 2 * dim + i] - values[2 + 3 * dim + i]) /
184 (values[0] - 1);
185 }
188 }
189 else if (pParams.end() != (it = pParams.find("box")))
190 {
191 vector<NekDouble> values;
192 ASSERTL0(ParseUtils::GenerateVector(it->second, values),
193 "Failed to interpret box string");
194
195 ASSERTL0(values.size() == 9, "box string should contain 9 values "
196 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
197
198 int dim = 3;
199 Array<OneD, int> npts(3);
200 npts[0] = values[0];
201 npts[1] = values[0] * values[1];
202 npts[2] = values[0] * values[1] * values[2];
203
204 Array<OneD, NekDouble> delta(6, 0.);
205 for (int i = 0; i < dim; ++i)
206 {
207 delta[i + 0] = values[3 + 2 * i];
208 delta[i + 3] =
209 (values[4 + 2 * i] - values[3 + 2 * i]) / (values[i] - 1);
210 }
213 }
214 else
215 {
216 ASSERTL0(false, "Missing parameter 'Points'.");
217 }
218}
#define ASSERTL0(condition, msg)
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::map< LibUtilities::PtsType, Array< OneD, int > > m_pointNumMap
int m_outputPlane
plane to take history point from if using a homogeneous1D expansion
std::map< LibUtilities::PtsType, Array< OneD, NekDouble > > m_pointDatMap
SOLVER_UTILS_EXPORT std::string SetupOutput(const std::string ext, const ParamMap &pParams)
Definition Filter.h:139
LibUtilities::SessionReaderSharedPtr m_session
Definition Filter.h:93
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation)

References ASSERTL0, Nektar::LibUtilities::ePtsBox, Nektar::LibUtilities::ePtsFile, Nektar::LibUtilities::ePtsLine, Nektar::LibUtilities::ePtsPlane, Nektar::LibUtilities::Equation::Evaluate(), Nektar::ParseUtils::GenerateVector(), m_historyPointStream, m_isHomogeneous1D, m_outputFile, m_outputFrequency, m_outputOneFile, m_outputPlane, m_pointDatMap, m_pointNumMap, Nektar::SolverUtils::Filter::m_session, m_waveSpace, and Nektar::SolverUtils::Filter::SetupOutput().

◆ ~FilterHistoryPoints()

SOLVER_UTILS_EXPORT Nektar::SolverUtils::FilterHistoryPoints::~FilterHistoryPoints ( )
overridedefault

Member Function Documentation

◆ create()

static FilterSharedPtr Nektar::SolverUtils::FilterHistoryPoints::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::shared_ptr< EquationSystem > &  pEquation,
const std::map< std::string, std::string > &  pParams 
)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file FilterHistoryPoints.h.

55 {
58 pSession, pEquation, pParams);
59 return p;
60 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Filter > FilterSharedPtr
A shared pointer to a Driver object.
Definition Filter.h:52
std::vector< double > p(NPUPPER)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ GetPoint()

bool Nektar::SolverUtils::FilterHistoryPoints::GetPoint ( Array< OneD, NekDouble gloCoord,
int  I 
)
protected

Definition at line 220 of file FilterHistoryPoints.cpp.

221{
223 {
224 m_historyPointStream >> gloCoord[0] >> gloCoord[1] >> gloCoord[2];
225 return !m_historyPointStream.fail();
226 }
228 {
230 {
231 return false;
232 }
233 Array<OneD, NekDouble> values = m_pointDatMap[LibUtilities::ePtsLine];
234 Array<OneD, NekDouble> delta =
236 for (int n = 0; n < 3; ++n)
237 {
238 gloCoord[n] = values[n] + I * delta[n];
239 }
240 return true;
241 }
243 {
245 {
246 return false;
247 }
248 Array<OneD, NekDouble> values = m_pointDatMap[LibUtilities::ePtsPlane];
249 Array<OneD, NekDouble> delta =
251 Array<OneD, int> i(2);
253 i[0] = I - i[1] * m_pointNumMap[LibUtilities::ePtsPlane][0];
254 double n1 = -1. + (NekDouble)m_pointNumMap[LibUtilities::ePtsPlane][2];
255 for (int n = 0; n < 3; ++n)
256 {
257 gloCoord[n] = (values[n] + i[0] * delta[n]) * (1.0 - i[1] / n1) +
258 (values[3 + n] + i[0] * delta[3 + n]) * (i[1] / n1);
259 }
260 return true;
261 }
262 else if (m_pointNumMap.count(LibUtilities::ePtsBox))
263 {
265 {
266 return false;
267 }
268 Array<OneD, NekDouble> values = m_pointDatMap[LibUtilities::ePtsBox];
269 Array<OneD, NekDouble> delta = m_pointDatMap[LibUtilities::ePtsBox] + 3;
270 Array<OneD, int> i(3);
272 I -= i[2] * m_pointNumMap[LibUtilities::ePtsBox][1];
274 i[0] = I - i[1] * m_pointNumMap[LibUtilities::ePtsBox][0];
275 for (int n = 0; n < 3; ++n)
276 {
277 gloCoord[n] = values[n] + i[n] * delta[n];
278 }
279 return true;
280 }
281 return false;
282}

References Nektar::LibUtilities::ePtsBox, Nektar::LibUtilities::ePtsFile, Nektar::LibUtilities::ePtsLine, Nektar::LibUtilities::ePtsPlane, m_historyPointStream, m_pointDatMap, and m_pointNumMap.

Referenced by v_Initialise().

◆ v_Finalise()

void Nektar::SolverUtils::FilterHistoryPoints::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 686 of file FilterHistoryPoints.cpp.

689{
690 if (pFields[0]->GetComm()->GetRank() == 0 && m_outputOneFile)
691 {
692 if (m_outputStream.is_open())
693 {
694 m_outputStream.close();
695 }
696 }
697}

References m_outputOneFile, and m_outputStream.

◆ v_Initialise()

void Nektar::SolverUtils::FilterHistoryPoints::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 287 of file FilterHistoryPoints.cpp.

290{
291 ASSERTL0(!m_historyPointStream.fail(), "No history points in stream.");
292
293 LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
294
295 // All processes read all the history points
296 Array<OneD, NekDouble> gloCoord(3, 0.0);
297 std::vector<Array<OneD, const NekDouble>> GloCoords;
298 const int coordim = pFields[0]->GetGraph()->GetSpaceDimension();
299
300 int i = -1;
301 while (GetPoint(gloCoord, ++i))
302 {
303 // Overwrite gloCoord[2] for 3DH1D using m_outputPlane
304 // if it is defined
306 {
307 int nplanes = pFields[0]->GetHomogeneousBasis()->GetZ().size();
308 NekDouble lhom = pFields[0]->GetHomoLen();
309 int plane;
310 if (m_outputPlane != -1)
311 {
312 plane = m_outputPlane;
313 }
314 else
315 {
316 // Pick plane near the point
317 plane = round((gloCoord[coordim] * nplanes) / lhom);
318 }
319 if (m_waveSpace)
320 {
321 m_planeIDs.push_back(plane);
322 }
323 NekDouble Z = (pFields[0]->GetHomogeneousBasis()->GetZ())[plane];
324 Z = (Z + 1) * lhom / 2;
325 if (fabs(gloCoord[coordim] - Z) >
327 vComm->GetRank() == 0)
328 {
329 cout << "Resetting History point from z = " << gloCoord[coordim]
330 << " to z = " << Z << endl;
331 }
332 gloCoord[coordim] = Z;
333 }
334
335 // Save a copy of the global coordinate
336 GloCoords.push_back(
337 Array<OneD, const NekDouble>(gloCoord.size(), gloCoord.data()));
338 }
339
340 // Check which history points this process is responsible for
341 const int vRank = vComm->GetRank();
342 const int vColumnRank = vComm->GetColumnComm()->GetRank();
343 const int vRowRank = vComm->GetRowComm()->GetRank();
344 m_historyPointsSize = GloCoords.size();
345 Array<OneD, int> procList(m_historyPointsSize, -1);
346 Array<OneD, int> idList(m_historyPointsSize, -1);
347
348 Array<OneD, NekDouble> locCoord(pFields[0]->GetShapeDimension(), 0.);
349 std::vector<Array<OneD, const NekDouble>> LocCoords;
350
351 // For each history point, find the element that contains it. If no element
352 // is available on this process, idList[i] = -1 and procList[i] = -1
353 for (i = 0; i < m_historyPointsSize; ++i)
354 {
355 // Create a copy of the global coordinate
356 gloCoord = GloCoords[i];
357
358 // Determine the expansion and local coordinates
360 {
361 idList[i] = pFields[0]->GetPlane(0)->GetExpIndex(
362 gloCoord, locCoord, NekConstants::kGeomFactorsTol);
363 }
364 else
365 {
366 idList[i] = pFields[0]->GetExpIndex(gloCoord, locCoord,
368 }
369
370 for (int j = 0; j < locCoord.size(); ++j)
371 {
372 locCoord[j] = std::max(locCoord[j], -1.0);
373 locCoord[j] = std::min(locCoord[j], 1.0);
374 }
375
376 // If this process owns an element that contains the history point, we
377 // flag this by updating the corresponding element in procList
378 if (idList[i] != -1 && vColumnRank == 0)
379 {
380 procList[i] = vRank;
381 }
382
383 // Save a copy of the local coordinates
384 LocCoords.push_back(
385 Array<OneD, const NekDouble>(locCoord.size(), locCoord.data()));
386 }
387
388 // Clear list before populating it
389 m_historyList.clear();
390
391 // Share process ranks among all processes. If multiple processes found
392 // that they own a history point, procList will only contain the rank of
393 // the process with the largest rank
394 vComm->AllReduce(procList, LibUtilities::ReduceMax);
395 for (i = 0; i < m_historyPointsSize; ++i)
396 {
397 // If process owns a history point, it saves a reference to its global
398 // and local coordinates. Note that, if multiple processes have found
399 // that they own a history point, which can happen if the point is
400 // located on a partition boundary, only the process with the highest
401 // rank will store the point.
402 if (procList[i] == vRowRank)
403 {
404 // Note that the reference counting in the Array class prevents the
405 // data stored in GloCoords and LocCoords from being deallocated
406 // when they go out of scope, since m_historyList will increase the
407 // reference counter by 1 when it gets a reference to the data.
408 m_historyList.push_back(
409 std::make_tuple(GloCoords[i], LocCoords[i], i, idList[i]));
410 }
411 }
412
413 // Root process must have access to all coordinates for writing the file
414 if (vComm->TreatAsRankZero())
415 {
417 Array<OneD, Array<OneD, const NekDouble>>(m_historyPointsSize);
418
419 for (i = 0; i < m_historyPointsSize; ++i)
420 {
421 // Create a reference to the underlying array. Note that the data
422 // stored in GloCoords won't be deallocated because the Array class
423 // has a reference counter.
424 m_historyPoints[i] = GloCoords[i];
425 }
426 }
427
428 // Check that each history point is allocated to a process
429 if (vComm->TreatAsRankZero())
430 {
431 for (i = 0; i < m_historyPointsSize; ++i)
432 {
433 gloCoord = m_historyPoints[i];
434
435 // Write an error if no process owns history point
436 ASSERTL0(procList[i] != -1,
437 "History point " +
438 boost::lexical_cast<std::string>(gloCoord[0]) + ", " +
439 boost::lexical_cast<std::string>(gloCoord[1]) + ", " +
440 boost::lexical_cast<std::string>(gloCoord[2]) +
441 " cannot be found in the mesh.");
442 }
443
444 m_session->MatchSolverInfo("Driver", "Adaptive", m_adaptive, false);
445 }
446
448 {
449 v_Update(pFields, time);
450 }
451
452 if (m_session->DefinesCmdLineArgument(
453 "set-filter-historypoints-start-number"))
454 {
455 m_index = std::stoi(m_session->GetCmdLineArgument<std::string>(
456 "set-filter-historypoints-start-number"));
457 }
458}
Array< OneD, Array< OneD, const NekDouble > > m_historyPoints
bool GetPoint(Array< OneD, NekDouble > gloCoord, int I)
SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
std::list< std::tuple< Array< OneD, const NekDouble >, Array< OneD, const NekDouble >, int, int > > m_historyList
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition Comm.h:55
static const NekDouble kVertexTheSameDouble
static const NekDouble kGeomFactorsTol

References ASSERTL0, GetPoint(), Nektar::NekConstants::kGeomFactorsTol, Nektar::NekConstants::kVertexTheSameDouble, m_adaptive, m_historyList, m_historyPoints, m_historyPointsSize, m_historyPointStream, m_index, m_isHomogeneous1D, m_outputPlane, m_planeIDs, Nektar::SolverUtils::Filter::m_session, Nektar::SolverUtils::Filter::m_updateOnInitialise, m_waveSpace, Nektar::LibUtilities::ReduceMax, and v_Update().

◆ v_IsTimeDependent()

bool Nektar::SolverUtils::FilterHistoryPoints::v_IsTimeDependent ( )
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 702 of file FilterHistoryPoints.cpp.

703{
704 return true;
705}

◆ v_Update()

void Nektar::SolverUtils::FilterHistoryPoints::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 463 of file FilterHistoryPoints.cpp.

466{
467 // Only output every m_outputFrequency.
468 if ((m_index++) % m_outputFrequency)
469 {
470 return;
471 }
472
473 const int numFields = pFields.size();
474 const int coordim = pFields[0]->GetGraph()->GetSpaceDimension();
475 LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
476 Array<OneD, NekDouble> data(m_historyPointsSize * numFields, 0.0);
477 Array<OneD, NekDouble> physvals;
478 Array<OneD, NekDouble> locCoord;
479
480 // Pull out data values field by field
481 Array<OneD, NekDouble> gloCoord(3, 0.0);
482 for (int j = 0; j < numFields; ++j)
483 {
485 {
486 Array<OneD, const unsigned int> planes = pFields[j]->GetZIDs();
487 int nPlanes = pFields[j]->GetHomogeneousBasis()->GetZ().size();
488 NekDouble lHom = pFields[j]->GetHomoLen();
489 for (auto &x : m_historyList)
490 {
491 ASSERTL0(pFields[j]->GetWaveSpace(),
492 "HistoryPoints in Homogeneous1D require that solution "
493 "is in wavespace");
494 gloCoord = std::get<0>(x);
495 locCoord = std::get<1>(x);
496 const int indx = std::get<2>(x);
497 const int expId = std::get<3>(x);
498
499 NekDouble value = 0.0;
500 NekDouble BetaT =
501 2. * M_PI * fmod(gloCoord[coordim], lHom) / lHom;
502 for (size_t n = 0; n < planes.size(); ++n)
503 {
504 if (m_waveSpace && planes[n] != m_planeIDs[indx])
505 {
506 continue;
507 }
508 physvals = pFields[j]->GetPlane(n)->UpdatePhys() +
509 pFields[j]->GetPhys_Offset(expId);
510
511 // transform elemental data if required.
512 if (pFields[j]->GetPhysState() == false)
513 {
514 pFields[j]->GetPlane(n)->GetExp(expId)->BwdTrans(
515 pFields[j]->GetPlane(n)->GetCoeffs() +
516 pFields[j]->GetCoeff_Offset(expId),
517 physvals);
518 }
519 // Interpolate data
520 NekDouble coeff =
521 pFields[j]->GetPlane(n)->GetExp(expId)->StdPhysEvaluate(
522 locCoord, physvals);
523
524 if (m_waveSpace)
525 {
526 value = coeff;
527 }
528 else
529 {
530 if (planes[n] == 0)
531 {
532 value += coeff;
533 }
534 else if (planes[n] == 1)
535 {
536 value += cos(0.5 * nPlanes * BetaT) * coeff;
537 }
538 else if (planes[n] % 2 == 0)
539 {
540 NekDouble phase = (planes[n] >> 1) * BetaT;
541 value += cos(phase) * coeff;
542 }
543 else
544 {
545 NekDouble phase = (planes[n] >> 1) * BetaT;
546 value += -sin(phase) * coeff;
547 }
548 }
549 }
550 // store data
551 data[indx * numFields + j] = value;
552 }
553 }
554 else
555 {
556 for (auto &x : m_historyList)
557 {
558 locCoord = std::get<1>(x);
559 const int indx = std::get<2>(x);
560 const int expId = std::get<3>(x);
561
562 physvals = pFields[j]->UpdatePhys() +
563 pFields[j]->GetPhys_Offset(expId);
564
565 // transform elemental data if required.
566 if (pFields[j]->GetPhysState() == false)
567 {
568 pFields[j]->GetExp(expId)->BwdTrans(
569 pFields[j]->GetCoeffs() +
570 pFields[j]->GetCoeff_Offset(expId),
571 physvals);
572 }
573
574 // interpolate point
575 data[indx * numFields + j] =
576 pFields[j]->GetExp(expId)->StdPhysEvaluate(locCoord,
577 physvals);
578 }
579 }
580 }
581
582 // Exchange history data
583 // This could be improved to reduce communication but works for now
584 vComm->AllReduce(data, LibUtilities::ReduceSum);
585
586 // TODO: Why not only call this routine if we are rank 0?
587 v_WriteData(vComm->GetRank(), data, numFields, time);
588}
SOLVER_UTILS_EXPORT void v_WriteData(const int &rank, const Array< OneD, NekDouble > &data, const int &numFields, const NekDouble &time)

References ASSERTL0, m_historyList, m_historyPointsSize, m_index, m_isHomogeneous1D, m_outputFrequency, m_planeIDs, m_waveSpace, Nektar::LibUtilities::ReduceSum, and v_WriteData().

Referenced by v_Initialise().

◆ v_WriteData()

void Nektar::SolverUtils::FilterHistoryPoints::v_WriteData ( const int &  rank,
const Array< OneD, NekDouble > &  data,
const int &  numFields,
const NekDouble time 
)
protected

Definition at line 590 of file FilterHistoryPoints.cpp.

594{
595 // Only the root process writes out history data
596 if (rank == 0)
597 {
598 Array<OneD, NekDouble> gloCoord(3, 0.0);
599 if (!m_outputOneFile || m_index == 1)
600 {
601 std::stringstream vTmpFilename;
602 std::string vOutputFilename;
603 // get the file extension
604 std::string ext = fs::path(m_outputFile).extension().string();
605 if (m_outputOneFile)
606 {
607 vTmpFilename << m_outputFile;
608 }
609 else
610 {
611 vTmpFilename
612 << fs::path(m_outputFile).replace_extension("").string()
613 << "_" << m_outputIndex << ext;
614 }
615 // back up the file if already exists and backup switch is turned on
616 vOutputFilename = Filter::SetupOutput(ext, vTmpFilename.str());
617
619 if (m_adaptive)
620 {
621 m_outputStream.open(vOutputFilename.c_str(), ofstream::app);
622 }
623 else
624 {
625 m_outputStream.open(vOutputFilename.c_str());
626 }
627 m_outputStream << "# History data for variables (:";
628
629 for (int i = 0; i < numFields; ++i)
630 {
631 m_outputStream << m_session->GetVariable(i) << ",";
632 }
633
635 {
636 m_outputStream << ") at points:" << endl;
637 }
638 else
639 {
640 m_outputStream << ") at points:" << endl;
641 }
642
643 for (int i = 0; i < m_historyPoints.size(); ++i)
644 {
645 gloCoord = m_historyPoints[i];
646
647 m_outputStream << "# " << boost::format("%6.0f") % i;
648 m_outputStream << " " << boost::format("%25.19e") % gloCoord[0];
649 m_outputStream << " " << boost::format("%25.19e") % gloCoord[1];
650 m_outputStream << " " << boost::format("%25.19e") % gloCoord[2];
651 m_outputStream << endl;
652 }
653
655 {
656 if (m_waveSpace)
657 {
658 m_outputStream << "# (in Wavespace)" << endl;
659 }
660 }
661 }
662
663 // Write data values point by point
664 for (int k = 0; k < m_historyPoints.size(); ++k)
665 {
666 m_outputStream << boost::format("%25.19e") % time;
667 for (int j = 0; j < numFields; ++j)
668 {
670 << " "
671 << boost::format("%25.19e") % data[k * numFields + j];
672 }
673 m_outputStream << endl;
674 }
675
676 if (!m_outputOneFile)
677 {
678 m_outputStream.close();
679 }
680 }
681}

References m_adaptive, m_historyPoints, m_index, m_isHomogeneous1D, m_outputFile, m_outputIndex, m_outputOneFile, m_outputStream, Nektar::SolverUtils::Filter::m_session, m_waveSpace, and Nektar::SolverUtils::Filter::SetupOutput().

Referenced by v_Update().

Friends And Related Symbol Documentation

◆ MemoryManager< FilterHistoryPoints >

friend class MemoryManager< FilterHistoryPoints >
friend

Definition at line 1 of file FilterHistoryPoints.h.

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::FilterHistoryPoints::className
static
Initial value:
=
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
FilterFactory & GetFilterFactory()

Name of the class.

Definition at line 65 of file FilterHistoryPoints.h.

◆ cmdSetStartFilterFileNum

std::string Nektar::SolverUtils::FilterHistoryPoints::cmdSetStartFilterFileNum
static
Initial value:
=
"set-filter-historypoints-start-number", "",
"Set the starting number of the history points filter file number.")
static std::string RegisterCmdLineArgument(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line argument with the session reader.

Definition at line 62 of file FilterHistoryPoints.h.

◆ m_adaptive

bool Nektar::SolverUtils::FilterHistoryPoints::m_adaptive
protected

◆ m_historyList

std::list<std::tuple<Array<OneD, const NekDouble>, Array<OneD, const NekDouble>, int, int> > Nektar::SolverUtils::FilterHistoryPoints::m_historyList
protected

◆ m_historyPoints

Array<OneD, Array<OneD, const NekDouble> > Nektar::SolverUtils::FilterHistoryPoints::m_historyPoints
protected
Initial value:
=
Array<OneD, Array<OneD, const NekDouble>>(0)

Definition at line 90 of file FilterHistoryPoints.h.

Referenced by v_Initialise(), Nektar::FilterCellHistoryPoints::v_Update(), v_WriteData(), and Nektar::FilterCellHistoryPoints::v_WriteData().

◆ m_historyPointsSize

size_t Nektar::SolverUtils::FilterHistoryPoints::m_historyPointsSize = 0
protected

Definition at line 92 of file FilterHistoryPoints.h.

Referenced by v_Initialise(), and v_Update().

◆ m_historyPointStream

std::stringstream Nektar::SolverUtils::FilterHistoryPoints::m_historyPointStream
protected

Definition at line 102 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), GetPoint(), and v_Initialise().

◆ m_index

unsigned int Nektar::SolverUtils::FilterHistoryPoints::m_index = 0
protected

◆ m_isHomogeneous1D

bool Nektar::SolverUtils::FilterHistoryPoints::m_isHomogeneous1D
protected

◆ m_outputFile

std::string Nektar::SolverUtils::FilterHistoryPoints::m_outputFile
protected

◆ m_outputFrequency

unsigned int Nektar::SolverUtils::FilterHistoryPoints::m_outputFrequency
protected

◆ m_outputIndex

unsigned int Nektar::SolverUtils::FilterHistoryPoints::m_outputIndex = 0
protected

◆ m_outputOneFile

bool Nektar::SolverUtils::FilterHistoryPoints::m_outputOneFile
protected

◆ m_outputPlane

int Nektar::SolverUtils::FilterHistoryPoints::m_outputPlane
protected

plane to take history point from if using a homogeneous1D expansion

Definition at line 96 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), v_Initialise(), and Nektar::FilterCellHistoryPoints::v_Update().

◆ m_outputStream

std::ofstream Nektar::SolverUtils::FilterHistoryPoints::m_outputStream
protected

◆ m_planeIDs

std::vector<int> Nektar::SolverUtils::FilterHistoryPoints::m_planeIDs
protected

Definition at line 97 of file FilterHistoryPoints.h.

Referenced by v_Initialise(), and v_Update().

◆ m_pointDatMap

std::map<LibUtilities::PtsType, Array<OneD, NekDouble> > Nektar::SolverUtils::FilterHistoryPoints::m_pointDatMap
protected

Definition at line 112 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), and GetPoint().

◆ m_pointNumMap

std::map<LibUtilities::PtsType, Array<OneD, int> > Nektar::SolverUtils::FilterHistoryPoints::m_pointNumMap
protected

Definition at line 113 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), and GetPoint().

◆ m_waveSpace

bool Nektar::SolverUtils::FilterHistoryPoints::m_waveSpace
protected