HeartSolver.hpp 19 KB
Newer Older
thomaskummer's avatar
thomaskummer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
//
//  HeartSolver.cpp
//  LifeV
//
//  Created by Thomas Kummer on 03.05.16.
//  Copyright © 2016 Thomas Kummer. All rights reserved.
//

#ifndef _HEARTDATA_H_
#define _HEARTDATA_H_


#include <stdio.h>
thomaskummer's avatar
thomaskummer committed
14
#include <lifev/em/solver/EMSolver.hpp>
thomaskummer's avatar
thomaskummer committed
15
#include <lifev/em/solver/circulation/Circulation.hpp>
thomaskummer's avatar
thomaskummer committed
16

thomaskummer's avatar
thomaskummer committed
17
#include <lifev/em/solver/HeartData.hpp>
thomaskummer's avatar
thomaskummer committed
18

thomaskummer's avatar
thomaskummer committed
19
20
21
22

namespace LifeV
{

thomaskummer's avatar
thomaskummer committed
23
#define PI 3.14159265359
thomaskummer's avatar
thomaskummer committed
24

thomaskummer's avatar
thomaskummer committed
25
    
thomaskummer's avatar
thomaskummer committed
26
27
28
29
template <class EmSolver>
class HeartSolver {
   
public:
thomaskummer's avatar
thomaskummer committed
30
    
thomaskummer's avatar
thomaskummer committed
31
    typedef RegionMesh<LinearTetra>                         mesh_Type;
thomaskummer's avatar
thomaskummer committed
32
    typedef boost::shared_ptr<mesh_Type>                    meshPtr_Typ;
thomaskummer's avatar
thomaskummer committed
33
34
35
36
    typedef ExporterHDF5<mesh_Type>                         exporter_Type;
    typedef boost::shared_ptr<exporter_Type>                exporterPtr_Type;
    
    
thomaskummer's avatar
thomaskummer committed
37
38
    HeartSolver(EmSolver& emSolver,  Circulation& circulationSolver) :
        M_emSolver          (emSolver),
thomaskummer's avatar
thomaskummer committed
39
40
        M_circulationSolver (circulationSolver),
        M_heartData         (HeartData())
thomaskummer's avatar
thomaskummer committed
41
    {}
thomaskummer's avatar
thomaskummer committed
42
    
thomaskummer's avatar
thomaskummer committed
43
    virtual ~HeartSolver() {}
thomaskummer's avatar
thomaskummer committed
44
45
46
47
48
49
50
51
52
53

    EmSolver& emSolver()
    {
        return M_emSolver;
    }
    
    Circulation& circulation()
    {
        return M_heartData;
    }
thomaskummer's avatar
thomaskummer committed
54
    
thomaskummer's avatar
thomaskummer committed
55
    const HeartData& data() const
thomaskummer's avatar
thomaskummer committed
56
57
58
59
    {
        return M_heartData;
    }
    
thomaskummer's avatar
thomaskummer committed
60
    void setup(const GetPot& datafile)
thomaskummer's avatar
thomaskummer committed
61
    {
thomaskummer's avatar
thomaskummer committed
62
        M_heartData.setup(datafile);
thomaskummer's avatar
thomaskummer committed
63
    }
thomaskummer's avatar
thomaskummer committed
64
    
thomaskummer's avatar
thomaskummer committed
65
    template <class lambda>
thomaskummer's avatar
thomaskummer committed
66
    void preload(const lambda& modifyFeBC, const std::vector<Real>& bcValues)
thomaskummer's avatar
thomaskummer committed
67
    {
thomaskummer's avatar
thomaskummer committed
68
        M_emSolver.structuralOperatorPtr() -> data() -> dataTime() -> setTime(0.0);
thomaskummer's avatar
thomaskummer committed
69
70
71
72
73
74
75
76
77
78
        
        auto preloadPressure = [] (std::vector<double> p, const int& step, const int& steps)
        {
            for (auto& i : p) {i *= double(step) / double(steps);}
            return p;
        };
        
        LifeChrono chronoSave;
        chronoSave.start();
        
thomaskummer's avatar
thomaskummer committed
79
        M_emSolver.saveSolution (-1.0);
thomaskummer's avatar
thomaskummer committed
80
        
thomaskummer's avatar
thomaskummer committed
81
        if ( 0 == M_emSolver.comm()->MyPID() )
thomaskummer's avatar
thomaskummer committed
82
83
84
85
86
87
88
89
90
91
92
        {
            std::cout << "\n*****************************************************************";
            std::cout << "\nData stored in " << chronoSave.diff() << " s";
            std::cout << "\n*****************************************************************\n";
        }
        
        LifeChrono chronoPreload;
        chronoPreload.start();
        
        for (int i (1); i <= data().preloadSteps(); i++)
        {
thomaskummer's avatar
thomaskummer committed
93
            if ( 0 == M_emSolver.comm()->MyPID() )
thomaskummer's avatar
thomaskummer committed
94
95
96
97
98
99
100
            {
                std::cout << "\n*****************************************************************";
                std::cout << "\nPreload step: " << i << " / " << data().preloadSteps();
                std::cout << "\n*****************************************************************\n";
            }
            
            // Update pressure b.c.
thomaskummer's avatar
thomaskummer committed
101
            modifyFeBC(preloadPressure(bcValues, i, data().preloadSteps() ));
thomaskummer's avatar
thomaskummer committed
102
103
            
            // Solve mechanics
thomaskummer's avatar
thomaskummer committed
104
105
            M_emSolver.bcInterfacePtr() -> updatePhysicalSolverVariables();
            M_emSolver.solveMechanics();
thomaskummer's avatar
thomaskummer committed
106
107
            
            // Safe preload steps
thomaskummer's avatar
thomaskummer committed
108
            if ( data().safePreload() ) M_emSolver.saveSolution (i-1);
thomaskummer's avatar
thomaskummer committed
109
110
        }
        
thomaskummer's avatar
thomaskummer committed
111
        if ( 0 == M_emSolver.comm()->MyPID() )
thomaskummer's avatar
thomaskummer committed
112
113
114
115
116
117
118
        {
            std::cout << "\n*****************************************************************";
            std::cout << "\nPreload done in: " << chronoPreload.diff();
            std::cout << "\n*****************************************************************\n";
        }

    }
thomaskummer's avatar
thomaskummer committed
119
120
    
    
thomaskummer's avatar
thomaskummer committed
121
    void restart(std::string& restartInput, const GetPot& command_line, Real& t)
thomaskummer's avatar
thomaskummer committed
122
    {
thomaskummer's avatar
thomaskummer committed
123
        const std::string restartDir = ""; //command_line.follow (problemFolder.c_str(), 2, "-rd", "--restartDir");
thomaskummer's avatar
thomaskummer committed
124
125
126
127
128
129
130
131
132
133
134
        
        Real dtExport = 10.;
        
        // Set time variable
        const unsigned int restartInputStr = std::stoi(restartInput);
        const unsigned int nIter = (restartInputStr - 1) * dtExport / data().dt_mechanics();
        t = nIter * data().dt_mechanics();
        
        // Set time exporter time index
        M_emSolver.setTimeIndex(restartInputStr + 1);
        //solver.importHdf5();
thomaskummer's avatar
thomaskummer committed
135

thomaskummer's avatar
thomaskummer committed
136
        // Load restart solutions from output files
thomaskummer's avatar
thomaskummer committed
137
        std::string polynomialDegree = data().elementOrder();
thomaskummer's avatar
thomaskummer committed
138

thomaskummer's avatar
thomaskummer committed
139
        ElectrophysiologyUtility::importVectorField ( M_emSolver.structuralOperatorPtr() -> displacementPtr(), "MechanicalSolution" , "displacement", M_emSolver.localMeshPtr(), restartDir, polynomialDegree, restartInput );
thomaskummer's avatar
thomaskummer committed
140
141
142
        ElectrophysiologyUtility::importScalarField (M_emSolver.activationModelPtr() -> fiberActivationPtr(), "ActivationSolution" , "Activation", M_emSolver.localMeshPtr(), restartDir, polynomialDegree, restartInput );
        //ElectrophysiologyUtility::importScalarField (solver.activationTimePtr(), "ActivationTimeSolution" , "Activation Time", solver.localMeshPtr(), restartDir, polynomialDegree, restartInput );
        
thomaskummer's avatar
thomaskummer committed
143
144
145
146
        for ( unsigned int i = 0; i < M_emSolver.electroSolverPtr()->globalSolution().size() ; ++i )
        {
            ElectrophysiologyUtility::importScalarField (M_emSolver.electroSolverPtr()->globalSolution().at(i), "ElectroSolution" , ("Variable" + std::to_string(i)), M_emSolver.localMeshPtr(), restartDir, polynomialDegree, restartInput );
        }
thomaskummer's avatar
thomaskummer committed
147

thomaskummer's avatar
thomaskummer committed
148
149
150
151
        if ( 0 == M_emSolver.comm()->MyPID() )
        {
            std::cout << "\nLoad from restart: " << restartInput << ",  nIterCirculation = " << nIter << ",  time = " << t << std::endl;
        }
thomaskummer's avatar
thomaskummer committed
152
        
thomaskummer's avatar
thomaskummer committed
153
        M_circulationSolver.restartFromFile ( restartDir + "solution.dat" , nIter );
thomaskummer's avatar
thomaskummer committed
154
155
    }
    
thomaskummer's avatar
thomaskummer committed
156
    
thomaskummer's avatar
thomaskummer committed
157
    static Real Iapp (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/)
thomaskummer's avatar
thomaskummer committed
158
159
160
161
162
163
164
    {
        bool coords ( Y < -7. );
        //bool coords ( Y > 4. ); //( Y > 1.5 && Y < 3 );
        bool time ( fmod(t, 800.) < 4 && fmod(t, 800.) > 2);
        return ( coords && time ? 30 : 0 );
    }
    
thomaskummer's avatar
thomaskummer committed
165
    Real sinSquared (const Real& time, const Real& Tmax, const Real& tmax, const Real& tduration) const
thomaskummer's avatar
thomaskummer committed
166
    {
thomaskummer's avatar
thomaskummer committed
167
        Real timeInPeriod = fmod(time-tmax+0.5*tduration, 800.);
thomaskummer's avatar
thomaskummer committed
168
        bool inPeriod ( timeInPeriod < tduration && timeInPeriod > 0);
thomaskummer's avatar
thomaskummer committed
169
        Real sinusSquared = std::pow( std::sin(timeInPeriod * PI / tduration) , 2 ) * Tmax;
thomaskummer's avatar
thomaskummer committed
170
        return ( inPeriod ? sinusSquared : 0 );
thomaskummer's avatar
thomaskummer committed
171
172
    }
    
thomaskummer's avatar
thomaskummer committed
173
    
thomaskummer's avatar
thomaskummer committed
174
    template<class bcVectorType>
thomaskummer's avatar
thomaskummer committed
175
    void extrapolate4thOrderAdamBashforth(bcVectorType& bcValues, bcVectorType& bcValuesPre, const Real& dpMax)
thomaskummer's avatar
thomaskummer committed
176
177
178
179
180
181
    {
        VectorSmall<4> ABcoef;
        ABcoef (0) = 55/24; ABcoef (1) = -59/24; ABcoef (2) = 37/24; ABcoef (3) = -3/8;
        
        for ( unsigned int i = ABcoef.size() - 1; i > 0; --i )
        {
thomaskummer's avatar
thomaskummer committed
182
183
            m_ABdplv(i) = m_ABdplv(i-1);
            m_ABdprv(i) = m_ABdprv(i-1);
thomaskummer's avatar
thomaskummer committed
184
185
        }
        
thomaskummer's avatar
thomaskummer committed
186
187
        m_ABdplv(0) = bcValues[0] - bcValuesPre[0];
        m_ABdprv(0) = bcValues[1] - bcValuesPre[1];
thomaskummer's avatar
thomaskummer committed
188
189
190
        
        bcValuesPre = bcValues;
        
thomaskummer's avatar
thomaskummer committed
191
192
        bcValues[0] += std::min( std::max( ABcoef.dot( m_ABdplv ) , - dpMax ) , dpMax );
        bcValues[1] += std::min( std::max( ABcoef.dot( m_ABdprv ) , - dpMax ) , dpMax );
thomaskummer's avatar
thomaskummer committed
193
    }
thomaskummer's avatar
thomaskummer committed
194
    
thomaskummer's avatar
thomaskummer committed
195
    
thomaskummer's avatar
thomaskummer committed
196
    void setupExporter(std::string problemFolder = "./", std::string outputFileName = "humanHeartSolution")
thomaskummer's avatar
thomaskummer committed
197
198
    {
        m_exporter.reset (new exporter_Type());
thomaskummer's avatar
thomaskummer committed
199
        setupExporter<mesh_Type>(*m_exporter, M_emSolver.localMeshPtr(), M_emSolver.comm(), outputFileName, problemFolder);
thomaskummer's avatar
thomaskummer committed
200

thomaskummer's avatar
thomaskummer committed
201
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
202
                                     "Displacement",
thomaskummer's avatar
thomaskummer committed
203
204
205
206
207
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
                                     M_emSolver.structuralOperatorPtr()->displacementPtr(),
                                     UInt (0) );
        
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::ScalarField,
thomaskummer's avatar
thomaskummer committed
208
                                     "Von Mises stress",
thomaskummer's avatar
thomaskummer committed
209
210
211
212
                                     M_emSolver.electroSolverPtr()->feSpacePtr(),
                                     M_emSolver.tensionEstimator().vonMisesStressPtr(),
                                     UInt (0) );
        
thomaskummer's avatar
thomaskummer committed
213
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
214
                                     "Principal stress",
thomaskummer's avatar
thomaskummer committed
215
216
217
218
219
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
                                     M_emSolver.tensionEstimator().principalStressesPtr(),
                                     UInt (0) );
        
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
220
                                     "X stress",
thomaskummer's avatar
thomaskummer committed
221
222
223
224
225
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
                                     M_emSolver.tensionEstimator().sigmaXPtr(),
                                     UInt (0) );
    
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
226
                                     "Y stress",
thomaskummer's avatar
thomaskummer committed
227
228
229
230
231
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
                                     M_emSolver.tensionEstimator().sigmaYPtr(),
                                     UInt (0) );
    
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
232
                                     "Z stress",
thomaskummer's avatar
thomaskummer committed
233
234
235
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
                                     M_emSolver.tensionEstimator().sigmaZPtr(),
                                     UInt (0) );
thomaskummer's avatar
thomaskummer committed
236
        
thomaskummer's avatar
thomaskummer committed
237
238
239
240
241
242
243
244
245
246
247
//        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
//                                     "Patch displacement",
//                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
//                                     this->patchDispSumPtr(),
//                                     UInt (0) );
//
//        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::ScalarField,
//                                     "Patch location",
//                                     M_emSolver.electroSolverPtr()->feSpacePtr(),
//                                     this->patchLocSumPtr(),
//                                     UInt (0) );
thomaskummer's avatar
thomaskummer committed
248
        
thomaskummer's avatar
thomaskummer committed
249
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
250
                                     "Fibers",
thomaskummer's avatar
thomaskummer committed
251
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
thomaskummer's avatar
thomaskummer committed
252
253
                                     M_emSolver.structuralOperatorPtr()->fPtr(),
                                     // M_emSolver.structuralOperatorPtr()->EMMaterial()->fiberVectorPtr(),
thomaskummer's avatar
thomaskummer committed
254
255
256
                                     UInt (0) );
        
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::VectorField,
thomaskummer's avatar
thomaskummer committed
257
                                     "Sheets",
thomaskummer's avatar
thomaskummer committed
258
                                     M_emSolver.structuralOperatorPtr()->dispFESpacePtr(),
thomaskummer's avatar
thomaskummer committed
259
260
                                     M_emSolver.structuralOperatorPtr()->sPtr(),
                                     //M_emSolver.structuralOperatorPtr()->EMMaterial()->sheetVectorPtr(),
thomaskummer's avatar
thomaskummer committed
261
262
263
264
265
266
267
                                     UInt (0) );
        
        m_exporter->addVariable (    ExporterData<RegionMesh<LinearTetra> >::ScalarField,
                                     "Activation",
                                     M_emSolver.electroSolverPtr()->feSpacePtr(),
                                     M_emSolver.activationModelPtr()->fiberActivationPtr(),
                                     UInt (0) );
thomaskummer's avatar
thomaskummer committed
268
            
thomaskummer's avatar
thomaskummer committed
269
270
271
272
273
        m_exporter -> addVariable (  ExporterData<RegionMesh<LinearTetra> >::ScalarField,
                                     "Activation time",
                                     M_emSolver.electroSolverPtr() -> feSpacePtr(),
                                     M_emSolver.activationTimePtr(),
                                     UInt (0) );
thomaskummer's avatar
thomaskummer committed
274
        
thomaskummer's avatar
thomaskummer committed
275
        for (int i = 0; i < M_emSolver.electroSolverPtr()->ionicModelPtr()->Size(); ++i)
thomaskummer's avatar
thomaskummer committed
276
277
        {
            std::string variableName = "Ionic Variable " + boost::lexical_cast<std::string> (i);
thomaskummer's avatar
thomaskummer committed
278
            m_exporter->addVariable (ExporterData<mesh_Type>::ScalarField,
thomaskummer's avatar
thomaskummer committed
279
280
281
282
283
284
285
                                     variableName,
                                     M_emSolver.electroSolverPtr()->feSpacePtr(),
                                     M_emSolver.electroSolverPtr()->globalSolution().at(i),
                                     UInt (0) );
        }

        
thomaskummer's avatar
thomaskummer committed
286
287
288
    }

    
thomaskummer's avatar
thomaskummer committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
    template<class Mesh>
    void setupExporter (ExporterHDF5<Mesh>& exporter,
                        boost::shared_ptr<Mesh> localMeshPtr,
                        boost::shared_ptr<Epetra_Comm> commPtr,
                        std::string fileName,
                        std::string folder)
    {
        exporter.setMeshProcId (localMeshPtr, commPtr->MyPID() );
        exporter.setPrefix (fileName);
        exporter.exportPID (localMeshPtr, commPtr);
        exporter.setPostDir (folder);
    }
    
    
thomaskummer's avatar
thomaskummer committed
303
    void postProcess(const Real& time)
thomaskummer's avatar
thomaskummer committed
304
    {        
thomaskummer's avatar
thomaskummer committed
305
        // Compute Von Mises stress, principal stresses and Cauchy stresses
thomaskummer's avatar
thomaskummer committed
306
        M_emSolver.tensionEstimator().setDisplacement ( M_emSolver.structuralOperatorPtr()->displacement() );
thomaskummer's avatar
thomaskummer committed
307
        M_emSolver.tensionEstimator().analyzeTensionsRecoveryCauchyStresses();
thomaskummer's avatar
thomaskummer committed
308
        M_emSolver.tensionEstimator().analyzeTensionsRecoveryVonMisesStress();
thomaskummer's avatar
thomaskummer committed
309
        //M_emSolver.tensionEstimator().analyzeTensionsRecoveryEigenvalues();
thomaskummer's avatar
thomaskummer committed
310

thomaskummer's avatar
thomaskummer committed
311
        // Compute deformed fiber direction
thomaskummer's avatar
thomaskummer committed
312
        M_emSolver.computeDeformedFiberDirection (M_emSolver.structuralOperatorPtr()->f(), *M_emSolver.structuralOperatorPtr()->EMMaterial()->fiberVectorPtr(), *M_emSolver.structuralOperatorPtr()->displacementPtr(), M_emSolver.structuralOperatorPtr()->dispFESpacePtr());
thomaskummer's avatar
thomaskummer committed
313

thomaskummer's avatar
thomaskummer committed
314
315
        // Compute deformed sheet direction
        M_emSolver.computeDeformedFiberDirection (M_emSolver.structuralOperatorPtr()->s(), *M_emSolver.structuralOperatorPtr()->EMMaterial()->sheetVectorPtr(), *M_emSolver.structuralOperatorPtr()->displacementPtr(), M_emSolver.structuralOperatorPtr()->dispFESpacePtr());
thomaskummer's avatar
thomaskummer committed
316
                
thomaskummer's avatar
thomaskummer committed
317
        // Write on hdf5 output file
thomaskummer's avatar
thomaskummer committed
318
319
        m_exporter->postProcess(time);
    }
thomaskummer's avatar
thomaskummer committed
320
321
    
    
thomaskummer's avatar
thomaskummer committed
322
    exporterPtr_Type exporter()
thomaskummer's avatar
thomaskummer committed
323
324
325
326
    {
        return m_exporter;
    }
    
thomaskummer's avatar
thomaskummer committed
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
    Real
    externalPower ( const VectorEpetra& dispCurrent,
                   const VectorEpetra& dispPrevious,
                   const boost::shared_ptr<ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > > dispETFESpace,
                   Real pressure,
                   Real dt,
                   const unsigned int bdFlag) const
    {
        VectorEpetra traction ( dispCurrent.map() );
        VectorEpetra velocity ( (dispCurrent - dispPrevious) / dt );
        
        MatrixSmall<3,3> Id;
        Id(0,0) = 1.; Id(0,1) = 0., Id(0,2) = 0.;
        Id(1,0) = 0.; Id(1,1) = 1., Id(1,2) = 0.;
        Id(2,0) = 0.; Id(2,1) = 0., Id(2,2) = 1.;
        
        {
            using namespace ExpressionAssembly;
            
            auto I = value(Id);
            auto Grad_u = grad( dispETFESpace, dispCurrent, 0);
            auto F =  Grad_u + I;
            auto FmT = minusT(F);
            auto J = det(F);
            auto p = value(pressure);
            
            QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria7pt) );
            
            integrate ( boundary ( dispETFESpace->mesh(), bdFlag),
                       myBDQR,
                       dispETFESpace,
thomaskummer's avatar
thomaskummer committed
358
                       value(-1.0) * p * J * dot( FmT * Nface,  phi_i)
thomaskummer's avatar
thomaskummer committed
359
360
361
362
363
364
365
366
367
                       //p * J * dot( FmT * Nface,  phi_i)
                       //value(-1.0) * J * dot (vE1, FmT * Nface) * phi_i) >> intergral
                       ) >> traction;
            
            traction.globalAssemble();
        }
        
        return traction.dot(velocity);
    }
thomaskummer's avatar
thomaskummer committed
368
    
thomaskummer's avatar
thomaskummer committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
//    void setPatchDisplacementSumPtr(vectorPtr_Type patchDisplacementSumPtr)
//    {
//        m_patchDisplacementSumPtr = patchDisplacementSumPtr;
//    }
//    
//    vectorPtr_Type patchDispSumPtr()
//    {
//        return m_patchDisplacementSumPtr;
//    }
//
//    void setPatchLocationSumPtr(vectorPtr_Type patchLocationSumPtr)
//    {
//        m_patchLocationSumPtr = patchLocationSumPtr;
//    }
//
//    vectorPtr_Type patchLocSumPtr()
//    {
//        return m_patchLocationSumPtr;
//    }
thomaskummer's avatar
thomaskummer committed
388
    
thomaskummer's avatar
thomaskummer committed
389
    
thomaskummer's avatar
thomaskummer committed
390
protected:
thomaskummer's avatar
thomaskummer committed
391
    
thomaskummer's avatar
thomaskummer committed
392
393
    EmSolver& M_emSolver;
    Circulation& M_circulationSolver;
thomaskummer's avatar
thomaskummer committed
394
    
thomaskummer's avatar
thomaskummer committed
395
    HeartData M_heartData;
thomaskummer's avatar
thomaskummer committed
396
    
thomaskummer's avatar
thomaskummer committed
397
    exporterPtr_Type m_exporter;
thomaskummer's avatar
thomaskummer committed
398
    
thomaskummer's avatar
thomaskummer committed
399
400
401
    VectorSmall<2> M_pressure;
    VectorSmall<2> M_volume;

thomaskummer's avatar
thomaskummer committed
402
    VectorSmall<4> m_ABdplv, m_ABdprv;
thomaskummer's avatar
thomaskummer committed
403

thomaskummer's avatar
thomaskummer committed
404
    boost::shared_ptr<VectorEpetra> m_patchDisplacementSumPtr;
thomaskummer's avatar
thomaskummer committed
405
    boost::shared_ptr<VectorEpetra> m_patchLocationSumPtr;
thomaskummer's avatar
thomaskummer committed
406
    
thomaskummer's avatar
thomaskummer committed
407
408
409
    
    
    
thomaskummer's avatar
thomaskummer committed
410
411
412
413
414
415
416
417
418
419
420
    std::string pipeToString ( const char* command )
    {
        FILE* file = popen( command, "r" ) ;
        std::ostringstream stm ;
        char line[6] ;
        fgets( line, 6, file );
        stm << line;
        pclose(file) ;
        return stm.str() ;
    };
    
thomaskummer's avatar
thomaskummer committed
421
422
423


    Real patchDispFunNormal (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& i)
thomaskummer's avatar
thomaskummer committed
424
    {
thomaskummer's avatar
thomaskummer committed
425
        return (-0.000 - 0.00005*t);// sinSquared(t, 0.1, 50, 100)); // -0.001;// (t * 1e-5);
thomaskummer's avatar
thomaskummer committed
426
427
    }
    
thomaskummer's avatar
thomaskummer committed
428
    Real patchFunction (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/)
thomaskummer's avatar
thomaskummer committed
429
    {
thomaskummer's avatar
thomaskummer committed
430
        Real disp = std::pow( std::sin(fmod(t, 800.) * 3.14159265359/300) , 2 )*15;
thomaskummer's avatar
thomaskummer committed
431
432
433
        return disp;
    }
    
thomaskummer's avatar
thomaskummer committed
434
    Real potentialMultiplyerFcn (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/)
thomaskummer's avatar
thomaskummer committed
435
    {
thomaskummer's avatar
thomaskummer committed
436
437
        bool time ( fmod(t, 800.) < 4 && fmod(t, 800.) > 2);
        return 1.4 * time; // ( Y < 2.5 && Y > 0.5 ? 1.0 : 0.0 );
thomaskummer's avatar
thomaskummer committed
438
439
    }
    
thomaskummer's avatar
thomaskummer committed
440
    Real patchDispFun1 (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& i)
thomaskummer's avatar
thomaskummer committed
441
    {
thomaskummer's avatar
thomaskummer committed
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
        switch (i)
        {
            case 0:
                return (t);
                break;
            case 1:
                return 0;
                break;
            case 2:
                return (t);
                break;
            default:
                ERROR_MSG ("This entry is not allowed");
                return 0.;
                break;
        }
    }
    
    Real patchDispFun2 (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& i)
    {
        switch (i)
        {
            case 0:
                return (-t);
                break;
            case 1:
                return 0;
                break;
            case 2:
                return (-t);
                break;
            default:
                ERROR_MSG ("This entry is not allowed");
                return 0.;
                break;
        }
    }
    
    Real normalDirection ( const Real& /*t*/, const Real& x , const Real& y, const Real& z, const ID& i)
    {
        Real nnorm = std::sqrt(x * x + y * y + z * z);
        switch (i)
        {
            case 0:
                return 1/std::sqrt(2);
                break;
            case 1:
                return 0;
                break;
            case 2:
                return 1/std::sqrt(2);
                break;
            default:
                ERROR_MSG ("This entry is not allowed");
                return 0.;
                break;
        }
thomaskummer's avatar
thomaskummer committed
499
    }
thomaskummer's avatar
thomaskummer committed
500
501

    
thomaskummer's avatar
thomaskummer committed
502
503
504
505
};

}

thomaskummer's avatar
thomaskummer committed
506
#endif