36 #include "AbstractCardiacProblem.hpp" 38 #include "GenericMeshReader.hpp" 40 #include "HeartConfig.hpp" 41 #include "HeartEventHandler.hpp" 42 #include "TimeStepper.hpp" 44 #include "DistributedVector.hpp" 45 #include "ProgressReporter.hpp" 46 #include "LinearSystem.hpp" 47 #include "PostProcessingWriter.hpp" 48 #include "Hdf5ToMeshalyzerConverter.hpp" 49 #include "Hdf5ToCmguiConverter.hpp" 50 #include "Hdf5ToVtkConverter.hpp" 53 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
57 mAllocatedMemoryForMesh(false),
60 mpCardiacTissue(NULL),
62 mpCellFactory(pCellFactory),
66 mpTimeAdaptivityController(NULL),
68 mUseHdf5DataWriterCache(false),
69 mHdf5DataWriterChunkSizeAndAlignment(0)
74 EXCEPTION(
"AbstractCardiacProblem: Please supply a cell factory pointer to your cardiac problem constructor.");
79 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
103 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
118 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
126 WARNING(
"Using a non-distributed mesh in a parallel simulation is not a good idea.");
137 std::shared_ptr<AbstractMeshReader<ELEMENT_DIM, SPACE_DIM> > p_mesh_reader
139 mpMesh->ConstructFromMeshReader(*p_mesh_reader);
151 c_vector<double, 1> fibre_length;
153 mpMesh->ConstructRegularSlabMesh(inter_node_space, fibre_length[0]);
158 c_vector<double, 2> sheet_dimensions;
160 mpMesh->ConstructRegularSlabMesh(inter_node_space, sheet_dimensions[0], sheet_dimensions[1]);
165 c_vector<double, 3> slab_dimensions;
167 mpMesh->ConstructRegularSlabMesh(inter_node_space, slab_dimensions[0], slab_dimensions[1], slab_dimensions[2]);
183 EXCEPTION(std::string(
"No mesh given: define it in XML parameters file or call SetMesh()\n") + e.
GetShortMessage());
218 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
224 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
230 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
235 EXCEPTION(
"Cardiac tissue is null, Initialise() probably hasn't been called");
239 EXCEPTION(
"End time should be in the future");
245 EXCEPTION(
"Either explicitly specify not to print output (call PrintOutput(false)) or specify the output directory and filename prefix");
260 if (fabs(end_time - pde_time*round(end_time/pde_time)) > 1e-10)
262 EXCEPTION(
"PDE timestep does not seem to divide end time - check parameters");
266 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
270 Vec initial_condition = p_factory->
CreateVec(PROBLEM_DIM);
272 std::vector<DistributedVector::Stripe> stripe;
273 stripe.reserve(PROBLEM_DIM);
275 for (
unsigned i=0; i<PROBLEM_DIM; i++)
284 stripe[0][index] =
mpCardiacTissue->GetCardiacCell(index.Global)->GetVoltage();
287 stripe[1][index] = 0;
293 return initial_condition;
296 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
304 assert(pMesh != NULL);
309 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
315 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
321 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
327 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
330 return mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(
mSolution);
333 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
339 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
346 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
351 EXCEPTION(
"Tissue not yet set up, you may need to call Initialise() before GetTissue().");
356 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
372 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
377 std::vector<double> additional_stopping_times;
384 additional_stopping_times);
393 for (
unsigned problem_index=0; problem_index<PROBLEM_DIM; problem_index++)
404 Vec initial_condition;
414 std::string progress_reporter_dir;
419 bool extending_file =
false;
460 progress_reporter_dir =
"";
462 BOOST_FOREACH(boost::shared_ptr<AbstractOutputModifier> p_output_modifier,
mOutputModifiers)
464 p_output_modifier->InitialiseAtStart(this->
mpMesh->GetDistributedVectorFactory());
465 p_output_modifier->ProcessSolutionAtTimeStep(stepper.
GetTime(), initial_condition, PROBLEM_DIM);
489 mpSolver->SetInitialCondition( initial_condition );
555 BOOST_FOREACH(boost::shared_ptr<AbstractOutputModifier> p_output_modifier,
mOutputModifiers)
557 p_output_modifier->ProcessSolutionAtTimeStep(stepper.
GetTime(),
mSolution, PROBLEM_DIM);
581 BOOST_FOREACH(boost::shared_ptr<AbstractOutputModifier> p_output_modifier,
mOutputModifiers)
583 p_output_modifier->FinaliseAtEnd();
589 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
686 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
717 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
725 std::vector<std::string> output_variables;
727 const unsigned num_vars = output_variables.size();
731 for (
unsigned var_index=0; var_index<num_vars; var_index++)
734 std::string var_name = output_variables[var_index];
755 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
759 std::vector<std::string> output_variables;
765 assert(output_variables.size() == num_vars);
768 for (
unsigned var_index=0; var_index<num_vars; var_index++)
771 Vec variable_data = this->
mpMesh->GetDistributedVectorFactory()->CreateVec();
772 DistributedVector distributed_var_data = this->
mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(variable_data);
776 index!= distributed_var_data.
End();
784 distributed_var_data[index] = 0.0;
789 distributed_var_data[index] = this->
mpCardiacTissue->GetCardiacCell(index.Global)->
790 GetAnyVariable(output_variables[var_index],
mCurrentTime);
793 distributed_var_data.
Restore();
802 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
834 ", but it already contains results up to time = " << times.back() <<
"." 835 " Calling HeartConfig::Instance()->SetOutputDirectory() before Solve() will direct results elsewhere.");
868 if (success ==
false)
883 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
889 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
895 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
901 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
906 EXCEPTION(
"Data reader invalid as data writer cannot be initialised");
911 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
917 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
virtual void WriteOneStep(double time, Vec voltageVec)=0
BccType mpDefaultBoundaryConditionsContainer
bool ApplyPermutation(const std::vector< unsigned > &rPermutation, bool unsafeExtendingMode=false)
void WritePostProcessingFiles()
std::string GetOutputFilenamePrefix() const
double GetSimulationDuration() const
static bool IsRegionBath(HeartRegionType regionId)
Hdf5DataWriter * mpWriter
std::vector< boost::shared_ptr< AbstractOutputModifier > > mOutputModifiers
std::string mMeshFilename
unsigned mVoltageColumnId
void PrintOutput(bool rPrintOutput)
int GetVariableByName(const std::string &rVariableName)
void Update(double currentTime)
std::string GetAbsolutePath() const
DistributedVector CreateDistributedVector(Vec vec, bool readOnly=false)
void Write(bool useArchiveLocationInfo=false, std::string subfolderName="output")
void GetSlabDimensions(c_vector< double, 3 > &slabDimensions) const
hsize_t mHdf5DataWriterChunkSizeAndAlignment
#define EXCEPTION(message)
static void BeginEvent(unsigned event)
virtual Vec CreateInitialCondition()
virtual void CreateMeshFromHeartConfig()
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
void SetOutputUsingOriginalNodeOrdering(bool useOriginal)
void GetOutputVariables(std::vector< std::string > &rOutputVariables) const
DistributedTetrahedralMeshPartitionType::type GetMeshPartitioning() const
std::vector< unsigned > mExtraVariablesId
AbstractTimeAdaptivityController * mpTimeAdaptivityController
virtual void SetUpAdditionalStoppingTimes(std::vector< double > &rAdditionalStoppingTimes)
virtual void PreSolveChecks()
double GetPdeTimeStep() const
std::string GetMeshName() const
void GetFibreLength(c_vector< double, 1 > &fibreLength) const
void SetTargetChunkSize(hsize_t targetSize)
void AdvanceOneTimeStep()
void CloseFilesAndPostProcess()
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
void SetHdf5DataWriterTargetChunkSizeAndAlignment(hsize_t size)
bool mAllocatedMemoryForMesh
void GetSheetDimensions(c_vector< double, 2 > &sheetDimensions) const
Hdf5DataReader GetDataReader()
void SetUseTimeAdaptivityController(bool useAdaptivity, AbstractTimeAdaptivityController *pController=NULL)
virtual void WriteInfo(double time)=0
BccType mpBoundaryConditionsContainer
AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * GetTissue()
void AdvanceAlongUnlimitedDimension()
std::vector< double > GetUnlimitedDimensionValues()
int DefineVariable(const std::string &rVariableName, const std::string &rVariableUnits)
std::vector< unsigned > mNodesToOutput
virtual void OnEndOfTimestep(double time)
std::string GetSubdirectory()
void PutVector(int variableID, Vec petscVector)
unsigned EstimateTimeSteps() const
void SetMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)
double GetInterNodeSpace() const
void SetUseHdf5DataWriterCache(bool useCache=true)
AbstractCardiacCellFactory< ELEMENT_DIM, SPACE_DIM > * mpCellFactory
bool mUseHdf5DataWriterCache
virtual bool GetHasBath()
void DefineFixedDimension(long dimensionSize)
void SetOutputNodes(std::vector< unsigned > &rNodesToOutput)
AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM > * mpSolver
virtual void DefineWriterColumns(bool extending)
virtual ~AbstractCardiacProblem()
virtual AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * CreateCardiacTissue()=0
void SetBoundaryConditionsContainer(BccType pBcc)
virtual void SetElectrodes()
bool GetVisualizeWithMeshalyzer() const
void SetAlignment(hsize_t alignment)
std::string GetOutputDirectory() const
AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * mpCardiacTissue
static void EndEvent(unsigned event)
static std::string GetChasteTestOutputDirectory()
double GetNextTime() const
void SetWriteInfo(bool writeInfo=true)
virtual AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM > * CreateSolver()=0
void WriteExtraVariablesOneStep()
DistributedVector GetSolutionDistributedVector()
std::string GetShortMessage() const
static HeartConfig * Instance()
virtual void AtBeginningOfTimestep(double time)
void DefineExtraVariablesWriterColumns(bool extending)
virtual void EndDefineMode()
void DefineUnlimitedDimension(const std::string &rVariableName, const std::string &rVariableUnits, unsigned estimatedLength=1)