PostProcessingWriter.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "UblasCustomFunctions.hpp"
00030 #include "HeartConfig.hpp"
00031 #include "PostProcessingWriter.hpp"
00032 #include "PetscTools.hpp"
00033 #include "OutputFileHandler.hpp"
00034 #include <iostream>
00035 
00036 PostProcessingWriter::PostProcessingWriter(Hdf5DataReader* pDataReader)
00037 {
00038     mpCalculator = new PropagationPropertiesCalculator(pDataReader);
00039     mNumberOfNodes = pDataReader->GetNumberOfRows();
00040 }
00041     
00042 PostProcessingWriter::~PostProcessingWriter()
00043 {
00044     delete mpCalculator;
00045 }
00046 
00047 
00048 void PostProcessingWriter::WriteApdMapFile(double threshold, double repolarisationPercentage)
00049 {
00050     OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00051     if(PetscTools::AmMaster())
00052     {
00053         out_stream p_file=out_stream(NULL);
00054         std::stringstream stream;
00055         stream << repolarisationPercentage;
00056         p_file = output_file_handler.OpenOutputFile("Apd" + stream.str() + "Map.dat");
00057         for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00058         { 
00059             std::vector<double> apds;
00060             try
00061             {
00062                 apds = mpCalculator->CalculateAllActionPotentialDurations(repolarisationPercentage, node_index, threshold);
00063                 assert(apds.size() != 0);
00064             }
00065             catch(Exception& e)
00066             {                    
00067                 apds.push_back(0);
00068                 assert(apds.size() == 1);
00069             }
00070             for (unsigned i = 0; i < apds.size(); i++)
00071             {
00072                 *p_file << apds[i] << "\t";
00073             }
00074             *p_file << std::endl;
00075         }
00076         p_file->close();
00077     }
00078 }
00079 
00080 
00081 void PostProcessingWriter::WriteUpstrokeTimeMap(double threshold)
00082 {
00083     if(PetscTools::AmMaster())
00084     {
00085         out_stream p_file=out_stream(NULL);
00086         OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00087         p_file = output_file_handler.OpenOutputFile("UpstrokeTimeMap.dat");
00088         for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00089         { 
00090             std::vector<double> upstroke_times;
00091             upstroke_times = mpCalculator->CalculateUpstrokeTimes(node_index, threshold);
00092             assert(upstroke_times.size()!=0); 
00093             for (unsigned i = 0; i < upstroke_times.size(); i++)
00094             {
00095                 *p_file << upstroke_times[i] << "\t";
00096             }
00097             *p_file << std::endl;
00098         }
00099         p_file->close();
00100     }
00101 }
00102 
00103 void PostProcessingWriter::WriteMaxUpstrokeVelocityMap(double threshold)
00104 {
00105     if(PetscTools::AmMaster())
00106     {
00107         out_stream p_file=out_stream(NULL);
00108         OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00109         p_file = output_file_handler.OpenOutputFile("MaxUpstrokeVelocityMap.dat");
00110         for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00111         { 
00112             std::vector<double> upstroke_velocities;
00113             upstroke_velocities = mpCalculator->CalculateAllMaximumUpstrokeVelocities(node_index, threshold);
00114             assert(upstroke_velocities.size()!=0); 
00115             for (unsigned i = 0; i < upstroke_velocities.size(); i++)
00116             {
00117                 *p_file << upstroke_velocities[i] << "\t";
00118             }
00119             *p_file << std::endl;
00120          }
00121          p_file->close();
00122     }
00123 }
00124 
00125 void PostProcessingWriter::WriteConductionVelocityMap(unsigned originNode, std::vector<double> distancesFromOriginNode)
00126 {
00127     if(PetscTools::AmMaster())
00128     {
00129         out_stream p_file=out_stream(NULL);
00130         OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00131         
00132         std::stringstream filename;
00133         filename << "ConductionVelocityFromNode" << originNode << ".dat";               
00134         p_file = output_file_handler.OpenOutputFile(filename.str());
00135         for (unsigned dest_node = 0; dest_node < mNumberOfNodes; dest_node++)
00136         { 
00137             std::vector<double> conduction_velocities;
00138             conduction_velocities = mpCalculator->CalculateAllConductionVelocities(originNode, dest_node, distancesFromOriginNode[dest_node]);
00139             assert(conduction_velocities.size()!=0);
00140             for (unsigned i = 0; i < conduction_velocities.size(); i++)
00141             {
00142                 *p_file << conduction_velocities[i] << "\t";
00143             }
00144             *p_file << std::endl;
00145          }
00146          p_file->close();
00147     }        
00148 }
00149 

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5