Chaste Release::3.1
CardiacElectroMechanicsProblem.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 
00037 #ifndef CARDIACELECTROMECHANICSPROBLEM_HPP_
00038 #define CARDIACELECTROMECHANICSPROBLEM_HPP_
00039 
00040 #include <vector>
00041 #include <string>
00042 #include "UblasIncludes.hpp"
00043 
00044 #include "AbstractCardiacCellFactory.hpp"
00045 #include "MonodomainProblem.hpp"
00046 #include "TetrahedralMesh.hpp"
00047 #include "QuadraticMesh.hpp"
00048 #include "AbstractOdeBasedContractionModel.hpp"
00049 #include "AbstractCardiacMechanicsSolver.hpp"
00050 #include "AbstractCardiacMechanicsSolverInterface.hpp"
00051 #include "FineCoarseMeshPair.hpp"
00052 #include "AbstractConductivityModifier.hpp"
00053 #include "ElectroMechanicsProblemDefinition.hpp"
00054 
00059 typedef enum ElectricsProblemType_
00060 {
00061     MONODOMAIN,
00062     BIDOMAIN,   
00063     BIDOMAIN_WITH_BATH
00064     //EXTENDED_BIDOMAIN
00065 } ElectricsProblemType;
00066 
00093 template<unsigned DIM, unsigned ELEC_PROB_DIM=1>
00094 class CardiacElectroMechanicsProblem
00095     : public AbstractConductivityModifier<DIM,DIM> // this only inherits from this class so it can be passed to the tissue to
00096                                                    // allow deformation-based altering of the conductivity
00097 {
00098 
00099 friend class TestCardiacElectroMechanicsProblem;
00100 friend class TestCardiacElectroMechanicsFurtherFunctionality;
00101 
00102 protected :
00104     CompressibilityType mCompressibilityType;
00105 
00107     AbstractCardiacProblem<DIM,DIM,ELEC_PROB_DIM>* mpElectricsProblem;
00108 
00111     AbstractCardiacMechanicsSolverInterface<DIM>* mpCardiacMechSolver;
00114     AbstractNonlinearElasticitySolver<DIM>* mpMechanicsSolver;
00115 
00117     unsigned mNumElecTimestepsPerMechTimestep;
00118 
00123     std::vector<double> mInterpolatedCalciumConcs;
00124 
00129     std::vector<double> mInterpolatedVoltages;
00130 
00132     TetrahedralMesh<DIM,DIM>* mpElectricsMesh;
00134     QuadraticMesh<DIM>* mpMechanicsMesh;
00135 
00137     ElectroMechanicsProblemDefinition<DIM>* mpProblemDefinition;
00138 
00140     bool mHasBath;
00141 
00143     FineCoarseMeshPair<DIM>* mpMeshPair;
00144 
00146     std::string mOutputDirectory;
00148     std::string mDeformationOutputDirectory;
00150     bool mWriteOutput;
00152     bool mNoElectricsOutput;
00153 
00155     static const int WRITE_EVERY_NTH_TIME = 1; //hardcoded for the time being ///\todo, allow user to set this
00156 
00158     bool mIsWatchedLocation;
00160     c_vector<double,DIM> mWatchedLocation;
00162     unsigned mWatchedElectricsNodeIndex;
00164     unsigned mWatchedMechanicsNodeIndex;
00166     out_stream mpWatchedLocationFile;
00167 
00169     unsigned mNumTimestepsToOutputDeformationGradientsAndStress;
00170 
00172     std::vector<double> mStretchesForEachMechanicsElement;
00174     std::vector<c_matrix<double,DIM,DIM> > mDeformationGradientsForEachMechanicsElement;
00175 
00179     std::pair<unsigned, c_matrix<double,DIM,DIM> > mLastModifiedConductivity;
00180 
00181 
00185     void DetermineWatchedNodes();
00186 
00187 
00194     void WriteWatchedLocationData(double time, Vec voltage);
00195 
00196 
00197 public :
00198 
00209     CardiacElectroMechanicsProblem(CompressibilityType compressibilityType,
00210                                    ElectricsProblemType electricsProblemType,
00211                                    TetrahedralMesh<DIM,DIM>* pElectricsMesh,
00212                                    QuadraticMesh<DIM>* pMechanicsMesh,
00213                                    AbstractCardiacCellFactory<DIM>* pCellFactory,
00214                                    ElectroMechanicsProblemDefinition<DIM>* pProblemDefinition,
00215                                    std::string outputDirectory);
00216 
00225     virtual ~CardiacElectroMechanicsProblem();
00226 
00231     void Initialise();
00232 
00236     void Solve();
00237 
00242     double Max(std::vector<double>& vec);
00243 
00245     void SetNoElectricsOutput();
00246 
00257     void SetWatchedPosition(c_vector<double,DIM> watchedLocation);
00258 
00266     void SetOutputDeformationGradientsAndStress(double timestep);
00267 
00269     std::vector<c_vector<double,DIM> >& rGetDeformedPosition();
00270 
00271 
00279     c_matrix<double,DIM,DIM>& rGetModifiedConductivityTensor(unsigned elementIndex, const c_matrix<double,DIM,DIM>& rOriginalConductivity);
00280 
00281 
00285     virtual void PrepareForSolve(){}
00286 
00291     virtual void OnEndOfTimeStep(unsigned counter)
00292     {
00293     }
00294 };
00295 
00296 
00297 
00298 #endif /*CARDIACELECTROMECHANICSPROBLEM_HPP_*/