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 #ifndef HEARTCONFIG_HPP_
00031 #define HEARTCONFIG_HPP_
00032
00033 #include <string>
00034 #include <vector>
00035 #include <set>
00036
00037 #include "UblasIncludes.hpp"
00038
00039 #include "ArchiveLocationInfo.hpp"
00040 #include "ChasteParameters_3_0.hpp"
00041
00042 #include "AbstractStimulusFunction.hpp"
00043
00044 #include "SimpleStimulus.hpp"
00045 #include "RegularStimulus.hpp"
00046
00047 #include "ChastePoint.hpp"
00048 #include "ChasteCuboid.hpp"
00049 #include "ChasteEllipsoid.hpp"
00050 #include "DistributedTetrahedralMeshPartitionType.hpp"
00051
00052 #include <boost/shared_ptr.hpp>
00053
00054 #include "ChasteSerialization.hpp"
00055 #include "ChasteSerializationVersion.hpp"
00056 #include <boost/serialization/split_member.hpp>
00057
00058 namespace cp = chaste::parameters::v3_0;
00059
00060
00061 class HeartFileFinder;
00062
00063
00074 class HeartConfig
00075 {
00076 private:
00083 void CheckTimeSteps() const;
00084
00086 friend class boost::serialization::access;
00093 template<class Archive>
00094 void save(Archive & archive, const unsigned int version) const
00095 {
00096
00097 if (PetscTools::AmMaster())
00098 {
00099 mpInstance->Write( true );
00100 }
00101 PetscTools::Barrier("HeartConfig::save");
00102 }
00103
00110 template<class Archive>
00111 void load(Archive & archive, const unsigned int version)
00112 {
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 assert(mpUserParameters.use_count() > 0);
00123 boost::shared_ptr<cp::chaste_parameters_type> p_new_parameters = mpUserParameters;
00124
00125 std::string defaults_filename_xml = ArchiveLocationInfo::GetArchiveDirectory() + "ChasteDefaults.xml";
00126 HeartConfig::Instance()->SetDefaultsFile(defaults_filename_xml);
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 std::string parameters_filename_xml = ArchiveLocationInfo::GetArchiveDirectory() + "ChasteParameters.xml";
00137 HeartConfig::Instance()->SetParametersFile(parameters_filename_xml);
00138
00139 HeartConfig::Instance()->SetCheckpointSimulation(false);
00140
00141
00142 if (p_new_parameters->ResumeSimulation().present())
00143 {
00144 UpdateParametersFromResumeSimulation(p_new_parameters);
00145 }
00146 }
00147 BOOST_SERIALIZATION_SPLIT_MEMBER()
00148
00149
00155 void UpdateParametersFromResumeSimulation(boost::shared_ptr<cp::chaste_parameters_type> pResumeParameters);
00156
00157 public:
00162 typedef std::map<std::string, std::string> SchemaLocationsMap;
00163
00164 private:
00168 SchemaLocationsMap mSchemaLocations;
00169
00173 void SetDefaultSchemaLocations();
00174
00175 public:
00181 static HeartConfig* Instance();
00182
00188 void SetUseFixedSchemaLocation(bool useFixedSchemaLocation);
00189
00196 void SetFixedSchemaLocations(const SchemaLocationsMap& rSchemaLocations);
00197
00202 void SetDefaultsFile(const std::string& rFileName);
00203
00208 void SetParametersFile(const std::string& rFileName);
00209
00221 void Write(bool useArchiveLocationInfo=false, std::string subfolderName="output");
00222
00228 void CopySchema(const std::string& rToDirectory);
00229
00234 boost::shared_ptr<cp::chaste_parameters_type> ReadFile(const std::string& rFileName);
00235
00240 static void Reset();
00241
00242 ~HeartConfig();
00250 unsigned GetVersionFromNamespace(const std::string& rNamespaceUri);
00251
00253
00254
00255
00257
00262 FileFinder GetParametersFilePath();
00263
00264
00265
00271 bool IsSimulationDefined() const;
00272
00278 bool IsSimulationResumed() const;
00279
00280
00281 unsigned GetSpaceDimension() const;
00282 double GetSimulationDuration() const;
00289 cp::domain_type GetDomain() const;
00290
00298 cp::ionic_model_selection_type GetDefaultIonicModel() const;
00299
00310 template<unsigned DIM>
00311 void GetIonicModelRegions(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rDefinedRegions,
00312 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00313
00325 void SetIonicModelRegions(std::vector<ChasteCuboid<3> >& rDefinedRegions,
00326 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00327
00328 bool IsMeshProvided() const;
00329 bool GetCreateMesh() const;
00330 bool GetCreateSlab() const;
00331 bool GetCreateSheet() const;
00332 bool GetCreateFibre() const;
00333 bool GetLoadMesh() const;
00338 void GetSlabDimensions(c_vector<double, 3>& slabDimensions) const;
00342 void GetSheetDimensions(c_vector<double, 2>& sheetDimensions) const;
00346 void GetFibreLength(c_vector<double, 1>& fibreLength) const;
00347 double GetInterNodeSpace() const;
00349 std::string GetMeshName() const;
00351 cp::media_type GetConductivityMedia() const;
00362 template<unsigned DIM>
00363 void GetStimuli(std::vector<boost::shared_ptr<AbstractStimulusFunction> >& rStimuliApplied,
00364 std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rStimulatedAreas) const;
00365
00381 template<unsigned DIM>
00382 void GetCellHeterogeneities( std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rCellHeterogeneityRegions,
00383 std::vector<double>& rScaleFactorGks,
00384 std::vector<double>& rScaleFactorIto,
00385 std::vector<double>& rScaleFactorGkr,
00386 std::vector<std::map<std::string, double> >* pParameterSettings);
00387
00388 bool GetConductivityHeterogeneitiesProvided() const;
00393 bool AreCellularTransmuralHeterogeneitiesRequested();
00394
00398 double GetEpiLayerFraction();
00399
00403 double GetEndoLayerFraction();
00404
00408 double GetMidLayerFraction();
00409
00413 unsigned GetEpiLayerIndex();
00414
00418 unsigned GetEndoLayerIndex();
00419
00423 unsigned GetMidLayerIndex();
00424
00425
00434 template<unsigned DIM>
00435 void GetConductivityHeterogeneities(std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& conductivitiesHeterogeneityAreas,
00436 std::vector< c_vector<double,3> >& intraConductivities,
00437 std::vector< c_vector<double,3> >& extraConductivities) const;
00438 std::string GetOutputDirectory() const;
00450 std::string GetOutputFilenamePrefix() const;
00451
00455 bool GetOutputVariablesProvided() const;
00456
00463 void GetOutputVariables(std::vector<std::string>& rOutputVariables) const;
00464
00470 bool GetOutputUsingOriginalNodeOrdering();
00471
00477 bool GetCheckpointSimulation() const;
00478
00484 double GetCheckpointTimestep() const;
00485
00491 unsigned GetMaxCheckpointsOnDisk() const;
00492
00493
00497 HeartFileFinder GetArchivedSimulationDir() const;
00498
00499
00500
00505 void GetIntracellularConductivities(c_vector<double, 3>& intraConductivities) const;
00510 void GetIntracellularConductivities(c_vector<double, 2>& intraConductivities) const;
00515 void GetIntracellularConductivities(c_vector<double, 1>& intraConductivities) const;
00516
00521 void GetExtracellularConductivities(c_vector<double, 3>& extraConductivities) const;
00526 void GetExtracellularConductivities(c_vector<double, 2>& extraConductivities) const;
00531 void GetExtracellularConductivities(c_vector<double, 1>& extraConductivities) const;
00532
00540 double GetBathConductivity(unsigned bathRegion=UINT_MAX) const;
00541
00547 const std::set<unsigned>& rGetTissueIdentifiers();
00548
00554 const std::set<unsigned>& rGetBathIdentifiers();
00555
00556
00557 double GetSurfaceAreaToVolumeRatio() const;
00559 double GetCapacitance() const;
00561
00562 double GetOdeTimeStep() const;
00563 double GetPdeTimeStep() const;
00564 double GetPrintingTimeStep() const;
00566 bool GetUseAbsoluteTolerance() const;
00567 double GetAbsoluteTolerance() const;
00569 bool GetUseRelativeTolerance() const;
00570 double GetRelativeTolerance() const;
00572 const char* GetKSPSolver() const;
00573 const char* GetKSPPreconditioner() const;
00575 DistributedTetrahedralMeshPartitionType::type GetMeshPartitioning() const;
00577
00581 bool IsAdaptivityParametersPresent() const;
00582
00586 double GetTargetErrorForAdaptivity() const;
00587
00591 double GetSigmaForAdaptivity() const;
00592
00596 double GetMaxEdgeLengthForAdaptivity() const;
00597
00601 double GetMinEdgeLengthForAdaptivity() const;
00602
00606 double GetGradationForAdaptivity() const;
00607
00611 unsigned GetMaxNodesForAdaptivity() const;
00612
00616 unsigned GetNumberOfAdaptiveSweeps() const;
00617
00618
00622 bool IsPostProcessingSectionPresent() const;
00623
00627 void EnsurePostProcessingSectionPresent();
00628
00632 bool IsPostProcessingRequested() const;
00633
00637 bool IsApdMapsRequested() const;
00638
00644 void GetApdMaps(std::vector<std::pair<double,double> >& rApdMaps) const;
00645
00649 bool IsUpstrokeTimeMapsRequested() const;
00654 void GetUpstrokeTimeMaps (std::vector<double>& rUpstrokeTimeMaps) const;
00655
00659 bool IsMaxUpstrokeVelocityMapRequested() const;
00660
00665 void GetMaxUpstrokeVelocityMaps(std::vector<double>& rUpstrokeVelocityMaps) const;
00666
00670 bool IsConductionVelocityMapsRequested() const;
00671
00676 void GetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps) const;
00677
00681 bool IsAnyNodalTimeTraceRequested() const;
00682
00686 void GetNodalTimeTraceRequested(std::vector<unsigned>& rRequestedNodes) const;
00687
00691 bool IsPseudoEcgCalculationRequested() const;
00692
00697 template<unsigned SPACE_DIM>
00698 void GetPseudoEcgElectrodePositions(std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions) const;
00699
00703 bool GetUseStateVariableInterpolation() const;
00704
00705
00706
00707
00709 bool IsOutputVisualizerPresent() const;
00710
00712 bool GetVisualizeWithMeshalyzer() const;
00713
00715 bool GetVisualizeWithCmgui() const;
00716
00718 bool GetVisualizeWithVtk() const;
00719
00721 bool GetVisualizeWithParallelVtk() const;
00722
00724 unsigned GetVisualizerOutputPrecision();
00725
00726
00730 bool IsElectrodesPresent() const;
00731
00732
00742 void GetElectrodeParameters(bool& rGroundSecondElectrode,
00743 unsigned& rIndex, double& rMagnitude,
00744 double& rStartTime, double& rDuration );
00745
00749 bool GetUseMassLumping();
00750
00754 bool GetUseMassLumpingForPrecond();
00755
00760 bool GetUseReactionDiffusionOperatorSplitting();
00761
00765 bool GetUseFixedNumberIterationsLinearSolver();
00766
00770 unsigned GetEvaluateNumItsEveryNSolves();
00771
00772
00774
00775
00776
00778
00779
00783 void SetSpaceDimension(unsigned spaceDimension);
00784
00789 void SetSimulationDuration(double simulationDuration);
00790
00797 void SetDomain(const cp::domain_type& rDomain);
00798
00806 void SetDefaultIonicModel(const cp::ionic_models_available_type& rIonicModel);
00807
00815 void SetSlabDimensions(double x, double y, double z, double inter_node_space);
00822 void SetSheetDimensions(double x, double y, double inter_node_space);
00828 void SetFibreLength(double x, double inter_node_space);
00829
00836 void SetMeshFileName(std::string meshPrefix, cp::media_type fibreDefinition=cp::media_type::NoFibreOrientation);
00837
00845 void SetConductivityHeterogeneities(std::vector<ChasteCuboid<3> >& rConductivityAreas,
00846 std::vector< c_vector<double,3> >& rIntraConductivities,
00847 std::vector< c_vector<double,3> >& rExtraConductivities);
00855 void SetConductivityHeterogeneitiesEllipsoid(std::vector<ChasteEllipsoid<3> >& conductivityAreas,
00856 std::vector< c_vector<double,3> >& intraConductivities,
00857 std::vector< c_vector<double,3> >& extraConductivities);
00861 void SetOutputDirectory(const std::string& rOutputDirectory);
00872 void SetOutputFilenamePrefix(const std::string& rOutputFilenamePrefix);
00873
00880 void SetOutputVariables(const std::vector<std::string>& rOutputVariables);
00881
00890 void SetOutputUsingOriginalNodeOrdering(bool useOriginal);
00891
00899 void SetCheckpointSimulation(bool checkpointSimulation, double checkpointTimestep=-1.0, unsigned maxCheckpointsOnDisk=UINT_MAX);
00900
00901
00906 void SetIntracellularConductivities(const c_vector<double, 3>& rIntraConductivities);
00911 void SetIntracellularConductivities(const c_vector<double, 2>& rIntraConductivities);
00916 void SetIntracellularConductivities(const c_vector<double, 1>& rIntraConductivities);
00917
00922 void SetExtracellularConductivities(const c_vector<double, 3>& rExtraConductivities);
00927 void SetExtracellularConductivities(const c_vector<double, 2>& rExtraConductivities);
00932 void SetExtracellularConductivities(const c_vector<double, 1>& rExtraConductivities);
00933
00939 void SetBathConductivity(double bathConductivity);
00940
00946 void SetBathMultipleConductivities(std::map<unsigned, double> bathConductivities);
00947
00954 void SetTissueAndBathIdentifiers(const std::set<unsigned>& tissueIds, const std::set<unsigned>& bathIds);
00955
00962
00963
00968 void SetSurfaceAreaToVolumeRatio(double ratio);
00969
00974 void SetCapacitance(double capacitance);
00975
00976
00983 void SetOdePdeAndPrintingTimeSteps(double odeTimeStep, double pdeTimeStep, double printingTimeStep);
00984
00989 void SetOdeTimeStep(double odeTimeStep);
00990
00995 void SetPdeTimeStep(double pdeTimeStep);
00996
01001 void SetPrintingTimeStep(double printingTimeStep);
01002
01006 void SetUseRelativeTolerance(double relativeTolerance);
01007
01011 void SetUseAbsoluteTolerance(double absoluteTolerance);
01012
01016 void SetKSPSolver(const char* kspSolver);
01017
01021 void SetKSPPreconditioner(const char* kspPreconditioner);
01022
01026 void SetMeshPartitioning(const char* meshPartioningMethod);
01027
01039 void SetAdaptivityParameters(double targetError, double sigma, double maxEdgeLength, double minEdgeLength,
01040 double gradation, unsigned maxNodes, unsigned numSweeps );
01041
01047 void SetTargetErrorForAdaptivity(double targetError);
01048
01054 void SetSigmaForAdaptivity(double sigma);
01055
01061 void SetMaxEdgeLengthForAdaptivity(double maxEdgeLength);
01062
01068 void SetMinEdgeLengthForAdaptivity(double minEdgeLength);
01069
01075 void SetGradationForAdaptivity(double gradation);
01076
01082 void SetMaxNodesForAdaptivity(unsigned maxNodes);
01083
01089 void SetNumberOfAdaptiveSweeps(unsigned numSweeps);
01090
01097 void SetApdMaps(const std::vector<std::pair<double,double> >& rApdMaps);
01098
01104 void SetUpstrokeTimeMaps(std::vector<double>& rUpstrokeTimeMaps);
01105
01111 void SetMaxUpstrokeVelocityMaps(std::vector<double>& rMaxUpstrokeVelocityMaps);
01112
01117 void SetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps);
01118
01125 void SetRequestedNodalTimeTraces(std::vector<unsigned>& requestedNodes);
01126
01132 template<unsigned SPACE_DIM>
01133 void SetPseudoEcgElectrodePositions(const std::vector<ChastePoint<SPACE_DIM> >& rPseudoEcgElectrodePositions);
01134
01135
01136
01137
01139 void EnsureOutputVisualizerExists(void);
01140
01145 void SetVisualizeWithMeshalyzer(bool useMeshalyzer=true);
01146
01151 void SetVisualizeWithCmgui(bool useCmgui=true);
01152
01157 void SetVisualizeWithVtk(bool useVtk=true);
01158
01163 void SetVisualizeWithParallelVtk(bool useParallelVtk=true);
01164
01171 void SetVisualizerOutputPrecision(unsigned numberOfDigits);
01172
01182 void SetElectrodeParameters( bool groundSecondElectrode,
01183 unsigned index, double magnitude,
01184 double startTime, double duration );
01185
01192 void SetUseStateVariableInterpolation( bool useStateVariableInterpolation = true);
01193
01199 void SetUseMassLumping(bool useMassLumping = true);
01200
01206 void SetUseMassLumpingForPrecond(bool useMassLumping = true);
01207
01216 void SetUseReactionDiffusionOperatorSplitting(bool useOperatorSplitting = true);
01217
01224 void SetUseFixedNumberIterationsLinearSolver(bool useFixedNumberIterations = true, unsigned evaluateNumItsEveryNSolves=UINT_MAX);
01225
01229 bool HasDrugDose() const;
01230
01234 double GetDrugDose() const;
01235
01239 void SetDrugDose(double drugDose);
01240
01248 void SetIc50Value(const std::string& rCurrentName, double ic50, double hill=1.0);
01249
01255 std::map<std::string, std::pair<double, double> > GetIc50Values();
01256
01257 private:
01258
01259 friend class TestHeartConfig;
01260
01261
01262 HeartConfig();
01263
01267 boost::shared_ptr<cp::chaste_parameters_type> mpUserParameters;
01268
01272 boost::shared_ptr<cp::chaste_parameters_type> mpDefaultParameters;
01273
01275 static std::auto_ptr<HeartConfig> mpInstance;
01276
01280 FileFinder mParametersFilePath;
01281
01286 bool mUseFixedSchemaLocation;
01287
01291 double mEpiFraction;
01292
01296 double mEndoFraction;
01297
01301 double mMidFraction;
01302
01306 unsigned mIndexMid;
01307
01311 unsigned mIndexEpi;
01312
01316 unsigned mIndexEndo;
01317
01321 bool mUserAskedForCellularTransmuralHeterogeneities;
01322
01326 bool mUseMassLumping;
01327
01331 bool mUseMassLumpingForPrecond;
01332
01337 bool mUseReactionDiffusionOperatorSplitting;
01338
01342 std::map<unsigned, double> mBathConductivities;
01343
01347 std::set<unsigned> mTissueIdentifiers;
01348
01352 std::set<unsigned> mBathIdentifiers;
01353
01357 bool mUseFixedNumberIterations;
01358
01364 unsigned mEvaluateNumItsEveryNSolves;
01365
01375 template<class TYPE>
01376 TYPE* DecideLocation(TYPE* params_ptr, TYPE* defaults_ptr, const std::string& rNameParameter) const;
01377
01387 void CheckSimulationIsDefined(std::string callingMethod="") const;
01388
01398 void CheckResumeSimulationIsDefined(std::string callingMethod="") const;
01399 };
01400
01401
01402 BOOST_CLASS_VERSION(HeartConfig, 1)
01403 #include "SerializationExportWrapper.hpp"
01404
01405 CHASTE_CLASS_EXPORT(HeartConfig)
01406
01407 #endif