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
00036 #include "UblasIncludes.hpp"
00037
00038 #include "ArchiveLocationInfo.hpp"
00039 #include "ChasteParameters_2_1.hpp"
00040
00041 #include "AbstractStimulusFunction.hpp"
00042
00043 #include "SimpleStimulus.hpp"
00044 #include "RegularStimulus.hpp"
00045
00046 #include "ChasteCuboid.hpp"
00047 #include "ChasteEllipsoid.hpp"
00048 #include "AbstractTetrahedralMesh.hpp"
00049
00050 #include <xercesc/dom/DOM.hpp>
00051 #include <xercesc/dom/DOMDocument.hpp>
00052 #include <xercesc/dom/DOMElement.hpp>
00053
00054
00055 #include <boost/shared_ptr.hpp>
00056
00057 #include "ChasteSerialization.hpp"
00058 #include <boost/serialization/split_member.hpp>
00059
00060 namespace cp = chaste::parameters::v2_1;
00061
00062
00063 class HeartFileFinder;
00064
00065
00076 class HeartConfig
00077 {
00078 private:
00085 void CheckTimeSteps() const;
00086
00088 friend class boost::serialization::access;
00095 template<class Archive>
00096 void save(Archive & archive, const unsigned int version) const
00097 {
00098
00099 if (PetscTools::AmMaster())
00100 {
00101 mpInstance->Write( true );
00102 }
00103 PetscTools::Barrier("HeartConfig::save");
00104 }
00105
00112 template<class Archive>
00113 void load(Archive & archive, const unsigned int version)
00114 {
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 assert(mpUserParameters.use_count() > 0);
00125 boost::shared_ptr<cp::chaste_parameters_type> p_new_parameters = mpUserParameters;
00126
00127 std::string defaults_filename_xml = ArchiveLocationInfo::GetArchiveDirectory() + "ChasteDefaults.xml";
00128 HeartConfig::Instance()->SetDefaultsFile(defaults_filename_xml);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 std::string parameters_filename_xml = ArchiveLocationInfo::GetArchiveDirectory() + "ChasteParameters.xml";
00139 HeartConfig::Instance()->SetParametersFile(parameters_filename_xml);
00140
00141 HeartConfig::Instance()->SetCheckpointSimulation(false);
00142
00143
00144 if (p_new_parameters->ResumeSimulation().present())
00145 {
00146 UpdateParametersFromResumeSimulation(p_new_parameters);
00147 }
00148 }
00149 BOOST_SERIALIZATION_SPLIT_MEMBER()
00150
00151
00157 void UpdateParametersFromResumeSimulation(boost::shared_ptr<cp::chaste_parameters_type> pResumeParameters);
00158
00159 public:
00164 typedef std::map<std::string, std::string> SchemaLocationsMap;
00165
00166 private:
00170 SchemaLocationsMap mSchemaLocations;
00171
00175 void SetDefaultSchemaLocations();
00176
00184 std::string EscapeSpaces(const std::string& rPath);
00185
00186 public:
00192 static HeartConfig* Instance();
00193
00199 void SetUseFixedSchemaLocation(bool useFixedSchemaLocation);
00200
00207 void SetFixedSchemaLocations(const SchemaLocationsMap& rSchemaLocations);
00208
00213 void SetDefaultsFile(const std::string& rFileName);
00214
00219 void SetParametersFile(const std::string& rFileName);
00220
00232 void Write(bool useArchiveLocationInfo=false, std::string subfolderName="output");
00233
00239 void CopySchema(const std::string& rToDirectory);
00240
00245 boost::shared_ptr<cp::chaste_parameters_type> ReadFile(const std::string& rFileName);
00246
00251 static void Reset();
00252
00253 ~HeartConfig();
00261 unsigned GetVersionFromNamespace(const std::string& rNamespaceUri);
00262
00263
00264
00265
00266
00267
00273 bool IsSimulationDefined() const;
00274
00280 bool IsSimulationResumed() const;
00281
00282
00283 unsigned GetSpaceDimension() const;
00284 double GetSimulationDuration() const;
00291 cp::domain_type GetDomain() const;
00292
00300 cp::ionic_model_selection_type GetDefaultIonicModel() const;
00301
00312 template<unsigned DIM>
00313 void GetIonicModelRegions(std::vector<ChasteCuboid<DIM> >& rDefinedRegions,
00314 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00315
00327 void SetIonicModelRegions(std::vector<ChasteCuboid<3> >& rDefinedRegions,
00328 std::vector<cp::ionic_model_selection_type>& rIonicModels) const;
00329
00330 bool IsMeshProvided() const;
00331 bool GetCreateMesh() const;
00332 bool GetCreateSlab() const;
00333 bool GetCreateSheet() const;
00334 bool GetCreateFibre() const;
00335 bool GetLoadMesh() const;
00336
00337
00340 void GetSlabDimensions(c_vector<double, 3>& slabDimensions) const;
00344 void GetSheetDimensions(c_vector<double, 2>& sheetDimensions) const;
00348 void GetFibreLength(c_vector<double, 1>& fibreLength) const;
00349 double GetInterNodeSpace() const;
00351 std::string GetMeshName() const;
00353 cp::media_type GetConductivityMedia() const;
00364 template<unsigned DIM>
00365 void GetStimuli(std::vector<boost::shared_ptr<AbstractStimulusFunction> >& rStimuliApplied, std::vector<ChasteCuboid<DIM> >& rStimulatedAreas) const;
00366
00382 template<unsigned DIM>
00383 void GetCellHeterogeneities( std::vector<AbstractChasteRegion<DIM>* >& rCellHeterogeneityRegions,
00384 std::vector<double>& rScaleFactorGks,
00385 std::vector<double>& rScaleFactorIto,
00386 std::vector<double>& rScaleFactorGkr,
00387 std::vector<std::map<std::string, double> >* pParameterSettings);
00388
00389 bool GetConductivityHeterogeneitiesProvided() const;
00394 bool AreCellularTransmuralHeterogeneitiesRequested();
00395
00399 bool AreCellularHeterogeneitiesSpecifiedByCuboids();
00400
00404 double GetEpiLayerFraction();
00405
00409 double GetEndoLayerFraction();
00410
00414 double GetMidLayerFraction();
00415
00419 unsigned GetEpiLayerIndex();
00420
00424 unsigned GetEndoLayerIndex();
00425
00429 unsigned GetMidLayerIndex();
00430
00431
00440 template<unsigned DIM>
00441 void GetConductivityHeterogeneities(std::vector<AbstractChasteRegion<DIM>* >& conductivitiesHeterogeneityAreas,
00442 std::vector< c_vector<double,3> >& intraConductivities,
00443 std::vector< c_vector<double,3> >& extraConductivities) const;
00444 std::string GetOutputDirectory() const;
00456 std::string GetOutputFilenamePrefix() const;
00457
00461 bool GetOutputVariablesProvided() const;
00462
00469 void GetOutputVariables(std::vector<std::string>& rOutputVariables) const;
00470
00476 bool GetOutputUsingOriginalNodeOrdering();
00477
00483 bool GetCheckpointSimulation() const;
00484
00490 double GetCheckpointTimestep() const;
00491
00497 unsigned GetMaxCheckpointsOnDisk() const;
00498
00499
00503 HeartFileFinder GetArchivedSimulationDir() const;
00504
00505
00506
00511 void GetIntracellularConductivities(c_vector<double, 3>& intraConductivities) const;
00516 void GetIntracellularConductivities(c_vector<double, 2>& intraConductivities) const;
00521 void GetIntracellularConductivities(c_vector<double, 1>& intraConductivities) const;
00522
00527 void GetExtracellularConductivities(c_vector<double, 3>& extraConductivities) const;
00532 void GetExtracellularConductivities(c_vector<double, 2>& extraConductivities) const;
00537 void GetExtracellularConductivities(c_vector<double, 1>& extraConductivities) const;
00538
00539 double GetBathConductivity() const;
00542 double GetSurfaceAreaToVolumeRatio() const;
00544 double GetCapacitance() const;
00546
00547 double GetOdeTimeStep() const;
00548 double GetPdeTimeStep() const;
00549 double GetPrintingTimeStep() const;
00551 bool GetUseAbsoluteTolerance() const;
00552 double GetAbsoluteTolerance() const;
00554 bool GetUseRelativeTolerance() const;
00555 double GetRelativeTolerance() const;
00557 const char* GetKSPSolver() const;
00558 const char* GetKSPPreconditioner() const;
00561
00565 bool IsAdaptivityParametersPresent() const;
00566
00570 double GetTargetErrorForAdaptivity() const;
00571
00575 double GetSigmaForAdaptivity() const;
00576
00580 double GetMaxEdgeLengthForAdaptivity() const;
00581
00585 double GetMinEdgeLengthForAdaptivity() const;
00586
00590 double GetGradationForAdaptivity() const;
00591
00595 unsigned GetMaxNodesForAdaptivity() const;
00596
00600 unsigned GetNumberOfAdaptiveSweeps() const;
00601
00602
00606 bool IsPostProcessingSectionPresent() const;
00607
00611 void EnsurePostProcessingSectionPresent();
00612
00616 bool IsPostProcessingRequested() const;
00617
00621 bool IsApdMapsRequested() const;
00627 void GetApdMaps(std::vector<std::pair<double,double> >& rApdMaps) const;
00628
00632 bool IsUpstrokeTimeMapsRequested() const;
00637 void GetUpstrokeTimeMaps (std::vector<double>& rUpstrokeTimeMaps) const;
00638
00642 bool IsMaxUpstrokeVelocityMapRequested() const;
00643
00648 void GetMaxUpstrokeVelocityMaps(std::vector<double>& rUpstrokeVelocityMaps) const;
00649
00653 bool IsConductionVelocityMapsRequested() const;
00654
00659 void GetConductionVelocityMaps(std::vector<unsigned>& rConductionVelocityMaps) const;
00660
00661
00662
00663
00665 bool IsOutputVisualizerPresent() const;
00666
00668 bool GetVisualizeWithMeshalyzer() const;
00669
00671 bool GetVisualizeWithCmgui() const;
00672
00674 bool GetVisualizeWithVtk() const;
00675
00679 bool IsElectrodesPresent() const;
00680
00681
00682
00683
00684
00685
00689 void SetSpaceDimension(unsigned spaceDimension);
00690
00694 void SetSimulationDuration(double simulationDuration);
00695
00702 void SetDomain(const cp::domain_type& rDomain);
00703
00711 void SetDefaultIonicModel(const cp::ionic_models_available_type& rIonicModel);
00712
00720 void SetSlabDimensions(double x, double y, double z, double inter_node_space);
00727 void SetSheetDimensions(double x, double y, double inter_node_space);
00733 void SetFibreLength(double x, double inter_node_space);
00734
00741 void SetMeshFileName(std::string meshPrefix, cp::media_type fibreDefinition=cp::media_type::NoFibreOrientation);
00742
00750 void SetConductivityHeterogeneities(std::vector<ChasteCuboid<3> >& rConductivityAreas,
00751 std::vector< c_vector<double,3> >& rIntraConductivities,
00752 std::vector< c_vector<double,3> >& rExtraConductivities);
00760 void SetConductivityHeterogeneitiesEllipsoid(std::vector<ChasteEllipsoid<3> >& conductivityAreas,
00761 std::vector< c_vector<double,3> >& intraConductivities,
00762 std::vector< c_vector<double,3> >& extraConductivities);
00766 void SetOutputDirectory(const std::string& rOutputDirectory);
00777 void SetOutputFilenamePrefix(const std::string& rOutputFilenamePrefix);
00778
00790 void SetOutputVariables(const std::vector<std::string>& rOutputVariables);
00791
00800 void SetOutputUsingOriginalNodeOrdering(bool useOriginal);
00801
00809 void SetCheckpointSimulation(bool checkpointSimulation, double checkpointTimestep=-1.0, unsigned maxCheckpointsOnDisk=UINT_MAX);
00810
00811
00812
00817 void SetIntracellularConductivities(const c_vector<double, 3>& rIntraConductivities);
00822 void SetIntracellularConductivities(const c_vector<double, 2>& rIntraConductivities);
00827 void SetIntracellularConductivities(const c_vector<double, 1>& rIntraConductivities);
00828
00833 void SetExtracellularConductivities(const c_vector<double, 3>& rExtraConductivities);
00838 void SetExtracellularConductivities(const c_vector<double, 2>& rExtraConductivities);
00843 void SetExtracellularConductivities(const c_vector<double, 1>& rExtraConductivities);
00844
00850 void SetBathConductivity(double bathConductivity);
00851
00856 void SetSurfaceAreaToVolumeRatio(double ratio);
00857
00862 void SetCapacitance(double capacitance);
00863
00864
00871 void SetOdePdeAndPrintingTimeSteps(double odeTimeStep, double pdeTimeStep, double printingTimeStep);
00872
00877 void SetOdeTimeStep(double odeTimeStep);
00878
00883 void SetPdeTimeStep(double pdeTimeStep);
00884
00889 void SetPrintingTimeStep(double printingTimeStep);
00890
00894 void SetUseRelativeTolerance(double relativeTolerance);
00895
00899 void SetUseAbsoluteTolerance(double absoluteTolerance);
00900
00904 void SetKSPSolver(const char* kspSolver);
00905
00909 void SetKSPPreconditioner(const char* kspPreconditioner);
00910
00922 void SetAdaptivityParameters(double targetError, double sigma, double maxEdgeLength, double minEdgeLength,
00923 double gradation, unsigned maxNodes, unsigned numSweeps );
00924
00930 void SetTargetErrorForAdaptivity(double targetError);
00931
00937 void SetSigmaForAdaptivity(double sigma);
00938
00944 void SetMaxEdgeLengthForAdaptivity(double maxEdgeLength);
00945
00951 void SetMinEdgeLengthForAdaptivity(double minEdgeLength);
00952
00958 void SetGradationForAdaptivity(double gradation);
00959
00965 void SetMaxNodesForAdaptivity(unsigned maxNodes);
00966
00972 void SetNumberOfAdaptiveSweeps(unsigned numSweeps);
00973
00980 void SetApdMaps(const std::vector<std::pair<double,double> >& rApdMaps);
00981
00986 void SetUpstrokeTimeMaps (std::vector<double>& rUpstrokeTimeMaps);
00987
00992 void SetMaxUpstrokeVelocityMaps (std::vector<double>& rMaxUpstrokeVelocityMaps);
00993
00998 void SetConductionVelocityMaps (std::vector<unsigned>& rConductionVelocityMaps);
00999
01000
01001
01002
01004 void EnsureOutputVisualizerExists(void);
01005
01010 void SetVisualizeWithMeshalyzer(bool useMeshalyzer=true);
01011
01016 void SetVisualizeWithCmgui(bool useCmgui=true);
01017
01022 void SetVisualizeWithVtk(bool useVtk=true);
01023
01033 void SetElectrodeParameters( bool groundSecondElectrode,
01034 unsigned index, double magnitude,
01035 double startTime, double duration );
01036
01046 void GetElectrodeParameters(bool& rGroundSecondElectrode,
01047 unsigned& rIndex, double& rMagnitude,
01048 double& rStartTime, double& rDuration );
01049
01050
01051 private:
01052
01053 friend class TestHeartConfig;
01054
01055
01056 HeartConfig();
01057
01061 boost::shared_ptr<cp::chaste_parameters_type> mpUserParameters;
01065 boost::shared_ptr<cp::chaste_parameters_type> mpDefaultParameters;
01066
01068 static std::auto_ptr<HeartConfig> mpInstance;
01069
01074 bool mUseFixedSchemaLocation;
01075
01079 double mEpiFraction;
01080
01084 double mEndoFraction;
01085
01089 double mMidFraction;
01090
01094 unsigned mIndexMid;
01095
01099 unsigned mIndexEpi;
01100
01104 unsigned mIndexEndo;
01105
01109 bool mUserAskedForCellularTransmuralHeterogeneities;
01110
01114 bool mUserAskedForCuboidsForCellularHeterogeneities;
01115
01125 template<class TYPE>
01126 TYPE* DecideLocation(TYPE* params_ptr, TYPE* defaults_ptr, const std::string& rNameParameter) const;
01127
01137 void CheckSimulationIsDefined(std::string callingMethod="") const;
01138
01148 void CheckResumeSimulationIsDefined(std::string callingMethod="") const;
01149
01150 };
01151
01152 #include "SerializationExportWrapper.hpp"
01153
01154 CHASTE_CLASS_EXPORT(HeartConfig)
01155
01156 #endif