main.cpp 22.5 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
#include <lifev/core/LifeV.hpp>
#include <lifev/electrophysiology/solver/ElectroETAMonodomainSolver.hpp>
#include <lifev/electrophysiology/solver/IonicModels/IonicMinimalModel.hpp>

#include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>

#include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
#include <lifev/structure/solver/StructuralOperator.hpp>
#include <lifev/em/solver/EMStructuralOperator.hpp>

#include <lifev/em/solver/EMNeoHookeanActivatedMaterial.hpp>

#include <lifev/core/filter/ExporterEnsight.hpp>
#ifdef HAVE_HDF5
#include <lifev/core/filter/ExporterHDF5.hpp>
#endif
#include <lifev/core/filter/ExporterEmpty.hpp>

#include <lifev/eta/fem/ETFESpace.hpp>
#include <lifev/eta/expression/Integrate.hpp>

#include <lifev/core/interpolation/RBFhtp.hpp>
#include <lifev/core/interpolation/RBFhtpVectorial.hpp>
#include <lifev/core/mesh/MeshLoadingUtility.hpp>
#include <lifev/core/mesh/MeshTransformer.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 <sys/stat.h>
#include <fstream>

#include <lifev/em/solver/EMSolver.hpp>
#include <lifev/em/solver/EMActiveStrainSolver.hpp>

using namespace LifeV;


void positionVector (const RegionMesh<LinearTetra>& mesh,  VectorEpetra& disp)
{

    //  std:: cout << "\n  mesh list point size : " <<       mesh.storedPoints()  << ",\t local mesh list point size " << localmesh.storedPoints();
    UInt nLocalDof = disp.epetraVector().MyLength();
    UInt nComponentLocalDof = nLocalDof / 3;

    for (UInt k (0); k < nComponentLocalDof; k++)
    {
        //          std::cout << "\n---------";

        UInt iGID = disp.blockMap().GID (k);
        UInt jGID = disp.blockMap().GID (k + nComponentLocalDof);
        UInt kGID = disp.blockMap().GID (k + 2 * nComponentLocalDof);

        //      UInt iLID = disp.blockMap().LID(k);
        //      UInt jLID = disp.blockMap().LID(k + nComponentLocalDof);
        //      UInt kLID = disp.blockMap().LID(k + 2 * nComponentLocalDof);


        //      disp[iGID] = mesh.point(iGID).x();
        //      std:: cout << "\n  i: " <<  k << ",\t j " << k+nComponentLocalDof << ",\t k " << k+nComponentLocalDof*2;
        //      std:: cout << "\n  x: " << mesh.point(k).x() << ",\t y " <<mesh.point(k+nComponentLocalDof).y()  << ",\t z " << mesh.point(k+nComponentLocalDof*2).z();
        //
        //
        //      std:: cout << "\n  i: " <<  iGID << ",\t j " << jGID << ",\t k " << kGID;
        //      std:: cout << "\n  x: " << mesh.point(iGID).x() << ",\t y " <<mesh.point(iGID).y()  << ",\t z " << mesh.point(iGID).z();
        //      std:: cout << "\n  x: " << localmesh.point(iGID).x() << ",\t y " << localmesh.point(iGID).y()  << ",\t z " << localmesh.point(iGID).z();

        disp[iGID] = mesh.point (iGID).x();
        disp[jGID] = mesh.point (iGID).y();
        disp[kGID] = mesh.point (iGID).z();



    }
    //  disp.setMapType(Repeated);
    //    for ( UInt i = 0; i < mesh.pointList.size(); ++i )
    //    {
    //      std:: cout << "\n--------------";
    //      UInt iGID = disp.blockMap().GID(i);
    //      UInt jGID = disp.blockMap().GID(i + nComponentLocalDof);
    //      UInt kGID = disp.blockMap().GID(i + 2 * nComponentLocalDof);
    ////        for ( UInt j = 0; j < nDimensions; ++j )
    ////        {
    //            int globalId = mesh.pointList[i].id();
    //
    //            std:: cout << "\n i " << i << ", GID " << globalId << ", GID from vector: " << disp.blockMap().GID(i);
    ////            ASSERT ( disp.isGlobalIDPresent ( globalId + dim * j ), "global ID missing" );
    //            std:: cout  << " x : " << disp[ iGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 0 );
    //            std:: cout  << " y : " << disp[ jGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 1 );
    //            std:: cout  << " z : " << disp[ kGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 2 );
    //            disp[ iGID ] = mesh.pointList[ iGID ].coordinate ( 0 );
    //            disp[ jGID ] = mesh.pointList[ iGID ].coordinate ( 1 );
    //            disp[ kGID ] = mesh.pointList[ iGID ].coordinate ( 2 );
    //            std:: cout  << " x : " << disp[ iGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 0 );
    //            std:: cout  << " y : " << disp[ jGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 1 );
    //            std:: cout  << " z : " << disp[ kGID ] << ", " << mesh.pointList[ iGID ].coordinate ( 2 );
    ////        }
    //    }
    //  disp.setMapType(Unique);


}

void changeMesh (const RegionMesh<LinearTetra>& /*mesh*/,  VectorEpetra& positionVector)
{
    Int nLocalDof = positionVector.epetraVector().MyLength();
    Int nComponentLocalDof = nLocalDof / 3;

    for (UInt k (0); k < nComponentLocalDof; k++)
    {
        //UInt iGID = positionVector.blockMap().GID (k);
        //UInt jGID = positionVector.blockMap().GID (k + nComponentLocalDof);
        //UInt kGID = positionVector.blockMap().GID (k + 2 * nComponentLocalDof);

        //      mesh.point(iGID).setX(positionVector[iGID]);
        //      mesh.point(iGID).setY(positionVector[jGID]);
        //      mesh.point(iGID).setZ(positionVector[kGID]);

    }
}


int main (int argc, char** argv)
{

    typedef RegionMesh<LinearTetra>                         mesh_Type;
    typedef boost::function < Real (const Real& /*t*/,
                                    const Real &   x,
                                    const Real &   y,
                                    const Real& /*z*/,
                                    const ID&   /*i*/ ) >   function_Type;

    typedef IonicMinimalModel                                        ionicModel_Type;
    typedef boost::shared_ptr<ionicModel_Type>                       ionicModelPtr_Type;
Simone Rossi's avatar
Simone Rossi committed
139
    typedef EMMonodomainSolver< mesh_Type, ionicModel_Type > monodomainSolver_Type;
Simone Rossi's avatar
Simone Rossi committed
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
    typedef boost::shared_ptr< monodomainSolver_Type >               monodomainSolverPtr_Type;

    typedef VectorEpetra                                             vector_Type;
    typedef boost::shared_ptr<vector_Type>                           vectorPtr_Type;

    typedef EMSolver<mesh_Type, ionicModel_Type>    emSolver_Type;
    typedef boost::shared_ptr<emSolver_Type> emSolverPtr_Type;

#ifdef HAVE_MPI
    MPI_Init ( &argc, &argv );
#endif

    boost::shared_ptr<Epetra_Comm> comm (new Epetra_MpiComm (MPI_COMM_WORLD) );



    //*********************************************//
    // creating output folder
    //*********************************************//
    GetPot commandLine ( argc, argv );
    std::string problemFolder = commandLine.follow ( "Output", 2, "-o", "--output" );
    // Create the problem folder
    if ( problemFolder.compare ("./") )
    {
        problemFolder += "/";

        if ( comm->MyPID() == 0 )
        {
            mkdir ( problemFolder.c_str(), 0777 );
        }
    }


    //********************************************//
    // Import parameters from an xml list. Use    //
    // Teuchos to create a list from a given file //
    // in the execution directory.                //
    //********************************************//

    if ( comm->MyPID() == 0 )
    {
        std::cout << "Importing parameters list...";
    }
    Teuchos::ParameterList monodomainList = * ( Teuchos::getParametersFromXmlFile ( "ParamList.xml" ) );
    if ( comm->MyPID() == 0 )
    {
        std::cout << " Done!" << endl;
    }

    //********************************************//
    // We need the GetPot datafile to setup       //
    //                                            //
    //********************************************//
    GetPot command_line (argc, argv);
    const string data_file_name = command_line.follow ("data", 2, "-f",
                                                       "--file");
    GetPot dataFile (data_file_name);

    //********************************************//
    // We create three solvers to solve with:     //
    // 1) Operator Splitting method               //
    //********************************************//
    if ( comm->MyPID() == 0 )
    {
        std::cout << "Building Monodomain Solvers... ";
    }

    emSolverPtr_Type emSolverPtr ( new emSolver_Type (monodomainList, data_file_name, comm) );

    if ( comm->MyPID() == 0 )
    {
        if (emSolverPtr -> monodomainPtr() -> displacementPtr() )
        {
            std::cout << "\nI've set the displacement ptr in monodomain: constructor";
        }
    }


    if ( comm->MyPID() == 0 )
    {
        std::cout << " solver done... ";

    }
    //********************************************//
    // Setting up the initial condition form      //
    // a given function.                          //
    //********************************************//
    if ( comm->MyPID() == 0 )
    {
        cout << "\nInitializing potential and gating variables:  " ;
    }

    //
    //    function_Type stimulus;
    //      stimulus = &PacingProtocolMM;
    //    emSolverPtr -> monodomainPtr() -> setAppliedCurrentFromFunction(stimulus, 0.0);
    //    if ( comm->MyPID() == 0 )
    //    {
    //        if(emSolverPtr -> monodomainPtr() -> displacementPtr()) std::cout << "\nI've set the displacement ptr in monodomain: applied current";
    //    }
    //    if ( comm->MyPID() == 0 )
    //    {
    //        cout << "Done! \n" ;
    //
    //    }

    //********************************************//
    // Create a fiber direction                   //
    //********************************************//
    if ( comm->MyPID() == 0 )
    {
        cout << "\nSetting fibers:  " ;
    }

    VectorSmall<3> fibers;
    fibers[0] = 0.0;
    fibers[1] = 0.0;
    fibers[2] = 1.0;
    emSolverPtr -> monodomainPtr() -> setupFibers ( fibers );
    emSolverPtr -> activationPtr() -> setFiberPtr ( emSolverPtr -> monodomainPtr() -> fiberPtr() );


    VectorSmall<3> sheets;
    sheets[0] = 0.0;
    sheets[1] = 1.0;
    sheets[2] = 0.0;
    emSolverPtr -> solidPtr() -> activeMaterial() -> setupFiberVector (fibers[0], fibers[1], fibers[2]);
    emSolverPtr -> solidPtr() -> activeMaterial() -> setupSheetVector (sheets[0], sheets[1], sheets[2]);
    emSolverPtr -> exportFibersAndSheetsFields (problemFolder);
    //    if ( comm->MyPID() == 0 )
    //    {
    //        if(emSolverPtr -> monodomainPtr() -> displacementPtr()) std::cout << "\nI've set the displacement ptr in monodomain: fibers";
    //    }
    //
    //    if ( comm->MyPID() == 0 )
    //    {
    //        cout << "Done! \n" ;
    //    }
    //
    //    if ( comm->MyPID() == 0 )
    //    {
    //        if(emSolverPtr -> monodomainPtr() -> displacementPtr()) std::cout << "\nI've set the displacement ptr in monodomain";
    //    }
    //********************************************//
    // Create the global matrix: mass + stiffness //
    //********************************************//
    if ( comm->MyPID() == 0 )
    {
        cout << "\nPointer 1:  " << emSolverPtr -> activationPtr() -> gammafPtr() ;
    }
    emSolverPtr -> setup (monodomainList, data_file_name);
    if ( comm->MyPID() == 0 )
    {
        cout << "\nPointer 2:  " << emSolverPtr -> activationPtr() -> gammafPtr() ;
    }
    emSolverPtr -> setupExporters (problemFolder);
    //********************************************//
    // Activation time                            //
    //********************************************//
    emSolverPtr -> registerActivationTime (0.0, 0.8);
    emSolverPtr -> exportSolution (0.0);

    //********************************************//
    // Solving the system                         //
    //********************************************//

    if ( comm->MyPID() == 0 )
    {
        cout << "\nImporting Time data from parametr list:  " ;
    }
    Real dt = monodomainList.get ("timeStep", 0.1);
    Real TF = monodomainList.get ("endTime", 150.0);
    Int iter = monodomainList.get ("saveStep", 1.0) / dt;
    Int reactionSubiter = monodomainList.get ("reaction_subiteration", 100);
    Int solidIter = monodomainList.get ("emdt", 1.0) / dt;
    bool coupling = monodomainList.get ("coupling", false);
    if ( comm->MyPID() == 0 )
    {
        std::cout << "\ndt: " << dt;
        std::cout << "\nTF: " << TF;
        std::cout << "\nIter: " << iter;
        std::cout << "\nsubiter: " << reactionSubiter;
        std::cout << "\nsolid iterations: " << solidIter;
        std::cout << "\nSolving coupled problem: " << coupling;
    }
//    Int k (0);

    ////    Real timeReac = 0.0;
    ////    Real timeDiff = 0.0;
    ////    Real timeReacDiff = 0.0;
    //
    //    std::string solutionMethod = monodomainList.get ("solutionMethod", "SVI");
    //

    //    EMEvaluate util;
    //    util.evaluate(*(emSolverPtr -> monodomainPtr() -> potentialPtr()),
    //                *(emSolverPtr -> activationSolidPtr()),
    //                *(emSolverPtr -> monodomainPtr() -> feSpacePtr()),
    //                emSolverPtr -> activationSolidFESpace(),
    //                *(emSolverPtr -> fullSolidMesh()) );



    //    for ( Real t = 0.0; t < TF - dt; )
    //    {
    //      //register activation time
    //      k++;
    //      t = t + dt;
    //
    //        if ( comm->MyPID() == 0 )
    //        {
    //            cout << "\n==============";
    //            cout << "\nTime: " << t;
    //            cout << "\n==============";
    //        }
    //
    //
    //        if ( comm->MyPID() == 0 )
    //        {
    //            cout << "\nSet applied current";
    //        }
    //
    //        emSolverPtr -> monodomainPtr() -> setAppliedCurrentFromFunction ( stimulus, t );
    //        emSolverPtr -> solveOneMonodomainStep();
    //
    //        if(coupling == true)
    //        {
    //            if ( comm->MyPID() == 0 )
    //            {
    //                cout << "\n---------------------";
    //                cout << "\nActive Strain Solver ";
    //                cout << "\n---------------------";
    //            }
    //          emSolverPtr -> solveOneActivationStep();
    //            if ( comm->MyPID() == 0 )
    //            {
    //                if(emSolverPtr -> monodomainPtr() -> displacementPtr()) std::cout << "\nI've set the displacement ptr in monodomain: activation";
    //            }
    //
    //
    //          if( k % solidIter == 0 )
    //          {
    //                if ( comm->MyPID() == 0 )
    //                {
    //                    cout << "\n---------------------";
    //                    cout << "\nInterpolating gammaf ";
    //                    cout << "\n---------------------";
    //                }
    //              emSolverPtr -> updateSolid();
    //                if ( comm->MyPID() == 0 )
    //                {
    //                    cout << "\n------------------";
    //                    cout << "\nStructural Solver ";
    //                    cout << "\n------------------";
    //                }

    boost::shared_ptr< Exporter<RegionMesh<LinearTetra> > > expc;
    expc.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, "configurations" ) );
    expc -> setPostDir ( problemFolder );
    expc ->setMeshProcId ( emSolverPtr -> solidPtr() -> mesh(), comm->MyPID() );
    //    exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "solid_gammaf", solidaFESpace, solidGammaf, UInt (0) );

    vectorPtr_Type Xk ( new vector_Type ( emSolverPtr -> solidPtr() -> displacement().map() ) );
    vectorPtr_Type Xoriginal ( new vector_Type ( Xk-> map() ) );
    vectorPtr_Type Xkp1 ( new vector_Type ( Xk-> map() ) );
    vectorPtr_Type res ( new vector_Type ( Xk-> map() ) );
    expc->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "Xk", emSolverPtr -> activationPtr() -> FESpacePtrSolid(), Xk, UInt (0) );
    expc->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "Xor", emSolverPtr -> activationPtr() -> FESpacePtrSolid(), Xoriginal, UInt (0) );
    expc->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "Xkp1", emSolverPtr -> activationPtr() -> FESpacePtrSolid(), Xkp1, UInt (0) );
    expc->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "disp", emSolverPtr -> activationPtr() -> FESpacePtrSolid(), emSolverPtr -> solidPtr() -> displacementPtr(), UInt (0) );


//    UInt ntotalDof = emSolverPtr -> solidPtr() -> dispFESpace().dof().numTotalDof();
    UInt nLocalDof = emSolverPtr -> solidPtr() -> displacement().epetraVector().MyLength();
    UInt dim = nLocalDof / 3;

    positionVector ( * (emSolverPtr -> fullSolidMesh() ),  *Xoriginal);
    emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().vertices (*Xkp1, dim);
    *Xk = *Xoriginal;
    //    positionVector( *(emSolverPtr -> fullSolidMesh() ),  *Xoriginal);
    //    positionVector( *(emSolverPtr -> fullSolidMesh() ),  *Xoriginal, *( emSolverPtr -> solidPtr() -> mesh() ));


    //emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().vertices(*Xk, 3); //moveMesh( -emSolverPtr -> solidPtr() -> displacement(), 3);
    // emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().vertices(*Xoriginal, 3); //moveMesh( -emSolverPtr -> solidPtr() -> displacement(), 3);

    expc -> postProcess (0);

    //
    emSolverPtr ->solidBCPtr() -> handler() -> showMe();



    //                emSolverPtr -> solveSolid();
    //
    //                *Xkp1 *= 0.0;
    //                *Xkp1 += *Xoriginal;
    //                *Xkp1 -= emSolverPtr -> solidPtr() -> displacement();
    //
    //                *res = *Xkp1;
    //                *res -= *Xk;
    //
    ////                *res = emSolverPtr -> solidPtr() -> displacement();
    //Real normres = 2.0;
    //Real normdisp = 2.0;
    // res -> norm2();

    Real tol = 1e-6;
    int iterk (0);
    //
    //
    //                  expc -> postProcess(1.0);
    //                  expc -> closeFile();
    //                emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().moveMesh( -emSolverPtr -> solidPtr() -> displacement(), 3);
    //                emSolverPtr -> fullSolidMesh() -> meshTransformer().moveMesh( -( emSolverPtr -> solidPtr() -> displacement()), 3);
    std::ofstream output ("res.txt");




    for ( Real t (0.0) ;  t < TF ; )
    {
        t += dt;
        emSolverPtr ->solidDataPtr() -> dataTime() -> setTime (t);

        if ( comm->MyPID() == 0 )
        {
            std::cout << "\n/////////////////////////////////////////////////////";
            std::cout << "\n Time " << t;
            std::cout << "\n/////////////////////////////////////////////////////";
                  }

                      if ( comm->MyPID() == 0 )
                  {
          output << "\nnormres" << ", " << "normdisp" << ", time: " << t ;
                  }

                      Real normres = 2.0;
                      Real normdisp = 2.0;
                      iterk = 0;
                      while (normres > tol)
                  {
                      iterk++;
                      emSolverPtr -> solidPtr() -> displacement() = *Xoriginal;
                      emSolverPtr -> solidPtr() -> displacement() -= *Xk;

                      emSolverPtr -> solveSolid();
                      emSolverPtr -> exportSolution (t + 0.01 * iterk);

                      *res = *Xk;
                      *res += emSolverPtr -> solidPtr() -> displacement();
                      *res -= *Xoriginal;

                      normres =  res -> normInf();
                      normdisp =  emSolverPtr -> solidPtr() -> displacement().normInf();
                      //
                      if ( comm->MyPID() == 0 )
                  {
          std::cout << "\n RESIDUAL : " << normres << ", Norm disp: " << normdisp ;
                      output << "\n" << normres << ", " << normdisp;
                  }

                      *Xk *= 0.0;
                      *Xk += *Xoriginal;
                      *Xk -= emSolverPtr -> solidPtr() -> displacement();


                      emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().moveMesh ( *Xk, dim, 1);
                      *Xkp1 = emSolverPtr -> solidPtr() -> displacement();
                      //emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().moveMesh( -emSolverPtr -> solidPtr() -> displacement(), dim, 0);

                      expc -> postProcess (t + 0.01 * iterk);

                      if (iterk > 15)
                  {
                      break;
                  }
                  }
                  }

                      output.close();
                      //      //

                      //                if ( comm->MyPID() == 0 )
                      //                {
                      //                    cout << "\n---------------------------";
                      //                    cout << "\nInterpolating displacement ";
                      //                    cout << "\n---------------------------";
                      //                }
                      //                emSolverPtr -> updateMonodomain();
                      //          }
                      //
                      //
                      //        }
                      //      emSolverPtr -> registerActivationTime(t, 0.8);
                      //      matrixPtr_Type broydenMatrix( emSolverPtr -> solidPtr() -> );
                      //        if( k % iter == 0 )
                      //        {
                      //            if ( comm->MyPID() == 0 )
                      //            {
                      //                cout << "\nExporting solutions";
                      //            }


                      //emSolverPtr -> solidPtr() -> mesh() -> meshTransformer().moveMesh( -( emSolverPtr -> solidPtr() -> displacement()), 3);
                      //emSolverPtr -> exportSolution(2.0);

                      //        }
                      //
                      //    }
                      //
                      //    if ( comm->MyPID() == 0 )
                      //    {
                      //        cout << "\nExporting Activation Time";
                      //    }
                      iterk++;
                      emSolverPtr -> exportSolution (iterk);
                      emSolverPtr -> closeExporters();
                      expc -> closeFile();




          std::cout << "\n\nThank you for using EMSolver.\nI hope to meet you again soon!\n All the best for your simulation :P\n  " ;
                          //   }

#ifdef HAVE_MPI
                          MPI_Finalize();
#endif
                          return 0;
                      }