Memosa-FVM  0.2
DistFunctFields.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 _DISTFUNCTFIELDS_H_
6 #define _DISTFUNCTFIELDS_H_
7 
8 #include "Mesh.h"
9 #include "Quadrature.h"
10 #include <stdio.h>
11 #include "Vector.h"
12 
13 #include "Field.h"
14 #include "MacroFields.h"
15 #include "FlowFields.h"
16 
17 #include "FlowBC.h"
18 
19 #include <math.h>
20 
21 template <class T>
22 
29 {
30  public:
31  typedef Array<T> TArray;
34 
35  //std::vector<shared_ptr<Field> > DistFunctFieldsPtr;
36  std::vector<Field*> dsf;
37 
38 
52  DistFunctFields(const MeshList& meshes,const MacroFields& macroPr, const Quadrature<T>& quad, const string dsfname):
53  _meshes(meshes),
54  _quadrature(quad)
55  {
60  const int numFields = _quadrature.getDirCount();
61  for(int n=0; n<numFields; n++)
62  {
63  stringstream ss;
64  ss << n;
65  string fieldName = dsfname + ss.str();
66  dsf.push_back(new Field(fieldName));
67  }
68  const int numMeshes = _meshes.size();
69  for (int n=0; n<numMeshes; n++)
70  {
71  const Mesh& mesh = *_meshes[n];
72  const StorageSite& cells = mesh.getCells();
73  const int nCells = cells.getCountLevel1();
74  double pi(3.14159);
75 
76  const TArray& density = dynamic_cast<const TArray&>(macroPr.density[cells]);
77  const TArray& temperature = dynamic_cast<const TArray&>(macroPr.temperature[cells]);
78  const VectorT3Array& v = dynamic_cast<const VectorT3Array&>(macroPr.velocity[cells]);
79 
80 
81  const TArray& cx = dynamic_cast<const TArray&>(*_quadrature.cxPtr);
82  const TArray& cy = dynamic_cast<const TArray&>(*_quadrature.cyPtr);
83  const TArray& cz = dynamic_cast<const TArray&>(*_quadrature.czPtr);
84 
85  /*
86  TArray* distfunAPtr;
87  distfunAPtr=new TArray(nCells);
88  TArray & distfunA= *distfunAPtr;
89  */
90 
91  for(int j=0;j<numFields;j++){
92  Field& fnd= *dsf[j];
93 
94  shared_ptr<TArray> fcPtr(new TArray(cells.getCountLevel1()));
95 
96  fnd.addArray(cells,fcPtr);
97 
98  //TArray& fc = dynamic_cast<TArray&>(fnd[cells]);
99  TArray& fc = *fcPtr;
100  for(int c=0; c<nCells;c++) {
101  fc[c]=density[c]/pow((pi*temperature[c]),1.5)*
102  exp(-(pow((cx[j]-v[c][0]),2.0)+pow((cy[j]-v[c][1]),2.0)+
103  pow((cz[j]-v[c][2]),2.0))/temperature[c]);
104  }
105 
106  }
107  }
108  }
109 
110  DistFunctFields(const MeshList& meshes, const Quadrature<T>& quad, const string dsfname):
111  _meshes(meshes),
112  _quadrature(quad)
113  {
114  //FILE * pFile;
115  //pFile=fopen("distfun.txt","w");
120  const int numFields = _quadrature.getDirCount();
121  for(int j=0; j<numFields; j++)
122  {
123  stringstream ss;
124  ss << j;
125  string fieldName = dsfname + ss.str();
126  dsf.push_back(new Field(fieldName));
127  }
128  const int numMeshes = _meshes.size();
129  for (int n=0; n<numMeshes; n++)
130  {
131  const Mesh& mesh = *_meshes[n];
132  const StorageSite& cells = mesh.getCells();
133  const int nCells = cells.getCountLevel1();
134 
135  double pi(3.14159);
136 
137  const TArray& cx = dynamic_cast<const TArray&>(*_quadrature.cxPtr);
138  const TArray& cy = dynamic_cast<const TArray&>(*_quadrature.cyPtr);
139  const TArray& cz = dynamic_cast<const TArray&>(*_quadrature.czPtr);
140  //const TArray& dcxyz = dynamic_cast<const TArray&>(*_quadrature.dcxyzPtr);
141  for(int j=0;j<numFields;j++){
142  Field& fnd= *dsf[j];
143  shared_ptr<TArray> fcPtr(new TArray(cells.getCountLevel1()));
144 
145  fnd.addArray(cells,fcPtr);
146 
147  TArray& fc = dynamic_cast<TArray&>(fnd[cells]);
148  //TArray& fc = *fcPtr;
149 
150  for(int c=0; c<nCells;c++){
151  fc[c]=1./pow(pi*1.0,1.5)*exp(-(pow((cx[j]-1.0),2.0)+pow((cy[j]-0.0),2.0)+ pow((cz[j]-0.0),2.0))/1.0);
152 
153  }
154  //fprintf(pFile,"%12.6f %12.6f %12.6f %12.6f %E \n",cx[j],cy[j],cz[j],dcxyz[j],fc[0]);
155  }
156 
157  }
158  //fclose(pFile);
159  }
160 
161 
163  {
164  const int numMeshes = _meshes.size();
165  for (int n=0; n<numMeshes; n++)
166  {
167  const Mesh& mesh = *_meshes[n];
168  const StorageSite& cells = mesh.getCells();
169  const int nCells = cells.getCountLevel1();
170  double pi(3.14159);
171 
172  const TArray& density = dynamic_cast<const TArray&>(macroPr.density[cells]);
173  const TArray& temperature = dynamic_cast<const TArray&>(macroPr.temperature[cells]);
174  const VectorT3Array& v = dynamic_cast<const VectorT3Array&>(macroPr.velocity[cells]);
175 
176  const TArray& cx = dynamic_cast<const TArray&>(*_quadrature.cxPtr);
177  const TArray& cy = dynamic_cast<const TArray&>(*_quadrature.cyPtr);
178  const TArray& cz = dynamic_cast<const TArray&>(*_quadrature.czPtr);
179  const int numFields= _quadrature.getDirCount();
180 
181  for(int j=0;j< numFields;j++){
182  Field& fnd = *dsfPtr.dsf[j];
183  TArray& f = dynamic_cast< TArray&>(fnd[cells]);
184  for(int c=0; c<nCells;c++){
185  f[c]=density[c]/pow((pi*temperature[c]),1.5)*
186  exp(-(pow((cx[j]-v[c][0]),2.0)+pow((cy[j]-v[c][1]),2.0)+
187  pow((cz[j]-v[c][2]),2.0))/temperature[c]);
188  }
189 
190  }
191  }
192  }
194  {
195  const int numMeshes = _meshes.size();
196  for (int n=0; n<numMeshes; n++)
197  {
198  const Mesh& mesh = *_meshes[n];
199  const StorageSite& cells = mesh.getCells();
200  const int nCells = cells.getCountLevel1();
201  double pi(3.14159);
202 
203  const TArray& cx = dynamic_cast<const TArray&>(*_quadrature.cxPtr);
204  const TArray& cy = dynamic_cast<const TArray&>(*_quadrature.cyPtr);
205  const TArray& cz = dynamic_cast<const TArray&>(*_quadrature.czPtr);
206  const int numFields= _quadrature.getDirCount();
207 
208  for(int j=0;j< numFields;j++){
209  Field& fnd = *dsfPtr.dsf[j];
210  TArray& f = dynamic_cast< TArray&>(fnd[cells]);
211  for(int c=0; c<nCells;c++){
212  f[c]=0.5*1.0/pow((pi*1.0),1.5)*exp(-(pow((cx[j]-4.0),2.0)+pow((cy[j]-0.0),2.0)+pow((cz[j]-0.0),2.0))/1.0)
213  +0.5*1.0/pow((pi*1.0),1.5)*exp(-(pow((cx[j]-4.0),2.0)+pow((cy[j]-0.0),2.0)+pow((cz[j]-0.0),2.0))/1.0);
214  }
215  }
216  }
217  }
218 
219  void OutputDistributionFunction(DistFunctFields<T>& dsfPtr) //, const char* filename)
220  {
221  FILE * pFile;
222  pFile = fopen("outputf0.plt","w");
223  int N1=_quadrature.getNVCount();
224  int N2=_quadrature.getNthetaCount();
225  int N3=_quadrature.getNphiCount();
226  fprintf(pFile,"%s \n", "VARIABLES= 'cx', 'cy', 'cz', 'f',");
227  fprintf(pFile, "%s %i %s %i %s %i \n","ZONE I=", N3,",J=",N2,"K=",N1);
228  fprintf(pFile,"%s\n","F=POINT");
229  const int numMeshes = _meshes.size();
230  for (int n=0; n<numMeshes; n++){
231  const TArray& cx = dynamic_cast<const TArray&>(*_quadrature.cxPtr);
232  const TArray& cy = dynamic_cast<const TArray&>(*_quadrature.cyPtr);
233  const TArray& cz = dynamic_cast<const TArray&>(*_quadrature.czPtr);
234  const int numFields= _quadrature.getDirCount();
235 
236  const Mesh& mesh = *_meshes[n];
237  const StorageSite& cells = mesh.getCells();
238  for(int j=0;j< numFields;j++){
239  Field& fnd = *dsfPtr.dsf[j];
240  TArray& f = dynamic_cast< TArray&>(fnd[cells]);
241  fprintf(pFile,"%E %E %E %E\n",cx[j],cy[j],cz[j],f[0]);
242  }
243  }
244  }
245 
246  const Field& getField(int indx) const {
247  return *dsf[indx];
248  }
249 
250 
251  private:
254  //KineticModelOptions<T> _options;
255 };
256 
257 
258 /*
259 //Fgamma, Macroparameters, -ESBGKMol.h
260 void Fgamma_alphas(){
261  for (int j=0;j<N123;j++){
262  malpha_BGK[j][0]=1.0;
263  malpha_BGK[j][1]=cx[j];
264  malpha_BGK[j][2]=pow(cx[j],2.0)+pow(cy[j],2.0)+pow(cz[j],2.0);
265  malpha_BGK[j][3]=cy[j];
266  }
267  if(solver == 2){
268  for (int j=0;j<N123;j++){
269  malpha_ES[j][0]=1.0;
270  malpha_ES[j][1]=cx[j];
271  malpha_ES[j][2]=cy[j];
272  malpha_ES[j][3]=pow(cx[j],2.0);
273  malpha_ES[j][4]=pow(cy[j],2.0);
274  malpha_ES[j][5]=pow(cz[j],2.0);
275  malpha_ES[j][6]=cx[j]*cy[j];
276  }}
277 
278 }
279 */
280 
281 #endif
static Cell< Quad > quad
Definition: Cell.cpp:210
const Quadrature< T > _quadrature
Definition: Field.h:14
Definition: Mesh.h:49
DistFunctFields(const MeshList &meshes, const MacroFields &macroPr, const Quadrature< T > &quad, const string dsfname)
Field temperature
Definition: MacroFields.h:22
DistFunctFields(const MeshList &meshes, const Quadrature< T > &quad, const string dsfname)
const StorageSite & getCells() const
Definition: Mesh.h:109
const MeshList _meshes
int getCountLevel1() const
Definition: StorageSite.h:72
Array< VectorT3 > VectorT3Array
void initializeMaxwellian(const MacroFields &macroPr, DistFunctFields< T > &dsfPtr)
void addArray(const StorageSite &, shared_ptr< ArrayBase > a)
Definition: Field.cpp:72
Array< T > TArray
Definition: Array.h:14
Field velocity
Definition: MacroFields.h:15
void OutputDistributionFunction(DistFunctFields< T > &dsfPtr)
std::vector< Field * > dsf
Vector< T, 3 > VectorT3
void weightedMaxwellian(DistFunctFields< T > &dsfPtr)
Field density
Definition: MacroFields.h:21
vector< Mesh * > MeshList
Definition: Mesh.h:439
const Field & getField(int indx) const