Memosa-FVM  0.2
BatteryFixInterfaceGhost.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 _BATTERYFIXINTERFACEGHOST_H_
6 #define _BATTERYFIXINTERFACEGHOST_H_
7 
8 #include "Mesh.h"
9 #include "NumType.h"
10 #include "Array.h"
11 #include "Vector.h"
12 #include "Field.h"
13 #include "CRConnectivity.h"
14 #include "StorageSite.h"
15 #include "MultiFieldMatrix.h"
16 #include "CRMatrix.h"
17 #include "FluxJacobianMatrix.h"
18 #include "DiagonalMatrix.h"
19 
20 
21 
22 
23 template<class X, class Diag, class OffDiag>
25 {
26  public:
29  typedef typename CCMatrix::DiagArray DiagArray;
31  typedef Array<X> XArray;
34 
35 
37  GeomFields& geomFields,
38  Field& varField,
39  Field& diffusivityField):
40  _meshes(meshes),
41  _geomFields(geomFields),
42  _varField(varField),
43  _diffusivityField(diffusivityField)
44  {}
45 
46 
48  {
49 
50  // this function edits the interface ghost cells when an unconnected
51  // doubleShell is present at that interface. It does 3 things:
52  //
53  // 1) changes the interface ghost cell's centroid to that of the interface
54  // instead of the interior cell of the adjacent mesh to which it is connected
55  // through the scatter/gather map that we want to remain intact.
56  // 2) copies the diffusivity from the interior cell to the interface ghost cell
57  // instead of the diffusivity that the ghost cell picked up from the adjacent mesh
58  // 3) copies in interface values being stored in the doubleShell mesh to the
59  // interface ghost cells instead of them holding the value from the interior
60  // cell of the adjacent mesh.
61 
62  cout << "BATTERY FIX INTEFACE GHOST" << endl;
63 
64  const int numMeshes = _meshes.size();
65 
66  for (int n=0; n<numMeshes; n++)
67  {
68  const Mesh& mesh = *_meshes[n];
69 
70  //only do process if it is an unconnected doubleShell
71  if ((mesh.isDoubleShell())&&(!(mesh.isConnectedShell())))
72  {
73  const StorageSite& cells = mesh.getCells();
74  const CRConnectivity& cellCells = mesh.getCellCells();
75  const XArray& varCell = dynamic_cast<const XArray&>(_varField[cells]);
76 
77  const int parentMeshID = mesh.getParentMeshID();
78  const Mesh& parentMesh = *_meshes[parentMeshID];
79  const StorageSite& parentFaces = mesh.getParentFaceGroupSite();
80  const CRConnectivity& parentFaceCells = parentMesh.getFaceCells(parentFaces);
81  const StorageSite& parentCells = parentMesh.getCells();
82  VectorT3Array& parentCellCentroid = dynamic_cast<VectorT3Array&>(_geomFields.coordinate[parentCells]);
83  VectorT3Array& parentFaceCentroid = dynamic_cast<VectorT3Array&>(_geomFields.coordinate[parentFaces]);
84  TArray& diffusivityParent = dynamic_cast<TArray&>(_diffusivityField[parentCells]);
85  XArray& varCellParent = dynamic_cast<XArray&>(_varField[parentCells]);
86 
87 
88  const int otherMeshID = mesh.getOtherMeshID();
89  const Mesh& otherMesh = *_meshes[otherMeshID];
90  const StorageSite& otherFaces = mesh.getOtherFaceGroupSite();
91  const CRConnectivity& otherFaceCells = otherMesh.getFaceCells(otherFaces);
92  const StorageSite& otherCells = otherMesh.getCells();
93  VectorT3Array& otherCellCentroid = dynamic_cast<VectorT3Array&>(_geomFields.coordinate[otherCells]);
94  VectorT3Array& otherFaceCentroid = dynamic_cast<VectorT3Array&>(_geomFields.coordinate[otherFaces]);
95  TArray& diffusivityOther = dynamic_cast<TArray&>(_diffusivityField[otherCells]);
96  XArray& varCellOther = dynamic_cast<XArray&>(_varField[otherCells]);
97 
98 
99  for (int f=0; f<parentFaces.getCount(); f++)
100  {
101  int c0p = parentFaceCells(f,0);
102  int c1p = parentFaceCells(f,1);
103  if (c1p < parentCells.getSelfCount())
104  {
105  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
106  // so that c1p refers to the ghost cell in the following
107  int temp = c0p;
108  c0p = c1p;
109  c1p = temp;
110  }
111  //cout << "Parent: " << c1p << " " << (parentCellCentroid[c1p])[0] << " " << (parentFaceCentroid[f])[0] << endl;
112 
113  // change centroid
114  parentCellCentroid[c1p] = parentFaceCentroid[f];
115 
116  // copy diffusivity from interior cell to ghost
117  // (instead of diff picked up from other mesh during sync)
118  diffusivityParent[c1p] = diffusivityParent[c0p];
119 
120  // copy solution variable value from shell to ghost cell
121  const int c0 = f;
122  varCellParent[c1p] = varCell[c0];
123 
124  }
125 
126  for (int f=0; f<otherFaces.getCount(); f++)
127  {
128  //get other mesh fluxes and coeffs
129  int c0o = otherFaceCells(f,0);
130  int c1o = otherFaceCells(f,1);
131  if (c1o < otherCells.getSelfCount())
132  {
133  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
134  // so that c1o refers to the ghost cell in the following
135  int temp = c0o;
136  c0o = c1o;
137  c1o = temp;
138  }
139 
140  //cout << "Other: " << c1o << " " << (otherCellCentroid[c1o])[0] << " " << (otherFaceCentroid[f])[0] << endl;
141 
142  // change centroid
143  otherCellCentroid[c1o] = otherFaceCentroid[f];
144 
145  // copy diffusivity from interior cell to ghost
146  // (instead of diff picked up from other mesh during sync)
147  diffusivityOther[c1o] = diffusivityOther[c0o];
148 
149  // copy solution variable value from shell to ghost cell
150  const int c1 = cellCells(f,0);
151  varCellOther[c1o] = varCell[c1];
152  }
153 
154  }
155  }
156 
157  //output for two material 54 cell case to check centroid changes
158  if (0)
159  {
160  for (int n=0; n<numMeshes; n++)
161  {
162  const Mesh& mesh = *_meshes[n];
163  const StorageSite& cells = mesh.getCells();
164 
165  const int nCells = cells.getCount();
166 
167  VectorT3Array& cellCentroid = dynamic_cast<VectorT3Array&>(_geomFields.coordinate[cells]);
168 
169  cout << "Mesh: " << n << endl;
170  for (int c=0; c<nCells; c++)
171  {
172  if (((cellCentroid[c])[2] < -3.33)&&((cellCentroid[c])[2] > -3.34))
173  cout << c << ": " << (cellCentroid[c])[0] << " " << (cellCentroid[c])[1] << endl;
174  }
175  }
176  }
177 
178  }
179  private:
180 
185 
186 };
187 
188 #endif
bool isDoubleShell() const
Definition: Mesh.h:324
CRMatrix< Diag, OffDiag, X > CCMatrix
int getSelfCount() const
Definition: StorageSite.h:40
Field coordinate
Definition: GeomFields.h:19
const StorageSite & getParentFaceGroupSite() const
Definition: Mesh.h:329
Definition: Field.h:14
bool isConnectedShell() const
Definition: Mesh.h:325
Definition: Mesh.h:49
BatteryFixInterfaceGhost(const MeshList &meshes, GeomFields &geomFields, Field &varField, Field &diffusivityField)
int getOtherMeshID() const
Definition: Mesh.h:327
const StorageSite & getOtherFaceGroupSite() const
Definition: Mesh.h:332
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
const StorageSite & getCells() const
Definition: Mesh.h:109
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
int getParentMeshID() const
Definition: Mesh.h:326
int getCount() const
Definition: StorageSite.h:39
NumTypeTraits< X >::T_Scalar T_Scalar
Vector< T_Scalar, 3 > VectorT3
vector< Mesh * > MeshList
Definition: Mesh.h:439