EMSolver.hpp 69.4 KB
Newer Older
Simone Rossi's avatar
Simone Rossi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//@HEADER
/*
 *******************************************************************************

 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University

 This file is part of LifeV.

 LifeV is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 LifeV is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with LifeV.  If not, see <http://www.gnu.org/licenses/>.

 *******************************************************************************
 */
//@HEADER
/*!
 @file
 @brief Class for solving the Monodomain equations in electrophysiology.

 @date 02-2013
 @author Simone Rossi <simone.rossi@epfl.ch>

 @last update 02-2013

 This class provides interfaces to solve the monodomain equation
 ( reaction diffusion equation ) using the ETA framework.
 The solution can be performed using three different methods:
 -operator splitting method (at this point available only with forward Euler
 for the reaction step and backward Euler for the diffusion step. );
 -Ionic Currents Interpolation (at this point only forward Euler);
 -State Variable interpolation (at this point only forward Euler).
 */

#ifndef _EMSOLVER_H_
#define _EMSOLVER_H_


Simone Rossi's avatar
Simone Rossi committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <lifev/em/solver/electrophysiology/EMMonodomainSolver.hpp>
//
//#include <lifev/em/solver/EMStructuralOperator.hpp>
//#include <lifev/em/solver/EMGeneralizedActiveHolzapfelOgdenMaterial.hpp>
//#include <lifev/em/solver/EMActiveStrainSolver.hpp>
//#include <lifev/core/interpolation/RBFlocallyRescaledVectorial.hpp>
//#include <lifev/core/interpolation/RBFlocallyRescaledScalar.hpp>
//#include <lifev/core/interpolation/RBFrescaledVectorial.hpp>
//#include <lifev/core/interpolation/RBFrescaledScalar.hpp>
////#include <lifev/core/interpolation/RBFscalar.hpp>
//#include <lifev/core/interpolation/RBFvectorial.hpp>
//
//#include <lifev/bc_interface/3D/bc/BCInterface3D.hpp>
//
//
//#include <lifev/em/solver/EMEvaluate.hpp>
Simone Rossi's avatar
Simone Rossi committed
64
65
66
67
68
69
70
71
72
73

namespace LifeV
{

//! EMSolver - Class featuring the solution of the electromechanical problem with monodomain equation

template<typename Mesh , typename IonicModel>
class EMSolver
{

Simone Rossi's avatar
Simone Rossi committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
//    //!Monodomain Solver
//    /*!
//     The monodomain equation reads
//     \f \Chi
//
//     */
//
//public:
//
//    //! @name Type definitions
//    //@{
//
//    typedef Mesh mesh_Type;
//    typedef boost::shared_ptr<mesh_Type> meshPtr_Type;
//
//    typedef VectorEpetra vector_Type;
//    typedef boost::shared_ptr<VectorEpetra> vectorPtr_Type;
//
//    typedef std::vector<vectorPtr_Type> vectorOfPtr_Type;
//
//    typedef MatrixEpetra<Real> matrix_Type;
//    typedef boost::shared_ptr<matrix_Type> matrixPtr_Type;
//
//    typedef Epetra_Comm comm_Type;
//    typedef boost::shared_ptr<comm_Type> commPtr_Type;
//
//    typedef ETFESpace<mesh_Type, MapEpetra, 3, 1> ETFESpace_Type;
//    typedef boost::shared_ptr<ETFESpace<mesh_Type, MapEpetra, 3, 1> > ETFESpacePtr_Type;
//
//    typedef ETFESpace<mesh_Type, MapEpetra, 3, 3> ETFESpaceVectorial_Type;
//    typedef boost::shared_ptr< ETFESpaceVectorial_Type > ETFESpaceVectorialPtr_Type;
//
//    typedef FESpace<mesh_Type, MapEpetra> feSpace_Type;
//    typedef boost::shared_ptr<feSpace_Type> feSpacePtr_Type;
//
//    typedef LinearSolver linearSolver_Type;
//    typedef boost::shared_ptr<LinearSolver> linearSolverPtr_Type;
//
//    typedef ExporterHDF5< mesh_Type >          exporter_Type;
//    typedef boost::shared_ptr<exporter_Type>                       exporterPtr_Type;
//    //  typedef Exporter<mesh_Type> exporter_Type;    //                IOFile_Type;
//    //  typedef boost::shared_ptr<exporter_Type> exporterPtr_Type; //                IOFilePtr_Type;
//
//    typedef LifeV::Preconditioner basePrec_Type;
//    typedef boost::shared_ptr<basePrec_Type> basePrecPtr_Type;
//    typedef LifeV::PreconditionerIfpack prec_Type;
//    typedef boost::shared_ptr<prec_Type> precPtr_Type;
//
//    typedef IonicModel ionicModel_Type;
//    typedef ElectroIonicModel superIonicModel;
//    typedef boost::shared_ptr<ionicModel_Type> ionicModelPtr_Type;
//
//    typedef Teuchos::ParameterList list_Type;
//
//    typedef boost::function <
//    Real (const Real& t, const Real& x, const Real& y, const Real& z,
//          const ID& i) > function_Type;
//
//    typedef MatrixSmall<3, 3>                          matrixSmall_Type;
//
//    typedef EMMonodomainSolver<mesh_Type, ionicModel_Type>                  monodomainSolver_Type;
//    typedef boost::shared_ptr<monodomainSolver_Type>                    monodomainSolverPtr_Type;
//
//    typedef FESpace< RegionMesh<LinearTetra>, MapEpetra >               FESpace_Type;
//    typedef boost::shared_ptr<FESpace_Type>                        FESpacePtr_Type;
//
//    typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 1 >       scalarETFESpace_Type;
//    typedef boost::shared_ptr<scalarETFESpace_Type>                      scalarETFESpacePtr_Type;
//    typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 >       solidETFESpace_Type;
//    typedef boost::shared_ptr<solidETFESpace_Type>                      solidETFESpacePtr_Type;
//
//    typedef StructuralConstitutiveLawData           structureData_Type;
//    typedef boost::shared_ptr<structureData_Type>           structureDataPtr_Type;
//
//    typedef EMStructuralOperator< RegionMesh<LinearTetra> > structuralOperator_Type;
//    typedef boost::shared_ptr< structuralOperator_Type > structuralOperatorPtr_Type;
//
//
//    typedef BCHandler                                          bc_Type;
//    typedef boost::shared_ptr< bc_Type >                       bcPtr_Type;
//    typedef StructuralOperator< RegionMesh<LinearTetra> >       physicalSolver_Type;
//    typedef BCInterface3D< bc_Type, physicalSolver_Type >      bcInterface_Type;
//    typedef boost::shared_ptr< bcInterface_Type >              bcInterfacePtr_Type;
//
//    typedef EMActiveStrainSolver<mesh_Type> activeStrain_Type;
//    typedef boost::shared_ptr< activeStrain_Type >  activeStrainPtr_Type;
//
//    typedef RBFInterpolation<mesh_Type>           interpolation_Type;
//    typedef boost::shared_ptr<interpolation_Type> interpolationPtr_Type;
//
//    typedef BCVector                                bcVector_Type;
//    typedef boost::shared_ptr<bcVector_Type>        bcVectorPtr_Type;
//    typedef std::vector<bcVectorPtr_Type>           bcVectorPtrs_Type;
//
//    typedef MapEpetra                               map_Type;
//    typedef boost::shared_ptr<map_Type>             mapPtr_Type;
//    ///////////////////////////////////////////////////////////////////////////
//
//    inline monodomainSolverPtr_Type    monodomainPtr()
//    {
//        return  M_monodomainPtr;
//    }
//    inline bool                     usingDifferentMeshes()
//    {
//        return M_usingDifferentMeshes;
//    }
//    inline structureDataPtr_Type       solidDataPtr()
//    {
//        return M_solidDataPtr;
//    }
//    inline structuralOperatorPtr_Type  solidPtr()
//    {
//        return M_solidPtr;
//    }
//    inline bcInterfacePtr_Type         solidBCPtr()
//    {
//        return M_solidBCPtr;
//    }
//    inline activeStrainPtr_Type         activationPtr()
//    {
//        return M_activationPtr;
//    }
//    inline Real                         monodomainTimeStep()
//    {
//        return M_monodomainTimeStep;
//    }
//    inline Real                         solidTimeStep()
//    {
//        return M_solidTimeStep;
//    }
//    inline Real                         lvPressure()
//    {
//        return M_lvPressure;
//    }
//    inline Real                         rvPressure()
//    {
//        return M_rvPressure;
//    }
//    inline Real                         lvVolume()
//    {
//        return M_lvVolume;
//    }
//    inline Real                         rvVolume()
//    {
//        return M_rvVolume;
//    }
//    inline std::vector<UInt>            lvFlags()
//    {
//        return M_lvFlags;
//    }
//    inline std::vector<UInt>            rvFlags()
//    {
//        return M_rvFlags;
//    }
//    inline bcVectorPtrs_Type            bcVectorPtrs()
//    {
//        return M_bcVectorPtrs;
//    }
//    inline bool                     oneWayCoupling()
//    {
//        return M_oneWayCoupling;
//    }
//    inline vectorPtr_Type               activationSolidPtr()
//    {
//        return M_activationSolidPtr;
//    }
//    inline FESpacePtr_Type              activationSolidFESpacePtr()
//    {
//        return M_solidActivationFESpacePtr;
//    }
//    inline FESpace_Type&                activationSolidFESpace()
//    {
//        return *M_solidActivationFESpacePtr;
//    }
//    inline meshPtr_Type                 fullSolidMesh()
//    {
//        return M_fullSolidMesh;
//    }
//
//    inline void setMonodomainPtr (monodomainSolverPtr_Type p)
//    {
//        M_monodomainPtr = p;
//    }
//    inline void setMonodomainPtr (monodomainSolver_Type& p)
//    {
//        *M_monodomainPtr = p;
//    }
//    inline void setUsingDifferentMeshes (bool p)
//    {
//        M_usingDifferentMeshes = p;
//    }
//    inline void setSolidDataPtr (structureDataPtr_Type p )
//    {
//        M_solidDataPtr = p;
//    }
//    inline void setSolidDataPtr (structureData_Type& p )
//    {
//        *M_solidDataPtr = p;
//    }
//    inline void setSolidPtr (structuralOperatorPtr_Type p)
//    {
//        M_solidPtr = p;
//    }
//    inline void setSolidPtr (structuralOperator_Type& p)
//    {
//        *M_solidPtr = p;
//    }
//    inline void setSolidBCPtr (bcInterfacePtr_Type p)
//    {
//        M_solidBCPtr = p;
//    }
//    inline void setSolidBCPtr (bcInterface_Type& p)
//    {
//        *M_solidBCPtr = p;
//    }
//    inline void setActivationPtr (activeStrainPtr_Type p)
//    {
//        M_activationPtr = p;
//    }
//    inline void setActivationPtr (activeStrain_Type& p)
//    {
//        *M_activationPtr = p;
//    }
//    inline void setMonodomainTimeStep (Real p)
//    {
//        M_monodomainTimeStep = p;
//    }
//    inline void setSolidTimeStep (Real p)
//    {
//        M_solidTimeStep = p;
//    }
//    inline void setLVPressure (Real p)
//    {
//        M_lvPressure = p;
//    }
//    inline void setRVPressure (Real p)
//    {
//        M_rvPressure = p;
//    }
//    inline void setLVVolume (Real p)
//    {
//        M_lvVolume = p;
//    }
//    inline void setRVVolume (Real p)
//    {
//        M_rvVolume = p;
//    }
//    inline void setLVFlags (std::vector<UInt> p)
//    {
//        M_lvFlags = p;
//    }
//    inline void setRVFlags (std::vector<UInt> p)
//    {
//        M_rvFlags = p;
//    }
//    inline void setBCVectorPtrs (bcVectorPtrs_Type p)
//    {
//        M_bcVectorPtrs = p;
//    }
//    inline void setOneWayCoupling ( bool p)
//    {
//        M_oneWayCoupling = p;
//    }
//
//
//
//    //@}
//
//    //! @name Constructors & Destructor
//    //@{
//    EMSolver( );
//
//    EMSolver (  Teuchos::ParameterList& parameterList,
//                const std::string data_file_name,
//                commPtr_Type comm );    //!Empty Constructor
//
//    EMSolver (  structuralOperatorPtr_Type solidPtr,
//                Teuchos::ParameterList& parameterList,
//                const std::string data_file_name,
//                commPtr_Type comm );
//
//    virtual ~EMSolver() {};
//
//    void setup (Teuchos::ParameterList& parameterList,
//                const std::string data_file_name,
//                std::string parameterListName = "ParamList.xml");
//
//    void setupMonodomainMatrix (Teuchos::ParameterList& parameterList);
//
//    void setupProjectionSolver (GetPot& dataFile, commPtr_Type comm);
//
//    void setupProjectionRhs();
//
//    void projection();
//
//    void updateMonodomainMatrix();
//
//    void updateMonodomain();
//
//    void updateSolid();
//
//    void solveOneMonodomainStep (int subiter = 1);
//
//    void solveOneReactionStepFE (int subiter = 1);
//
//    void solveOneICIStep();
//
//    void solveOneSVIStep();
//
//    void solveOneHLStep();
//
//    void solveOneOSStep (int subiter = 1);
//
//    void solveOneDiffusionStep();
//
//    void solveOneActivationStep();
//
//    inline void solveSolid()
//    {
//        M_solidPtr -> iterate ( M_solidBCPtr -> handler() );
//    }
//
//    void setupExporters (std::string dir = "./");
//
//    void exportSolution (Real time = 0.0);
//
//    void closeExporters();
//
//    void setupPreloadBC ( GetPot& dataFile, map_Type map );
//
//    void preloadRamp ( Real dt = 0.1);
//
//    void createReferencePositionVector();
//
//    void setupBC (const std::string data_file_name, map_Type map  );
//
//    void computeLVVolume (Real nx, Real ny, Real nz);
//    void computeRVVolume (Real nx, Real ny, Real nz);
//
//    void exportSolidFibersDirection (std::string dir = "./" );
//    void exportMonodomainFibersDirection (std::string dir = "./");
//    void exportSolidSheetsDirection (std::string dir = "./" );
//    void exportFibersAndSheetsFields (std::string dir = "./" );
//    void exportActivationTime (std::string dir = "./" );
//
//    inline void importSolidFibers (Teuchos::ParameterList& parameterList);
//    inline void importSolidSheets (Teuchos::ParameterList& parameterList);
//    inline void importMonodomainFibers (Teuchos::ParameterList& parameterList);
//
//    void setFibersAndSheets (Teuchos::ParameterList& parameterList);
//
//    void setupInterpolants (std::string parameterListName, Teuchos::ParameterList& parameterList, GetPot& dataFile);
//
//
//    inline void createLVPositionVector (Real nx, Real ny, Real nz)
//    {
//        M_lvPositionVectorPtr.reset (new vector_Type ( M_solidPtr -> activeMaterial() -> activationSpace() -> map() ) );
//        createPositionVector (nx, ny, nz, M_lvFlags, *M_lvPositionVectorPtr);
//    }
//    inline void createRVPositionVector (Real nx, Real ny, Real nz)
//    {
//        M_rvPositionVectorPtr.reset (new vector_Type ( M_solidPtr -> activeMaterial() -> activationSpace() -> map() ) );
//        createPositionVector (nx, ny, nz, M_rvFlags, *M_rvPositionVectorPtr );
//    }
//
//    void createPositionVector (Real nx, Real ny, Real nz, std::vector<UInt> flags, vector_Type& vec);
//
//    inline void registerActivationTime ( Real time, Real threshold = 0.0)
//    {
//        M_monodomainPtr -> registerActivationTime (*M_activationTimePtr, time, threshold);
//    }
//
//    inline void setSolidFibers (vector_Type& fibers)
//    {
//        M_solidPtr -> activeMaterial() -> setFiberVector (fibers);
//    }
//    inline void setSolidFibers (vectorPtr_Type fibers)
//    {
//        M_solidPtr -> activeMaterial() -> setFiberVector (*fibers);
//    }
//    inline void setSolidSheets (vector_Type& sheets)
//    {
//        M_solidPtr -> activeMaterial() -> setSheetVector (sheets);
//    }
//    inline void setSolidSheets (vectorPtr_Type sheets)
//    {
//        M_solidPtr -> activeMaterial() -> setSheetVector (*sheets);
//    }
//    //monodomain -> setFiberPtr( electroFibers )
//    inline void setMonodomainFibers (vectorPtr_Type fibers)
//    {
//        M_monodomainPtr -> setFiberPtr (fibers);
//    }
//    inline void setMonodomainFibers (vector_Type& fibers)
//    {
//        M_monodomainPtr -> setFiber (fibers);
//    }
//
//
//    //  void update();
//
//    inline void  setPotentialOnBoundary (Real value, UInt flag)
//    {
//        ElectrophysiologyUtility::setValueOnBoundary ( * (M_monodomainPtr -> potentialPtr() ), M_monodomainPtr -> fullMeshPtr(), value, flag);
//    }
//    inline void  setPotentialFromFunction (function_Type f, Real time = 0.0)
//    {
//        M_monodomainPtr -> setPotentialFromFunction ( f, time );
//    }
//
//    inline Real isochoricPressure (Real Cp, Real pn, Real dV)
//    {
//        return (pn + dV / Cp);
//    }
//    inline void isochoricLVPressure (Real Cp)
//    {
//        M_lvPressure = isochoricPressure (Cp, M_lvPressure, M_lvdV);
//    }
//    inline void isochoricRVPressure (Real Cp)
//    {
//        M_rvPressure = isochoricPressure (Cp, M_rvPressure, M_rvdV);
//    }
//    inline Real windkesselPressure (Real R, Real C, Real pn, Real dV, Real dt = 1.0)
//    {
//        return  pn - ( pn * dt / C / R + dV / C );
//    }
//
//    inline  void setSolutionMethod ( std::string p)
//    {
//        std::map< std::string, solutionMethod_Type > solutionMap;
//        solutionMap["OS"] = OS;
//        solutionMap["ICI"] = ICI;
//        solutionMap["HL"] = HL;
//        solutionMap["SVI"] = SVI;
//        M_solutionMethod   = solutionMap[p];
//    }
//    enum solutionMethod_Type { OS, ICI, HL, SVI };
//    solutionMethod_Type                 M_solutionMethod;
//    /*!
//    */
//    monodomainSolverPtr_Type    M_monodomainPtr;
//    bool                        M_usingDifferentMeshes;
//    structureDataPtr_Type       M_solidDataPtr;
//    structuralOperatorPtr_Type  M_solidPtr;
//    bcInterfacePtr_Type         M_solidBCPtr;
//    activeStrainPtr_Type        M_activationPtr;
//    Real                        M_monodomainTimeStep;
//    Real                        M_solidTimeStep;
//    exporterPtr_Type            M_monodomainExporterPtr;
//    exporterPtr_Type            M_solidExporterPtr;
//    exporterPtr_Type            M_activationExporterPtr;
//
//    //Coarse To Fine ( C2F )
//    vectorPtr_Type              M_monodomainDisplacementPtr;
//    interpolationPtr_Type       M_C2FPtr;
//    //Fine To Coarse ( F2C )
//    vectorPtr_Type              M_activationSolidPtr;
//    interpolationPtr_Type       M_F2CPtr;
//    meshPtr_Type                M_fullSolidMesh;
//
//    vectorPtr_Type              M_activationTimePtr;
//
//    Real                        M_lvPressure;
//    Real                        M_rvPressure;
//    Real                        M_lvVolume;
//    Real                        M_rvVolume;
//    Real                        M_lvdV;
//    Real                        M_rvdV;
//    std::ofstream               M_lvPVexporter;
//    std::ofstream               M_rvPVexporter;
//    bool                        M_lvPV;
//    bool                        M_rvPV;
//
//    std::vector<UInt>           M_lvFlags;
//    std::vector<UInt>           M_rvFlags;
//
//    bcVectorPtrs_Type           M_bcVectorPtrs;
//
//    vectorPtr_Type              M_referencePositionPtr;
//
//    Real                        M_lvPreloadPressure;
//    Real                        M_rvPreloadPressure;
//
//    vectorPtr_Type              M_lvPositionVectorPtr;//one of the orthogonal vectors with respect  to the normal of the lid
//    vectorPtr_Type              M_rvPositionVectorPtr;//one of the orthogonal vectors with respect  to the normal of the lid
//
//    bool                        M_oneWayCoupling;
//
//    commPtr_Type                M_comm;
//
//    matrixPtr_Type              M_projectionMassMatrix;
//    vectorPtr_Type              M_projectionRhs;
//    basePrecPtr_Type            M_precPtr;
//    linearSolver_Type           M_projectionSolver;
//
//    FESpacePtr_Type             M_solidActivationFESpacePtr;
//
//
//private:
Simone Rossi's avatar
Simone Rossi committed
573
574
575
576
577
    //    void initSolid();
    //    void initMonodomain();
    //    void initActivation();

};
Simone Rossi's avatar
Simone Rossi committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
//// ===================================================
////! Constructors
//// ===================================================
//template<typename Mesh, typename IonicModel>
//EMSolver<Mesh, IonicModel>::EMSolver() :
//    M_solutionMethod (SVI),
//    M_monodomainPtr(),
//    M_usingDifferentMeshes (false),
//    M_solidDataPtr(),
//    M_solidPtr(),
//    M_solidBCPtr(),
//    M_activationPtr(),
//    M_monodomainTimeStep (0.01),
//    M_solidTimeStep (1.0),
//    M_monodomainExporterPtr(),
//    M_solidExporterPtr(),
//    M_activationExporterPtr(),
//    M_monodomainDisplacementPtr(),
//    M_C2FPtr(),
//    M_activationSolidPtr(),
//    M_F2CPtr(),
//    M_fullSolidMesh(),
//    M_activationTimePtr(),
//    M_lvPressure (0.0),
//    M_rvPressure (0.0),
//    M_lvVolume (0.0),
//    M_rvVolume (0.0),
//    M_lvPVexporter(),
//    M_rvPVexporter(),
//    M_lvPV (false),
//    M_rvPV (false),
//    M_bcVectorPtrs(),
//    M_referencePositionPtr(),
//    M_lvPreloadPressure (0.0),
//    M_rvPreloadPressure (0.0),
//    M_lvPositionVectorPtr(),
//    M_rvPositionVectorPtr(),
//    M_oneWayCoupling (false),
//    M_comm(),
//    M_projectionMassMatrix(),
//    M_projectionRhs(),
//    M_precPtr(),
//    M_projectionSolver(),
//    M_solidActivationFESpacePtr()
//{}
//
//template<typename Mesh, typename IonicModel>
//EMSolver<Mesh, IonicModel>::EMSolver (   Teuchos::ParameterList& parameterList,
//                                         const std::string data_file_name, commPtr_Type comm )
//{
//    M_comm = comm;
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t EM SOLVER: 'YOU ROCK!!!!' ";
//        std::cout << "\n==========================================";
//    }
//
//
//    M_solidTimeStep = parameterList.get ("emdt", 1.0);
//    M_monodomainTimeStep = parameterList.get ("dt", 0.01);
//    M_lvPressure = parameterList.get ("lv_pressure", 0.0);
//    M_rvPressure  = parameterList.get ("rv_pressure", 0.0);
//    M_lvVolume  = 0.0;
//    M_rvVolume  = 0.0;
//    M_lvPV = parameterList.get ("lv_pv", false);
//    M_rvPV = parameterList.get ("rv_pv", false);
//    M_oneWayCoupling = parameterList.get ("one_way_coupling", false);
//    std::string solutionMethod = parameterList.get ( "solutionMethod", "SVI" );
//    setSolutionMethod (solutionMethod);
//    GetPot dataFile (data_file_name);
//    //Initializing monodomain solver
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Monodomain Solver";
//        std::cout << "\n==========================================";
//    }
//
//    std::string meshName = parameterList.get ("mesh_name", "lid16.mesh");
//    std::string meshPath = parameterList.get ("mesh_path", "./");
//    ionicModelPtr_Type ionicPtr ( new IonicModel() );
//    M_monodomainPtr.reset ( new monodomainSolver_Type ( meshName, meshPath, dataFile, ionicPtr ) );
//    M_monodomainPtr -> setInitialConditions();
//    M_monodomainPtr-> setParameters ( parameterList );
//
//    M_usingDifferentMeshes = false;
//
//    //Initializing structural solver
//
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Solid Data and Solid mesh";
//        std::cout << "\n==========================================";
//    }
//
//    //Material data
//    M_solidDataPtr.reset ( new structureData_Type() );
//    M_solidDataPtr -> setup (dataFile);
//
//    //mesh
//    std::string solidMeshName = parameterList.get ("solid_mesh_name", "no_solid_mesh");
//    if (solidMeshName == "no_solid_mesh")
//    {
//        solidMeshName   = dataFile ( "solid/pace_discretization/mesh_file",   "no_solid_mesh" );
//    }
//
//    if (solidMeshName == "no_solid_mesh" || solidMeshName == meshName )
//    {
//        M_usingDifferentMeshes = false;
//    }
//    else
//    {
//        M_usingDifferentMeshes = true;
//    }
//
//    std::string solidMeshPath = parameterList.get ("solid_mesh_path", "");
//    if (solidMeshPath == "")
//    {
//        solidMeshPath   = dataFile ( "solid/pace_discretization/mesh_dir",  "" );
//    }
//
//
//    M_fullSolidMesh.reset (new mesh_Type ( comm ) );
//    meshPtr_Type localSolidMesh (new mesh_Type ( comm ) );
//    if ( M_usingDifferentMeshes  )
//    {
//        localSolidMesh.reset (new mesh_Type ( comm ) );
//        MeshUtility::loadMesh (localSolidMesh, M_fullSolidMesh,  solidMeshName,  solidMeshPath );
//    }
//    else
//    {
//        M_fullSolidMesh = M_monodomainPtr -> fullMeshPtr();
//        localSolidMesh = M_monodomainPtr -> localMeshPtr();
//    }
//
//    //FESPACEs
//    std::string dOrder =  dataFile ( "solid/space_discretization/order", "P1");
//    FESpacePtr_Type dFESpace ( new FESpace_Type ( localSolidMesh,
//                                                  dOrder,
//                                                  3,
//                                                  localSolidMesh -> comm() ) );
//
//    solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (localSolidMesh, &feTetraP1, comm) );
//
//    //boundary conditions
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Creating BC handler";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//    setupBC ( data_file_name, dFESpace -> map() );
//
//
//    //setup structural operator
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Structure Solver";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//    M_solidPtr.reset (new structuralOperator_Type() );
//    M_solidPtr -> setup (M_solidDataPtr,
//                         dFESpace,
//                         dETFESpace,
//                         M_solidBCPtr -> handler(),
//                         comm);
//    M_solidPtr -> setDataFromGetPot (dataFile);
//
//    //activation
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Activation Solver";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//    M_activationPtr.reset ( new activeStrain_Type (parameterList, dataFile, M_monodomainPtr -> localMeshPtr(), comm) );
//
//    M_activationTimePtr.reset (new vector_Type ( M_monodomainPtr -> feSpacePtr() -> map() ) );
//    *M_activationTimePtr = -1.0;
//
//
//
//}
//
//
//
//template<typename Mesh, typename IonicModel>
//EMSolver<Mesh, IonicModel>::EMSolver (   structuralOperatorPtr_Type solidPtr, Teuchos::ParameterList& parameterList,
//                                         const std::string data_file_name, commPtr_Type comm )
//{
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t EM SOLVER: 'YOU ROCK!!!!' ";
//        std::cout << "\n==========================================";
//    }
//
//    M_solidTimeStep = parameterList.get ("emdt", 1.0);
//    M_monodomainTimeStep = parameterList.get ("dt", 0.01);
//    M_lvPressure = parameterList.get ("lv_pressure", 0.0);
//    M_rvPressure  = parameterList.get ("rv_pressure", 0.0);
//    M_lvVolume  = 0.0;
//    M_rvVolume  = 0.0;
//    M_lvPV = parameterList.get ("lv_pv", false);
//    M_rvPV = parameterList.get ("rv_pv", false);
//    M_oneWayCoupling = parameterList.get ("one_way_coupling", false);
//
//    GetPot dataFile (data_file_name);
//    //Initializing monodomain solver
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Monodomain Solver";
//        std::cout << "\n==========================================";
//    }
//
//    std::string meshName = parameterList.get ("mesh_name", "lid16.mesh");
//    std::string meshPath = parameterList.get ("mesh_path", "./");
//    ionicModelPtr_Type ionicPtr ( new IonicModel() );
//    M_monodomainPtr.reset ( new monodomainSolver_Type ( meshName, meshPath, dataFile, ionicPtr ) );
//    M_monodomainPtr -> setInitialConditions();
//    M_monodomainPtr-> setParameters ( parameterList );
//
//    M_usingDifferentMeshes = false;
//
//    //Initializing structural solver
//
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Solid Data and Solid mesh";
//        std::cout << "\n==========================================";
//    }
//
//    //Material data
//    M_solidDataPtr = solidPtr -> data();
//
//
//    //mesh
//    std::string solidMeshName = parameterList.get ("solid_mesh_name", "no_solid_mesh");
//    if (solidMeshName == "no_solid_mesh")
//    {
//        solidMeshName   = dataFile ( "solid/space_discretization/mesh_file",   "no_solid_mesh" );
//    }
//
//    if (solidMeshName == "no_solid_mesh" || solidMeshName == meshName )
//    {
//        M_usingDifferentMeshes = false;
//    }
//    else
//    {
//        M_usingDifferentMeshes = true;
//    }
//
//    std::string solidMeshPath = parameterList.get ("solid_mesh_path", "");
//    if (solidMeshPath == "")
//    {
//        solidMeshPath   = dataFile ( "solid/space_discretization/mesh_dir",  "" );
//    }
//
//
//    M_fullSolidMesh.reset (new mesh_Type ( M_comm ) );
//    meshPtr_Type localSolidMesh (new mesh_Type ( M_comm ) );
//    if ( M_usingDifferentMeshes  )
//    {
//        localSolidMesh.reset (new mesh_Type ( M_comm ) );
//        MeshUtility::loadMesh (localSolidMesh, M_fullSolidMesh,  solidMeshName,  solidMeshPath );
//    }
//    else
//    {
//        M_fullSolidMesh = M_monodomainPtr -> fullMeshPtr();
//        localSolidMesh = M_monodomainPtr -> localMeshPtr();
//    }
//
//    //FESPACEs
//    //    std::string dOrder =  dataFile ( "solid/space_discretization/order", "P1");
//    //    FESpacePtr_Type dFESpace ( new FESpace_Type ( localSolidMesh,
//    //                                                 dOrder,
//    //                                                 3,
//    //                                                 localSolidMesh -> M_comm() ) );
//    //
//    //    solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (localSolidMesh, &feTetraP1, M_comm) );
//
//    //boundary conditions
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Creating BC handler";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//
//    M_solidBCPtr.reset ( new bcInterface_Type() );
//    M_solidBCPtr-> setHandler ( solidPtr -> bcHandler() );
//    M_solidBCPtr -> setPhysicalSolver (solidPtr);
//
//    //setup structural operator
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Structure Solver";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//    M_solidPtr = solidPtr;
//    //    M_solidPtr -> setup (M_solidDataPtr,
//    //                      dFESpace,
//    //                      dETFESpace,
//    //                      M_solidBCPtr -> handler(),
//    //                      M_comm);
//    //    M_solidPtr -> setDataFromGetPot (dataFile);
//
//    //activation
//    if (M_comm->MyPID() == 0)
//    {
//        std::cout << "\n==========================================";
//        std::cout << "\n\t Initializing Activation Solver";
//        std::cout << "\n==========================================";
//        std::cout << "\n";
//    }
//    M_activationPtr.reset ( new activeStrain_Type (parameterList, dataFile, M_monodomainPtr -> localMeshPtr(), M_comm) );
//
//
//    M_activationTimePtr.reset (new vector_Type ( M_monodomainPtr -> feSpacePtr() -> map() ) );
//    *M_activationTimePtr = -1.0;
//}
//
//
//template<typename Mesh, typename IonicModel>
//void EMSolver<Mesh, IonicModel>::setup (Teuchos::ParameterList& parameterList,
//                                        const std::string data_file_name,
//                                        std::string parameterListName )
//{
//    if (M_usingDifferentMeshes)
//    {
//        M_monodomainDisplacementPtr.reset ( new vector_Type ( M_monodomainPtr -> displacementETFESpacePtr() -> map() ) );
//        M_activationSolidPtr.reset ( new vector_Type ( M_solidPtr -> activeMaterial() -> activationSpace() -> map() ) );
//        GetPot dataFile (data_file_name);
//        setupInterpolants (parameterListName, parameterList, dataFile);
//    }
//    else
//    {
//        M_monodomainDisplacementPtr = M_solidPtr -> displacementPtr();
//        M_activationSolidPtr = M_activationPtr -> gammafPtr();
//    }
//
//    if (M_oneWayCoupling == false)
//    {
//        M_monodomainPtr -> setDisplacementPtr ( M_monodomainDisplacementPtr );
//    }
//    M_solidPtr -> activeMaterial() -> setGammaf (*M_activationSolidPtr);
//    setupMonodomainMatrix (parameterList);
//
//    createReferencePositionVector();
//
//}
//
//template<typename Mesh, typename IonicModel>
//void EMSolver<Mesh, IonicModel>::setupProjectionSolver (GetPot& dataFile, commPtr_Type comm)
//{
//    if (M_comm -> MyPID() == 0)
//    {
//        std::cout << "\nEM Solver: Setting L2 projection Linear Solver";
//    }
//    prec_Type* precRawPtr;
//    precRawPtr = new prec_Type;
//    precRawPtr->setDataFromGetPot (dataFile, "prec");
//    M_precPtr.reset (precRawPtr);
//
//    Teuchos::RCP < Teuchos::ParameterList > solverParamList = Teuchos::rcp (
//                                                                  new Teuchos::ParameterList);
//
//    std::string xmlpath = dataFile ("activation/activation_xml_path",
//                                    "./");
//    std::string xmlfile = dataFile ("activation/activation_xml_file",
//                                    "ParamList.xml");
//
//    solverParamList = Teuchos::getParametersFromXmlFile (xmlpath + xmlfile);
//    //linearSolver_Type linearSolver;
//    M_projectionSolver.setCommunicator ( comm );
//    M_projectionSolver.setParameters ( *solverParamList );
//    M_projectionSolver.setPreconditioner ( M_precPtr );
//    M_projectionSolver.setOperator ( M_projectionMassMatrix );
//}
//
//template<typename Mesh, typename IonicModel>
//void EMSolver<Mesh, IonicModel>::setupMonodomainMatrix (Teuchos::ParameterList& parameterList)
//{
//    M_monodomainPtr -> setupMassMatrix();
//    M_monodomainPtr -> setupStiffnessMatrix();
//    M_monodomainPtr -> setupGlobalMatrix();
//}
//
//
//template<typename Mesh, typename IonicModel>
//void EMSolver<Mesh, IonicModel>::updateMonodomainMatrix()
//{
//    if (M_oneWayCoupling == false)
//    {
//        M_monodomainPtr -> setDisplacementPtr ( M_monodomainDisplacementPtr );
//        M_monodomainPtr -> setupMassMatrix();
//        M_monodomainPtr -> setupStiffnessMatrix();
//        M_monodomainPtr -> setupGlobalMatrix();
//    }
//}
//
//template<typename Mesh, typename IonicModel>
//void EMSolver<Mesh, IonicModel>::updateMonodomain()
//{
//    if (M_usingDifferentMeshes)
//    {
//        M_C2FPtr -> updateRhs ( M_solidPtr -> displacementPtr() );
//        M_C2FPtr -> interpolate();
//        M_C2FPtr -> solution (  M_monodomainDisplacementPtr );
//    }
//    updateMonodomainMatrix();