CardiacElectroMechanicsProblem.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef CARDIACELECTROMECHANICSPROBLEM_HPP_
00031 #define CARDIACELECTROMECHANICSPROBLEM_HPP_
00032 
00033 #include <vector>
00034 #include <string>
00035 #include "UblasIncludes.hpp"
00036 
00037 #include "AbstractCardiacCellFactory.hpp"
00038 #include "MonodomainProblem.hpp"
00039 #include "TetrahedralMesh.hpp"
00040 #include "QuadraticMesh.hpp"
00041 #include "AbstractOdeBasedContractionModel.hpp"
00042 #include "AbstractCardiacMechanicsSolver.hpp"
00043 #include "AbstractCardiacMechanicsSolverInterface.hpp"
00044 #include "FineCoarseMeshPair.hpp"
00045 #include "AbstractConductivityModifier.hpp"
00046 
00072 template<unsigned DIM>
00073 class CardiacElectroMechanicsProblem
00074     : public AbstractConductivityModifier<DIM,DIM> // this only inherits from this class so it can be passed to the tissue to
00075                                                    // allow deformation-based altering of the conductivity
00076 {
00077 
00078 friend class TestCardiacElectroMechanicsProblem;
00079 
00080 protected :
00082     ContractionModel mContractionModel;
00084     MonodomainProblem<DIM>* mpMonodomainProblem;
00085 
00087 
00088     AbstractCardiacMechanicsSolverInterface<DIM>* mpCardiacMechSolver;
00090     AbstractNonlinearElasticitySolver<DIM>* mpMechanicsSolver;
00091 
00093     double mEndTime;
00095     double mElectricsTimeStep;
00097     double mMechanicsTimeStep;
00099     unsigned mNumElecTimestepsPerMechTimestep;
00101     double mContractionModelOdeTimeStep;
00102 
00104     TetrahedralMesh<DIM,DIM>* mpElectricsMesh;
00106     QuadraticMesh<DIM>* mpMechanicsMesh;
00107 
00109     FineCoarseMeshPair<DIM>* mpMeshPair;
00110 
00112     std::string mOutputDirectory;
00114     std::string mDeformationOutputDirectory;
00116     bool mWriteOutput;
00118     bool mNoElectricsOutput;
00119 
00121     static const int WRITE_EVERY_NTH_TIME = 1; //hardcoded for the time being ///\todo, allow user to set this
00122 
00124     bool mIsWatchedLocation;
00126     c_vector<double,DIM> mWatchedLocation;
00128     unsigned mWatchedElectricsNodeIndex;
00130     unsigned mWatchedMechanicsNodeIndex;
00132     out_stream mpWatchedLocationFile;
00133 
00135     std::vector<unsigned> mFixedNodes;
00137     std::string mFibreSheetDirectionsFile;
00139     bool mFibreSheetDirectionsDefinedPerQuadraturePoint;
00140 
00142     std::vector<double> mStretchesForEachMechanicsElement;
00144     std::vector<c_matrix<double,DIM,DIM> > mDeformationGradientsForEachMechanicsElement;
00145 
00149     std::pair<unsigned, c_matrix<double,DIM,DIM> > mLastModifiedConductivity;
00150 
00152     bool mConductivityAffectedByDeformationMef;
00153 
00157     bool mCellModelsAffectedByDeformationMef;
00158 
00160     AbstractMaterialLaw<DIM>* mpMaterialLaw;
00161 
00163     bool mAllocatedMaterialLawMemory;
00164 
00165 
00169     void DetermineWatchedNodes();
00170 
00171 
00178     void WriteWatchedLocationData(double time, Vec voltage);
00179 
00180 
00182 //    std::vector<BoundaryElement<DIM-1,DIM>*>* mpImpactRegion;
00183 //    std::vector<c_vector<double,DIM> > mImpactTractions;
00184 //    void ApplyImpactTractions(double time);
00185 
00186 public :
00187 
00201     CardiacElectroMechanicsProblem(ContractionModel contractionModel,
00202                                    TetrahedralMesh<DIM,DIM>* pElectricsMesh,
00203                                    QuadraticMesh<DIM>* pMechanicsMesh,
00204                                    std::vector<unsigned> fixedMechanicsNodes,
00205                                    AbstractCardiacCellFactory<DIM>* pCellFactory,
00206                                    double endTime,
00207                                    double electricsPdeTimeStep,
00208                                    double mechanicsSolveTimestep,
00209                                    double contractionModelOdeTimeStep,
00210                                    std::string outputDirectory);
00211 
00220     virtual ~CardiacElectroMechanicsProblem();
00221 
00226     void Initialise();
00227 
00231     void Solve();
00232 
00237     double Max(std::vector<double>& vec);
00238 
00240     void SetNoElectricsOutput();
00241 
00252     void SetWatchedPosition(c_vector<double,DIM> watchedLocation);
00253 
00265     void SetVariableFibreSheetDirectionsFile(std::string orthoFile, bool definedPerQuadPoint);
00266 
00268     std::vector<c_vector<double,DIM> >& rGetDeformedPosition();
00269 
00284     void UseMechanoElectricFeedback()
00285     {
00286         mConductivityAffectedByDeformationMef = true;
00287         mCellModelsAffectedByDeformationMef = true;
00288     }
00289 
00297     c_matrix<double,DIM,DIM>& rGetModifiedConductivityTensor(unsigned elementIndex, const c_matrix<double,DIM,DIM>& rOriginalConductivity);
00298 
00300 //    void SetImpactRegion(std::vector<BoundaryElement<DIM-1,DIM>*>& rImpactRegion);
00301 
00305     virtual void PrepareForSolve(){}
00306 
00311     virtual void OnEndOfTimeStep(unsigned counter){}
00312 
00318     AbstractNonlinearElasticitySolver<DIM>* GetCardiacMechanicsSolver()
00319     {
00320         assert(mpMechanicsSolver);
00321         return mpMechanicsSolver;
00322     }
00323 
00328     void SetMaterialLaw(AbstractMaterialLaw<DIM>* pMaterialLaw)
00329     {
00330         assert(pMaterialLaw);
00331         assert(mpMaterialLaw == NULL); // only call SetMaterialLaw() before both Initialise() or Solve()
00332         mpMaterialLaw = pMaterialLaw;
00333         mAllocatedMaterialLawMemory = false;
00334     }
00335 };
00336 
00337 
00338 
00339 #endif /*CARDIACELECTROMECHANICSPROBLEM_HPP_*/

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5