Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | Friends | List of all members
Nektar::FilterElectrogram Class Reference

#include <FilterElectrogram.h>

Inheritance diagram for Nektar::FilterElectrogram:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FilterElectrogram:
Collaboration graph
[legend]

Public Member Functions

 FilterElectrogram (const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
 Electrogram filter constructor. More...
 
virtual ~FilterElectrogram ()
 Electrogram filter destructor. More...
 
- 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 SolverUtils::FilterSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
 Creates an instance of this class. More...
 

Static Public Attributes

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

Protected Member Functions

virtual void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 Initialises the electrogram filter and open output file. More...
 
virtual void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 Compute extracellular potential at egm points at current time. More...
 
virtual void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 Finalise the electrogram filter and close output file. More...
 
virtual bool v_IsTimeDependent ()
 Filter is time-dependent and should be called at each time-step. More...
 

Private Attributes

Array< OneD, Array< OneD,
NekDouble > > 
m_grad_R_x
 Gradient of the radius from each electrogram point in x-direction. More...
 
Array< OneD, Array< OneD,
NekDouble > > 
m_grad_R_y
 Gradient of the radius from each electrogram point in y-direction. More...
 
Array< OneD, Array< OneD,
NekDouble > > 
m_grad_R_z
 Gradient of the radius from each electrogram point in z-direction. More...
 
SpatialDomains::PointGeomVector m_electrogramPoints
 List of electrogram points. More...
 
unsigned int m_index
 Counts number of calls to update (number of timesteps) More...
 
unsigned int m_outputFrequency
 Number of timesteps between outputs. More...
 
std::string m_outputFile
 Filename to output electrogram data to. More...
 
std::ofstream m_outputStream
 Output file stream for electrogram data. More...
 
std::stringstream m_electrogramStream
 Point coordinate input string. More...
 

Friends

class MemoryManager< FilterElectrogram >
 

Additional Inherited Members

- Public Types inherited from Nektar::SolverUtils::Filter
typedef std::map< std::string,
std::string > 
ParamMap
 
- Protected Attributes inherited from Nektar::SolverUtils::Filter
LibUtilities::SessionReaderSharedPtr m_session
 

Detailed Description

Definition at line 45 of file FilterElectrogram.h.

Constructor & Destructor Documentation

Nektar::FilterElectrogram::FilterElectrogram ( const LibUtilities::SessionReaderSharedPtr pSession,
const ParamMap pParams 
)

Electrogram filter constructor.

Definition at line 50 of file FilterElectrogram.cpp.

References ASSERTL0, Nektar::LibUtilities::Equation::Evaluate(), m_electrogramStream, m_index, m_outputFile, m_outputFrequency, and Nektar::SolverUtils::Filter::m_session.

53  : Filter(pSession)
54 {
55  ParamMap::const_iterator it;
56 
57  // OutputFile
58  it = pParams.find("OutputFile");
59  if (it == pParams.end())
60  {
61  m_outputFile = m_session->GetSessionName();
62  }
63  else
64  {
65  ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
66  m_outputFile = it->second;
67  }
68  if (!(m_outputFile.length() >= 4
69  && m_outputFile.substr(m_outputFile.length() - 4) == ".ecg"))
70  {
71  m_outputFile += ".ecg";
72  }
73 
74  // OutputFrequency
75  it = pParams.find("OutputFrequency");
76  if (it == pParams.end())
77  {
79  }
80  else
81  {
82  LibUtilities::Equation equ(m_session, it->second);
83  m_outputFrequency = floor(equ.Evaluate());
84  }
85 
86  // Points
87  it = pParams.find("Points");
88  ASSERTL0(it != pParams.end(), "Missing parameter 'Points'.");
89  m_electrogramStream.str(it->second);
90  m_index = 0;
91 }
unsigned int m_index
Counts number of calls to update (number of timesteps)
std::string m_outputFile
Filename to output electrogram data to.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
std::stringstream m_electrogramStream
Point coordinate input string.
unsigned int m_outputFrequency
Number of timesteps between outputs.
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: Filter.cpp:52
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
Nektar::FilterElectrogram::~FilterElectrogram ( )
virtual

Electrogram filter destructor.

Definition at line 97 of file FilterElectrogram.cpp.

98 {
99 
100 }

Member Function Documentation

static SolverUtils::FilterSharedPtr Nektar::FilterElectrogram::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const ParamMap pParams 
)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file FilterElectrogram.h.

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

53  {
55  ::AllocateSharedPtr(pSession, pParams);
56  return p;
57  }
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::FilterElectrogram::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Finalise the electrogram filter and close output file.

Implements Nektar::SolverUtils::Filter.

Definition at line 270 of file FilterElectrogram.cpp.

References m_outputStream.

273 {
274  if (pFields[0]->GetComm()->GetRank() == 0)
275  {
276  m_outputStream.close();
277  }
278 }
std::ofstream m_outputStream
Output file stream for electrogram data.
void Nektar::FilterElectrogram::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Initialises the electrogram filter and open output file.

Implements Nektar::SolverUtils::Filter.

Definition at line 106 of file FilterElectrogram.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, m_electrogramPoints, m_electrogramStream, m_grad_R_x, m_grad_R_y, m_grad_R_z, m_index, m_outputFile, m_outputStream, Nektar::SolverUtils::Filter::m_session, npts, Vmath::Sadd(), Vmath::Sdiv(), v_Update(), Nektar::NekMeshUtils::vert, Vmath::Vsqrt(), Vmath::Vvtvp(), and Vmath::Vvtvvtp().

109 {
111  "No history points in stream.");
112 
113  m_index = 0;
114  Array<OneD, NekDouble> gloCoord(3,0.0);
115  LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
116 
117  // Read electrogram points
118  // Always use dim = 3 to allow electrode to be above surface
119  const int dim = 3;
120  int i = 0;
121 
122  while (!m_electrogramStream.fail())
123  {
124  m_electrogramStream >> gloCoord[0] >> gloCoord[1] >> gloCoord[2];
125  if (!m_electrogramStream.fail())
126  {
129  ::AllocateSharedPtr(dim, i, gloCoord[0],
130  gloCoord[1], gloCoord[2]);
131 
132  m_electrogramPoints.push_back(vert);
133  ++i;
134  }
135  }
136 
137  if (vComm->GetRank() == 0)
138  {
139  // Open output stream
140  m_outputStream.open(m_outputFile.c_str());
141  m_outputStream << "# Electrogram data for variables (:";
142 
143  for (i = 0; i < pFields.num_elements(); ++i)
144  {
145  m_outputStream << m_session->GetVariable(i) <<",";
146  }
147 
148  m_outputStream << ") at points:" << endl;
149 
150  for (i = 0; i < m_electrogramPoints.size(); ++i)
151  {
152  m_electrogramPoints[i]->GetCoords( gloCoord[0],
153  gloCoord[1],
154  gloCoord[2]);
155 
156  m_outputStream << "# \t" << i;
157  m_outputStream.width(8);
158  m_outputStream << gloCoord[0];
159  m_outputStream.width(8);
160  m_outputStream << gloCoord[1];
161  m_outputStream.width(8);
162  m_outputStream << gloCoord[2];
163  m_outputStream << endl;
164  }
165  }
166 
167  // Compute the distance function for each electrogram point
168  const unsigned int nq = pFields[0]->GetNpoints();
169  const unsigned int npts = m_electrogramPoints.size();
170  NekDouble px, py, pz;
174 
178 
179  Array<OneD, NekDouble> oneOverR(nq);
180  for (unsigned int i = 0; i < npts; ++i)
181  {
183  m_grad_R_y[i] = Array<OneD, NekDouble>(nq);
184  m_grad_R_z[i] = Array<OneD, NekDouble>(nq);
185 
186  // Compute 1/R
187  m_electrogramPoints[i]->GetCoords(px,py,pz);
188 
189  pFields[0]->GetCoords(x,y,z);
190 
191  Vmath::Sadd (nq, -px, x, 1, x, 1);
192  Vmath::Sadd (nq, -py, y, 1, y, 1);
193  Vmath::Sadd (nq, -pz, z, 1, z, 1);
194  Vmath::Vvtvvtp(nq, x, 1, x, 1, y, 1, y, 1, oneOverR, 1);
195  Vmath::Vvtvp (nq, z, 1, z, 1, oneOverR, 1, oneOverR, 1);
196  Vmath::Vsqrt (nq, oneOverR, 1, oneOverR, 1);
197  Vmath::Sdiv (nq, 1.0, oneOverR, 1, oneOverR, 1);
198 
199  // Compute grad 1/R
200  pFields[0]->PhysDeriv(oneOverR, m_grad_R_x[i], m_grad_R_y[i],
201  m_grad_R_z[i]);
202  }
203 
204  // Compute electrogram point for initial condition
205  v_Update(pFields, time);
206 }
unsigned int m_index
Counts number of calls to update (number of timesteps)
std::string m_outputFile
Filename to output electrogram data to.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:394
Array< OneD, Array< OneD, NekDouble > > m_grad_R_y
Gradient of the radius from each electrogram point in y-direction.
std::stringstream m_electrogramStream
Point coordinate input string.
std::ofstream m_outputStream
Output file stream for electrogram data.
SpatialDomains::PointGeomVector m_electrogramPoints
List of electrogram points.
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:428
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
Compute extracellular potential at egm points at current time.
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/y.
Definition: Vmath.cpp:257
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
static std::string npts
Definition: InputFld.cpp:43
double NekDouble
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.cpp:301
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
void Vvtvvtp(int n, const T *v, int incv, const T *w, int incw, const T *x, int incx, const T *y, int incy, T *z, int incz)
vvtvvtp (vector times vector plus vector times vector):
Definition: Vmath.cpp:523
Array< OneD, Array< OneD, NekDouble > > m_grad_R_z
Gradient of the radius from each electrogram point in z-direction.
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
Array< OneD, Array< OneD, NekDouble > > m_grad_R_x
Gradient of the radius from each electrogram point in x-direction.
bool Nektar::FilterElectrogram::v_IsTimeDependent ( )
protectedvirtual

Filter is time-dependent and should be called at each time-step.

Implements Nektar::SolverUtils::Filter.

Definition at line 284 of file FilterElectrogram.cpp.

285 {
286  return true;
287 }
void Nektar::FilterElectrogram::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
protectedvirtual

Compute extracellular potential at egm points at current time.

Implements Nektar::SolverUtils::Filter.

Definition at line 212 of file FilterElectrogram.cpp.

References m_electrogramPoints, m_grad_R_x, m_grad_R_y, m_grad_R_z, m_index, m_outputFrequency, m_outputStream, Nektar::LibUtilities::ReduceSum, Vmath::Vvtvp(), and Vmath::Vvtvvtp().

Referenced by v_Initialise().

215 {
216  // Only output every m_outputFrequency.
217  if ((m_index++) % m_outputFrequency)
218  {
219  return;
220  }
221 
222  const unsigned int nq = pFields[0]->GetNpoints();
223  const unsigned int npoints = m_electrogramPoints.size();
224  LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
225 
226  unsigned int i = 0;
227  Array<OneD, NekDouble> e(npoints);
228 
229  // Compute grad V
230  Array<OneD, NekDouble> grad_V_x(nq), grad_V_y(nq), grad_V_z(nq);
231  pFields[0]->PhysDeriv(pFields[0]->GetPhys(),
232  grad_V_x, grad_V_y, grad_V_z);
233 
234  for (i = 0; i < npoints; ++i)
235  {
236  // Multiply together
237  Array<OneD, NekDouble> output(nq);
238  Vmath::Vvtvvtp(nq, m_grad_R_x[i], 1, grad_V_x, 1, m_grad_R_y[i], 1,
239  grad_V_y, 1, output, 1);
240  Vmath::Vvtvp (nq, m_grad_R_z[i], 1, grad_V_z, 1, output, 1,
241  output, 1);
242 
243  e[i] = pFields[0]->Integral(output);
244  }
245 
246  // Exchange history data
247  // This could be improved to reduce communication but works for now
248  vComm->AllReduce(e, LibUtilities::ReduceSum);
249 
250  // Only the root process writes out electrogram data
251  if (vComm->GetRank() == 0)
252  {
253  m_outputStream.width(8);
254  m_outputStream << setprecision(6) << time;
255 
256  // Write data values point by point
257  for (i = 0; i < m_electrogramPoints.size(); ++i)
258  {
259  m_outputStream.width(25);
260  m_outputStream << setprecision(16) << e[i];
261  }
262  m_outputStream << endl;
263  }
264 }
unsigned int m_index
Counts number of calls to update (number of timesteps)
Array< OneD, Array< OneD, NekDouble > > m_grad_R_y
Gradient of the radius from each electrogram point in y-direction.
std::ofstream m_outputStream
Output file stream for electrogram data.
SpatialDomains::PointGeomVector m_electrogramPoints
List of electrogram points.
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:428
unsigned int m_outputFrequency
Number of timesteps between outputs.
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
void Vvtvvtp(int n, const T *v, int incv, const T *w, int incw, const T *x, int incx, const T *y, int incy, T *z, int incz)
vvtvvtp (vector times vector plus vector times vector):
Definition: Vmath.cpp:523
Array< OneD, Array< OneD, NekDouble > > m_grad_R_z
Gradient of the radius from each electrogram point in z-direction.
Array< OneD, Array< OneD, NekDouble > > m_grad_R_x
Gradient of the radius from each electrogram point in x-direction.

Friends And Related Function Documentation

friend class MemoryManager< FilterElectrogram >
friend

Definition at line 48 of file FilterElectrogram.h.

Member Data Documentation

std::string Nektar::FilterElectrogram::className
static
Initial value:

Name of the class.

Definition at line 60 of file FilterElectrogram.h.

SpatialDomains::PointGeomVector Nektar::FilterElectrogram::m_electrogramPoints
private

List of electrogram points.

Definition at line 94 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

std::stringstream Nektar::FilterElectrogram::m_electrogramStream
private

Point coordinate input string.

Definition at line 104 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Initialise().

Array<OneD, Array<OneD, NekDouble> > Nektar::FilterElectrogram::m_grad_R_x
private

Gradient of the radius from each electrogram point in x-direction.

Definition at line 88 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

Array<OneD, Array<OneD, NekDouble> > Nektar::FilterElectrogram::m_grad_R_y
private

Gradient of the radius from each electrogram point in y-direction.

Definition at line 90 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

Array<OneD, Array<OneD, NekDouble> > Nektar::FilterElectrogram::m_grad_R_z
private

Gradient of the radius from each electrogram point in z-direction.

Definition at line 92 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

unsigned int Nektar::FilterElectrogram::m_index
private

Counts number of calls to update (number of timesteps)

Definition at line 96 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), v_Initialise(), and v_Update().

std::string Nektar::FilterElectrogram::m_outputFile
private

Filename to output electrogram data to.

Definition at line 100 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Initialise().

unsigned int Nektar::FilterElectrogram::m_outputFrequency
private

Number of timesteps between outputs.

Definition at line 98 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Update().

std::ofstream Nektar::FilterElectrogram::m_outputStream
private

Output file stream for electrogram data.

Definition at line 102 of file FilterElectrogram.h.

Referenced by v_Finalise(), v_Initialise(), and v_Update().