Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
ActivationOutputModifier.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "ActivationOutputModifier.hpp"
37#include "OutputFileHandler.hpp"
38#include "HeartConfig.hpp"
39
40void ActivationOutputModifier::InitialiseAtStart(DistributedVectorFactory* pVectorFactory, const std::vector<unsigned>& rNodePermutation)
41{
42 mLocalSize = pVectorFactory->GetLocalOwnership();
44 mFirstRecoveryTimes.resize(mLocalSize, -1.0);
46 mSecondRecoveryTimes.resize(mLocalSize, -1.0);
47}
48
50{
51 //Dump out all data in a round-robin fashion
52 OutputFileHandler output_handler(HeartConfig::Instance()->GetOutputDirectory(), false);
53
54 // Belt and braces
55 std::stringstream filepath_process_specific;
56 filepath_process_specific << mFilename << "." << PetscTools::GetMyRank();
57 out_stream file_stream_process_specific = output_handler.OpenOutputFile(filepath_process_specific.str().c_str());
58 for (unsigned i=0; i<mLocalSize; i++)
59 {
60 (*file_stream_process_specific) << mFirstActivitationTimes[i] <<",\t"
61 << mFirstRecoveryTimes[i] <<",\t"
62 << mSecondActivitationTimes[i] <<",\t"
63 << mSecondRecoveryTimes[i] <<"\n";
64 }
65 file_stream_process_specific->close();
66
68 {
69 out_stream file_stream = out_stream(NULL);
70 // Open the file as new or append
72 {
73 file_stream = output_handler.OpenOutputFile(mFilename);
74 }
75 else
76 {
77 file_stream = output_handler.OpenOutputFile(mFilename, std::ios::app);
78 }
79 for (unsigned i=0; i<mLocalSize; i++)
80 {
81 (*file_stream) << mFirstActivitationTimes[i] <<",\t"
82 << mFirstRecoveryTimes[i] <<",\t"
83 << mSecondActivitationTimes[i] <<",\t"
84 << mSecondRecoveryTimes[i] <<"\n";
85 }
86 file_stream->close();
87 }
89}
90
91void ActivationOutputModifier::ProcessSolutionAtTimeStep(double time, Vec solution, unsigned problemDim)
92{
93 double* p_solution;
94 VecGetArray(solution, &p_solution);
95 for (unsigned local_index=0; local_index < mLocalSize; local_index++)
96 {
97 double v = p_solution[local_index*problemDim];
98 if (v > mThreshold && mFirstActivitationTimes[local_index] < 0.0)
99 {
100 mFirstActivitationTimes[local_index] = time;
101 }
102// LCOV_EXCL_START // Continuous tests are not long enough to allow recover
103 else if (mFirstActivitationTimes[local_index] >= 0.0 && mFirstRecoveryTimes[local_index] < 0.0 && v < mThreshold)
104 {
106 mFirstRecoveryTimes[local_index] = time;
107 }
108 else if (mFirstRecoveryTimes[local_index] >= 0.0 && mSecondActivitationTimes[local_index] < 0.0 && v > mThreshold)
109 {
110 mSecondActivitationTimes[local_index] = time;
111 }
112 else if (mSecondActivitationTimes[local_index] >= 0.0 && mSecondRecoveryTimes[local_index] < 0.0 && v < mThreshold)
113 {
114 mSecondRecoveryTimes[local_index] = time;
115 }
116// LCOV_EXCL_STOP // Continuous tests are not long enough to allow recover
117 }
118 VecRestoreArray(solution, &p_solution);
119}
120
#define CHASTE_CLASS_EXPORT(T)
virtual void InitialiseAtStart(DistributedVectorFactory *pVectorFactory, const std::vector< unsigned > &rNodePermutation)
virtual void ProcessSolutionAtTimeStep(double time, Vec solution, unsigned problemDim)
std::vector< double > mSecondRecoveryTimes
std::vector< double > mSecondActivitationTimes
std::vector< double > mFirstRecoveryTimes
std::vector< double > mFirstActivitationTimes
static HeartConfig * Instance()
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
static bool AmMaster()
static void EndRoundRobin()
static unsigned GetMyRank()
static void BeginRoundRobin()