Chaste Release::3.1
AdaptiveBidomainProblem.hpp
00001 /*
00002 
00003 Copyright (C) Fujitsu Laboratories of Europe, 2009-2010
00004 
00005 */
00006 
00007 /*
00008 
00009 Copyright (c) 2005-2012, University of Oxford.
00010 All rights reserved.
00011 
00012 University of Oxford means the Chancellor, Masters and Scholars of the
00013 University of Oxford, having an administrative office at Wellington
00014 Square, Oxford OX1 2JD, UK.
00015 
00016 This file is part of Chaste.
00017 
00018 Redistribution and use in source and binary forms, with or without
00019 modification, are permitted provided that the following conditions are met:
00020  * Redistributions of source code must retain the above copyright notice,
00021    this list of conditions and the following disclaimer.
00022  * Redistributions in binary form must reproduce the above copyright notice,
00023    this list of conditions and the following disclaimer in the documentation
00024    and/or other materials provided with the distribution.
00025  * Neither the name of the University of Oxford nor the names of its
00026    contributors may be used to endorse or promote products derived from this
00027    software without specific prior written permission.
00028 
00029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00033 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00035 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00036 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00037 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00038 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 
00040 */
00041 
00042 
00043 
00044 #ifndef ADAPTIVEBIDOMAINPROBLEM_HPP_
00045 #define ADAPTIVEBIDOMAINPROBLEM_HPP_
00046 
00047 #define CXXBLAS_H    // This stops multiple definition of blas headers (one via Chaste, one via libadaptivity/include/cxxblas.h)
00048                     // Might break things, no idea, will keep it here until problems appear....
00049 
00050 #ifdef CHASTE_ADAPTIVITY
00051 
00052 #include <vector>
00053 #include <string>
00054 #include <fstream>
00055 #include <sstream>
00056 #include <cassert>
00057 #include <cmath>
00058 
00059 // Include libadaptivity header files.
00060 // Need to add $LIBADAPTIVITY_DIR/include/ to the include path.
00061 #define HAVE_VTK
00062 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the strstream deprecated warning for now (gcc4.3)
00063 #include "vtk.h"
00064 #include "../metric_field/include/DiscreteGeometryConstraints.h"
00065 #include "../metric_field/include/ErrorMeasure.h"
00066 #include "../adapt3d/include/Adaptivity.h"
00067 
00068 #include "AbstractCardiacProblem.hpp"
00069 #include "BidomainProblem.hpp"
00070 #include "BidomainSolver.hpp"
00071 #include "BidomainTissue.hpp"
00072 #include "AdaptiveTetrahedralMesh.hpp"
00073 #include "AbstractStimulusFunction.hpp"
00074 #include "StimulusBoundaryCondition.hpp"
00075 #include "VtkMeshReader.hpp"
00076 
00077 #include <vtkDoubleArray.h>
00078 #include <vtkCellData.h>
00079 #include <vtkTetra.h>
00080 #include <vtkUnstructuredGrid.h>
00081 #include <vtkUnstructuredGridWriter.h>
00082 #include <vtkXMLUnstructuredGridWriter.h>
00083 
00094 class AdaptiveBidomainProblem : public BidomainProblem<3>
00095 {
00096     friend class TestAdaptiveBidomainProblem;
00097     friend class TestAdaptiveBidomainProblemNightly;
00098 
00099 private:
00100 
00105     BidomainSolver<3,3>* mpSolver;
00106 
00108     AdaptiveTetrahedralMesh *mpAdaptiveMesh;
00109 
00110     bool mIsMeshAdapting;     
00112     bool mInitializeFromVtu;    
00115     bool mUseNeumannBoundaryConditions;
00117     double mNeumannStimulusIndex;
00119     double mNeumannStimulusLowerValue;
00121     double mNeumannStimulusUpperValue;
00123     double mNeumannStimulusMagnitude;
00125     double mNeumannStimulusDuration;
00127     double mNeumannStimulusPeriod;
00129     AbstractStimulusFunction* mpNeumannStimulus;
00131     StimulusBoundaryCondition<3>* mpNeumannStimulusBoundaryCondition;
00132 
00133 //    /**
00134 //     * Determine whether or not an edge of the mesh is of sufficient quality. Edge is "good" if the error metric
00135 //     * associated  with it is in the range [ 1 - mGoodEdgeRange , 1 + mGoodEdgeRange ]
00136 //     */
00137 //    double mGoodEdgeRange;
00138 //
00139 //    /** Proportion of edges that must be deemed "bad" (i.e. not good) before an adapt takes place */
00140 //    double mBadEdgeCriterion;
00141 
00143     std::string mOutputDirectory;
00144 
00146     std::string mOutputFilenamePrefix;
00147 
00148 public:
00158     AdaptiveBidomainProblem(AbstractCardiacCellFactory<3>* pCellFactory, bool hasBath=false);
00159 
00163     ~AdaptiveBidomainProblem();
00164 
00168     void DoNotAdaptMesh();
00169 
00170 //
00171 //     * Set the values of mGoodEdgeRange and mBadEdgeCriterion to be used by the AdaptiveTetrahedralMesh
00172 //     * in determining whether an adapt is necessary or if the current mesh is of sufficient quality.
00173 //     *
00174 //     * @param range Value of mGoodEdgeRange to be used
00175 //     * @param criterion Value of mBadEdgeCriterion to be used
00176 //
00177 //    void SetAdaptCriterion(double range, double criterion);
00178 
00186     void AddCurrentSolutionToAdaptiveMesh( Vec solution );
00187 
00195     void InitializeSolutionOnAdaptedMesh( VtkMeshReader<3,3>* reader );
00196 
00204     void AdaptMesh();
00205 
00209     double GetTargetError();
00210 
00214     double GetSigma();
00215 
00219     double GetMaxEdgeLength();
00220 
00224     double GetMinEdgeLength();
00225 
00229     double GetGradation();
00230 
00234     unsigned GetMaxMeshNodes();
00235 
00239     unsigned GetNumAdaptSweeps();
00240 
00248     void UseNeumannBoundaryCondition( unsigned index = 0 );
00249 
00259     void SetNeumannStimulusMagnitudeAndDuration(double magnitude, double duration, double period = DBL_MAX);
00260 
00266     void SetupNeumannBoundaryConditionOnMesh();
00267 
00276     void LoadSimulationFromVtuFile();
00277 
00287     void Solve();
00288 };
00289 
00290 #endif // CHASTE_ADAPTIVITY
00291 
00292 #endif /*ADAPTIVEBIDOMAINPROBLEM_HPP_*/