Nektar++
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:
[legend]

Public Member Functions

 FilterElectrogram (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
 Electrogram filter constructor. More...
 
 ~FilterElectrogram () override
 Electrogram filter destructor. More...
 
- 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 ()
 
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 std::shared_ptr< SolverUtils::EquationSystem > &pEquation, 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

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

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
 
const std::weak_ptr< EquationSystemm_equ
 

Detailed Description

Definition at line 44 of file FilterElectrogram.h.

Constructor & Destructor Documentation

◆ FilterElectrogram()

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

Electrogram filter constructor.

Definition at line 50 of file FilterElectrogram.cpp.

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

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

◆ ~FilterElectrogram()

Nektar::FilterElectrogram::~FilterElectrogram ( )
override

Electrogram filter destructor.

Definition at line 95 of file FilterElectrogram.cpp.

96{
97}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 50 of file FilterElectrogram.h.

54 {
57 pSession, pEquation, pParams);
58 return p;
59 }
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:51

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ v_Finalise()

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

Finalise the electrogram filter and close output file.

Implements Nektar::SolverUtils::Filter.

Definition at line 259 of file FilterElectrogram.cpp.

262{
263 if (pFields[0]->GetComm()->GetRank() == 0)
264 {
265 m_outputStream.close();
266 }
267}
std::ofstream m_outputStream
Output file stream for electrogram data.

References m_outputStream.

◆ v_Initialise()

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

Initialises the electrogram filter and open output file.

Implements Nektar::SolverUtils::Filter.

Definition at line 102 of file FilterElectrogram.cpp.

105{
106 ASSERTL0(!m_electrogramStream.fail(), "No history points in stream.");
107
108 m_index = 0;
109 Array<OneD, NekDouble> gloCoord(3, 0.0);
110 LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
111
112 // Read electrogram points
113 // Always use dim = 3 to allow electrode to be above surface
114 const size_t dim = 3;
115 size_t i = 0;
116
117 while (!m_electrogramStream.fail())
118 {
119 m_electrogramStream >> gloCoord[0] >> gloCoord[1] >> gloCoord[2];
120 if (!m_electrogramStream.fail())
121 {
124 dim, i, gloCoord[0], gloCoord[1], gloCoord[2]);
125
126 m_electrogramPoints.push_back(vert);
127 ++i;
128 }
129 }
130
131 if (vComm->GetRank() == 0)
132 {
133 // Open output stream
134 m_outputStream.open(m_outputFile.c_str());
135 m_outputStream << "# Electrogram data for variables (:";
136
137 for (size_t i = 0; i < pFields.size(); ++i)
138 {
139 m_outputStream << m_session->GetVariable(i) << ",";
140 }
141
142 m_outputStream << ") at points:" << endl;
143
144 for (size_t i = 0; i < m_electrogramPoints.size(); ++i)
145 {
146 m_electrogramPoints[i]->GetCoords(gloCoord[0], gloCoord[1],
147 gloCoord[2]);
148
149 m_outputStream << "# \t" << i;
150 m_outputStream.width(8);
151 m_outputStream << gloCoord[0];
152 m_outputStream.width(8);
153 m_outputStream << gloCoord[1];
154 m_outputStream.width(8);
155 m_outputStream << gloCoord[2];
156 m_outputStream << endl;
157 }
158 }
159
160 // Compute the distance function for each electrogram point
161 const size_t nq = pFields[0]->GetNpoints();
162 const size_t npts = m_electrogramPoints.size();
163 NekDouble px, py, pz;
164 m_grad_R_x = Array<OneD, Array<OneD, NekDouble>>(npts);
165 m_grad_R_y = Array<OneD, Array<OneD, NekDouble>>(npts);
166 m_grad_R_z = Array<OneD, Array<OneD, NekDouble>>(npts);
167
168 Array<OneD, NekDouble> oneOverR(nq, 0.0);
169
170 for (size_t i = 0; i < npts; ++i)
171 {
172 m_grad_R_x[i] = Array<OneD, NekDouble>(nq, 0.0);
173 m_grad_R_y[i] = Array<OneD, NekDouble>(nq, 0.0);
174 m_grad_R_z[i] = Array<OneD, NekDouble>(nq, 0.0);
175
176 Array<OneD, NekDouble> x(nq, 0.0);
177 Array<OneD, NekDouble> y(nq, 0.0);
178 Array<OneD, NekDouble> z(nq, 0.0);
179
180 // Compute 1/R
181 m_electrogramPoints[i]->GetCoords(px, py, pz);
182 pFields[0]->GetCoords(x, y, z);
183
184 Vmath::Sadd(nq, -px, x, 1, x, 1);
185 Vmath::Sadd(nq, -py, y, 1, y, 1);
186 Vmath::Sadd(nq, -pz, z, 1, z, 1);
187 Vmath::Vvtvvtp(nq, x, 1, x, 1, y, 1, y, 1, oneOverR, 1);
188 Vmath::Vvtvp(nq, z, 1, z, 1, oneOverR, 1, oneOverR, 1);
189 Vmath::Vsqrt(nq, oneOverR, 1, oneOverR, 1);
190 Vmath::Sdiv(nq, 1.0, oneOverR, 1, oneOverR, 1);
191
192 // Compute grad 1/R
193 pFields[0]->PhysDeriv(oneOverR, m_grad_R_x[i], m_grad_R_y[i],
194 m_grad_R_z[i]);
195 }
196
197 // Compute electrogram point for initial condition
198 v_Update(pFields, time);
199}
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.
Array< OneD, Array< OneD, NekDouble > > m_grad_R_y
Gradient of the radius from each electrogram point in y-direction.
SpatialDomains::PointGeomVector m_electrogramPoints
List of electrogram points.
void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Compute extracellular potential at egm points at current time.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:57
std::vector< double > z(NPUPPER)
double NekDouble
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.hpp:340
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.hpp:366
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/x.
Definition: Vmath.hpp:154
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.hpp:194
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.hpp:439

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, Vmath::Sadd(), Vmath::Sdiv(), v_Update(), Vmath::Vsqrt(), Vmath::Vvtvp(), Vmath::Vvtvvtp(), and Nektar::UnitTests::z().

◆ v_IsTimeDependent()

bool Nektar::FilterElectrogram::v_IsTimeDependent ( )
overrideprotectedvirtual

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

Implements Nektar::SolverUtils::Filter.

Definition at line 272 of file FilterElectrogram.cpp.

273{
274 return true;
275}

◆ v_Update()

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

Compute extracellular potential at egm points at current time.

Implements Nektar::SolverUtils::Filter.

Definition at line 204 of file FilterElectrogram.cpp.

207{
208 // Only output every m_outputFrequency.
209 if ((m_index++) % m_outputFrequency)
210 {
211 return;
212 }
213
214 const size_t nq = pFields[0]->GetNpoints();
215 const size_t npoints = m_electrogramPoints.size();
216 LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
217
218 size_t i = 0;
219 Array<OneD, NekDouble> e(npoints);
220
221 // Compute grad V
222 Array<OneD, NekDouble> grad_V_x(nq), grad_V_y(nq), grad_V_z(nq);
223 pFields[0]->PhysDeriv(pFields[0]->GetPhys(), grad_V_x, grad_V_y, grad_V_z);
224
225 for (i = 0; i < npoints; ++i)
226 {
227 // Multiply together
228 Array<OneD, NekDouble> output(nq);
229 Vmath::Vvtvvtp(nq, m_grad_R_x[i], 1, grad_V_x, 1, m_grad_R_y[i], 1,
230 grad_V_y, 1, output, 1);
231 Vmath::Vvtvp(nq, m_grad_R_z[i], 1, grad_V_z, 1, output, 1, output, 1);
232
233 e[i] = pFields[0]->Integral(output);
234 }
235
236 // Exchange history data
237 // This could be improved to reduce communication but works for now
238 vComm->AllReduce(e, LibUtilities::ReduceSum);
239
240 // Only the root process writes out electrogram data
241 if (vComm->GetRank() == 0)
242 {
243 m_outputStream.width(8);
244 m_outputStream << setprecision(6) << time;
245
246 // Write data values point by point
247 for (i = 0; i < m_electrogramPoints.size(); ++i)
248 {
249 m_outputStream.width(25);
250 m_outputStream << setprecision(16) << e[i];
251 }
252 m_outputStream << endl;
253 }
254}

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().

Friends And Related Function Documentation

◆ MemoryManager< FilterElectrogram >

friend class MemoryManager< FilterElectrogram >
friend

Definition at line 1 of file FilterElectrogram.h.

Member Data Documentation

◆ className

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

Name of the class.

Definition at line 62 of file FilterElectrogram.h.

◆ m_electrogramPoints

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

List of electrogram points.

Definition at line 97 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

◆ m_electrogramStream

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

Point coordinate input string.

Definition at line 107 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Initialise().

◆ m_grad_R_x

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 91 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

◆ m_grad_R_y

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 93 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

◆ m_grad_R_z

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 95 of file FilterElectrogram.h.

Referenced by v_Initialise(), and v_Update().

◆ m_index

unsigned int Nektar::FilterElectrogram::m_index
private

Counts number of calls to update (number of timesteps)

Definition at line 99 of file FilterElectrogram.h.

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

◆ m_outputFile

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

Filename to output electrogram data to.

Definition at line 103 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Initialise().

◆ m_outputFrequency

unsigned int Nektar::FilterElectrogram::m_outputFrequency
private

Number of timesteps between outputs.

Definition at line 101 of file FilterElectrogram.h.

Referenced by FilterElectrogram(), and v_Update().

◆ m_outputStream

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

Output file stream for electrogram data.

Definition at line 105 of file FilterElectrogram.h.

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