VentilationProblem.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2014, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef VENTILATIONPROBLEM_HPP_
00037 #define VENTILATIONPROBLEM_HPP_
00038 
00039 #include <map>
00040 #include "TetrahedralMesh.hpp"
00041 #include "LinearSystem.hpp"
00042 #include "TimeStepper.hpp"
00043 #include "VtkMeshWriter.hpp"
00044 #include "Swan2012AcinarUnit.hpp"
00045 
00056 class VentilationProblem
00057 {
00058 private:
00059     TetrahedralMesh<1,3> mMesh; 
00060     unsigned mOutletNodeIndex; 
00061     bool mDynamicResistance; 
00062     bool mRadiusOnEdge; 
00072     double mViscosity;
00073 
00083     double mDensity;
00084 
00085     std::map<unsigned, Swan2012AcinarUnit*> mAcinarUnits; 
00086     std::vector<double> mFlux; 
00087     std::vector<double> mPressure; 
00088     std::map<unsigned, double> mPressureCondition; 
00089     bool mFluxGivenAtInflow; 
00099     Mat mTerminalInteractionMatrix;
00100     std::map<unsigned, unsigned> mTerminalToNodeIndex; 
00101     std::map<unsigned, unsigned> mTerminalToEdgeIndex; 
00103     Vec mTerminalFluxChangeVector; 
00104     Vec mTerminalPressureChangeVector; 
00105     KSP mTerminalKspSolver; 
00113     void SolveDirectFromFlux();
00114 
00115 
00122     void SetupIterativeSolver();
00133     void SolveIterativelyFromPressure();
00134 
00145     double CalculateResistance(Element<1,3>& rElement, bool usePedley=false, double flux=DBL_MAX);
00146 
00147 
00148 public:
00158     VentilationProblem();
00159 
00170     VentilationProblem(const std::string& rMeshDirFilePath, unsigned rootIndex=0u);
00174     ~VentilationProblem();
00175 
00180     void SetOutflowPressure(double pressure);
00181 
00185     void SetConstantInflowPressures(double pressure);
00186 
00191     void SetConstantInflowFluxes(double flux);
00192 
00193 
00203     void SetPressureAtBoundaryNode(const Node<3>& rNode, double pressure);
00204 
00211     double GetPressureAtBoundaryNode(const Node<3>& rNode);
00212 
00217     double GetFluxAtOutflow();
00227     void SetFluxAtBoundaryNode(const Node<3>& rNode, double flux);
00228 
00234     void Solve();
00235 
00236 
00241     void GetSolutionAsFluxesAndPressures(std::vector<double>& rFluxesOnEdges, std::vector<double>& rPressuresOnNodes);
00242 
00243 #ifdef CHASTE_VTK
00244 
00250     void AddDataToVtk(VtkMeshWriter<1, 3>& rVtkWriter, const std::string& rSuffix);
00251 
00257     void WriteVtk(const std::string& rDirName, const std::string& rFileBaseName);
00258 
00259 #endif // CHASTE_VTK
00260 
00267     void SetRadiusOnEdge(bool isOnEdges=true);
00268 
00272     TetrahedralMesh<1,3>& rGetMesh();
00273 
00284     void Solve(TimeStepper& rTimeStepper, void (*pBoundaryConditionFunction)(VentilationProblem*, TimeStepper& rTimeStepper, const Node<3>&), const std::string& rDirName, const std::string& rFileBaseName);
00285 
00293     void SolveProblemFromFile(const std::string& rInFilePath, const std::string& rOutFileDir,const std::string& rOutFileName);
00294 
00298     double GetViscosity() const
00299     {
00300         return mViscosity;
00301     }
00302 
00306     void SetViscosity(double viscosity)
00307     {
00308         mViscosity = viscosity;
00309     }
00310 
00314     double GetDensity() const
00315     {
00316         return mDensity;
00317     }
00318 
00322     void SetDensity(double density)
00323     {
00324         mDensity = density;
00325     }
00326 
00330     void SetDynamicResistance(bool dynamicResistance = true)
00331     {
00332         mDynamicResistance = dynamicResistance;
00333     }
00334 
00339     Swan2012AcinarUnit* GetAcinus(const Node<3>& rNode)
00340     {
00341         assert(mAcinarUnits.count(rNode.GetIndex()));
00342         return mAcinarUnits[rNode.GetIndex()];
00343     }
00344 
00345 };
00346 
00347 #endif /* VENTILATIONPROBLEM_HPP_ */

Generated by  doxygen 1.6.2