Nektar++
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:
Inheritance graph
[legend]
Collaboration diagram for Nektar::SolverUtils::FilterHistoryPoints:
Collaboration graph
[legend]

Public Member Functions

SOLVER_UTILS_EXPORT FilterHistoryPoints (const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
 
SOLVER_UTILS_EXPORT ~FilterHistoryPoints ()
 
- Public Member Functions inherited from Nektar::SolverUtils::Filter
SOLVER_UTILS_EXPORT Filter (const LibUtilities::SessionReaderSharedPtr &pSession)
 
virtual SOLVER_UTILS_EXPORT ~Filter ()
 
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 ()
 

Static Public Member Functions

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

Static Public Attributes

static std::string className = GetFilterFactory().RegisterCreatorFunction("HistoryPoints", FilterHistoryPoints::create)
 Name of the class. More...
 

Protected Member Functions

virtual SOLVER_UTILS_EXPORT void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT bool v_IsTimeDependent ()
 

Protected Attributes

SpatialDomains::PointGeomVector m_historyPoints
 
unsigned int m_index
 
unsigned int m_outputFrequency
 
unsigned int m_outputPlane
 plane to take history point from if using a homogeneous1D expansion More...
 
bool m_isHomogeneous1D
 
std::string m_outputFile
 
std::ofstream m_outputStream
 
std::stringstream m_historyPointStream
 
std::list< std::pair< SpatialDomains::PointGeomSharedPtr, Array< OneD, NekDouble > > > m_historyList
 
std::map< int, int > m_historyLocalPointMap
 
- Protected Attributes inherited from Nektar::SolverUtils::Filter
LibUtilities::SessionReaderSharedPtr m_session
 

Friends

class MemoryManager< FilterHistoryPoints >
 

Detailed Description

Definition at line 46 of file FilterHistoryPoints.h.

Constructor & Destructor Documentation

Nektar::SolverUtils::FilterHistoryPoints::FilterHistoryPoints ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::map< std::string, std::string > &  pParams 
)

Definition at line 49 of file FilterHistoryPoints.cpp.

References ASSERTL0, m_historyPointStream, m_index, m_isHomogeneous1D, m_outputFile, m_outputFrequency, m_outputPlane, and Nektar::SolverUtils::Filter::m_session.

51  :
52  Filter(pSession)
53  {
54  if (pParams.find("OutputFile") == pParams.end())
55  {
56  m_outputFile = m_session->GetSessionName();
57  }
58  else
59  {
60  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
61  "Missing parameter 'OutputFile'.");
62  m_outputFile = pParams.find("OutputFile")->second;
63  }
64  if (!(m_outputFile.length() >= 4
65  && m_outputFile.substr(m_outputFile.length() - 4) == ".his"))
66  {
67  m_outputFile += ".his";
68  }
69 
70  if (pParams.find("OutputFrequency") == pParams.end())
71  {
73  }
74  else
75  {
76  m_outputFrequency = atoi(pParams.find("OutputFrequency")->second.c_str());
77  }
78 
79 
80  m_session->MatchSolverInfo("Homogeneous","1D",m_isHomogeneous1D,false);
81 
83  {
84  if (pParams.find("OutputPlane") == pParams.end())
85  {
86  m_outputPlane = 0;
87  }
88  else
89  {
90  m_outputPlane = atoi(pParams.find("OutputPlane")->second.c_str());
91  }
92  }
93 
94  ASSERTL0(pParams.find("Points") != pParams.end(),
95  "Missing parameter 'Points'.");
96  m_historyPointStream.str(pParams.find("Points")->second);
97  m_index = 0;
98  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: Filter.cpp:52
unsigned int m_outputPlane
plane to take history point from if using a homogeneous1D expansion
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:76
Nektar::SolverUtils::FilterHistoryPoints::~FilterHistoryPoints ( )

Definition at line 104 of file FilterHistoryPoints.cpp.

105  {
106 
107  }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 52 of file FilterHistoryPoints.h.

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

54  {
56  ::AllocateSharedPtr(pSession, pParams);
57  return p;
58  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< Filter > FilterSharedPtr
A shared pointer to a Driver object.
Definition: Filter.h:50
void Nektar::SolverUtils::FilterHistoryPoints::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 455 of file FilterHistoryPoints.cpp.

References m_outputStream.

456  {
457  if (pFields[0]->GetComm()->GetRank() == 0)
458  {
459  m_outputStream.close();
460  }
461  }
void Nektar::SolverUtils::FilterHistoryPoints::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 113 of file FilterHistoryPoints.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::NekConstants::kGeomFactorsTol, Nektar::NekConstants::kVertexTheSameDouble, m_historyList, m_historyLocalPointMap, m_historyPoints, m_historyPointStream, m_index, m_isHomogeneous1D, m_outputFile, m_outputPlane, m_outputStream, Nektar::SolverUtils::Filter::m_session, Nektar::LibUtilities::ReduceMax, Nektar::LibUtilities::ReduceMin, v_Update(), and Vmath::Vcopy().

116  {
118  "No history points in stream.");
119 
120  m_index = 0;
121  m_historyList.clear();
122 
123  // Read history points
124  Array<OneD, NekDouble> gloCoord(3,0.0);
125  int dim = pFields[0]->GetGraph()->GetSpaceDimension();
126  int i = 0;
127  while (!m_historyPointStream.fail())
128  {
129  m_historyPointStream >> gloCoord[0]
130  >> gloCoord[1]
131  >> gloCoord[2];
132  if(m_isHomogeneous1D) // overwrite with plane z
133  {
134  NekDouble Z = (pFields[0]->GetHomogeneousBasis()
135  ->GetZ())[m_outputPlane];
136  if(fabs(gloCoord[2]-Z) > NekConstants::kVertexTheSameDouble)
137  {
138  cout << "Reseting History point from " << gloCoord[2]
139  << " to " << Z << endl;
140  }
141  gloCoord[2] = Z;
142  }
143 
144  if (!m_historyPointStream.fail())
145  {
148  ::AllocateSharedPtr(dim, i, gloCoord[0],
149  gloCoord[1], gloCoord[2]);
150 
151  m_historyPoints.push_back(vert);
152  ++i;
153  }
154  }
155 
156 
157  // Determine the unique process responsible for each history point
158  // For points on a partition boundary, must select a single process
159  LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
160  int vRank = vComm->GetRank();
161  int vHP = m_historyPoints.size();
162  Array<OneD, int> procList(vHP, -1 );
163  Array<OneD, int> idList (vHP, -1 );
164  Array<OneD, NekDouble> dist (vHP, 1e16);
165  Array<OneD, NekDouble> dist_loc(vHP, 1e16);
166  std::vector<Array<OneD, NekDouble> > LocCoords;
167 
168  // Find the nearest element on this process to which the history
169  // point could belong and note down the distance from the element
170  // and the process ID.
171  for (i = 0; i < vHP; ++i)
172  {
173  Array<OneD, NekDouble> locCoords(3);
174  m_historyPoints[i]->GetCoords( gloCoord[0],
175  gloCoord[1],
176  gloCoord[2]);
177 
178  // Determine the expansion and local coordinates
179  idList[i] = pFields[0]->GetExpIndex(gloCoord,locCoords,
181 
182  // Save Local coordinates for later
183  LocCoords.push_back(locCoords);
184 
185  // For those points for which a potential nearby element exists
186  // compute the perp. distance from the point to the element and
187  // store in the distances array.
188  if (idList[i] != -1)
189  {
191  pFields[0]->GetExp(idList[i])->GetGeom();
192  StdRegions::StdExpansionSharedPtr e = g->GetXmap();
193  Array<OneD, NekDouble> coordVals(e->GetTotPoints());
194  dist_loc[i] = 0.0;
195  for (int j = 0; j < g->GetCoordim(); ++j)
196  {
197  e->BwdTrans(g->GetCoeffs(j), coordVals);
198  NekDouble x = e->PhysEvaluate(locCoords, coordVals)
199  - gloCoord[j];
200  dist_loc[i] += x*x;
201  }
202  }
203  }
204 
205  // Reduce distances of points from elements, keeping the smallest
206  // distance.
207  Vmath::Vcopy(vHP, dist_loc, 1, dist, 1);
208  vComm->AllReduce(dist, LibUtilities::ReduceMin);
209 
210  // If multiple processes find they are the nearest (e.g. point lies
211  // on a partition boundary, we will choose the process of highest
212  // rank.
213  for (i = 0; i < vHP; ++i)
214  {
215  if (dist_loc[i] == dist[i])
216  {
217  // Set element id to Vid of m_history point for later use
218  m_historyPoints[i]->SetVid(idList[i]);
219  }
220  else
221  {
222  // This history point is not handled by this process
223  idList[i] = -1;
224  }
225 
226  // If a matching element is found on this process, note the
227  // process ID
228  if (idList[i] != -1)
229  {
231  {
232  int j;
234  = pFields[0]->GetZIDs();
235  for(j = 0; j < IDs.num_elements(); ++j)
236  {
237  if(IDs[j] == m_outputPlane)
238  {
239  break;
240  }
241  }
242 
243  if(j != IDs.num_elements())
244  {
245  m_outputPlane = j;
246  procList[i] = vRank;
247  }
248  }
249  else
250  {
251  procList[i] = vRank;
252  }
253  }
254  }
255 
256  // Reduce process IDs for all history points. The process with
257  // largest rank will handle the history point in the case where the
258  // distance was the same.
259  vComm->AllReduce(procList, LibUtilities::ReduceMax);
260 
261  // Determine the element in which each history point resides.
262  // If point is not in mesh (on this process), id is -1.
263  for (i = 0; i < vHP; ++i)
264  {
265  // If point lies on partition boundary, only the proc with max
266  // rank retains possession.
267  if (procList[i] != vRank)
268  {
269  idList[i] = -1;
270  }
271 
272  // If the current process owns this history point, add it to its
273  // local list of history points.
274  if (idList[i] != -1)
275  {
277  m_historyList.push_back(
280  (m_historyPoints[i], LocCoords[i]));
281  }
282  }
283 
284  // Collate the element ID list across processes and check each
285  // history point is allocated to a process
286  vComm->AllReduce(idList, LibUtilities::ReduceMax);
287  if (vComm->GetRank() == 0)
288  {
289  for (i = 0; i < vHP; ++i)
290  {
291  m_historyPoints[i]->GetCoords( gloCoord[0],
292  gloCoord[1],
293  gloCoord[2]);
294 
295  // Write an error if no process owns history point
296  ASSERTL0(idList[i] != -1,
297  "History point "
298  + boost::lexical_cast<std::string>(gloCoord[0])
299  + ", "
300  + boost::lexical_cast<std::string>(gloCoord[1])
301  + ", "
302  + boost::lexical_cast<std::string>(gloCoord[2])
303  + " cannot be found in the mesh.");
304 
305  // Print a warning if a process owns it but it is not close
306  // enough to the element.
307  if (dist[i] > NekConstants::kGeomFactorsTol)
308  {
309  cout << "Warning: History point " << i << " at ("
310  << gloCoord[0] << "," << gloCoord[1] << ","
311  << gloCoord[2] << ") lies a distance of "
312  << sqrt(dist[i]) << " from the manifold." << endl;
313  }
314  }
315 
316  // Open output stream
317  m_outputStream.open(m_outputFile.c_str());
318  m_outputStream << "# History data for variables (:";
319 
320  for (i = 0; i < pFields.num_elements(); ++i)
321  {
322  m_outputStream << m_session->GetVariable(i) <<",";
323  }
324 
326  {
327  m_outputStream << ") at points:";
328  }
329  else
330  {
331  m_outputStream << ") at points:" << endl;
332  }
333 
334  for (i = 0; i < vHP; ++i)
335  {
336  m_historyPoints[i]->GetCoords( gloCoord[0],
337  gloCoord[1],
338  gloCoord[2]);
339 
340  m_outputStream << "# \t" << i;
341  m_outputStream.width(8);
342  m_outputStream << gloCoord[0];
343  m_outputStream.width(8);
344  m_outputStream << gloCoord[1];
345  m_outputStream.width(8);
346  m_outputStream << gloCoord[2];
347  m_outputStream << endl;
348  }
349 
351  {
352  m_outputStream << "(in Wavespace)" << endl;
353  }
354  }
355  v_Update(pFields, time);
356  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
static const NekDouble kVertexTheSameDouble
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
unsigned int m_outputPlane
plane to take history point from if using a homogeneous1D expansion
SpatialDomains::PointGeomVector m_historyPoints
double NekDouble
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:76
static const NekDouble kGeomFactorsTol
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
virtual SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1016
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
std::list< std::pair< SpatialDomains::PointGeomSharedPtr, Array< OneD, NekDouble > > > m_historyList
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
bool Nektar::SolverUtils::FilterHistoryPoints::v_IsTimeDependent ( )
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 467 of file FilterHistoryPoints.cpp.

468  {
469  return true;
470  }
void Nektar::SolverUtils::FilterHistoryPoints::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Reimplemented in Nektar::SolverUtils::FilterCellHistoryPoints.

Definition at line 362 of file FilterHistoryPoints.cpp.

References Nektar::iterator, m_historyList, m_historyLocalPointMap, m_historyPoints, m_index, m_isHomogeneous1D, m_outputFrequency, m_outputPlane, m_outputStream, and Nektar::LibUtilities::ReduceSum.

Referenced by v_Initialise().

363  {
364  // Only output every m_outputFrequency.
365  if ((m_index++) % m_outputFrequency)
366  {
367  return;
368  }
369 
370  int j = 0;
371  int k = 0;
372  int numPoints = m_historyPoints.size();
373  int numFields = pFields.num_elements();
374  LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
375  Array<OneD, NekDouble> data(numPoints*numFields, 0.0);
376  Array<OneD, NekDouble> gloCoord(3, 0.0);
377  std::list<std::pair<SpatialDomains::PointGeomSharedPtr, Array<OneD, NekDouble> > >::iterator x;
378 
379  Array<OneD, NekDouble> physvals;
380  Array<OneD, NekDouble> locCoord;
381  int expId;
382 
383  // Pull out data values field by field
384  for (j = 0; j < numFields; ++j)
385  {
387  {
388  for (k = 0, x = m_historyList.begin(); x != m_historyList.end();
389  ++x, ++k)
390  {
391  locCoord = (*x).second;
392  expId = (*x).first->GetVid();
393 
394  physvals = pFields[j]->GetPlane(m_outputPlane)->UpdatePhys() + pFields[j]->GetPhys_Offset(expId);
395 
396  // transform elemental data if required.
397  if(pFields[j]->GetPhysState() == false)
398  {
399  pFields[j]->GetPlane(m_outputPlane)->GetExp(expId)->BwdTrans(pFields[j]->GetPlane(m_outputPlane)->GetCoeffs() + pFields[j]->GetCoeff_Offset(expId),physvals);
400  }
401 
402  // interpolate point can do with zero plane methods
403  data[m_historyLocalPointMap[k]*numFields+j] = pFields[j]->GetExp(expId)->StdPhysEvaluate(locCoord,physvals);
404 
405  }
406  }
407  else
408  {
409  for (k = 0, x = m_historyList.begin(); x != m_historyList.end(); ++x, ++k)
410  {
411  locCoord = (*x).second;
412  expId = (*x).first->GetVid();
413 
414  physvals = pFields[j]->UpdatePhys() + pFields[j]->GetPhys_Offset(expId);
415 
416  // transform elemental data if required.
417  if(pFields[j]->GetPhysState() == false)
418  {
419  pFields[j]->GetExp(expId)->BwdTrans(pFields[j]->GetCoeffs() + pFields[j]->GetCoeff_Offset(expId),physvals);
420  }
421 
422  // interpolate point
423  data[m_historyLocalPointMap[k]*numFields+j] = pFields[j]->GetExp(expId)->StdPhysEvaluate(locCoord,physvals);
424  }
425  }
426  }
427 
428  // Exchange history data
429  // This could be improved to reduce communication but works for now
430  vComm->AllReduce(data, LibUtilities::ReduceSum);
431 
432  // Only the root process writes out history data
433  if (vComm->GetRank() == 0)
434  {
435 
436  // Write data values point by point
437  for (k = 0; k < m_historyPoints.size(); ++k)
438  {
439  m_outputStream.width(8);
440  m_outputStream << setprecision(6) << time;
441  for (int j = 0; j < numFields; ++j)
442  {
443  m_outputStream.width(25);
444  m_outputStream << setprecision(16) << data[k*numFields+j];
445  }
446  m_outputStream << endl;
447  }
448  }
449  }
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
unsigned int m_outputPlane
plane to take history point from if using a homogeneous1D expansion
SpatialDomains::PointGeomVector m_historyPoints
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::list< std::pair< SpatialDomains::PointGeomSharedPtr, Array< OneD, NekDouble > > > m_historyList

Friends And Related Function Documentation

friend class MemoryManager< FilterHistoryPoints >
friend

Definition at line 49 of file FilterHistoryPoints.h.

Member Data Documentation

std::string Nektar::SolverUtils::FilterHistoryPoints::className = GetFilterFactory().RegisterCreatorFunction("HistoryPoints", FilterHistoryPoints::create)
static

Name of the class.

Definition at line 61 of file FilterHistoryPoints.h.

std::list<std::pair<SpatialDomains::PointGeomSharedPtr, Array<OneD, NekDouble> > > Nektar::SolverUtils::FilterHistoryPoints::m_historyList
protected
std::map<int, int > Nektar::SolverUtils::FilterHistoryPoints::m_historyLocalPointMap
protected
SpatialDomains::PointGeomVector Nektar::SolverUtils::FilterHistoryPoints::m_historyPoints
protected
std::stringstream Nektar::SolverUtils::FilterHistoryPoints::m_historyPointStream
protected

Definition at line 88 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), and v_Initialise().

unsigned int Nektar::SolverUtils::FilterHistoryPoints::m_index
protected
bool Nektar::SolverUtils::FilterHistoryPoints::m_isHomogeneous1D
protected
std::string Nektar::SolverUtils::FilterHistoryPoints::m_outputFile
protected

Definition at line 86 of file FilterHistoryPoints.h.

Referenced by FilterHistoryPoints(), and v_Initialise().

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

plane to take history point from if using a homogeneous1D expansion

Definition at line 84 of file FilterHistoryPoints.h.

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

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