VentilationProblem.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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