Memosa-FVM  0.2
FlowModelVelocityBC.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _FLOWMODELVELOCITYBC_H_
6 #define _FLOWMODELVELOCITYBC_H_
7 
8 // this file is meant to be included inside the FlowModel::Impl class
9 // the code is here just because FlowModel_impl.h has grown too big
10 
12  const Mesh& mesh,
13  MultiFieldMatrix& matrix,
14  MultiField& xField,
15  MultiField& rField,
16  const FlowBC<T>& bc)
17  {
18  const StorageSite& cells = mesh.getCells();
19 
20  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
21 
22  MultiField::ArrayIndex mfIndex(&_flowFields.massFlux,&faces);
23  MultiField::ArrayIndex vIndex(&_flowFields.velocity,&cells);
24  MultiField::ArrayIndex pIndex(&_flowFields.pressure,&cells);
25 
26  PPMatrix& ppMatrix =
27  dynamic_cast<PPMatrix&>(matrix.getMatrix(pIndex,pIndex));
28 
29  FMatrix& dFluxdP = dynamic_cast<FMatrix&>(matrix.getMatrix(mfIndex,pIndex));
30 
31  PPAssembler& ppAssembler = ppMatrix.getPairWiseAssembler(faceCells);
32  PPDiagArray& ppDiag = ppMatrix.getDiag();
33 
34  const VectorT3Array& faceArea =
35  dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
36 
37  TArray& rCell = dynamic_cast<TArray&>(rField[pIndex]);
38  TArray& massFlux = dynamic_cast<TArray&>(_flowFields.massFlux[faces]);
39  TArray& pCell = dynamic_cast<TArray&>(_flowFields.pressure[cells]);
40  const TArray& density = dynamic_cast<const TArray&>(_flowFields.density[cells]);
41 
43  bVelocity(bc.getVal("specifiedXVelocity"),
44  bc.getVal("specifiedYVelocity"),
45  bc.getVal("specifiedZVelocity"),
46  faces);
47 
48  FloatValEvaluator<T> bp(bc.getVal("specifiedPressure"), faces);
49 
50  const bool fixPressure = (bc.bcType == "FixedBoundary");
51 
52  const int nFaces = faces.getCount();
53 
54  T netFlux(0.);
55 
56  for(int f=0; f<nFaces; f++)
57  {
58  const int c0 = faceCells(f,0);
59  const int c1 = faceCells(f,1);
60 
61  massFlux[f] = density[c0]*dot(bVelocity[f],faceArea[f]);
62 
63  rCell[c0] -= massFlux[f];
64 
65  netFlux += massFlux[f];
66  ppAssembler.getCoeff01(f) =0;
67  ppDiag[c1] = -1;
68  if (fixPressure)
69  {
70  rCell[c1] = bp[f]-pCell[c1];
71  ppAssembler.getCoeff10(f) =0;
72  }
73  else
74  {
75  rCell[c1] = 0.;
76  ppAssembler.getCoeff10(f) =1;
77  }
78 
79  ppMatrix.setBoundary(c1);
80 
81  dFluxdP.setCoeffL(f,T(0.));
82  dFluxdP.setCoeffR(f,T(0.));
83 
84  }
85 #ifdef PV_COUPLED
86  if (matrix.hasMatrix(vIndex,pIndex))
87  {
88  VPMatrix& vpMatrix =
89  dynamic_cast<VPMatrix&>(matrix.getMatrix(vIndex,pIndex));
90 
91  VPAssembler& vpAssembler = vpMatrix.getPairWiseAssembler(faceCells);
92  VPDiagArray& vpDiag = vpMatrix.getDiag();
93 
94  for(int f=0; f<nFaces; f++)
95  {
96  const int c0 = faceCells(f,0);
97  vpDiag[c0] += vpAssembler.getCoeff01(f);
98  vpAssembler.getCoeff01(f) = NumTypeTraits<T>::getZero();
99  }
100  }
101 #endif
102  return netFlux;
103  }
104 
105 #endif
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
Definition: FlowBC.h:10
string bcType
Definition: FlowBC.h:20
bool hasMatrix(const Index &rowIndex, const Index &colIndex) const
Definition: Mesh.h:49
FloatVal< T > getVal(const string varName) const
Definition: FloatVarDict.h:85
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
const StorageSite & getCells() const
Definition: Mesh.h:109
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
int getCount() const
Definition: StorageSite.h:39
T fixedFluxContinuityBC(const StorageSite &faces, const Mesh &mesh, MultiFieldMatrix &matrix, MultiField &xField, MultiField &rField, const FlowBC< T > &bc)
T dot(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
Definition: Vector.h:253