AdaptiveBidomainProblem.hpp

00001 /*
00002 
00003 Copyright (C) Fujitsu Laboratories of Europe, 2009-2010
00004 
00005 */
00006 
00007 /*
00008 
00009 Copyright (C) University of Oxford, 2005-2011
00010 
00011 University of Oxford means the Chancellor, Masters and Scholars of the
00012 University of Oxford, having an administrative office at Wellington
00013 Square, Oxford OX1 2JD, UK.
00014 
00015 This file is part of Chaste.
00016 
00017 Chaste is free software: you can redistribute it and/or modify it
00018 under the terms of the GNU Lesser General Public License as published
00019 by the Free Software Foundation, either version 2.1 of the License, or
00020 (at your option) any later version.
00021 
00022 Chaste is distributed in the hope that it will be useful, but WITHOUT
00023 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00025 License for more details. The offer of Chaste under the terms of the
00026 License is subject to the License being interpreted in accordance with
00027 English Law and subject to any action against the University of Oxford
00028 being under the jurisdiction of the English Courts.
00029 
00030 You should have received a copy of the GNU Lesser General Public License
00031 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00032 
00033 */
00034 
00035 
00036 
00037 #ifndef ADAPTIVEBIDOMAINPROBLEM_HPP_
00038 #define ADAPTIVEBIDOMAINPROBLEM_HPP_
00039 
00040 #define CXXBLAS_H    // This stops multiple definition of blas headers (one via Chaste, one via libadaptivity/include/cxxblas.h)
00041                     // Might break things, no idea, will keep it here until problems appear....
00042 
00043 #ifdef CHASTE_ADAPTIVITY
00044 
00045 #include <vector>
00046 #include <string>
00047 #include <fstream>
00048 #include <sstream>
00049 #include <cassert>
00050 #include <cmath>
00051 
00052 // Include libadaptivity header files.
00053 // Need to add $LIBADAPTIVITY_DIR/include/ to the include path.
00054 #define HAVE_VTK
00055 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the strstream deprecated warning for now (gcc4.3)
00056 #include "vtk.h"
00057 #include "../metric_field/include/DiscreteGeometryConstraints.h"
00058 #include "../metric_field/include/ErrorMeasure.h"
00059 #include "../adapt3d/include/Adaptivity.h"
00060 
00061 #include "AbstractCardiacProblem.hpp"
00062 #include "BidomainProblem.hpp"
00063 #include "BidomainSolver.hpp"
00064 #include "BidomainTissue.hpp"
00065 #include "AdaptiveTetrahedralMesh.hpp"
00066 #include "AbstractStimulusFunction.hpp"
00067 #include "StimulusBoundaryCondition.hpp"
00068 #include "VtkMeshReader.hpp"
00069 
00070 #include <vtkDoubleArray.h>
00071 #include <vtkCellData.h>
00072 #include <vtkTetra.h>
00073 #include <vtkUnstructuredGrid.h>
00074 #include <vtkUnstructuredGridWriter.h>
00075 #include <vtkXMLUnstructuredGridWriter.h>
00076 
00087 class AdaptiveBidomainProblem : public BidomainProblem<3>
00088 {
00089     friend class TestAdaptiveBidomainProblem;
00090     friend class TestAdaptiveBidomainProblemNightly;
00091 
00092 private:
00093 
00098     BidomainSolver<3,3>* mpSolver;
00099 
00101     AdaptiveTetrahedralMesh *mpAdaptiveMesh;
00102 
00103     bool mIsMeshAdapting;     
00105     bool mInitializeFromVtu;    
00108     bool mUseNeumannBoundaryConditions;
00110     double mNeumannStimulusIndex;
00112     double mNeumannStimulusLowerValue;
00114     double mNeumannStimulusUpperValue;
00116     double mNeumannStimulusMagnitude;
00118     double mNeumannStimulusDuration;
00120     double mNeumannStimulusPeriod;
00122     AbstractStimulusFunction* mpNeumannStimulus;
00124     StimulusBoundaryCondition<3>* mpNeumannStimulusBoundaryCondition;
00125 
00126 //    /**
00127 //     * Determine whether or not an edge of the mesh is of sufficient quality. Edge is "good" if the error metric
00128 //     * associated  with it is in the range [ 1 - mGoodEdgeRange , 1 + mGoodEdgeRange ]
00129 //     */
00130 //    double mGoodEdgeRange;
00131 //
00132 //    /** Proportion of edges that must be deemed "bad" (i.e. not good) before an adapt takes place */
00133 //    double mBadEdgeCriterion;
00134 
00136     std::string mOutputDirectory;
00137 
00139     std::string mOutputFilenamePrefix;
00140 
00141 public:
00151     AdaptiveBidomainProblem(AbstractCardiacCellFactory<3>* pCellFactory, bool hasBath=false);
00152 
00156     ~AdaptiveBidomainProblem();
00157 
00161     void DoNotAdaptMesh();
00162 
00163 //
00164 //     * Set the values of mGoodEdgeRange and mBadEdgeCriterion to be used by the AdaptiveTetrahedralMesh
00165 //     * in determining whether an adapt is necessary or if the current mesh is of sufficient quality.
00166 //     *
00167 //     * @param range Value of mGoodEdgeRange to be used
00168 //     * @param criterion Value of mBadEdgeCriterion to be used
00169 //
00170 //    void SetAdaptCriterion(double range, double criterion);
00171 
00179     void AddCurrentSolutionToAdaptiveMesh( Vec solution );
00180 
00188     void InitializeSolutionOnAdaptedMesh( VtkMeshReader<3,3>* reader );
00189 
00197     void AdaptMesh();
00198 
00202     double GetTargetError();
00203 
00207     double GetSigma();
00208 
00212     double GetMaxEdgeLength();
00213 
00217     double GetMinEdgeLength();
00218 
00222     double GetGradation();
00223 
00227     unsigned GetMaxMeshNodes();
00228 
00232     unsigned GetNumAdaptSweeps();
00233 
00241     void UseNeumannBoundaryCondition( unsigned index = 0 );
00242 
00252     void SetNeumannStimulusMagnitudeAndDuration(double magnitude, double duration, double period = DBL_MAX);
00253 
00259     void SetupNeumannBoundaryConditionOnMesh();
00260 
00269     void LoadSimulationFromVtuFile();
00270 
00280     void Solve();
00281 };
00282 
00283 #endif // CHASTE_ADAPTIVITY
00284 
00285 #endif /*ADAPTIVEBIDOMAINPROBLEM_HPP_*/
Generated on Thu Dec 22 13:00:06 2011 for Chaste by  doxygen 1.6.3