HeartSolver.hpp 6.63 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
17


thomaskummer's avatar
thomaskummer committed
18
19
20
21
22

namespace LifeV
{

    
thomaskummer's avatar
thomaskummer committed
23
24
25
class HeartData
{
public:
thomaskummer's avatar
thomaskummer committed
26
    
thomaskummer's avatar
thomaskummer committed
27
28
    HeartData() {}
    
thomaskummer's avatar
thomaskummer committed
29
    virtual ~HeartData() {};
thomaskummer's avatar
thomaskummer committed
30
    
thomaskummer's avatar
thomaskummer committed
31
    const Real& dt_activation () const { return M_dt_activation; }
thomaskummer's avatar
thomaskummer committed
32
    const Real& dt_loadstep () const { return M_dt_loadstep; }
thomaskummer's avatar
thomaskummer committed
33
    const Real& activationLimit_loadstep () const { return M_activationLimit_loadstep; }
thomaskummer's avatar
thomaskummer committed
34
    
thomaskummer's avatar
thomaskummer committed
35
    
thomaskummer's avatar
thomaskummer committed
36
37
    const GetPot& datafile () { return M_datafile; }
    
thomaskummer's avatar
thomaskummer committed
38
protected:
thomaskummer's avatar
thomaskummer committed
39
40
41
    
    
    
thomaskummer's avatar
thomaskummer committed
42
    void setupData(const GetPot& datafile)
thomaskummer's avatar
thomaskummer committed
43
    {
thomaskummer's avatar
thomaskummer committed
44
45
        M_datafile = datafile;
        
thomaskummer's avatar
thomaskummer committed
46
        M_dt_activation = M_datafile ("activation/time_discretization/timestep", 0.05 );
thomaskummer's avatar
thomaskummer committed
47
48
        M_dt_loadstep =  M_datafile ( "solid/time_discretization/dt_loadstep", 1.0 );
        M_activationLimit_loadstep =  M_datafile ( "solid/time_discretization/activation_limit_loadstep", 0.0 );
thomaskummer's avatar
thomaskummer committed
49
        M_dt_mechanics = M_datafile ("solid/time_discretization/timestep", 1.0 );
thomaskummer's avatar
thomaskummer committed
50
        M_dt_save = M_datafile ( "exporter/save", 10. );
thomaskummer's avatar
thomaskummer committed
51
        M_endtime = M_datafile ("solid/time_discretization/endtime", 100000);
thomaskummer's avatar
thomaskummer committed
52
53
54
55
        M_mechanicsLoadstepIter = static_cast<UInt>( M_dt_loadstep / M_dt_activation );
        M_mechanicsCouplingIter = static_cast<UInt>( M_dt_mechanics / M_dt_activation );
        M_maxiter = static_cast<UInt>( M_endtime / M_dt_activation ) ;

thomaskummer's avatar
thomaskummer committed
56
57
58
59
60
61
        M_pPerturbationFe = M_datafile ( "solid/coupling/pPerturbationFe", 1e-2 );
        M_pPerturbationCirc = M_datafile ( "solid/coupling/pPerturbationCirc", 1e-3 );
        M_couplingError = M_datafile ( "solid/coupling/couplingError", 1e-6 );
        M_couplingJFeSubIter = M_datafile ( "solid/coupling/couplingJFeSubIter", 1 );
        M_couplingJFeSubStart = M_datafile ( "solid/coupling/couplingJFeSubStart", 1 );
        M_couplingJFeIter = M_datafile ( "solid/coupling/couplingJFeIter", 1 );
thomaskummer's avatar
thomaskummer committed
62
        
thomaskummer's avatar
thomaskummer committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    //        const Real dpMax = dataFile ( "solid/coupling/dpMax", 0.1 );
    //
    //        std::vector<std::vector<std::string> > bcNames { { "lv" , "p" } , { "rv" , "p" } };
    //        std::vector<double> bcValues { p ( "lv" ) , p ( "rv") };
    //        std::vector<double> bcValuesPre ( bcValues );
    //
    //        VectorSmall<4> ABdplv, ABdprv, ABcoef;
    //        ABcoef (0) = 55/24; ABcoef (1) = -59/24; ABcoef (2) = 37/24; ABcoef (3) = -3/8;
    //
    //        VectorSmall<2> VCirc, VCircNew, VCircPert, VFe, VFeNew, VFePert, R, dp;
    //        MatrixSmall<2,2> JFe, JCirc, JR;
    //        
    //        UInt iter (0);
    //        Real t (0);
    
thomaskummer's avatar
thomaskummer committed
78
79
80
        
    }
    
thomaskummer's avatar
thomaskummer committed
81
82
83
84
85
86
87
88
89
90
    Real M_dt_activation;
    Real M_dt_loadstep;
    Real M_activationLimit_loadstep;
    Real M_dt_mechanics;
    Real M_dt_save;
    Real M_endtime;
    UInt M_mechanicsLoadstepIter;
    UInt M_mechanicsCouplingIter;
    UInt M_maxiter;
    
thomaskummer's avatar
thomaskummer committed
91
92
93
94
95
96
    Real M_pPerturbationFe;
    Real M_pPerturbationCirc;
    Real M_couplingError;
    UInt M_couplingJFeSubIter;
    UInt M_couplingJFeSubStart;
    UInt M_couplingJFeIter;
thomaskummer's avatar
thomaskummer committed
97
    
thomaskummer's avatar
thomaskummer committed
98
    GetPot M_datafile;
thomaskummer's avatar
thomaskummer committed
99
    
thomaskummer's avatar
thomaskummer committed
100
};
thomaskummer's avatar
thomaskummer committed
101
    
thomaskummer's avatar
thomaskummer committed
102
    
thomaskummer's avatar
thomaskummer committed
103
104
105
106
template <class EmSolver>
class HeartSolver {
   
public:
thomaskummer's avatar
thomaskummer committed
107
    
thomaskummer's avatar
thomaskummer committed
108
109
    HeartSolver(EmSolver& emSolver,  Circulation& circulationSolver) :
        M_emSolver          (emSolver),
thomaskummer's avatar
thomaskummer committed
110
111
        M_circulationSolver (circulationSolver),
        M_heartData         (HeartData())
thomaskummer's avatar
thomaskummer committed
112
    {}
thomaskummer's avatar
thomaskummer committed
113
    
thomaskummer's avatar
thomaskummer committed
114
    virtual ~HeartSolver() {}
thomaskummer's avatar
thomaskummer committed
115
    
thomaskummer's avatar
thomaskummer committed
116
117
118
119
120
    const HeartData& data()
    {
        return M_heartData;
    }
    
thomaskummer's avatar
thomaskummer committed
121
    void preloadHeart(const VectorSmall<2>& endocardiaBC);
thomaskummer's avatar
thomaskummer committed
122

thomaskummer's avatar
thomaskummer committed
123
    void setupData(const GetPot& datafile)
thomaskummer's avatar
thomaskummer committed
124
    {
thomaskummer's avatar
thomaskummer committed
125
        M_heartData.setupData(datafile);
thomaskummer's avatar
thomaskummer committed
126
    }
thomaskummer's avatar
thomaskummer committed
127
    
thomaskummer's avatar
thomaskummer committed
128
129
130
131
132
    
    
    
    
    
thomaskummer's avatar
thomaskummer committed
133
protected:
thomaskummer's avatar
thomaskummer committed
134
    
thomaskummer's avatar
thomaskummer committed
135
    
thomaskummer's avatar
thomaskummer committed
136
    EmSolver M_emSolver;
thomaskummer's avatar
thomaskummer committed
137
    Circulation M_circulationSolver;
thomaskummer's avatar
thomaskummer committed
138
    
thomaskummer's avatar
thomaskummer committed
139
    HeartData M_heartData;
thomaskummer's avatar
thomaskummer committed
140
    
thomaskummer's avatar
thomaskummer committed
141
    
thomaskummer's avatar
thomaskummer committed
142
143
144
145
    VectorSmall<2> M_pressure;
    VectorSmall<2> M_volume;

    
thomaskummer's avatar
thomaskummer committed
146

thomaskummer's avatar
thomaskummer committed
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
    
    Real patchForce (const Real& t, const Real& Tmax, const Real& tmax, const Real& tduration) const
    {
        bool time ( fmod(t-tmax+0.5*tduration, 700.) < tduration && fmod(t-tmax+0.5*tduration, 700.) > 0);
        Real force = std::pow( std::sin(fmod(t-tmax+0.5*tduration, 700.)*3.14159265359/tduration) , 2 ) * Tmax;
        return ( time ? force : 0 );
    }
    
    Real patchFunction (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/) const
    {
        Real disp = std::pow( std::sin(fmod(t, 700.) * 3.14159265359/300) , 2 )*15;
        return disp;
    }
    
    Real Iapp (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/) const
    {
        bool coords ( Y < -7. );
        //bool coords ( Y > 4. ); //( Y > 1.5 && Y < 3 );
        bool time ( fmod(t, 700.) < 4 && fmod(t, 700.) > 2);
        return ( coords && time ? 30 : 0 );
    }
    
    Real potentialMultiplyerFcn (const Real& t, const Real&  X, const Real& Y, const Real& Z, const ID& /*i*/) const
    {
        bool time ( fmod(t, 700.) < 4 && fmod(t, 700.) > 2);
        return 1.4 * time; // ( Y < 2.5 && Y > 0.5 ? 1.0 : 0.0 );
    }
    
thomaskummer's avatar
thomaskummer committed
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
    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,
                       p * J * dot( FmT * Nface,  phi_i)
                       //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
218
219
220
221
};

}

thomaskummer's avatar
thomaskummer committed
222
#endif