00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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_1.hpp"
00048
00049 #include "AbstractStimulusFunction.hpp"
00050
00051 #include "SimpleStimulus.hpp"
00052 #include "RegularStimulus.hpp"
00053
00054 #include "ChastePoint.hpp"
00055 #include "ChasteCuboid.hpp"
00056 #include "ChasteEllipsoid.hpp"
00057 #include "DistributedTetrahedralMeshPartitionType.hpp"
00058
00059 #include <boost/shared_ptr.hpp>
00060
00061 #include "ChasteSerialization.hpp"
00062 #include "ChasteSerializationVersion.hpp"
00063 #include <boost/serialization/split_member.hpp>
00064
00065 namespace cp = chaste::parameters::v3_1;
00066
00067
00068 class HeartFileFinder;
00069
00070
00081 class HeartConfig
00082 {
00083 private:
00090 void CheckTimeSteps() const;
00091
00093 friend class boost::serialization::access;
00100 template<class Archive>
00101 void save(Archive & archive, const unsigned int version) const
00102 {
00103
00104 if (PetscTools::AmMaster())
00105 {
00106 mpInstance->Write( true );
00107 }
00108 PetscTools::Barrier("HeartConfig::save");
00109 }
00110
00117 template<class Archive>
00118 void load(Archive & archive, const unsigned int version)
00119 {
00120 LoadFromCheckpoint();
00121 }
00122 BOOST_SERIALIZATION_SPLIT_MEMBER()
00123
00124
00128 void LoadFromCheckpoint();
00129
00136 void UpdateParametersFromResumeSimulation(boost::shared_ptr<cp::chaste_parameters_type> pResumeParameters);
00137
00138 public:
00143 typedef std::map<std::string, std::string> SchemaLocationsMap;
00144
00145 private:
00149 SchemaLocationsMap mSchemaLocations;
00150
00154 void SetDefaultSchemaLocations();
00155
00156 public:
00162 static HeartConfig* Instance();
00163
00169 void SetUseFixedSchemaLocation(bool useFixedSchemaLocation);
00170
00177 void SetFixedSchemaLocations(const SchemaLocationsMap& rSchemaLocations);
00178
00183 void SetParametersFile(const std::string& rFileName);
00184
00196 void Write(bool useArchiveLocationInfo=false, std::string subfolderName="output");
00197
00207 void CopySchema(const std::string& rToDirectory);
00208
00214 boost::shared_ptr<cp::chaste_parameters_type> ReadFile(const std::string& rFileName);
00215
00220 static void Reset();
00221
00222 ~HeartConfig();
00230 unsigned GetVersionFromNamespace(const std::string& rNamespaceUri);
00231
00233
00234
00235
00237
00242 FileFinder GetParametersFilePath();
00243
00244
00245
00251 bool IsSimulationDefined() const;
00252
00258 bool IsSimulationResumed() const;
00259
00260
00261 unsigned GetSpaceDimension() const;
00262 double GetSimulationDuration() const;
00269 cp::domain_type GetDomain() const;
00270
00278 cp::ionic_model_selection_type GetDefaultIonicModel() const;
00279
00290 template<unsigned DIM>
00291 void GetIonicModelRegions(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rDefinedRegions,
00292 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00293
00305 void SetIonicModelRegions(std::vector<ChasteCuboid<3> >& rDefinedRegions,
00306 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00307
00308 bool IsMeshProvided() const;
00309 bool GetCreateMesh() const;
00310 bool GetCreateSlab() const;
00311 bool GetCreateSheet() const;
00312 bool GetCreateFibre() const;
00313 bool GetLoadMesh() const;
00318 void GetSlabDimensions(c_vector<double, 3>& slabDimensions) const;
00322 void GetSheetDimensions(c_vector<double, 2>& sheetDimensions) const;
00326 void GetFibreLength(c_vector<double, 1>& fibreLength) const;
00327 double GetInterNodeSpace() const;
00329 std::string GetMeshName() const;
00331 cp::media_type GetConductivityMedia() const;
00342 template<unsigned DIM>
00343 void GetStimuli(std::vector<boost::shared_ptr<AbstractStimulusFunction> >& rStimuliApplied,
00344 std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rStimulatedAreas) const;
00345
00361 template<unsigned DIM>
00362 void GetCellHeterogeneities( std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rCellHeterogeneityRegions,
00363 std::vector<double>& rScaleFactorGks,
00364 std::vector<double>& rScaleFactorIto,
00365 std::vector<double>& rScaleFactorGkr,
00366 std::vector<std::map<std::string, double> >* pParameterSettings);
00367
00368 bool GetConductivityHeterogeneitiesProvided() const;
00373 bool AreCellularTransmuralHeterogeneitiesRequested();
00374
00378 double GetEpiLayerFraction();
00379
00383 double GetEndoLayerFraction();
00384
00388 double GetMidLayerFraction();
00389
00393 unsigned GetEpiLayerIndex();
00394
00398 unsigned GetEndoLayerIndex();
00399
00403 unsigned GetMidLayerIndex();
00404
00405
00414 template<unsigned DIM>
00415 void GetConductivityHeterogeneities(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& conductivitiesHeterogeneityAreas,
00416 std::vector< c_vector<double,3> >& intraConductivities,
00417 std::vector< c_vector<double,3> >& extraConductivities) const;
00418 std::string GetOutputDirectory() const;
00430 std::string GetOutputFilenamePrefix() const;
00431
00435 bool GetOutputVariablesProvided() const;
00436
00443 void GetOutputVariables(std::vector<std::string>& rOutputVariables) const;
00444
00450 bool GetOutputUsingOriginalNodeOrdering();
00451
00457 bool GetCheckpointSimulation() const;
00458
00464 double GetCheckpointTimestep() const;
00465
00471 unsigned GetMaxCheckpointsOnDisk() const;
00472
00473
00477 HeartFileFinder GetArchivedSimulationDir() const;
00478
00479
00480
00485 void GetIntracellularConductivities(c_vector<double, 3>& intraConductivities) const;
00490 void GetIntracellularConductivities(c_vector<double, 2>& intraConductivities) const;
00495 void GetIntracellularConductivities(c_vector<double, 1>& intraConductivities) const;
00496
00501 void GetExtracellularConductivities(c_vector<double, 3>& extraConductivities) const;
00506 void GetExtracellularConductivities(c_vector<double, 2>& extraConductivities) const;
00511 void GetExtracellularConductivities(c_vector<double, 1>& extraConductivities) const;
00512
00520 double GetBathConductivity(unsigned bathRegion=UINT_MAX) const;
00521
00527 const std::set<unsigned>& rGetTissueIdentifiers();
00528
00534 const std::set<unsigned>& rGetBathIdentifiers();
00535
00536
00537 double GetSurfaceAreaToVolumeRatio() const;
00539 double GetCapacitance() const;
00541
00542 double GetOdeTimeStep() const;
00543 double GetPdeTimeStep() const;
00544 double GetPrintingTimeStep() const;
00546 bool GetUseAbsoluteTolerance() const;
00547 double GetAbsoluteTolerance() const;
00549 bool GetUseRelativeTolerance() const;
00550 double GetRelativeTolerance() const;
00552 const char* GetKSPSolver() const;
00553 const char* GetKSPPreconditioner() const;
00555 DistributedTetrahedralMeshPartitionType::type GetMeshPartitioning() const;
00557
00562 bool IsAdaptivityParametersPresent() const;
00563
00564
00568 bool IsPostProcessingSectionPresent() const;
00569
00573 void EnsurePostProcessingSectionPresent();
00574
00578 bool IsPostProcessingRequested() const;
00579
00583 bool IsApdMapsRequested() const;
00584
00590 void GetApdMaps(std::vector<std::pair<double,double> >& rApdMaps) const;
00591
00595 bool IsUpstrokeTimeMapsRequested() const;
00600 void GetUpstrokeTimeMaps (std::vector<double>& rUpstrokeTimeMaps) const;
00601
00605 bool IsMaxUpstrokeVelocityMapRequested() const;
00606
00611 void GetMaxUpstrokeVelocityMaps(std::vector<double>& rUpstrokeVelocityMaps) const;
00612
00616 bool IsConductionVelocityMapsRequested() const;
00617
00622 void GetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps) const;
00623
00627 bool IsAnyNodalTimeTraceRequested() const;
00628
00632 void GetNodalTimeTraceRequested(std::vector<unsigned>& rRequestedNodes) const;
00633
00637 bool IsPseudoEcgCalculationRequested() const;
00638
00643 template<unsigned SPACE_DIM>
00644 void GetPseudoEcgElectrodePositions(std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions) const;
00645
00649 bool GetUseStateVariableInterpolation() const;
00650
00651
00652
00653
00655 bool IsOutputVisualizerPresent() const;
00656
00658 bool GetVisualizeWithMeshalyzer() const;
00659
00661 bool GetVisualizeWithCmgui() const;
00662
00664 bool GetVisualizeWithVtk() const;
00665
00667 bool GetVisualizeWithParallelVtk() const;
00668
00670 unsigned GetVisualizerOutputPrecision();
00671
00675 bool IsElectrodesPresent() const;
00676
00677
00687 void GetElectrodeParameters(bool& rGroundSecondElectrode,
00688 unsigned& rIndex, double& rMagnitude,
00689 double& rStartTime, double& rDuration );
00690
00694 bool GetUseMassLumping();
00695
00699 bool GetUseMassLumpingForPrecond();
00700
00705 bool GetUseReactionDiffusionOperatorSplitting();
00706
00710 bool GetUseFixedNumberIterationsLinearSolver();
00711
00715 unsigned GetEvaluateNumItsEveryNSolves();
00716
00717
00719
00720
00721
00723
00724
00728 void SetSpaceDimension(unsigned spaceDimension);
00729
00734 void SetSimulationDuration(double simulationDuration);
00735
00742 void SetDomain(const cp::domain_type& rDomain);
00743
00751 void SetDefaultIonicModel(const cp::ionic_models_available_type& rIonicModel);
00752
00760 void SetSlabDimensions(double x, double y, double z, double inter_node_space);
00767 void SetSheetDimensions(double x, double y, double inter_node_space);
00773 void SetFibreLength(double x, double inter_node_space);
00774
00781 void SetMeshFileName(std::string meshPrefix, cp::media_type fibreDefinition=cp::media_type::NoFibreOrientation);
00782
00790 void SetConductivityHeterogeneities(std::vector<ChasteCuboid<3> >& rConductivityAreas,
00791 std::vector< c_vector<double,3> >& rIntraConductivities,
00792 std::vector< c_vector<double,3> >& rExtraConductivities);
00800 void SetConductivityHeterogeneitiesEllipsoid(std::vector<ChasteEllipsoid<3> >& conductivityAreas,
00801 std::vector< c_vector<double,3> >& intraConductivities,
00802 std::vector< c_vector<double,3> >& extraConductivities);
00806 void SetOutputDirectory(const std::string& rOutputDirectory);
00817 void SetOutputFilenamePrefix(const std::string& rOutputFilenamePrefix);
00818
00825 void SetOutputVariables(const std::vector<std::string>& rOutputVariables);
00826
00835 void SetOutputUsingOriginalNodeOrdering(bool useOriginal);
00836
00844 void SetCheckpointSimulation(bool checkpointSimulation, double checkpointTimestep=-1.0, unsigned maxCheckpointsOnDisk=UINT_MAX);
00845
00846
00851 void SetIntracellularConductivities(const c_vector<double, 3>& rIntraConductivities);
00856 void SetIntracellularConductivities(const c_vector<double, 2>& rIntraConductivities);
00861 void SetIntracellularConductivities(const c_vector<double, 1>& rIntraConductivities);
00862
00867 void SetExtracellularConductivities(const c_vector<double, 3>& rExtraConductivities);
00872 void SetExtracellularConductivities(const c_vector<double, 2>& rExtraConductivities);
00877 void SetExtracellularConductivities(const c_vector<double, 1>& rExtraConductivities);
00878
00884 void SetBathConductivity(double bathConductivity);
00885
00891 void SetBathMultipleConductivities(std::map<unsigned, double> bathConductivities);
00892
00899 void SetTissueAndBathIdentifiers(const std::set<unsigned>& tissueIds, const std::set<unsigned>& bathIds);
00900
00907
00908
00913 void SetSurfaceAreaToVolumeRatio(double ratio);
00914
00919 void SetCapacitance(double capacitance);
00920
00921
00945 void SetOdePdeAndPrintingTimeSteps(double odeTimeStep, double pdeTimeStep, double printingTimeStep);
00946
00959 void SetOdeTimeStep(double odeTimeStep);
00960
00965 void SetPdeTimeStep(double pdeTimeStep);
00966
00976 void SetPrintingTimeStep(double printingTimeStep);
00977
00981 void SetUseRelativeTolerance(double relativeTolerance);
00982
00986 void SetUseAbsoluteTolerance(double absoluteTolerance);
00987
00993 void SetKSPSolver(const char* kspSolver, bool warnOfChange=false);
00994
00998 void SetKSPPreconditioner(const char* kspPreconditioner);
00999
01003 void SetMeshPartitioning(const char* meshPartioningMethod);
01004
01011 void SetApdMaps(const std::vector<std::pair<double,double> >& rApdMaps);
01012
01018 void SetUpstrokeTimeMaps(std::vector<double>& rUpstrokeTimeMaps);
01019
01025 void SetMaxUpstrokeVelocityMaps(std::vector<double>& rMaxUpstrokeVelocityMaps);
01026
01031 void SetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps);
01032
01039 void SetRequestedNodalTimeTraces(std::vector<unsigned>& requestedNodes);
01040
01046 template<unsigned SPACE_DIM>
01047 void SetPseudoEcgElectrodePositions(const std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions);
01048
01049
01050
01051
01053 void EnsureOutputVisualizerExists(void);
01054
01059 void SetVisualizeWithMeshalyzer(bool useMeshalyzer=true);
01060
01065 void SetVisualizeWithCmgui(bool useCmgui=true);
01066
01071 void SetVisualizeWithVtk(bool useVtk=true);
01072
01077 void SetVisualizeWithParallelVtk(bool useParallelVtk=true);
01078
01085 void SetVisualizerOutputPrecision(unsigned numberOfDigits);
01086
01096 void SetElectrodeParameters( bool groundSecondElectrode,
01097 unsigned index, double magnitude,
01098 double startTime, double duration );
01099
01106 void SetUseStateVariableInterpolation( bool useStateVariableInterpolation = true);
01107
01113 void SetUseMassLumping(bool useMassLumping = true);
01114
01120 void SetUseMassLumpingForPrecond(bool useMassLumping = true);
01121
01130 void SetUseReactionDiffusionOperatorSplitting(bool useOperatorSplitting = true);
01131
01138 void SetUseFixedNumberIterationsLinearSolver(bool useFixedNumberIterations = true, unsigned evaluateNumItsEveryNSolves=UINT_MAX);
01139
01143 bool HasDrugDose() const;
01144
01148 double GetDrugDose() const;
01149
01153 void SetDrugDose(double drugDose);
01154
01162 void SetIc50Value(const std::string& rCurrentName, double ic50, double hill=1.0);
01163
01169 std::map<std::string, std::pair<double, double> > GetIc50Values();
01170
01171
01172
01173
01174
01178 bool HasPurkinje();
01179
01183 double GetPurkinjeCapacitance();
01184
01189 void SetPurkinjeCapacitance(double capacitance);
01190
01194 double GetPurkinjeSurfaceAreaToVolumeRatio();
01195
01200 void SetPurkinjeSurfaceAreaToVolumeRatio(double ratio);
01201
01205 double GetPurkinjeConductivity();
01206
01211 void SetPurkinjeConductivity(double conductivity);
01212
01213 private:
01214
01215 friend class TestHeartConfig;
01216
01217
01218 HeartConfig();
01219
01221 boost::shared_ptr<cp::chaste_parameters_type> mpParameters;
01222
01224 static std::auto_ptr<HeartConfig> mpInstance;
01225
01229 FileFinder mParametersFilePath;
01230
01235 bool mUseFixedSchemaLocation;
01236
01240 double mEpiFraction;
01241
01245 double mEndoFraction;
01246
01250 double mMidFraction;
01251
01255 unsigned mIndexMid;
01256
01260 unsigned mIndexEpi;
01261
01265 unsigned mIndexEndo;
01266
01270 bool mUserAskedForCellularTransmuralHeterogeneities;
01271
01275 bool mUseMassLumping;
01276
01280 bool mUseMassLumpingForPrecond;
01281
01286 bool mUseReactionDiffusionOperatorSplitting;
01287
01291 std::map<unsigned, double> mBathConductivities;
01292
01296 std::set<unsigned> mTissueIdentifiers;
01297
01301 std::set<unsigned> mBathIdentifiers;
01302
01306 bool mUseFixedNumberIterations;
01307
01313 unsigned mEvaluateNumItsEveryNSolves;
01314
01324 void CheckSimulationIsDefined(std::string callingMethod="") const;
01325
01335 void CheckResumeSimulationIsDefined(std::string callingMethod="") const;
01336 };
01337
01338
01339 BOOST_CLASS_VERSION(HeartConfig, 1)
01340 #include "SerializationExportWrapper.hpp"
01341
01342 CHASTE_CLASS_EXPORT(HeartConfig)
01343
01344 #endif