LifeV
ElectrophysiologyUtility.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3  *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23  *******************************************************************************
24  */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Utilities
30 
31  @contributor Simone Palamara <palamara.simone@gmail.com>
32  @maintainer Simone Palamara <palamara.simone@gmail.com>
33 
34  This file contains a set of base utilities used to applied current on a specified point.
35  */
36 
37 #ifndef ELECTROPHYSIOLOGYUTILITY_H
38 #define ELECTROPHYSIOLOGYUTILITY_H 1
39 
40 #include <lifev/core/LifeV.hpp>
41 #include <lifev/core/array/VectorEpetra.hpp>
42 #include <lifev/core/array/MatrixEpetra.hpp>
43 #include <lifev/core/array/MapEpetra.hpp>
44 #include <lifev/core/filter/ExporterEnsight.hpp>
45 #include <lifev/core/filter/ExporterHDF5.hpp>
46 #include <lifev/core/filter/ExporterEmpty.hpp>
47 #include <lifev/core/filter/Exporter.hpp>
48 #include <lifev/core/mesh/RegionMesh.hpp>
49 #include <lifev/core/fem/FESpace.hpp>
50 #include <Teuchos_ScalarTraitsDecl.hpp>
51 #include <time.h> /* time */
52 #include <math.h> /* floor */
53 #include <lifev/core/mesh/NeighborMarker.hpp>
54 #include <unordered_set>
55 
56 namespace LifeV
57 {
58 
59 // Predeclaration
60 
62 {
63 
66 
67 //! HeartUtility - A string parser grammar based on \c boost::spirit::qi
68 /*!
69  * @author(s) Simone Palamara
70  *
71  * \c ElectrophysiologyUtility contains methods for applied current on a specified point.
72  *
73  */
74 
75 //! @name Methods
76 //@{
77 
78 //! Find closest point within radius and applied a constant current
79 /*!
80  * @param point Vector of real containing the coordinates of the point within the radius
81  * @param radius Radius used to find point.
82  * @param appliedCurrentVector Vector epetra containing the applied current.
83  * @param valueAppliedCurrent Value of the current to apply at the specified point.
84  * @param fullMesh Pointer to the mesh.
85  * @param Comm EpetraMpi comunicator.
86  */
88 {
90 
91  Int ids;
92  for ( UInt i (0); i < n; i++)
93  {
94  int iGID = appliedCurrentVector -> blockMap().GID ( static_cast<EpetraInt_Type> (i) );
95  Real px = fullMesh -> point ( iGID ).x();
96  Real py = fullMesh -> point ( iGID ).y();
97  Real pz = fullMesh -> point ( iGID ).z();
98 
99  Real distance = std::sqrt ( ( point[0] - px) * (point[0] - px)
100  + ( point[1] - py) * (point[1] - py)
101  + ( point[2] - pz) * (point[2] - pz) );
102  if (distance <= Radius)
103  {
104  ids = iGID;
105  Radius = distance;
106  }
107 
108 
109  }
111  Real globalRadius (0);
112  Comm->Barrier();
114 
115  if (globalRadius == localRadius)
116  {
118  }
119 
120 }
121 
122 //! Find all the points within radius and applied a constant current
123 /*!
124  * @param point Vector of real containing the coordinates of the point within the radius
125  * @param radius Radius used to find point.
126  * @param appliedCurrentVector Vector epetra containing the applied current.
127  * @param valueAppliedCurrent Value of the current to apply at the specified point.
128  * @param fullMesh Pointer to the mesh.
129  */
131 {
133 
134  std::vector<UInt> ids;
135  for ( UInt i (0); i < n; i++)
136  {
137  int iGID = appliedCurrentVector -> blockMap().GID ( static_cast<EpetraInt_Type> (i) );
138  Real px = fullMesh -> point ( iGID ).x();
139  Real py = fullMesh -> point ( iGID ).y();
140  Real pz = fullMesh -> point ( iGID ).z();
141 
142  Real distance = std::sqrt ( ( point[0] - px) * (point[0] - px)
143  + ( point[1] - py) * (point[1] - py)
144  + ( point[2] - pz) * (point[2] - pz) );
145  if (distance <= Radius)
146  {
147  ids.push_back (iGID);
148  }
149 
150 
151  }
152 
153  for (int i (0); i < ids.size(); i++)
154  {
156  }
157 }
158 
159 //! Find closest point to a given one in the mesh
160 /*!
161  * @param point Vector of real containing the coordinates of the point within the radius
162  * @param vec Vector epetra used to recover Global id.
163  * @param fullMesh Pointer to the mesh.
164  * @param Comm EpetraMpi comunicator.
165  * @return The ids of the closest point
166  */
168 {
169  Int n = vec -> epetraVector().MyLength();
170  Real Radius = 100000.0;
171  Int ids;
172  for ( UInt i (0); i < n; i++)
173  {
174  Int iGID = vec -> blockMap().GID ( static_cast<EpetraInt_Type> (i) );
175  Real px = fullMesh -> point ( iGID ).x();
176  Real py = fullMesh -> point ( iGID ).y();
177  Real pz = fullMesh -> point ( iGID ).z();
178 
179  Real distance = std::sqrt ( ( point[0] - px) * (point[0] - px)
180  + ( point[1] - py) * (point[1] - py)
181  + ( point[2] - pz) * (point[2] - pz) );
182  if (distance <= Radius)
183  {
184  ids = iGID;
185  Radius = distance;
186  }
187 
188 
189  }
191  Real globalRadius (0);
192  Comm->Barrier();
194  if (globalRadius == localRadius)
195  {
196  return ids;
197  }
198  else
199  {
200  return -1;
201  }
202 
203 }
204 
205 //! Collect all the ids of points with a given flag in a local vector for each processor
206 /*!
207  * @param containerIds Vector containig all the ids of the points with a given flag
208  * @param flag Flag.
209  * @param vec Vector epetra used to recover Global id.
210  * @param fullMesh Pointer to the mesh.
211  */
213 {
214  for ( Int j (0); j < vec->epetraVector().MyLength() ; ++j )
215  {
216  if ( fullMesh -> point ( vec->blockMap().GID ( static_cast<EpetraInt_Type> (j) ) ).markerID() == flag )
217  {
218  containerIds.push_back (vec->blockMap().GID ( static_cast<EpetraInt_Type> (j) ) );
219  }
220  }
221 }
222 
223 //! Select randomly a value in a given set and update the set by deleting the chosen value from the set
224 /*!
225  * @param container vector containig all the value
226  * @return Selected value
227  */
228 template<typename Type> inline Type randomPointInSet (std::vector<Type>& container )
229 {
230  /* generate uniform random number: */
231  UInt number = std::floor ( (Teuchos::ScalarTraits<Real>::random() + 1.0) / 2.0 * container.size() );
234  return value;
235 }
236 
237 
238 //! Select randomly a point in a given set and its neighborhood and update the set by deleting the chosen value from the set
239 /*!
240  * @param container vector containig all the value
241  * @param selectedPoints selected points
242  * @param neighbors cointainer of the neighbors
243  */
245 {
246  /* generate uniform random number: */
247  UInt number = std::floor ( (Teuchos::ScalarTraits<Real>::random() + 1.0) / 2.0 * container.size() );
250  for (int i = 0; i < neighbors[container[number]].size(); i++)
251  {
253  it++;
254  }
256 }
257 
258 
259 
260 //! Select randomly N values in a given set and update the set by deleting the chosen N values from the set
261 /*!
262  * @param container Set containig all the value
263  * @param selectedValue vector containg the selected values
264  * @param N number of values we want to select
265  */
266 template<typename Type> inline void randomNPointsInSet (std::vector<Type>& container, std::vector<Type>& selectedValue, UInt N )
267 {
268  /* initialize random seed: */
269  Teuchos::ScalarTraits<Real>::seedrandom (time (NULL) );
270  for (int i = 0; i < N; i++)
271  {
273  }
274 }
275 
276 //! Select randomly N values in a given set and update the set by deleting the chosen N values from the set
277 /*!
278  * @param container Set containig all the value
279  * @param selectedValue vector containg the selected values
280  * @param N number of values we want to select
281  * @param fullMesh mesh used to determine the neighborhood
282  */
284 {
285  /* initialize random seed: */
286  Teuchos::ScalarTraits<Real>::seedrandom (time (NULL) );
289  Real timePmj (Comm->MyPID() *deltaT);
290  for (int i = 0; i < N; i++)
291  {
294  for (int j = 0; j < localValue.size(); j++)
295  {
298  }
299  }
300 }
301 
302 
303 
304 //! Apply given current to a set of points
305 /*!
306  * @param container Set containig all the globalIDs of points to which we want to apply the current
307  * @param appliedCurrentVector vector containg the current
308  * @param valueAppliedCurrent value of the current we want to apply
309  */
311 {
312  for (int i (0); i < container.size(); i++)
313  {
315  if (lrow >= 0)
316  {
318  }
319  }
320 }
321 
322 
323 //! Apply given current with a set of PMJs.
324 /*!
325  * @param container vector containig all the globalIDs of the PMJs to which we want to apply the current
326  * @param timeActivation vector containig the activation time of the PMJs
327  * @param appliedCurrentVector vector containg the applied current
328  * @param valueAppliedCurrent vector containig the apply current during the all simulation time
329  * @param shiftVector vector containig the index that refers to the value of applied current in each PMJ
330  * @param currentTime current time
331  */
333 {
334  for (int i (0); i < container.size(); i++)
335  {
336  if (activationTime[i] <= currentTime)
337  {
338  shiftVector[i] += 1;
340  if (lrow >= 0)
341  {
343  }
344  }
345  else
346  {
348  if (lrow >= 0)
349  {
350  appliedCurrentVector -> operator [] ( container[i] ) = 0;
351  }
352  }
353 
354 
355  }
356 }
357 
358 //@}
359 
360 } // namespace ElectrophysiologyUtility
361 
362 } // namespace LifeV
363 
364 #endif /* HEARTUTILITY_H */
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
std::vector< neighbors_Type > neighborList_Type
Type randomPointInSet(std::vector< Type > &container)
Select randomly a value in a given set and update the set by deleting the chosen value from the set...
void allIdsPointsWithGivenFlag(std::vector< ID > &containerIds, UInt flag, std::shared_ptr< VectorEpetra > vec, std::shared_ptr< Mesh > fullMesh)
Collect all the ids of points with a given flag in a local vector for each processor.
void appliedCurrentPointsWithinRadius(std::vector< Real > &point, Real Radius, std::shared_ptr< VectorEpetra > appliedCurrentVector, Real valueAppliedCurrent, std::shared_ptr< Mesh > fullMesh)
Find all the points within radius and applied a constant current.
UInt findClosestPoint(std::vector< Real > &point, std::shared_ptr< VectorEpetra > vec, std::shared_ptr< Mesh > fullMesh, std::shared_ptr< Epetra_Comm > Comm)
Find closest point to a given one in the mesh.
void randomPointInSetAndNeighborhood(std::vector< ID > &container, std::vector< ID > &selectedPoints, neighborList_Type &neighbors)
Select randomly a point in a given set and its neighborhood and update the set by deleting the chosen...
void applyCurrentGivenSetOfPoints(std::vector< Type > &container, std::vector< Real > activationTime, std::shared_ptr< VectorEpetra > appliedCurrentVector, std::vector< Real > &valueAppliedCurrent, std::vector< UInt > &shiftVector, Real currentTime)
Apply given current with a set of PMJs.
void appliedCurrentClosestPointWithinRadius(std::vector< Real > &point, Real Radius, std::shared_ptr< VectorEpetra > appliedCurrentVector, Real valueAppliedCurrent, std::shared_ptr< Mesh > fullMesh, std::shared_ptr< Epetra_Comm > Comm)
Find closest point within radius and applied a constant current.