HeartConfig.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 HEARTCONFIG_HPP_
00038 #define HEARTCONFIG_HPP_
00039 
00040 #include <string>
00041 #include <vector>
00042 #include <set>
00043 
00044 #include "UblasIncludes.hpp"
00045 
00046 #include "ArchiveLocationInfo.hpp"
00047 #include "ChasteParameters_3_3.hpp"
00048 
00049 #include "AbstractStimulusFunction.hpp"
00050 
00051 #include "ChastePoint.hpp"
00052 #include "ChasteCuboid.hpp"
00053 #include "ChasteEllipsoid.hpp"
00054 #include "DistributedTetrahedralMeshPartitionType.hpp"
00055 
00056 #include <boost/shared_ptr.hpp>
00057 
00058 #include "ChasteSerialization.hpp"
00059 #include "ChasteSerializationVersion.hpp"
00060 #include <boost/serialization/split_member.hpp>
00061 
00062 namespace cp = chaste::parameters::v3_3;
00063 
00064 // Forward declaration to avoid circular includes
00065 class HeartFileFinder;
00066 
00067 
00078 class HeartConfig
00079 {
00080 private:
00087     void CheckTimeSteps() const;
00088 
00090     friend class boost::serialization::access;
00097     template<class Archive>
00098     void save(Archive & archive, const unsigned int version) const
00099     {
00100         //Only the Master should be writing the configuration file
00101         if (PetscTools::AmMaster())
00102         {
00103             mpInstance->Write( true );
00104         }
00105         PetscTools::Barrier("HeartConfig::save");
00106     }
00107 
00114     template<class Archive>
00115     void load(Archive & archive, const unsigned int version)
00116     {
00117         LoadFromCheckpoint();
00118     }
00119     BOOST_SERIALIZATION_SPLIT_MEMBER()
00120 
00121     
00125     void LoadFromCheckpoint();
00126 
00133     void UpdateParametersFromResumeSimulation(boost::shared_ptr<cp::chaste_parameters_type> pResumeParameters);
00134 
00135 public:
00140     typedef std::map<std::string, std::string> SchemaLocationsMap;
00141 
00142 private:
00146     SchemaLocationsMap mSchemaLocations;
00147 
00151     void SetDefaultSchemaLocations();
00152 
00153 public:
00159     static HeartConfig* Instance();
00160 
00166     void SetUseFixedSchemaLocation(bool useFixedSchemaLocation);
00167 
00174     void SetFixedSchemaLocations(const SchemaLocationsMap& rSchemaLocations);
00175 
00180     void SetParametersFile(const std::string& rFileName);
00181 
00193     void Write(bool useArchiveLocationInfo=false, std::string subfolderName="output");
00194 
00204     void CopySchema(const std::string& rToDirectory);
00205 
00211     boost::shared_ptr<cp::chaste_parameters_type> ReadFile(const std::string& rFileName);
00212 
00217     static void Reset();
00218 
00219     ~HeartConfig(); 
00227     unsigned GetVersionFromNamespace(const std::string& rNamespaceUri);
00228 
00230     //
00231     //  Get methods
00232     //
00234 
00239     FileFinder GetParametersFilePath();
00240 
00241     // Methods for asking the configuration file about which sections are defined.
00242 
00248     bool IsSimulationDefined() const;
00249 
00255     bool IsSimulationResumed() const;
00256 
00257     // Simulation
00258     unsigned GetSpaceDimension() const; 
00259     double GetSimulationDuration() const; 
00266     cp::domain_type GetDomain() const;
00267 
00275     cp::ionic_model_selection_type GetDefaultIonicModel() const;
00276 
00287     template<unsigned DIM>
00288     void GetIonicModelRegions(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rDefinedRegions,
00289                                std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00290 
00302     void SetIonicModelRegions(std::vector<ChasteCuboid<3> >& rDefinedRegions,
00303                               std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00304 
00305     bool IsMeshProvided() const; 
00306     bool GetCreateMesh() const; 
00307     bool GetCreateSlab() const; 
00308     bool GetCreateSheet() const; 
00309     bool GetCreateFibre() const; 
00310     bool GetLoadMesh() const; 
00315     void GetSlabDimensions(c_vector<double, 3>& slabDimensions) const;
00319     void GetSheetDimensions(c_vector<double, 2>& sheetDimensions) const;
00323     void GetFibreLength(c_vector<double, 1>& fibreLength) const;
00324     double GetInterNodeSpace() const; 
00326     std::string GetMeshName() const;
00328     cp::media_type GetConductivityMedia() const;
00339     template<unsigned DIM>
00340     void GetStimuli(std::vector<boost::shared_ptr<AbstractStimulusFunction> >& rStimuliApplied,
00341                     std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rStimulatedAreas) const;
00342 
00358     template<unsigned DIM>
00359     void GetCellHeterogeneities( std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rCellHeterogeneityRegions,
00360                                  std::vector<double>& rScaleFactorGks,
00361                                  std::vector<double>& rScaleFactorIto,
00362                                  std::vector<double>& rScaleFactorGkr,
00363                                  std::vector<std::map<std::string, double> >* pParameterSettings);
00364 
00365     bool GetConductivityHeterogeneitiesProvided() const; 
00370     bool AreCellularTransmuralHeterogeneitiesRequested();
00371 
00375     double GetEpiLayerFraction();
00376 
00380     double GetEndoLayerFraction();
00381 
00385     double GetMidLayerFraction();
00386 
00390     unsigned GetEpiLayerIndex();
00391 
00395     unsigned GetEndoLayerIndex();
00396 
00400     unsigned GetMidLayerIndex();
00401 
00402 
00411     template<unsigned DIM>
00412     void GetConductivityHeterogeneities(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& conductivitiesHeterogeneityAreas,
00413                                         std::vector< c_vector<double,3> >& intraConductivities,
00414                                         std::vector< c_vector<double,3> >& extraConductivities) const;
00415     std::string GetOutputDirectory() const; 
00427     std::string GetOutputFilenamePrefix() const;
00428 
00432     bool GetOutputVariablesProvided() const;
00433 
00440     void GetOutputVariables(std::vector<std::string>& rOutputVariables) const;
00441 
00447     bool GetOutputUsingOriginalNodeOrdering();
00448 
00454     bool GetCheckpointSimulation() const;
00455 
00461     double GetCheckpointTimestep() const;
00462 
00468     unsigned GetMaxCheckpointsOnDisk() const;
00469 
00470     // ResumeSimulation
00474     HeartFileFinder GetArchivedSimulationDir() const;
00475 
00476 
00477     // Physiological
00482     void GetIntracellularConductivities(c_vector<double, 3>& intraConductivities) const;
00483 
00488     void GetIntracellularConductivities(c_vector<double, 2>& intraConductivities) const;
00489 
00494     void GetIntracellularConductivities(c_vector<double, 1>& intraConductivities) const;
00495 
00500     void GetExtracellularConductivities(c_vector<double, 3>& extraConductivities) const;
00501 
00506     void GetExtracellularConductivities(c_vector<double, 2>& extraConductivities) const;
00507 
00512     void GetExtracellularConductivities(c_vector<double, 1>& extraConductivities) const;
00513 
00521     double GetBathConductivity(unsigned bathRegion=UINT_MAX) const;
00522 
00528     const std::set<unsigned>& rGetTissueIdentifiers();
00529 
00535     const std::set<unsigned>& rGetBathIdentifiers();
00536 
00537 
00538     double GetSurfaceAreaToVolumeRatio() const; 
00540     double GetCapacitance() const; 
00542     // Numerical
00543     double GetOdeTimeStep() const; 
00544     double GetPdeTimeStep() const; 
00545     double GetPrintingTimeStep() const; 
00547     bool GetUseAbsoluteTolerance() const; 
00548     double GetAbsoluteTolerance() const; 
00550     bool GetUseRelativeTolerance() const; 
00551     double GetRelativeTolerance() const;  
00553     const char* GetKSPSolver() const; 
00554     const char* GetKSPPreconditioner() const; 
00556     DistributedTetrahedralMeshPartitionType::type GetMeshPartitioning() const; 
00558     // Adaptivity
00563     bool IsAdaptivityParametersPresent() const;
00564 
00565     // Post processing
00569     bool IsPostProcessingSectionPresent() const;
00570 
00574     void EnsurePostProcessingSectionPresent();
00575 
00579     bool IsPostProcessingRequested() const;
00580 
00584     bool IsApdMapsRequested() const;
00585 
00591     void GetApdMaps(std::vector<std::pair<double,double> >& rApdMaps) const;
00592 
00596     bool IsUpstrokeTimeMapsRequested() const;
00601     void GetUpstrokeTimeMaps (std::vector<double>& rUpstrokeTimeMaps) const;
00602 
00606     bool IsMaxUpstrokeVelocityMapRequested() const;
00607 
00612     void GetMaxUpstrokeVelocityMaps(std::vector<double>& rUpstrokeVelocityMaps) const;
00613 
00617     bool IsConductionVelocityMapsRequested() const;
00618 
00623     void GetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps) const;
00624 
00628     bool IsAnyNodalTimeTraceRequested() const;
00629 
00633     void GetNodalTimeTraceRequested(std::vector<unsigned>& rRequestedNodes) const;
00634 
00638     bool IsPseudoEcgCalculationRequested() const;
00639 
00644     template<unsigned SPACE_DIM>
00645     void GetPseudoEcgElectrodePositions(std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions) const;
00646 
00650     bool GetUseStateVariableInterpolation() const;
00651 
00652 
00653     // Output visualization
00654 
00656     bool IsOutputVisualizerPresent() const;
00657 
00659     bool GetVisualizeWithMeshalyzer() const;
00660 
00662     bool GetVisualizeWithCmgui() const;
00663 
00665     bool GetVisualizeWithVtk() const;
00666 
00668     bool GetVisualizeWithParallelVtk() const;
00669 
00671     unsigned GetVisualizerOutputPrecision();
00672 
00676     bool IsElectrodesPresent() const;
00677 
00678 
00688     void GetElectrodeParameters(bool& rGroundSecondElectrode,
00689                                 unsigned& rIndex, double& rMagnitude,
00690                                 double& rStartTime, double& rDuration );
00691 
00695     bool GetUseMassLumping();
00696 
00700     bool GetUseMassLumpingForPrecond();
00701 
00706     bool GetUseReactionDiffusionOperatorSplitting();
00707 
00711     bool GetUseFixedNumberIterationsLinearSolver();
00712 
00716     unsigned GetEvaluateNumItsEveryNSolves();
00717 
00718 
00720     //
00721     //  Set methods
00722     //
00724 
00725     // Simulation
00729     void SetSpaceDimension(unsigned spaceDimension);
00730 
00735     void SetSimulationDuration(double simulationDuration);
00736 
00743     void SetDomain(const cp::domain_type& rDomain);
00744 
00752     void SetDefaultIonicModel(const cp::ionic_models_available_type& rIonicModel);
00753 
00761     void SetSlabDimensions(double x, double y, double z, double inter_node_space);
00762 
00769     void SetSheetDimensions(double x, double y, double inter_node_space);
00770 
00776     void SetFibreLength(double x, double inter_node_space);
00777 
00784     void SetMeshFileName(std::string meshPrefix, cp::media_type fibreDefinition=cp::media_type::NoFibreOrientation);
00785 
00793     void SetConductivityHeterogeneities(std::vector<ChasteCuboid<3> >& rConductivityAreas,
00794                                         std::vector< c_vector<double,3> >& rIntraConductivities,
00795                                         std::vector< c_vector<double,3> >& rExtraConductivities);
00803     void SetConductivityHeterogeneitiesEllipsoid(std::vector<ChasteEllipsoid<3> >& conductivityAreas,
00804             std::vector< c_vector<double,3> >& intraConductivities,
00805             std::vector< c_vector<double,3> >& extraConductivities);
00809     void SetOutputDirectory(const std::string& rOutputDirectory);
00810 
00821     void SetOutputFilenamePrefix(const std::string& rOutputFilenamePrefix);
00822 
00829     void SetOutputVariables(const std::vector<std::string>& rOutputVariables);
00830 
00839     void SetOutputUsingOriginalNodeOrdering(bool useOriginal);
00840 
00848      void SetCheckpointSimulation(bool checkpointSimulation, double checkpointTimestep=-1.0, unsigned maxCheckpointsOnDisk=UINT_MAX);
00849 
00850     // Physiological
00855     void SetIntracellularConductivities(const c_vector<double, 3>& rIntraConductivities);
00856 
00861     void SetIntracellularConductivities(const c_vector<double, 2>& rIntraConductivities);
00862 
00867     void SetIntracellularConductivities(const c_vector<double, 1>& rIntraConductivities);
00868 
00873     void SetExtracellularConductivities(const c_vector<double, 3>& rExtraConductivities);
00874 
00879     void SetExtracellularConductivities(const c_vector<double, 2>& rExtraConductivities);
00880 
00885     void SetExtracellularConductivities(const c_vector<double, 1>& rExtraConductivities);
00886 
00892     void SetBathConductivity(double bathConductivity);
00893 
00899     void SetBathMultipleConductivities(std::map<unsigned, double> bathConductivities);
00900 
00907     void SetTissueAndBathIdentifiers(const std::set<unsigned>& tissueIds, const std::set<unsigned>& bathIds);
00908 
00915     //void SetTissueIdentifiers(const std::set<unsigned>& tissueIds);
00916 
00921     void SetSurfaceAreaToVolumeRatio(double ratio);
00922 
00927     void SetCapacitance(double capacitance);
00928 
00929     // Numerical
00953     void SetOdePdeAndPrintingTimeSteps(double odeTimeStep, double pdeTimeStep, double printingTimeStep);
00954 
00967     void SetOdeTimeStep(double odeTimeStep);
00968 
00973     void SetPdeTimeStep(double pdeTimeStep);
00974 
00984      void SetPrintingTimeStep(double printingTimeStep);
00985 
00989     void SetUseRelativeTolerance(double relativeTolerance);
00990 
00994     void SetUseAbsoluteTolerance(double absoluteTolerance);
00995 
01001     void SetKSPSolver(const char* kspSolver, bool warnOfChange=false);
01002 
01006     void SetKSPPreconditioner(const char* kspPreconditioner);
01007 
01011     void SetMeshPartitioning(const char* meshPartioningMethod);
01012 
01019     void SetApdMaps(const std::vector<std::pair<double,double> >& rApdMaps);
01020 
01026     void SetUpstrokeTimeMaps(std::vector<double>& rUpstrokeTimeMaps);
01027 
01033     void SetMaxUpstrokeVelocityMaps(std::vector<double>& rMaxUpstrokeVelocityMaps);
01034 
01039     void SetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps);
01040 
01047     void SetRequestedNodalTimeTraces(std::vector<unsigned>& requestedNodes);
01048 
01054     template<unsigned SPACE_DIM>
01055     void SetPseudoEcgElectrodePositions(const std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions);
01056 
01057 
01058     // Output visualization
01059 
01061     void EnsureOutputVisualizerExists(void);
01062 
01067     void SetVisualizeWithMeshalyzer(bool useMeshalyzer=true);
01068 
01073     void SetVisualizeWithCmgui(bool useCmgui=true);
01074 
01079     void SetVisualizeWithVtk(bool useVtk=true);
01080 
01085     void SetVisualizeWithParallelVtk(bool useParallelVtk=true);
01086 
01093     void SetVisualizerOutputPrecision(unsigned numberOfDigits);
01094 
01104     void SetElectrodeParameters( bool groundSecondElectrode,
01105                                  unsigned index, double magnitude,
01106                                  double startTime, double duration );
01107 
01114     void SetUseStateVariableInterpolation( bool useStateVariableInterpolation = true);
01115 
01121     void SetUseMassLumping(bool useMassLumping = true);
01122 
01128     void SetUseMassLumpingForPrecond(bool useMassLumping = true);
01129 
01138     void SetUseReactionDiffusionOperatorSplitting(bool useOperatorSplitting = true);
01139 
01146     void SetUseFixedNumberIterationsLinearSolver(bool useFixedNumberIterations = true, unsigned evaluateNumItsEveryNSolves=UINT_MAX);
01147 
01151     bool HasDrugDose() const;
01152 
01156     double GetDrugDose() const;
01157 
01161     void SetDrugDose(double drugDose);
01162 
01170     void SetIc50Value(const std::string& rCurrentName, double ic50, double hill=1.0);
01171 
01177     std::map<std::string, std::pair<double, double> > GetIc50Values();
01178 
01179     //
01180     // Purkinje-related methods
01181     //
01182 
01186     bool HasPurkinje();
01187 
01191     double GetPurkinjeCapacitance();
01192 
01197     void SetPurkinjeCapacitance(double capacitance);
01198 
01202     double GetPurkinjeSurfaceAreaToVolumeRatio();
01203 
01208     void SetPurkinjeSurfaceAreaToVolumeRatio(double ratio);
01209 
01213     double GetPurkinjeConductivity();
01214 
01219     void SetPurkinjeConductivity(double conductivity);
01220 
01221 private:
01222     // Only to be accessed by the tests
01223     friend class TestHeartConfig;
01224 
01225     /*Constructor is private, since the class is only accessed by the singleton instance() method*/
01226     HeartConfig();
01227 
01229     boost::shared_ptr<cp::chaste_parameters_type> mpParameters;
01230 
01232     static std::auto_ptr<HeartConfig> mpInstance;
01233 
01237     FileFinder mParametersFilePath;
01238 
01243     bool mUseFixedSchemaLocation;
01244 
01248     double mEpiFraction;
01249 
01253     double mEndoFraction;
01254 
01258     double mMidFraction;
01259 
01263     unsigned mIndexMid;
01264 
01268     unsigned mIndexEpi;
01269 
01273     unsigned mIndexEndo;
01274 
01278     bool mUserAskedForCellularTransmuralHeterogeneities;
01279 
01283     bool mUseMassLumping;
01284 
01288     bool mUseMassLumpingForPrecond;
01289 
01294     bool mUseReactionDiffusionOperatorSplitting;
01295 
01299     std::map<unsigned, double> mBathConductivities;
01300 
01304     std::set<unsigned> mTissueIdentifiers;
01305 
01309     std::set<unsigned> mBathIdentifiers;
01310 
01314     bool mUseFixedNumberIterations;
01315 
01321     unsigned mEvaluateNumItsEveryNSolves;
01322 
01332     void CheckSimulationIsDefined(std::string callingMethod="") const;
01333 
01343     void CheckResumeSimulationIsDefined(std::string callingMethod="") const;
01344 };
01345 
01346 
01347 BOOST_CLASS_VERSION(HeartConfig, 1)
01348 #include "SerializationExportWrapper.hpp"
01349 // Declare identifier for the serializer
01350 CHASTE_CLASS_EXPORT(HeartConfig)
01351 
01352 #endif /*HEARTCONFIG_HPP_*/

Generated by  doxygen 1.6.2