Carmen Code
 All Classes Files Functions Variables Macros Pages
Public Member Functions | Public Attributes | List of all members
FineMesh Class Reference

An object FineMesh is a regular fine mesh, used for finite volume computations. It is not used for multiresolution computations. More...

#include <FineMesh.h>

Collaboration diagram for FineMesh:
Collaboration graph
[legend]

Public Member Functions

 FineMesh ()
 Constructor of FineMesh class Generates a regular fine mesh containing 2**(Dimension*ScaleNb) cells. The cell-averages are initialized from the initial condition contained in file carmen.ini. More...
 
 ~FineMesh ()
 Destructor the regular fine mesh. More...
 
void store ()
 Stores cell-average values into temporary cell-average values. More...
 
void storeGrad ()
 Stores gradient values into temporary gradient values. More...
 
void computeDivergence (int)
 Computes the divergence vector with the space discretization scheme. More...
 
void computeDivergence_cell (int)
 Computes one Cell Divirgence. More...
 
void RungeKutta_cell (int)
 Computes one Runge-Kutta step. More...
 
void RungeKutta (int)
 Computes the Runge-Kutta step. More...
 
void computeIntegral ()
 Computes integral values like e.g. flame velocity, global error, etc. More...
 
void computeCorrection (int)
 Computes divergence cleaning source term (only for MHD). More...
 
void computeCorrection_cell (int)
 Computes divergence cleaning source term (only for MHD) at one cell. More...
 
void computeGradient (int)
 Computes velocity gradient (only for Navier-Stokes). one cell. More...
 
void computeGradient_cell (int)
 Computes velocity gradient (only for Navier-Stokes). each cells. More...
 
void computeTimeAverage ()
 Computes the time-average value in every cell. More...
 
void checkStability () const
 Checks if the computation is numerically unstable, i.e. if one of the cell-averages is overflow. In case of numerical instability, the computation is stopped and a message appears. More...
 
void writeHeader (const char *FileName) const
 Write header for GNUplot, Data Explorer, TecPLot and VTK into file FileName. More...
 
void writeAverage (const char *FileName)
 Write cell-averages for GNUplot, Data Explorer, TecPLot and VTK into file FileName. More...
 
void writeTimeAverage (const char *FileName) const
 Write time-averages into file FileName. More...
 
void backup ()
 Backs up the tree structure and the cell-averages into a file carmen.bak. In further computations, the data can be recovered using Restore(). More...
 
void restore ()
 Restores the tree structure and the cell-averages from the file carmen.bak. This file was created by the method Backup(). More...
 

Public Attributes

Cell *** Neighbour_iL
 
Cell *** Neighbour_iU
 
Cell *** Neighbour_jL
 
Cell *** Neighbour_jU
 
Cell *** Neighbour_kL
 
Cell *** Neighbour_kU
 
CellMeshCell
 

Detailed Description

An object FineMesh is a regular fine mesh, used for finite volume computations. It is not used for multiresolution computations.

It contains an array of cells *MeshCell.

NOTE: for reasons of simplicity, only periodic and Neuman boundary conditions have been implemented.

Constructor & Destructor Documentation

FineMesh::FineMesh ( )

Constructor of FineMesh class Generates a regular fine mesh containing 2**(Dimension*ScaleNb) cells. The cell-averages are initialized from the initial condition contained in file carmen.ini.

!!DEBUG

34 {
35  // --- Local variables ---
36 
37  int n=0, i=0, j=0, k=0; // position numbers
38 
39  real x=0., y=0., z=0.; // positions
40  real dx=0., dy=0., dz=0.; // space steps
41 
42  // --- Create an array of 2^(ScaleNb*Dimension) cells ---
43 
44  MeshCell = new Cell[(1<<(ScaleNb*Dimension))];
45 
46 //Parallel
47 
48 #if defined PARMPI
49  Neighbour_iL = new Cell**[NeighbourNb];
50  Neighbour_iU = new Cell**[NeighbourNb];
51  Neighbour_jL = new Cell**[NeighbourNb];
52  Neighbour_jU = new Cell**[NeighbourNb];
53  Neighbour_kL = new Cell**[NeighbourNb];
54  Neighbour_kU = new Cell**[NeighbourNb];
55 
56  for (i=0;i<NeighbourNb;i++) {
57  Neighbour_iL[i] = new Cell*[one_D];
58  Neighbour_iU[i] = new Cell*[one_D];
59  Neighbour_jL[i] = new Cell*[one_D];
60  Neighbour_jU[i] = new Cell*[one_D];
61  Neighbour_kL[i] = new Cell*[one_D];
62  Neighbour_kU[i] = new Cell*[one_D];
63  }
64 
65  for (i=0;i<NeighbourNb;i++)
66  for (j=0;j<one_D;j++) {
67  Neighbour_iL[i][j] = new Cell[two_D];
68  Neighbour_iU[i][j] = new Cell[two_D];
69  Neighbour_jL[i][j] = new Cell[two_D];
70  Neighbour_jU[i][j] = new Cell[two_D];
71  Neighbour_kL[i][j] = new Cell[two_D];
72  Neighbour_kU[i][j] = new Cell[two_D];
73  }
74 #endif
75 
76 
77 
78  // --- Create a time-average grid ---
79 
80  if (TimeAveraging)
81  MyTimeAverageGrid = new TimeAverageGrid(ScaleNb);
82 
83  // --- Compute dx, dy, dz ---
84 
85  dx = (XMax[1]-XMin[1])/(1<<ScaleNb);
86  if (Dimension > 1) dy = (XMax[2]-XMin[2])/(1<<ScaleNb);
87  if (Dimension > 2) dz = (XMax[3]-XMin[3])/(1<<ScaleNb);
88 
89  // --- Loop on all cells ---
90 
91  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
92  {
93  // -- Compute i, j, k --
94 
95  i = n%(1<<ScaleNb);
96  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
97  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
98  // -- Compute x, y, z --
99 
100  x = XMin[1] + (i+.5)*dx;
101  if (Dimension > 1) y = XMin[2] + (j+.5)*dy;
102  if (Dimension > 2) z = XMin[3] + (k+.5)*dz;
103 
104  // -- Set position --
105 
106  cell(n)->setCenter(1,x);
107  if (Dimension > 1) cell(n)->setCenter(2,y);
108  if (Dimension > 2) cell(n)->setCenter(3,z);
109 
110  // -- Set size --
111 
112  cell(n)->setSize(1,dx);
113  if (Dimension > 1) cell(n)->setSize(2,dy);
114  if (Dimension > 2) cell(n)->setSize(3,dz);
115  }
116  // --- End loop on all cells ---
117 
118 //Parallel
119 
120 #if defined PARMPI
121 
122  for (i=0;i<one_D;i++)
123  for (j=0;j<two_D;j++)
124  for (k=0;k<NeighbourNb;k++) {
125  Neighbour_iL[k][i][j].setSize(1,dx);
126  Neighbour_iU[k][i][j].setSize(1,dx);
127  Neighbour_jL[k][i][j].setSize(1,dx);
128  Neighbour_jU[k][i][j].setSize(1,dx);
129  Neighbour_kL[k][i][j].setSize(1,dx);
130  Neighbour_kU[k][i][j].setSize(1,dx);
131 
132  if (Dimension > 1) {
133  Neighbour_iL[k][i][j].setSize(2,dy);
134  Neighbour_iU[k][i][j].setSize(2,dy);
135  Neighbour_jL[k][i][j].setSize(2,dy);
136  Neighbour_jU[k][i][j].setSize(2,dy);
137  Neighbour_kL[k][i][j].setSize(2,dy);
138  Neighbour_kU[k][i][j].setSize(2,dy);
139  }
140 
141  if (Dimension > 2) {
142  Neighbour_iL[k][i][j].setSize(3,dz);
143  Neighbour_iU[k][i][j].setSize(3,dz);
144  Neighbour_jL[k][i][j].setSize(3,dz);
145  Neighbour_jU[k][i][j].setSize(3,dz);
146  Neighbour_kL[k][i][j].setSize(3,dz);
147  Neighbour_kU[k][i][j].setSize(3,dz);
148  }
149  }
150 
151 #endif
152 
153 
154 
155  // -- Set initial cell-average value --
156 
157 
159  /*
160  printf("\nRecovery: %d",Recovery);
161  printf("\nUseBackup: %d",UseBackup);
162  printf("\nComputeCPUTimeRef: %d\n",ComputeCPUTimeRef);
163 */
164 
165  if (Recovery && UseBackup && !ComputeCPUTimeRef) {
166 // printf("\nRestore!\n");
167  restore();
168  }
169  else
170  {
171  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
172  {
173  cell(n)->setAverageZero();
174 
175  if (UseBoundaryRegions && BoundaryRegion(cell(n)->center()) != 0)
176  {
177  x = cell(n)->center(1);
178  y = (Dimension > 1)? cell(n)->center(2): 0.;
179  z = (Dimension > 2)? cell(n)->center(3): 0.;
180  cell(n)->setAverage(InitAverage(x,y,z));
181  }
182  else
183  {
184 
185  switch (Dimension)
186  {
187  case 1:
188  for (i=0;i<=1;i++)
189  cell(n)->setAverage( cell(n)->average()+.5* InitAverage(
190  cell(n)->center(1)+(i-0.5)*cell(n)->size(1)) );
191  break;
192 
193  case 2:
194  if(IcNb){
195  for (i=0;i<=1;i++)
196  for (j=0;j<=1;j++){
197  cell(n)->setAverage( cell(n)->average()+.25* InitAverage(
198  cell(n)->center(1)+(i-0.5)*cell(n)->size(1),
199  cell(n)->center(2)+(j-0.5)*cell(n)->size(2) ) );
200  cell(n)->setRes(InitResistivity(cell(n)->center(1),cell(n)->center(2)));
201  }
202  }else{
203  cell(n)->setAverage(InitAverage(cell(n)->center(1),cell(n)->center(2)));
204  cell(n)->setRes(InitResistivity(cell(n)->center(1),cell(n)->center(2)));
205  }
206  break;
207 
208  case 3:
209  if(IcNb){
210  for (i=0;i<=1;i++)
211  for (j=0;j<=1;j++)
212  for (k=0;k<=1;k++){
213  cell(n)->setAverage( cell(n)->average()+.125* InitAverage(
214  cell(n)->center(1)+(i-0.5)*cell(n)->size(1),
215  cell(n)->center(2)+(j-0.5)*cell(n)->size(2),
216  cell(n)->center(3)+(k-0.5)*cell(n)->size(3) ) );
217  cell(n)->setRes(InitResistivity(cell(n)->center(1),cell(n)->center(2),cell(n)->center(3)));
218  }
219  }else{
220  cell(n)->setAverage(InitAverage(cell(n)->center(1),cell(n)->center(2),cell(n)->center(3)));
221  cell(n)->setRes(InitResistivity(cell(n)->center(1),cell(n)->center(2),cell(n)->center(3)));
222  }
223 
224  break;
225  };
226  }
227  }
228  }
229 
230  #if defined PARMPI
231  //Important moment: Exchange boundary (neighbour) cells before start computation (1st iteration)
232 
233  CPUExchange(this, SendQ);
234  if (MPIRecvType == 1) MPI_Waitall(4*Dimension,req,st); //Send quantity number one (code name "Q")
235 
236  if (EquationType==6) {
237  CPUExchange(this, SendGrad);
238  if (MPIRecvType == 1) MPI_Waitall(4*Dimension,req,st); //Send gradient
239  }
240  #endif
241 
242 }
Cell *** Neighbour_iU
Definition: FineMesh.h:234
int one_D
Definition: Parameters.cpp:236
An object Cell contains all the informations of a cell for both multiresolution and finite volume com...
Definition: Cell.h:41
void setAverageZero()
Sets all the cell-average values to zero.
Definition: Cell.h:937
int ScaleNb
Definition: Parameters.cpp:87
real InitResistivity(real x, real y=0., real z=0.)
Returns the initial resistivity condition in (x, y, z) form the one defined in carmen.eta.
Definition: InitAverage.cpp:50
real center(const int AxisNo) const
Returns the component no. AxisNo of the cell-center position.
Definition: Cell.h:1112
bool TimeAveraging
Definition: Parameters.cpp:60
bool ComputeCPUTimeRef
Definition: Parameters.cpp:62
int IcNb
Definition: Parameters.cpp:89
real XMax[4]
Definition: Parameters.cpp:77
int MPIRecvType
Definition: Parameters.cpp:239
void restore()
Restores the tree structure and the cell-averages from the file carmen.bak. This file was created by ...
Definition: FineMesh.cpp:1768
Cell *** Neighbour_jU
Definition: FineMesh.h:234
int Dimension
Definition: Parameters.cpp:74
Cell *** Neighbour_iL
Definition: FineMesh.h:234
void setRes(const real UserAverage)
Set resistivity.
Definition: Cell.h:1011
Cell *** Neighbour_kU
Definition: FineMesh.h:234
int BoundaryRegion(const Vector &X)
Returns the boundary region type at the position X=(x,y,z). The returned value correspond to: 0 = Fl...
Definition: BoundaryRegion.cpp:63
void setSize(const int AxisNo, const real UserSize)
Sets the size of the cell in the direction AxisNo to UserSize. Example:
Definition: Cell.h:888
real XMin[4]
Definition: Parameters.cpp:76
bool UseBackup
Definition: Parameters.cpp:58
int two_D
Definition: Parameters.cpp:236
Cell *** Neighbour_kL
Definition: FineMesh.h:234
Time Average Grid.
Definition: TimeAverageGrid.h:24
int NeighbourNb
Definition: Parameters.cpp:228
int size
Definition: Parameters.cpp:224
bool Recovery
Definition: Parameters.cpp:59
int EquationType
Definition: Parameters.cpp:66
bool UseBoundaryRegions
Definition: Parameters.cpp:80
void setCenter(const int AxisNo, const real UserX)
Sets the coordinate of the cell-center in the direction AxisNo to UserX. Example: ...
Definition: Cell.h:905
Cell *** Neighbour_jL
Definition: FineMesh.h:234
Cell * MeshCell
Definition: FineMesh.h:256
int SendQ
Definition: Parameters.cpp:252
int SendGrad
Definition: Parameters.cpp:251
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921
Vector InitAverage(real x, real y=0., real z=0.)
Returns the initial condition in (x, y, z) form the one defined in carmen.ini.
Definition: InitAverage.cpp:22
void CPUExchange(FineMesh *Root, int)
Parallel function DOES NOT WORK!
Definition: Parallel.cpp:350
#define real
Definition: PreProcessor.h:31
FineMesh::~FineMesh ( )

Destructor the regular fine mesh.

251 {
252  // --- Delete pointers to cells ---
253 
254  delete[] MeshCell;
255 
256  #if defined PARMPI
257  int i,j;
258 
259  for (i=0;i<NeighbourNb;i++)
260  for (j=0;j<one_D;j++) {
261  delete[] Neighbour_iL[i][j];
262  delete[] Neighbour_iU[i][j];
263  delete[] Neighbour_jL[i][j];
264  delete[] Neighbour_jU[i][j];
265  delete[] Neighbour_kL[i][j];
266  delete[] Neighbour_kU[i][j];
267  }
268 
269  for (i=0;i<NeighbourNb;i++) {
270  delete[] Neighbour_iL[i];
271  delete[] Neighbour_iU[i];
272  delete[] Neighbour_jL[i];
273  delete[] Neighbour_jU[i];
274  delete[] Neighbour_kL[i];
275  delete[] Neighbour_kU[i];
276  }
277 
278  delete[] Neighbour_iL;
279  delete[] Neighbour_iU;
280  delete[] Neighbour_jL;
281  delete[] Neighbour_jU;
282  delete[] Neighbour_kL;
283  delete[] Neighbour_kU;
284  #endif
285 
286 
287  if (TimeAveraging)
288  delete MyTimeAverageGrid;
289 }
Cell *** Neighbour_iU
Definition: FineMesh.h:234
int one_D
Definition: Parameters.cpp:236
bool TimeAveraging
Definition: Parameters.cpp:60
Cell *** Neighbour_jU
Definition: FineMesh.h:234
Cell *** Neighbour_iL
Definition: FineMesh.h:234
Cell *** Neighbour_kU
Definition: FineMesh.h:234
Cell *** Neighbour_kL
Definition: FineMesh.h:234
int NeighbourNb
Definition: Parameters.cpp:228
Cell *** Neighbour_jL
Definition: FineMesh.h:234
Cell * MeshCell
Definition: FineMesh.h:256

Member Function Documentation

void FineMesh::backup ( )

Backs up the tree structure and the cell-averages into a file carmen.bak. In further computations, the data can be recovered using Restore().

Returns
void
1742 {
1743  int n=0; // Cell number
1744  FILE* output; // Output file
1745  int QuantityNo; // Counter on quantities
1746 
1747  // --- Init ---
1748 
1749  output = fopen(BackupName,"w");
1750 
1751  // --- Backup data on cells ---
1752 
1753  fprintf(output, "Backup at iteration %i, physical time %e\n", IterationNo, ElapsedTime);
1754  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
1755  for (QuantityNo=1; QuantityNo <= QuantityNb; QuantityNo++)
1756  fprintf(output, FORMAT, cell(n)->average(QuantityNo));
1757 
1758  fclose(output);
1759 }
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
int Dimension
Definition: Parameters.cpp:74
int IterationNo
Definition: Parameters.cpp:168
real ElapsedTime
Definition: Parameters.cpp:95
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
char BackupName[255]
Definition: Parameters.cpp:257
#define FORMAT
Definition: PreProcessor.h:32

Here is the caller graph for this function:

void FineMesh::checkStability ( ) const

Checks if the computation is numerically unstable, i.e. if one of the cell-averages is overflow. In case of numerical instability, the computation is stopped and a message appears.

Returns
void
928 {
929  // --- Local variables ---
930 
931  int n=0, iaux; // cell number
932  real x=0., y=0., z=0.; // Real position
933  iaux = 0;
934  // --- Loop on all cells ---
935 
936  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
937  {
938  // --- Compute x, y, z ---
939 
940  x = cell(n)->center(1);
941  if (Dimension > 1) y = cell(n)->center(2);
942  if (Dimension > 2) z = cell(n)->center(3);
943 
944  // --- Test if one cell is overflow ---
945 
946  if (cell(n)->isOverflow())
947  {
948  iaux=system("echo Unstable computation.>> carmen.prf");
949  if (Cluster == 0) iaux=system("echo carmen: unstable computation. >> OUTPUT");
950  cout << "carmen: instability detected at iteration no. "<< IterationNo <<"\n";
951  cout << "carmen: position ("<< x <<", "<<y<<", "<<z<<")\n";
952  cout << "carmen: abort execution.\n";
953  exit(1);
954  }
955  }
956  // --- End loop on all cells ---
957 }
int ScaleNb
Definition: Parameters.cpp:87
real center(const int AxisNo) const
Returns the component no. AxisNo of the cell-center position.
Definition: Cell.h:1112
int Cluster
Definition: Parameters.cpp:170
int Dimension
Definition: Parameters.cpp:74
int IterationNo
Definition: Parameters.cpp:168
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::computeCorrection ( int  mode)

Computes divergence cleaning source term (only for MHD).

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
541 {
542  int i,j,k,d;
543  // --- Loops for internal cells
544  if (mode==0) {
545  if (Dimension==1)
546  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++) {
547  j=0; k=0;
548  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
550  }
551 
552  if (Dimension==2)
553  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
554  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++) {
555  k=0;
556  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
558  }
559 
560 
561  if (Dimension==3)
562  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
563  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++)
564  for (k=NeighbourNb;k<(1<<ScaleNb)-NeighbourNb;k++) {
565  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
567  }
568  }
569 
570 // --- loop for neighbour cells
571  if (mode==1) {
572 
573  if (Dimension==1)
574  for (i=0;i<(1<<ScaleNb);i++)
575  if (i<NeighbourNb || i>=(1<<ScaleNb)-NeighbourNb) {
576  j=0; k=0;
577  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
579  }
580 
581  if (Dimension==2)
582  for (i=0;i<(1<<ScaleNb);i++)
583  for (j=0;j<one_D;j++)
584  if (i<NeighbourNb || j<NeighbourNb ||
585  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb) {
586  k=0;
587  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
589  }
590 
591  if (Dimension==3)
592  for (i=0;i<(1<<ScaleNb);i++)
593  for (j=0;j<one_D;j++)
594  for (k=0;k<two_D;k++)
595  if (i<NeighbourNb || j<NeighbourNb || k<NeighbourNb ||
596  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb || k>=(1<<ScaleNb)-NeighbourNb) {
597  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
599  }
600  }
601 /*
602  int n;
603  for (n = 0; n < 1<<(ScaleNb*Dimension); n++) computeDivergence_cell(n);*/
604 }
int one_D
Definition: Parameters.cpp:236
int ScaleNb
Definition: Parameters.cpp:87
void computeCorrection_cell(int)
Computes divergence cleaning source term (only for MHD) at one cell.
Definition: FineMesh.cpp:507
int Dimension
Definition: Parameters.cpp:74
int two_D
Definition: Parameters.cpp:236
int NeighbourNb
Definition: Parameters.cpp:228

Here is the caller graph for this function:

void FineMesh::computeCorrection_cell ( int  n)

Computes divergence cleaning source term (only for MHD) at one cell.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
508 {
509  // --- Local variables ---
510  real rho=0., psi=0.; // Variables density and psi
511  int q=0; // Counters
512  real Bx=0.; // Magnetic field
513 
514  // --- Computation ---
515 
516 
517  if(DivClean==1) // EGLM
518  {
519 
520  rho = cell(n)->density();
521  psi = cell(n)->psi();
522 
523  for (q=1; q <= 3; q++) //GLM
524  {
525  Bx = cell(n)->magField(q);
526  cell(n)->setAverage(q+1, cell(n)->average(q+1) - TimeStep*Bx*Bdivergence/(ch*ch));
527  }
528 
529  cell(n)->setAverage(5, cell(n)->average(5) - TimeStep*PsiGrad);
530  cell(n)->setAverage(6,psi*exp(-(cr*ch*TimeStep/SpaceStep)));
531 
532  }else if(DivClean==2)
533  {
534  psi = cell(n)->psi();
535  cell(n)->setAverage(6,psi*exp(-(cr*ch*TimeStep/SpaceStep)));
536  }
537 
538 
539 }
real ch
Definition: Parameters.cpp:140
real density() const
Returns the cell-average density.
Definition: Cell.h:1262
real SpaceStep
Definition: Parameters.cpp:156
real cr
Definition: Parameters.cpp:194
int DivClean
Definition: Parameters.cpp:70
real magField(const int AxisNo) const
Returns the component no. AxisNo of the cell-average magnetic field.
Definition: Cell.h:1336
real TimeStep
Definition: Parameters.cpp:40
real PsiGrad
Definition: Parameters.cpp:139
real Bdivergence
Definition: Parameters.cpp:138
real psi() const
Returns the cell-average density.
Definition: Cell.h:1280
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::computeDivergence ( int  mode)

Computes the divergence vector with the space discretization scheme.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
427 {
428  int i,j,k,d;
429 
430 
431  // --- Loops for internal cells
432  if (mode==0)
433  {
434  if (Dimension==1)
435  for (i=2*NeighbourNb;i<(1<<ScaleNb)-2*NeighbourNb;i++)
436  {
437  j=0; k=0;
438  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
440  }
441 
442  if (Dimension==2)
443  for (i=2*NeighbourNb;i<(1<<ScaleNb)-2*NeighbourNb;i++)
444  for (j=2*NeighbourNb;j<(1<<ScaleNb)-2*NeighbourNb;j++)
445  {
446  k=0;
447  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
449  }
450 
451 
452  if (Dimension==3)
453  for (i=2*NeighbourNb;i<(1<<ScaleNb)-2*NeighbourNb;i++)
454  for (j=2*NeighbourNb;j<(1<<ScaleNb)-2*NeighbourNb;j++)
455  for (k=2*NeighbourNb;k<(1<<ScaleNb)-2*NeighbourNb;k++) {
456  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
458  }
459  }
460 
461 // --- loop for neighbour cells
462  if (mode==1) {
463 
464  if (Dimension==1)
465  for (i=0;i<(1<<ScaleNb);i++)
466  if (i<2*NeighbourNb || i>=(1<<ScaleNb)-2*NeighbourNb) {
467  j=0; k=0;
468  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
470  }
471 
472  if (Dimension==2)
473  for (i=0;i<(1<<ScaleNb);i++)
474  for (j=0;j<one_D;j++)
475  if (i<2*NeighbourNb || j<2*NeighbourNb ||
476  i>=(1<<ScaleNb)-2*NeighbourNb || j>=(1<<ScaleNb)-2*NeighbourNb) {
477  k=0;
478  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
480  }
481 
482  if (Dimension==3)
483  for (i=0;i<(1<<ScaleNb);i++)
484  for (j=0;j<one_D;j++)
485  for (k=0;k<two_D;k++)
486  if (i<2*NeighbourNb || j<2*NeighbourNb || k<2*NeighbourNb ||
487  i>=(1<<ScaleNb)-2*NeighbourNb || j>=(1<<ScaleNb)-2*NeighbourNb || k>=(1<<ScaleNb)-2*NeighbourNb) {
488  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
490  }
491 
492 }
493 
494 /*
495  int n;
496  for (n = 0; n < 1<<(ScaleNb*Dimension); n++) computeDivergence_cell(n);*/
497 }
int one_D
Definition: Parameters.cpp:236
int ScaleNb
Definition: Parameters.cpp:87
void computeDivergence_cell(int)
Computes one Cell Divirgence.
Definition: FineMesh.cpp:334
int Dimension
Definition: Parameters.cpp:74
int two_D
Definition: Parameters.cpp:236
int NeighbourNb
Definition: Parameters.cpp:228

Here is the caller graph for this function:

void FineMesh::computeDivergence_cell ( int  n)

Computes one Cell Divirgence.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void

2D resistive part of the model added to the Flux

335 {
336  // --- Local variables ---
337 
338  int i=0, j=0, k=0; // position numbers
339  Vector FluxIn, FluxOut; // ingoing and outgoing fluxes
340  real divCor=0.;
341 
342  // --- Loop on all cells ---
343 
344  // --- Only in fluid region ---
345 
346  if (!UseBoundaryRegions || BoundaryRegion(cell(n)->center())==0)
347  {
348  // --- Compute source term --
349 
350  cell(n)->setDivergence(Source(*cell(n)));
351 
352  // -- Compute i, j, k --
353 
354  i = n%(1<<ScaleNb);
355  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
356  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
357 
358  // Add flux in x-direction
359 
360  FluxIn = Flux( *cell(i-2, j, k), *cell(i-1, j, k), *cell(i, j, k), *cell(i+1, j, k), 1 );
361  divCor = -auxvar;
362  FluxOut = Flux( *cell(i-1, j, k), *cell(i , j, k), *cell(i+1, j, k), *cell(i+2, j, k), 1 );
363  divCor += auxvar;
364 
366 
367  if(Resistivity){
368  FluxIn = FluxIn - ResistiveTerms(*cell(i,j,k) , *cell(i-1,j,k), *cell(i,j-1,k) , *cell(i,j,k-1) , 1);
369  FluxOut = FluxOut - ResistiveTerms(*cell(i+1,j,k), *cell(i,j,k) , *cell(i+1,j-1,k), *cell(i+1,j,k-1), 1);
370  }
371 
372  cell(n)->setDivergence( cell(n)->divergence() + (FluxIn - FluxOut)/(cell(n)->size(1)));
373 
374  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
375  PsiGrad = cell(n)->average(7)*(FluxOut.value(7) - FluxIn.value(7) - divCor)/(cell(n)->size(1));
376  Bdivergence += (FluxOut.value(6) - FluxIn.value(6))/(cell(n)->size(1));
377 
378  // Add flux in y-direction
379 
380  if (Dimension > 1)
381  {
382  FluxIn = Flux( *cell(i, j-2, k), *cell(i, j-1, k), *cell(i, j , k), *cell(i, j+1, k), 2 );
383  divCor = -auxvar;
384  FluxOut = Flux( *cell(i, j-1, k), *cell(i, j , k), *cell(i, j+1, k), *cell(i, j+2, k), 2 );
385  divCor += auxvar;
386 
387  if(Resistivity){
388  FluxIn = FluxIn - ResistiveTerms(*cell(i,j,k) , *cell(i-1,j,k) , *cell(i,j-1,k), *cell(i,j,k-1) , 2);
389  FluxOut = FluxOut - ResistiveTerms(*cell(i,j+1,k), *cell(i-1,j+1,k), *cell(i,j,k) , *cell(i,j+1,k-1), 2);
390  }
391 
392  cell(n)->setDivergence( cell(n)->divergence() + (FluxIn - FluxOut)/(cell(n)->size(2)) );
393 
394  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
395  PsiGrad += cell(n)->average(8)*(FluxOut.value(8) - FluxIn.value(8) - divCor)/(cell(n)->size(2));
396  Bdivergence += (FluxOut.value(6) - FluxIn.value(6))/(cell(n)->size(2));
397  }
398 
399  // Add flux in z-direction
400 
401  if (Dimension > 2)
402  {
403  FluxIn = Flux( *cell(i, j, k-2), *cell(i, j, k-1), *cell(i, j, k ), *cell(i, j, k+1), 3 );
404  divCor = -auxvar;
405  FluxOut = Flux( *cell(i, j, k-1), *cell(i, j, k ), *cell(i, j, k+1), *cell(i, j, k+2), 3 );
406  divCor += auxvar;
407 
408  if(Resistivity){
409  FluxIn = FluxIn - ResistiveTerms(*cell(i,j,k) , *cell(i-1,j,k) , *cell(i,j-1,k) , *cell(i,j,k-1), 3);
410  FluxOut = FluxOut - ResistiveTerms(*cell(i,j,k+1), *cell(i-1,j,k+1), *cell(i,j-1,k+1), *cell(i,j,k) , 3);
411  }
412 
413  cell(n)->setDivergence( cell(n)->divergence() + (FluxIn - FluxOut)/(cell(n)->size(3)) );
414 
415  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
416  PsiGrad += cell(n)->average(9)*(FluxOut.value(9) - FluxIn.value(9) - divCor)/(cell(n)->size(3));
417  Bdivergence += (FluxOut.value(6) - FluxIn.value(6))/(cell(n)->size(3));
418  }
419  }
420 
421  // --- End loop on all cells ---
422 }
int ScaleNb
Definition: Parameters.cpp:87
Standard class for every vector in Carmen.
Definition: Vector.h:29
bool Resistivity
Definition: Parameters.cpp:120
void setDivergence(const int QuantityNo, const real UserAverage)
Identical to void setAverage (int QuantityNo, real UserAverage), but for the divergence vector...
Definition: Cell.h:1019
Vector Source(Cell &UserCell)
Returns the source term in the cell UserCell.
Definition: Source.cpp:23
real auxvar
Definition: Parameters.cpp:141
int Dimension
Definition: Parameters.cpp:74
int BoundaryRegion(const Vector &X)
Returns the boundary region type at the position X=(x,y,z). The returned value correspond to: 0 = Fl...
Definition: BoundaryRegion.cpp:63
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
Vector ResistiveTerms(Cell &Cell1, Cell &Cell2, Cell &Cell3, Cell &Cell4, int AxisNo)
Returns the resistive source terms in the cell UserCell.
Definition: ResistiveTerms.cpp:11
Vector Flux(Cell &Cell1, Cell &Cell2, Cell &Cell3, Cell &Cell4, int AxisNo)
Returns the flux at the interface between Cell2 and Cell3. Here a 4-point space scheme is used...
Definition: Flux.cpp:22
real PsiGrad
Definition: Parameters.cpp:139
int size
Definition: Parameters.cpp:224
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
bool UseBoundaryRegions
Definition: Parameters.cpp:80
real Bdivergence
Definition: Parameters.cpp:138
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::computeGradient ( int  mode)

Computes velocity gradient (only for Navier-Stokes). one cell.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
690 {
691  int i,j,k,d;
692  // --- Loops for internal cells
693  if (mode==0) {
694  if (Dimension==1)
695  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++) {
696  j=0; k=0;
697  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
699  }
700 
701  if (Dimension==2)
702  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
703  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++) {
704  k=0;
705  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
707  }
708 
709 
710  if (Dimension==3)
711  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
712  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++)
713  for (k=NeighbourNb;k<(1<<ScaleNb)-NeighbourNb;k++) {
714  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
716  }
717  }
718 
719 // --- loop for neighbour cells
720  if (mode==1) {
721 
722  if (Dimension==1)
723  for (i=0;i<(1<<ScaleNb);i++)
724  if (i<NeighbourNb || i>=(1<<ScaleNb)-NeighbourNb) {
725  j=0; k=0;
726  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
728  }
729 
730  if (Dimension==2)
731  for (i=0;i<(1<<ScaleNb);i++)
732  for (j=0;j<one_D;j++)
733  if (i<NeighbourNb || j<NeighbourNb ||
734  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb) {
735  k=0;
736  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
738  }
739 
740  if (Dimension==3)
741  for (i=0;i<(1<<ScaleNb);i++)
742  for (j=0;j<one_D;j++)
743  for (k=0;k<two_D;k++)
744  if (i<NeighbourNb || j<NeighbourNb || k<NeighbourNb ||
745  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb || k>=(1<<ScaleNb)-NeighbourNb) {
746  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
748  }
749  }
750 /*
751  int n;
752  for (n = 0; n < 1<<(ScaleNb*Dimension); n++) computeDivergence_cell(n);*/
753 }
int one_D
Definition: Parameters.cpp:236
int ScaleNb
Definition: Parameters.cpp:87
int Dimension
Definition: Parameters.cpp:74
int two_D
Definition: Parameters.cpp:236
int NeighbourNb
Definition: Parameters.cpp:228
void computeGradient_cell(int)
Computes velocity gradient (only for Navier-Stokes). each cells.
Definition: FineMesh.cpp:614
void FineMesh::computeGradient_cell ( int  n)

Computes velocity gradient (only for Navier-Stokes). each cells.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
615 {
616  // --- Local variables ---
617  int i=0, j=0, k=0; // Counter on children
618  real V1=0., V2=0.; // Velocities
619  real dx=0.; // Distance between the centers of the neighbour cells
620  real dxV=0.; // Correction of dx for the computation of GradV close to solid walls // Cell size
621  real rho1=0., rho2=0.; // Densities
622  real rhoE1=0., rhoE2=0.; // Energies
623  int p=0, q=0; // Counters on dimension (between 0 and Dimension)
624  int ei=0, ej=0, ek=0; // 1 if this direction is chosen, 0 elsewhere
625 
626  real result;
627  result = 0.;
628 
629  // --- Recursion ---
630 
631  if (EquationType != 6)
632  {
633  cout << "FineMesh.cpp: In method `void FineMesh::computeGradient()':\n";
634  cout << "FineMesh.cpp: EquationType not equal to 6 \n";
635  cout << "carmen: *** [FineMesh.o] Execution error\n";
636  cout << "carmen: abort execution.\n";
637  exit(1);
638  }
639 
640  // --- Loop on all cells ---
641 
642  // Only in the fluid
643  if (BoundaryRegion(cell(n)->center()) == 0)
644  {
645  i = n%(1<<ScaleNb);
646  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
647  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
648 
649  for (p=1; p <= Dimension; p++)
650  {
651  ei = (p==1)? 1:0;
652  ej = (p==2)? 1:0;
653  ek = (p==3)? 1:0;
654 
655  dx = cell(i,j,k)->size(p);
656  dx *= 2.;
657 
658  // dxV = correction on dx for the computation of GradV close to solid walls
659 
660  if (BoundaryRegion(cell(i+ei,j+ej,k+ek)->center()) > 3 ||
661  BoundaryRegion(cell(i-ei,j-ej,k-ek)->center()) > 3 )
662  dxV = 0.75*dx;
663  else
664  dxV = dx;
665 
666  rho1 = cell(i+ei,j+ej,k+ek)->density();
667  rho2 = cell(i-ei,j-ej,k-ek)->density();
668 
669  cell(n)->setGradient(p, 1, (rho1-rho2)/dx);
670 
671  for (q=1; q <= Dimension; q++)
672  {
673  V1=cell(i+ei,j+ej,k+ek)->velocity(q);
674  V2=cell(i-ei,j-ej,k-ek)->velocity(q);
675  result = (V1-V2)/dx;
676  cell(n)->setGradient(p, q+1, (V1-V2)/dxV);
677  }
678 
679  rhoE1 = cell(i+ei,j+ej,k+ek)->energy();
680  rhoE2 = cell(i-ei,j-ej,k-ek)->energy();
681 
682  cell(n)->setGradient(p, Dimension+2, (rhoE1-rhoE2)/dx);
683  }
684  }
685 
686 }
int ScaleNb
Definition: Parameters.cpp:87
void setGradient(const int i, const int j, const real UserAverage)
Sets the component no. i, j of the quantity gradient to UserAverage.
Definition: Cell.h:1051
real density() const
Returns the cell-average density.
Definition: Cell.h:1262
int Dimension
Definition: Parameters.cpp:74
real velocity(const int AxisNo) const
Returns the component no. AxisNo of the cell-average velocity.
Definition: Cell.h:1354
int BoundaryRegion(const Vector &X)
Returns the boundary region type at the position X=(x,y,z). The returned value correspond to: 0 = Fl...
Definition: BoundaryRegion.cpp:63
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
int EquationType
Definition: Parameters.cpp:66
real energy() const
Returns the cell-average energy per unit of volume.
Definition: Cell.h:1307
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::computeIntegral ( )

Computes integral values like e.g. flame velocity, global error, etc.

Returns
void
966 {
967  // --- Local variables ---
968 
969  int n=0; // cell number
970  int AxisNo; // Counter on dimension
971  real dx=0., dy=0., dz=0.; // Cell size
972  Vector Center(Dimension); // local center of the flame ball
973  real VelocityMax=0.; // local maximum of the velocity
974  real divB=0;
975  Vector GradDensity(Dimension); // gradient of density
976  Vector GradPressure(Dimension);// gradient of pressure
977  real B1=0., B2=0.; // Left and right magnetic field cells
978  real modB=0.;
979  real MaxSpeed;
980  real QuantityNo=0.;
981 
982  int ei=0, ej=0, ek=0; // 1 if this direction is chosen, 0 elsewhere
983  int i=0, j=0, k=0; // Counter on children
984 
985  // --- Init ---
986 
987  // Init integral values
988 
989  FlameVelocity = 0.;
990  GlobalMomentum = 0.;
991  GlobalEnergy = 0.;
992  GlobalEnstrophy = 0.;
993  ExactMomentum = 0.;
994  ExactEnergy = 0.;
995 
996  GlobalReactionRate = 0.;
997  AverageRadius = 0.;
998  ReactionRateMax = 0.;
999 
1000  for (AxisNo=1; AxisNo <= Dimension; AxisNo++)
1001  Center.setValue(AxisNo,XCenter[AxisNo]);
1002 
1003  ErrorMax = 0.;
1004  ErrorMid = 0.;
1005  ErrorL2 = 0.;
1006  ErrorNb = 0;
1007 
1008  RKFError = 0.;
1009 
1010  Eigenvalue = 0.;
1011  QuantityMax.setZero();
1012 
1013  IntVorticity=0.;
1014  IntDensity=0.;
1015  IntMomentum.setZero();
1016  BaroclinicEffect=0.;
1017 
1018 // --- Loop on all cells ---
1019 
1020  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
1021  {
1022  i = n%(1<<ScaleNb);
1023  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1024  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
1025 
1026  dx = cell(n)->size(1);
1027  dy = (Dimension > 1) ? cell(n)->size(2) : 1.;
1028  dz = (Dimension > 2) ? cell(n)->size(3) : 1.;
1029 
1030  // --- Compute the global momentum, global energy and global enstrophy ---
1031 
1032  GlobalMomentum += cell(n)->average(2)*dx*dy*dz;
1033  GlobalEnergy += .5*(cell(n)->magField()*cell(n)->magField() + cell(n)->density()*(cell(n)->velocity()*cell(n)->velocity())) + cell(n)->pressure()/(Gamma-1.0);
1034  //GlobalEnergy += .5*(cell(n)->density()*(cell(n)->velocity()*cell(n)->velocity()));
1035  GlobalEnergy *= dx*dy*dz;
1036  Helicity += (cell(n)->magField(2)*cell(n)->velocity(3) - cell(n)->magField(3)*cell(n)->velocity(2))*cell(n)->magField(1) +
1037  (cell(n)->magField(3)*cell(n)->velocity(1) - cell(n)->magField(1)*cell(n)->velocity(3))*cell(n)->magField(2) +
1038  (cell(n)->magField(1)*cell(n)->velocity(2) - cell(n)->magField(2)*cell(n)->velocity(1))*cell(n)->magField(3);
1039  Helicity *= 2*dx*dy*dz;
1040 
1041  // --- Compute maximum of the conservative quantities ---
1042 
1043  for (QuantityNo=1; QuantityNo <=QuantityNb; QuantityNo++)
1044  {
1045  if ( QuantityMax.value(QuantityNo) < fabs(cell(n)->average(QuantityNo)) )
1046  QuantityMax.setValue(QuantityNo, fabs(cell(n)->average(QuantityNo)) );
1047  }
1048 
1049  // --- Compute the maximal eigenvalue ---
1050 
1051  VelocityMax = 0.;
1052  MaxSpeed = 0.;
1053  for (AxisNo=1; AxisNo <= Dimension; AxisNo ++){
1054  VelocityMax = Max( VelocityMax, fabs(cell(n)->velocity(AxisNo)));
1055  MaxSpeed = Max( MaxSpeed , fabs(cell(n)->fastSpeed(AxisNo)));
1056  }
1057 
1058  VelocityMax += MaxSpeed;
1059 
1060  EigenvalueMax = Max (EigenvalueMax, VelocityMax);
1061 
1062  for (AxisNo = 1; AxisNo <= Dimension; AxisNo ++)
1063  {
1064 
1065  ei = (AxisNo == 1)? 1:0;
1066  ej = (AxisNo == 2)? 1:0;
1067  ek = (AxisNo == 3)? 1:0;
1068 
1069  dx = cell(n)->size(AxisNo);
1070  // dx *= 2.;
1071 
1072  B1=cell(i+ei,j+ej,k+ek)->magField(AxisNo);
1073  B2=cell(i-ei,j-ej,k-ek)->magField(AxisNo);
1074  modB += (B1 + B2)/dx;
1075  divB += (B1-B2)/dx;
1076 
1077  }
1078  modB += 1.120e-13;
1079  DIVBMax = Max(DIVBMax,0.5*Abs(divB));
1080  DIVB = DIVBMax/modB;
1081  break;
1082  }
1083 
1084  // --- End loop on all cells ---
1085 
1087 }
real DIVB
Definition: Parameters.cpp:136
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
real ReactionRateMax
Definition: Parameters.cpp:210
Standard class for every vector in Carmen.
Definition: Vector.h:29
real DIVBMax
Definition: Parameters.cpp:137
real XCenter[4]
Definition: Parameters.cpp:209
real Eigenvalue
Definition: Parameters.cpp:157
real density() const
Returns the cell-average density.
Definition: Cell.h:1262
int ErrorNb
Definition: Parameters.cpp:185
int Dimension
Definition: Parameters.cpp:74
real RKFError
Definition: Parameters.cpp:190
real velocity(const int AxisNo) const
Returns the component no. AxisNo of the cell-average velocity.
Definition: Cell.h:1354
real IntVorticity
Definition: Parameters.cpp:215
real Gamma
Definition: Parameters.cpp:109
Vector IntMomentum
Definition: Parameters.cpp:217
real ExactMomentum
Definition: Parameters.cpp:199
real GlobalEnergy
Definition: Parameters.cpp:197
real ErrorL2
Definition: Parameters.cpp:183
real ErrorMax
Definition: Parameters.cpp:179
real GlobalMomentum
Definition: Parameters.cpp:196
real AverageRadius
Definition: Parameters.cpp:206
real Helicity
Definition: Parameters.cpp:195
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
void setValue(const int n, const real a)
Sets the component n to value a.
Definition: Vector.h:545
real FlameVelocity
Definition: Parameters.cpp:201
real magField(const int AxisNo) const
Returns the component no. AxisNo of the cell-average magnetic field.
Definition: Cell.h:1336
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
real IntDensity
Definition: Parameters.cpp:216
#define Abs(x)
Definition: Carmen.h:78
void ReduceIntegralValues()
Parallel function DOES NOT WORK!
Definition: Parallel.cpp:469
real pressure() const
Returns the cell-average pressure.
Definition: Cell.cpp:84
real GlobalReactionRate
Definition: Parameters.cpp:205
Vector QuantityMax
Definition: Parameters.cpp:162
real EigenvalueMax
Definition: Parameters.cpp:161
real ExactEnergy
Definition: Parameters.cpp:200
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
real BaroclinicEffect
Definition: Parameters.cpp:219
real GlobalEnstrophy
Definition: Parameters.cpp:198
#define Max(x, y)
Definition: Carmen.h:54
real ErrorMid
Definition: Parameters.cpp:181
void setZero()
Sets all the components to zero.
Definition: Vector.cpp:228
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::computeTimeAverage ( )

Computes the time-average value in every cell.

Returns
void
1804 {
1805  // Local variables
1806 
1807  int i=0, j=0, k=0, n=0; // Counters on directions
1808 
1809  // Start this procedure when the physical time is larger than StartTimeAveraging
1810 
1812  return;
1813 
1814  // Update time-average values with values in FineMesh
1815 
1816  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
1817  {
1818  i = n%(1<<ScaleNb);
1819  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1820  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
1821 
1822  MyTimeAverageGrid->updateValue(i,j,k,cell(i,j,k)->average());
1823  }
1824 
1825  // Update the number of samples (Warning: currently only for constant time step !!)
1826  MyTimeAverageGrid->updateSample();
1827 }
int ScaleNb
Definition: Parameters.cpp:87
void updateSample()
Update number of samples.
Definition: TimeAverageGrid.h:171
void updateValue(const int ElementNo, const int QuantityNo, const real UserValue)
Update Values. For a given element.
Definition: TimeAverageGrid.cpp:107
int Dimension
Definition: Parameters.cpp:74
int IterationNo
Definition: Parameters.cpp:168
real TimeStep
Definition: Parameters.cpp:40
real StartTimeAveraging
Definition: Parameters.cpp:61

Here is the caller graph for this function:

void FineMesh::restore ( )

Restores the tree structure and the cell-averages from the file carmen.bak. This file was created by the method Backup().

Returns
void
1769 {
1770  int n,iaux; // Cell number
1771  int QuantityNo; // Counter on quantities
1772  FILE* input; // Input file
1773  real buf; // Buffer
1774 // char line[1024];
1775 
1776  // --- Init ---
1777 
1778  input = fopen(BackupName,"r");
1779 
1780  // When there is no back-up file, return
1781  if (!input) return;
1782 
1783  // --- Restore data on cells ---
1784 
1785  //fgets(line, 1024, input);
1786  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
1787  for (QuantityNo=1; QuantityNo <= QuantityNb; QuantityNo++)
1788  {
1789  iaux=fscanf(input, BACKUP_FILE_FORMAT, &buf);
1790  cell(n)->setAverage(QuantityNo, buf);
1791  }
1792 
1793  fclose(input);
1794  return;
1795 }
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
int Dimension
Definition: Parameters.cpp:74
char BackupName[255]
Definition: Parameters.cpp:257
#define BACKUP_FILE_FORMAT
Definition: PreProcessor.h:35
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::RungeKutta ( int  mode)

Computes the Runge-Kutta step.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
807  {
808  int i,j,k,d;
809 
810  // --- Loops for internal cells
811 
812  if (mode==0) {
813  if (Dimension==1)
814  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++) {
815  j=0; k=0;
816  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
817  RungeKutta_cell(d);
818  }
819 
820  if (Dimension==2)
821  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
822  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++) {
823  k=0;
824  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
825  RungeKutta_cell(d);
826  }
827 
828 
829  if (Dimension==3)
830  for (i=NeighbourNb;i<(1<<ScaleNb)-NeighbourNb;i++)
831  for (j=NeighbourNb;j<(1<<ScaleNb)-NeighbourNb;j++)
832  for (k=NeighbourNb;k<(1<<ScaleNb)-NeighbourNb;k++) {
833  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
834  RungeKutta_cell(d);
835  }
836  }
837 
838 // --- loop for neighbour cells
839  if (mode==1) {
840 
841  if (Dimension==1)
842  for (i=0;i<(1<<ScaleNb);i++)
843  if (i<NeighbourNb || i>=(1<<ScaleNb)-NeighbourNb) {
844  j=0; k=0;
845  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
846  RungeKutta_cell(d);
847  }
848 
849  if (Dimension==2)
850  for (i=0;i<(1<<ScaleNb);i++)
851  for (j=0;j<one_D;j++)
852  if (i<NeighbourNb || j<NeighbourNb ||
853  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb) {
854  k=0;
855  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
856  RungeKutta_cell(d);
857  }
858 
859  if (Dimension==3)
860  for (i=0;i<(1<<ScaleNb);i++)
861  for (j=0;j<one_D;j++)
862  for (k=0;k<two_D;k++)
863  if (i<NeighbourNb || j<NeighbourNb || k<NeighbourNb ||
864  i>=(1<<ScaleNb)-NeighbourNb || j>=(1<<ScaleNb)-NeighbourNb || k>=(1<<ScaleNb)-NeighbourNb) {
865  d=i + (1<<ScaleNb)*(j + (1<<ScaleNb)*k);
866  RungeKutta_cell(d);
867  }
868 
869  }
870 
871 // int n;
872 // for (n = 0; n < 1<<(ScaleNb*Dimension); n++) RungeKutta_cell(n);
873 }
int one_D
Definition: Parameters.cpp:236
int ScaleNb
Definition: Parameters.cpp:87
int Dimension
Definition: Parameters.cpp:74
void RungeKutta_cell(int)
Computes one Runge-Kutta step.
Definition: FineMesh.cpp:763
int two_D
Definition: Parameters.cpp:236
int NeighbourNb
Definition: Parameters.cpp:228

Here is the caller graph for this function:

void FineMesh::RungeKutta_cell ( int  n)

Computes one Runge-Kutta step.

Parameters
intIt can be zero or one. Associated to the time integration scheme.
Returns
void
764 {
765  // --- Local variables ---
766  real c1=0., c2=0., c3=0.; // Runge-Kutta coefficients
767 
768  Vector Q(QuantityNb), Qs(QuantityNb), D(QuantityNb); // Cell-average, temporary cell-average and divergence
769 
770  // --- Loop on all cells ---
771 
772  if (!UseBoundaryRegions || BoundaryRegion(cell(n)->center()) == 0)
773  {
774  switch(StepNo)
775  {
776  case 1:
777  c1 = 1.; c2 = 0.; c3 = 1.;
778  break;
779  case 2:
780  if (StepNb == 2) {c1 = .5; c2 = .5; c3 = .5; }
781  if (StepNb == 3) {c1 = .75; c2 = .25; c3 = .25; }
782  break;
783  case 3:
784  if (StepNb == 3) {c1 = 1./3.; c2 = 2.*c1; c3 = c2;}
785  break;
786  };
787 
788  // --- Runge-Kutta step ---
789 
790  Q = cell(n)->average();
791  Qs = cell(n)->tempAverage();
792  D = cell(n)->divergence();
793 
794  cell(n)->setAverage( c1*Qs + c2*Q + (c3 * TimeStep)*D );
795  }
796 
797 }
int QuantityNb
Definition: Parameters.cpp:171
Standard class for every vector in Carmen.
Definition: Vector.h:29
int StepNo
Definition: Parameters.cpp:167
real divergence(const int QuantityNo) const
Returns the component no. QuantityNo of the divergence vector.
Definition: Cell.h:1192
int BoundaryRegion(const Vector &X)
Returns the boundary region type at the position X=(x,y,z). The returned value correspond to: 0 = Fl...
Definition: BoundaryRegion.cpp:63
int StepNb
Definition: Parameters.cpp:36
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
real tempAverage(const int QuantityNo) const
Returns the component no. QuantityNo of the temporary cell-average value.
Definition: Cell.h:1144
real TimeStep
Definition: Parameters.cpp:40
bool UseBoundaryRegions
Definition: Parameters.cpp:80
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::store ( )

Stores cell-average values into temporary cell-average values.

Returns
void
883 {
884  // --- Local variables ---
885 
886  int n=0; // cell number
887 
888  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
889  {
890  if (UseBoundaryRegions)
891  {
892  if (IterationNo == 1)
893  cell(n)->setOldAverage(cell(n)->average());
894  else
895  cell(n)->setOldAverage(cell(n)->tempAverage());
896  }
897 
898  cell(n)->setTempAverage(cell(n)->average());
899  }
900 }
int ScaleNb
Definition: Parameters.cpp:87
void setOldAverage(const int QuantityNo, const real UserAverage)
Identical to setAverage (int QuantityNo, real UserAverage), but for the vector of the old cell-averag...
Definition: Cell.h:985
int Dimension
Definition: Parameters.cpp:74
int IterationNo
Definition: Parameters.cpp:168
void setTempAverage(const int QuantityNo, const real UserAverage)
Identical to setAverage (int QuantityNo, real UserAverage), but for the vector of the temporary cell-...
Definition: Cell.h:945
bool UseBoundaryRegions
Definition: Parameters.cpp:80

Here is the caller graph for this function:

void FineMesh::storeGrad ( )

Stores gradient values into temporary gradient values.

Returns
void
911 {
912  // --- Local variables ---
913 
914  int n=0; // cell number
915 
916  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
917  cell(n)->setTempGradient(cell(n)->gradient());
918 }
int ScaleNb
Definition: Parameters.cpp:87
int Dimension
Definition: Parameters.cpp:74
void setTempGradient(const int i, const int j, const real UserAverage)
Identical to the previous one for the temporary values. Does not work for MHD!
Definition: Cell.h:1059
void FineMesh::writeAverage ( const char *  FileName)

Write cell-averages for GNUplot, Data Explorer, TecPLot and VTK into file FileName.

Parameters
FileNameName of the file to write.
Returns
void
1264 {
1265  // --- Local variables ---
1266 
1267  int i=0,j=0,k=0, n=0; // Coordinates
1268  FILE *output; // pointer to output file
1269 
1270  //real x=0., y=0., z=0., t=0.;
1271 
1272  // --- Open file ---
1273 
1274  if ((output = fopen(FileName,"a")) != NULL)
1275  {
1276  // --- Eventually coarsen grid
1277  if (PrintMoreScales == -1)
1278  {
1279  coarsen();
1280  ScaleNb--;
1281  }
1282 
1283  // --- Loop on all cells ---
1284 
1285  for (n=0; n < (1<<(Dimension*ScaleNb)); n++)
1286  {
1287 
1288  // -- Compute i, j, k --
1289 
1290  // For Gnuplot and DX, loop order: for i... {for j... {for k...} }
1291  if (PostProcessing != 3)
1292  {
1293  switch(Dimension)
1294  {
1295  case 1:
1296  i = n;
1297  j = k = 0;
1298  break;
1299 
1300  case 2:
1301  j = n%(1<<ScaleNb);
1302  i = n/(1<<ScaleNb);
1303  k = 0;
1304  break;
1305 
1306  case 3:
1307  k = n%(1<<ScaleNb);
1308  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1309  i = n/(1<<(2*ScaleNb));
1310  break;
1311  };
1312  }
1313  else
1314  {
1315  // For Tecplot, loop order: for k... {for j... {for i...} }
1316  i = n%(1<<ScaleNb);
1317  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1318  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
1319  }
1320 
1321  if(PostProcessing == 4)
1322  {
1323  fprintf(output, "\n\nSCALARS eta float\nLOOKUP_TABLE default\n");
1324  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1325  switch(Dimension)
1326  {
1327  case 1:
1328  i = n;
1329  j = k = 0;
1330  break;
1331 
1332  case 2:
1333  j = n%(1<<ScaleNb);
1334  i = n/(1<<ScaleNb);
1335  k = 0;
1336  break;
1337 
1338  case 3:
1339  k = n%(1<<ScaleNb);
1340  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1341  i = n/(1<<(2*ScaleNb));
1342  break;
1343  };
1344  FileWrite(output, FORMAT, cell(i,j,k)->etaConst());
1345  fprintf(output, "\n");
1346  }
1347 
1348  fprintf(output, "\n\nSCALARS Density float\nLOOKUP_TABLE default\n");
1349  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1350  switch(Dimension)
1351  {
1352  case 1:
1353  i = n;
1354  j = k = 0;
1355  break;
1356 
1357  case 2:
1358  j = n%(1<<ScaleNb);
1359  i = n/(1<<ScaleNb);
1360  k = 0;
1361  break;
1362 
1363  case 3:
1364  k = n%(1<<ScaleNb);
1365  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1366  i = n/(1<<(2*ScaleNb));
1367  break;
1368  };
1369  FileWrite(output, FORMAT, cell(i,j,k)->density());
1370  fprintf(output, "\n");
1371  }
1372 
1373  fprintf(output, "\n\nSCALARS Pressure float\nLOOKUP_TABLE default\n");
1374  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1375  switch(Dimension)
1376  {
1377  case 1:
1378  i = n;
1379  j = k = 0;
1380  break;
1381 
1382  case 2:
1383  j = n%(1<<ScaleNb);
1384  i = n/(1<<ScaleNb);
1385  k = 0;
1386  break;
1387 
1388  case 3:
1389  k = n%(1<<ScaleNb);
1390  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1391  i = n/(1<<(2*ScaleNb));
1392  break;
1393  };
1394  FileWrite(output, FORMAT, cell(i,j,k)->pressure());
1395  fprintf(output, "\n");
1396  }
1397 
1398  fprintf(output, "\n\nSCALARS Energy float\nLOOKUP_TABLE default\n");
1399  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1400  switch(Dimension)
1401  {
1402  case 1:
1403  i = n;
1404  j = k = 0;
1405  break;
1406 
1407  case 2:
1408  j = n%(1<<ScaleNb);
1409  i = n/(1<<ScaleNb);
1410  k = 0;
1411  break;
1412 
1413  case 3:
1414  k = n%(1<<ScaleNb);
1415  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1416  i = n/(1<<(2*ScaleNb));
1417  break;
1418  };
1419  FileWrite(output, FORMAT, cell(i,j,k)->energy());
1420  fprintf(output, "\n");
1421  }
1422 
1423  fprintf(output, "\n\nSCALARS Vx float\nLOOKUP_TABLE default\n");
1424  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1425  switch(Dimension)
1426  {
1427  case 1:
1428  i = n;
1429  j = k = 0;
1430  break;
1431 
1432  case 2:
1433  j = n%(1<<ScaleNb);
1434  i = n/(1<<ScaleNb);
1435  k = 0;
1436  break;
1437 
1438  case 3:
1439  k = n%(1<<ScaleNb);
1440  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1441  i = n/(1<<(2*ScaleNb));
1442  break;
1443  };
1444  FileWrite(output, FORMAT, cell(i,j,k)->velocity(1));
1445  fprintf(output, "\n");
1446  }
1447 
1448  fprintf(output, "\n\nSCALARS Vy float\nLOOKUP_TABLE default\n");
1449  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1450  switch(Dimension)
1451  {
1452  case 1:
1453  i = n;
1454  j = k = 0;
1455  break;
1456 
1457  case 2:
1458  j = n%(1<<ScaleNb);
1459  i = n/(1<<ScaleNb);
1460  k = 0;
1461  break;
1462 
1463  case 3:
1464  k = n%(1<<ScaleNb);
1465  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1466  i = n/(1<<(2*ScaleNb));
1467  break;
1468  };
1469  FileWrite(output, FORMAT, cell(i,j,k)->velocity(2));
1470  fprintf(output, "\n");
1471  }
1472 
1473  fprintf(output, "\n\nSCALARS Vz float\nLOOKUP_TABLE default\n");
1474  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1475  switch(Dimension)
1476  {
1477  case 1:
1478  i = n;
1479  j = k = 0;
1480  break;
1481 
1482  case 2:
1483  j = n%(1<<ScaleNb);
1484  i = n/(1<<ScaleNb);
1485  k = 0;
1486  break;
1487 
1488  case 3:
1489  k = n%(1<<ScaleNb);
1490  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1491  i = n/(1<<(2*ScaleNb));
1492  break;
1493  };
1494  FileWrite(output, FORMAT, cell(i,j,k)->velocity(3));
1495  fprintf(output, "\n");
1496  }
1497 
1498  fprintf(output, "\n\nSCALARS Bx float\nLOOKUP_TABLE default\n");
1499  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1500  switch(Dimension)
1501  {
1502  case 1:
1503  i = n;
1504  j = k = 0;
1505  break;
1506 
1507  case 2:
1508  j = n%(1<<ScaleNb);
1509  i = n/(1<<ScaleNb);
1510  k = 0;
1511  break;
1512 
1513  case 3:
1514  k = n%(1<<ScaleNb);
1515  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1516  i = n/(1<<(2*ScaleNb));
1517  break;
1518  };
1519  FileWrite(output, FORMAT, cell(i,j,k)->magField(1));
1520  fprintf(output, "\n");
1521  }
1522 
1523  fprintf(output, "\n\nSCALARS By float\nLOOKUP_TABLE default\n");
1524  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1525  switch(Dimension)
1526  {
1527  case 1:
1528  i = n;
1529  j = k = 0;
1530  break;
1531 
1532  case 2:
1533  j = n%(1<<ScaleNb);
1534  i = n/(1<<ScaleNb);
1535  k = 0;
1536  break;
1537 
1538  case 3:
1539  k = n%(1<<ScaleNb);
1540  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1541  i = n/(1<<(2*ScaleNb));
1542  break;
1543  };
1544  FileWrite(output, FORMAT, cell(i,j,k)->magField(2));
1545  fprintf(output, "\n");
1546  }
1547 
1548  fprintf(output, "\n\nSCALARS Bz float\nLOOKUP_TABLE default\n");
1549  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1550  switch(Dimension)
1551  {
1552  case 1:
1553  i = n;
1554  j = k = 0;
1555  break;
1556 
1557  case 2:
1558  j = n%(1<<ScaleNb);
1559  i = n/(1<<ScaleNb);
1560  k = 0;
1561  break;
1562 
1563  case 3:
1564  k = n%(1<<ScaleNb);
1565  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1566  i = n/(1<<(2*ScaleNb));
1567  break;
1568  };
1569  FileWrite(output, FORMAT, cell(i,j,k)->magField(3));
1570  fprintf(output, "\n");
1571  }
1572 
1573  fprintf(output, "\n\nSCALARS DivB float\nLOOKUP_TABLE default\n");
1574  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1575  switch(Dimension)
1576  {
1577  case 1:
1578  i = n;
1579  j = k = 0;
1580  break;
1581 
1582  case 2:
1583  j = n%(1<<ScaleNb);
1584  i = n/(1<<ScaleNb);
1585  k = 0;
1586  break;
1587 
1588  case 3:
1589  k = n%(1<<ScaleNb);
1590  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1591  i = n/(1<<(2*ScaleNb));
1592  break;
1593  };
1594  real divB=0, B1=0., B2=0.,dx=0.;
1595  int ei=0,ej=0,ek=0;
1596  for (int AxisNo = 1; AxisNo <= Dimension; AxisNo ++)
1597  {
1598 
1599  ei = (AxisNo == 1)? 1:0;
1600  ej = (AxisNo == 2)? 1:0;
1601  ek = (AxisNo == 3)? 1:0;
1602 
1603  dx = cell(i,j,k)->size(AxisNo);
1604  dx *= 2.;
1605 
1606  B1 = cell(i+ei, j+ej, k+ek)->magField(AxisNo);
1607  B2 = cell(i-ei, j-ej, k-ek)->magField(AxisNo);
1608 
1609  divB += (B1-B2)/dx;
1610  }
1611  FileWrite(output, FORMAT, divB);
1612  fprintf(output, "\n");
1613  }
1614 
1615  fprintf(output, "\n\nVECTORS Velocity float\n");
1616  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1617  switch(Dimension)
1618  {
1619  case 1:
1620  i = n;
1621  j = k = 0;
1622  break;
1623 
1624  case 2:
1625  j = n%(1<<ScaleNb);
1626  i = n/(1<<ScaleNb);
1627  k = 0;
1628  break;
1629 
1630  case 3:
1631  k = n%(1<<ScaleNb);
1632  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1633  i = n/(1<<(2*ScaleNb));
1634  break;
1635  };
1636 
1637 
1638  FileWrite(output, FORMAT, cell(i,j,k)->velocity(1));
1639  FileWrite(output, FORMAT, cell(i,j,k)->velocity(2));
1640  FileWrite(output, FORMAT, cell(i,j,k)->velocity(3));
1641  }
1642 
1643 
1644  fprintf(output, "\n\nVECTORS MagField float\n");
1645  for (n=0; n < (1<<(Dimension*ScaleNb)); n++){
1646  switch(Dimension)
1647  {
1648  case 1:
1649  i = n;
1650  j = k = 0;
1651  break;
1652 
1653  case 2:
1654  j = n%(1<<ScaleNb);
1655  i = n/(1<<ScaleNb);
1656  k = 0;
1657  break;
1658 
1659  case 3:
1660  k = n%(1<<ScaleNb);
1661  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1662  i = n/(1<<(2*ScaleNb));
1663  break;
1664  };
1665 
1666 
1667  FileWrite(output, FORMAT, cell(i,j,k)->magField(1));
1668  FileWrite(output, FORMAT, cell(i,j,k)->magField(2));
1669  FileWrite(output, FORMAT, cell(i,j,k)->magField(3));
1670  }
1671 
1672  }else{
1673  // MHD
1674  if (ScalarEqNb == 1)
1675  FileWrite(output, FORMAT, cell(i,j,k)->average(Dimension+3)/cell(i,j,k)->density());
1676  else
1677  FileWrite(output, FORMAT, cell(i,j,k)->density());
1678 
1679  FileWrite(output, FORMAT, cell(i,j,k)->pressure()*Gamma*Ma*Ma); // Dimensionless pressure
1680  FileWrite(output, FORMAT, cell(i,j,k)->temperature());
1681  FileWrite(output, FORMAT, cell(i,j,k)->energy());
1682  if (PostProcessing == 1) FileWrite(output, FORMAT, 0.);
1683  for (int AxisNo = 1; AxisNo <= Dimension; AxisNo++)
1684  FileWrite(output, FORMAT, cell(i,j,k)->velocity(AxisNo));
1685 
1686  }
1687 
1688 
1689 
1690  if (!DataIsBinary)
1691  fprintf(output,"\n");
1692 
1693  if (PostProcessing == 1)
1694  {
1695  if (j==(1<<ScaleNb)-1)
1696  fprintf(output,"\n");
1697 
1698  if (k==(1<<ScaleNb)-1)
1699  fprintf(output,"\n");
1700  }
1701  }
1702  fclose(output);
1703 
1704  // --- Eventually refine grid
1705 
1706  if (PrintMoreScales == -1)
1707  {
1708  ScaleNb++;
1709  refine();
1710  }
1711  }
1712  else
1713  {
1714  cout << "FineMesh.cpp: In method `void FineMesh::writeAverage()':\n";
1715  cout << "FineMesh.cpp: cannot open file " << FileName << '\n';
1716  cout << "carmen: *** [FineMesh.o] Execution error\n";
1717  cout << "carmen: abort execution.\n";
1718  exit(1);
1719  }
1720 }
int ScaleNb
Definition: Parameters.cpp:87
int PrintMoreScales
Definition: Parameters.cpp:90
int FileWrite(FILE *f, const char *format, real arg)
Writes in binary or ASCII mode the real number arg into the file f with the format format...
Definition: FileWrite.cpp:22
int ScalarEqNb
Definition: Parameters.cpp:69
int Dimension
Definition: Parameters.cpp:74
real Gamma
Definition: Parameters.cpp:109
int PostProcessing
Definition: Parameters.cpp:144
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
real magField(const int AxisNo) const
Returns the component no. AxisNo of the cell-average magnetic field.
Definition: Cell.h:1336
bool DataIsBinary
Definition: Parameters.cpp:145
#define FORMAT
Definition: PreProcessor.h:32
real Ma
Definition: Parameters.cpp:110
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::writeHeader ( const char *  FileName) const

Write header for GNUplot, Data Explorer, TecPLot and VTK into file FileName.

Parameters
FileNameName of the file to write.
Returns
void
1097 {
1098  // --- Local variables ---
1099 
1100  real dx=0., dy=0., dz=0.; // deltas in x, y, and z
1101  FILE *output; // Pointer to output file
1102  int GridPoints; // Grid points
1103  char DependencyType[12]; // positions or connections
1104 
1105 
1106  // --- For the final data, use positions instead of connections ---
1107 
1108  if (WriteAsPoints)
1109  {
1110  GridPoints = (1<<(ScaleNb+PrintMoreScales));
1111  sprintf(DependencyType,"positions");
1112  }
1113  else
1114  {
1115  GridPoints = (1<<(ScaleNb+PrintMoreScales))+1;
1116  sprintf(DependencyType,"connections");
1117  }
1118 
1119  // --- Open file ---
1120 
1121  if ((output = fopen(FileName,"w")) != NULL)
1122  {
1123  // --- Header ---
1124 
1125 
1126  dx = (XMax[1]-XMin[1])/((1<<(ScaleNb+PrintMoreScales))-1);
1127  dy = (XMax[2]-XMin[2])/((1<<(ScaleNb+PrintMoreScales))-1);
1128  dz = (XMax[3]-XMin[3])/((1<<(ScaleNb+PrintMoreScales))-1);
1129 
1130  // GNUPLOT
1131 
1132  switch(PostProcessing)
1133  {
1134  // GNUPLOT
1135  case 1:
1136  fprintf(output,"#");
1137  fprintf(output, TXTFORMAT, " x");
1138  fprintf(output, TXTFORMAT, "Density");
1139  fprintf(output, TXTFORMAT, "Pressure");
1140  fprintf(output, TXTFORMAT, "Temperature");
1141  fprintf(output, TXTFORMAT, "Energy");
1142  fprintf(output, TXTFORMAT, "Velocity");
1143  fprintf(output, "\n");
1144  break;
1145 
1146  // DATA EXPLORER
1147  case 2:
1148  fprintf(output, "# Data Explorer file\n# generated by Carmen\n");
1149 
1150  switch(Dimension)
1151  {
1152  case 2:
1153  dx = (XMax[1]-XMin[1])/(1<<(ScaleNb+PrintMoreScales));
1154  dy = (XMax[2]-XMin[2])/(1<<(ScaleNb+PrintMoreScales));
1155  fprintf(output, "grid = %d x %d\n", GridPoints, GridPoints);
1156  fprintf(output, "positions = %f, %f, %f, %f\n#\n",XMin[1],dx,XMin[2],dy );
1157  break;
1158 
1159  case 3:
1160  dx = (XMax[1]-XMin[1])/(1<<(ScaleNb+PrintMoreScales));
1161  dy = (XMax[2]-XMin[2])/(1<<(ScaleNb+PrintMoreScales));
1162  dz = (XMax[3]-XMin[3])/(1<<(ScaleNb+PrintMoreScales));
1163  fprintf(output, "grid = %d x %d x %d\n", GridPoints, GridPoints, GridPoints);
1164  fprintf(output, "positions = %f, %f, %f, %f, %f, %f\n#\n",XMin[1],dx,XMin[2],dy,XMin[3],dz);
1165  break;
1166  };
1167 
1168  if (DataIsBinary)
1169  fprintf(output, "format = binary\n");
1170  else
1171  fprintf(output, "format = ascii\n");
1172 
1173  fprintf(output, "interleaving = field\n");
1174  fprintf(output, "field = density, pressure, temperature, energy, velocity\n");
1175  fprintf(output, "structure = scalar, scalar, scalar, scalar, %d-vector\n",Dimension);
1176  fprintf(output, "type = %s, %s, %s, %s, %s\n", REAL, REAL, REAL, REAL, REAL);
1177  fprintf(output, "dependency = %s, %s, %s, %s, %s\n", DependencyType, DependencyType, DependencyType, DependencyType, DependencyType);
1178 
1179 
1180  fprintf(output, "header = marker \"START_DATA\\n\" \n");
1181  fprintf(output, "end\n");
1182  fprintf(output, "START_DATA\n");
1183 
1184  break;
1185 
1186  // TECPLOT
1187  case 3:
1188  fprintf(output, "VARIABLES = \"x\"\n");
1189  if (Dimension > 1)
1190  fprintf(output,"\"y\"\n");
1191  if (Dimension > 2)
1192  fprintf(output,"\"z\"\n");
1193  fprintf(output,"\"RHO\"\n\"P\"\n\"T\"\n\"E\"\n\"U\"\n");
1194  if (Dimension > 1)
1195  fprintf(output,"\"V\"\n");
1196  if (Dimension > 2)
1197  fprintf(output,"\"W\"\n");
1198  fprintf(output,"ZONE T=\"Carmen %3.1f\"\n", CarmenVersion);
1199  fprintf(output,"I=%i, ",GridPoints-1);
1200  if (Dimension > 1)
1201  fprintf(output,"J=%i, ",GridPoints-1);
1202  if (Dimension > 2)
1203  fprintf(output,"K=%i, ",GridPoints-1);
1204  fprintf(output,"F=POINT\n");
1205  break;
1206 
1207 
1208  case 4:
1209  int N=(1<<ScaleNb);
1210  fprintf(output, "# vtk DataFile Version 2.8\nSolucao MHD\n");
1211  if(DataIsBinary)
1212  fprintf(output, "BINARY\n");
1213  else
1214  fprintf(output, "ASCII\n");
1215 
1216  fprintf(output, "DATASET STRUCTURED_GRID\n");
1217  if (Dimension == 2)
1218  {
1219  fprintf(output, "DIMENSIONS %d %d %d \n", N,N,1);
1220  fprintf(output, "POINTS %d FLOAT\n", N*N);
1221  for (int i = 0; i < N; i++)
1222  for (int j = 0; j < N; j++)
1223  fprintf(output, "%f %f %f \n", XMin[1] + i*dx, XMin[2] + j*dy, 0.0);
1224 
1225  fprintf(output, "\n\nPOINT_DATA %d \n", N*N);
1226  }
1227  if (Dimension == 3)
1228  {
1229  fprintf(output, "DIMENSIONS %d %d %d \n", N,N,N);
1230  fprintf(output, "POINTS %d FLOAT\n", N*N*N);
1231  for (int i = 0; i < N; i++)
1232  for (int j = 0; j < N; j++)
1233  for (int k = 0; k < N; k++)
1234  fprintf(output, "%f %f %f \n", XMin[1] + i*dx, XMin[2] + j*dy, XMin[3] + k*dz);
1235 
1236  fprintf(output, "\n\nPOINT_DATA %d \n", N*N*N);
1237  }
1238 
1239  break;
1240  };
1241 
1242  fclose(output);
1243  return;
1244 
1245  }
1246  else
1247  {
1248  cout << "FineMesh.cpp: In method `void FineMesh::writeHeader()':\n";
1249  cout << "FineMesh.cpp: cannot open file " << FileName << '\n';
1250  cout << "carmen: *** [FineMesh.o] Execution error\n";
1251  cout << "carmen: abort execution.\n";
1252  exit(1);
1253  }
1254 }
int ScaleNb
Definition: Parameters.cpp:87
real XMax[4]
Definition: Parameters.cpp:77
int PrintMoreScales
Definition: Parameters.cpp:90
bool WriteAsPoints
Definition: Parameters.cpp:147
#define TXTFORMAT
Definition: PreProcessor.h:33
int Dimension
Definition: Parameters.cpp:74
real CarmenVersion
Definition: Parameters.cpp:28
int PostProcessing
Definition: Parameters.cpp:144
real XMin[4]
Definition: Parameters.cpp:76
bool DataIsBinary
Definition: Parameters.cpp:145
#define REAL
Definition: PreProcessor.h:34
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void FineMesh::writeTimeAverage ( const char *  FileName) const

Write time-averages into file FileName.

Parameters
FileNameName of the file to write.
Returns
void
1836 {
1837  // --- Local variables ---
1838 
1839  int n=0, i=0, j=0, k=0;
1840 
1841  real dx, dy, dz; // deltas in x, y, and z
1842  real x=0, y=0, z=0; // positions
1843  FILE *output; // Pointer to output file
1844  int GridPoints = (1<<ScaleNb)+1;// Grid points
1845 
1846  // --- Open file ---
1847 
1848  if ((output = fopen(FileName,"w")) != NULL)
1849  {
1850  // --- Header ---
1851 
1852  switch(PostProcessing)
1853  {
1854  // GNUPLOT
1855  case 1:
1856  fprintf(output,"# x Velocity Stress\n");
1857  break;
1858 
1859  // DATA EXPLORER
1860  case 2:
1861  fprintf(output, "# Data Explorer file\n# generated by Carmen\n");
1862 
1863  switch(Dimension)
1864  {
1865  case 2:
1866  dx = (XMax[1]-XMin[1])/(1<<ScaleNb);
1867  dy = (XMax[2]-XMin[2])/(1<<ScaleNb);
1868  fprintf(output, "grid = %d x %d\n", GridPoints, GridPoints);
1869  fprintf(output, "positions = %f, %f, %f, %f\n#\n",XMin[1],dx,XMin[2],dy );
1870  break;
1871 
1872  case 3:
1873  dx = (XMax[1]-XMin[1])/(1<<ScaleNb);
1874  dy = (XMax[2]-XMin[2])/(1<<ScaleNb);
1875  dz = (XMax[3]-XMin[3])/(1<<ScaleNb);
1876  fprintf(output, "grid = %d x %d x %d\n", GridPoints, GridPoints, GridPoints);
1877  fprintf(output, "positions = %f, %f, %f, %f, %f, %f\n#\n",XMin[1],dx,XMin[2],dy,XMin[3],dz);
1878  break;
1879  };
1880 
1881  if (DataIsBinary)
1882  fprintf(output, "format = binary\n");
1883  else
1884  fprintf(output, "format = ascii\n");
1885 
1886  fprintf(output, "interleaving = field\n");
1887 
1888  fprintf(output, "field = U, V");
1889 
1890  if (Dimension >2)
1891  fprintf(output, ", W");
1892 
1893  fprintf(output, ", U\'U\', U\'V\', V\'V\'");
1894 
1895  if (Dimension >2)
1896  fprintf(output, ", U\'W\', V\'W\', W\'W\'");
1897 
1898  fprintf(output, "\n");
1899 
1900  fprintf(output, "structure = scalar");
1901  for (n=1; n < (Dimension*(Dimension+3))/2 ; n++)
1902  fprintf(output, ", scalar");
1903  fprintf(output, "\n");
1904 
1905  fprintf(output, "type = %s", REAL);
1906  for (n=1; n < (Dimension*(Dimension+3))/2 ; n++)
1907  fprintf(output, ", %s", REAL);
1908  fprintf(output, "\n");
1909 
1910  fprintf(output, "dependency = connections");
1911  for (n=1; n < (Dimension*(Dimension+3))/2 ; n++)
1912  fprintf(output, ", connections");
1913  fprintf(output, "\n");
1914 
1915  fprintf(output, "header = marker \"START_DATA\\n\" \n");
1916  fprintf(output, "end\n");
1917  fprintf(output, "START_DATA\n");
1918 
1919  break;
1920 
1921  // TECPLOT
1922  case 3:
1923 
1924  // --- Write axes (x,y,z) ---
1925 
1926  fprintf(output, "VARIABLES = \"x\"\n");
1927  if (Dimension > 1)
1928  fprintf(output,"\"y\"\n");
1929  if (Dimension > 2)
1930  fprintf(output,"\"z\"\n");
1931 
1932  // --- Write averages U, V, W ---
1933 
1934  fprintf(output,"\"U\"\n");
1935  if (Dimension > 1)
1936  fprintf(output,"\"V\"\n");
1937  if (Dimension > 2)
1938  fprintf(output,"\"W\"\n");
1939 
1940  // --- Write stress tensor U'U', U'V', V'V', U'W', V'W', W'W' ---
1941 
1942  fprintf(output,"\"U\'U\'\"\n");
1943  if (Dimension > 1)
1944  {
1945  fprintf(output,"\"U\'V\'\"\n");
1946  fprintf(output,"\"V\'V\'\"\n");
1947  }
1948  if (Dimension > 2)
1949  {
1950  fprintf(output,"\"U\'W\'\"\n");
1951  fprintf(output,"\"V\'W\'\"\n");
1952  fprintf(output,"\"W\'W\'\"\n");
1953  }
1954 
1955  fprintf(output,"ZONE T=\"Carmen %3.1f\"\n",CarmenVersion);
1956  fprintf(output,"I=%i, ",(1<<ScaleNb));
1957  if (Dimension > 1)
1958  fprintf(output,"J=%i, ",(1<<ScaleNb));
1959  if (Dimension > 2)
1960  fprintf(output,"K=%i, ",(1<<ScaleNb));
1961  fprintf(output,"F=POINT\n");
1962  break;
1963  };
1964 
1965  // --- Loop on all cells ---
1966 
1967  for (n=0; n < (1<<(Dimension*ScaleNb)); n++)
1968  {
1969 
1970  // -- Compute i, j, k --
1971 
1972  // For Gnuplot and DX, loop order: for i... {for j... {for k...} }
1973 
1974  if (PostProcessing != 3)
1975  {
1976  switch(Dimension)
1977  {
1978  case 1:
1979  i = n;
1980  break;
1981 
1982  case 2:
1983  j = n%(1<<ScaleNb);
1984  i = n/(1<<ScaleNb);
1985  break;
1986 
1987  case 3:
1988  k = n%(1<<ScaleNb);
1989  j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
1990  i = n/(1<<(2*ScaleNb));
1991  break;
1992  };
1993  }
1994  else
1995  {
1996  // For Tecplot, loop order: for k... {for j... {for i...} }
1997 
1998  i = n%(1<<ScaleNb);
1999  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
2000  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
2001  }
2002 
2003  // Compute x,y,z
2004 
2005  x = cell(i,j,k)->center(1);
2006  if (Dimension > 1)
2007  y = cell(i,j,k)->center(2);
2008  if (Dimension > 2)
2009  z = cell(i,j,k)->center(3);
2010 
2011  // Write cell-center coordinates (only for Gnuplot and Tecplot)
2012 
2013  if (PostProcessing != 2)
2014  {
2015  fprintf(output, FORMAT, x);
2016  if (Dimension > 1)
2017  fprintf(output, FORMAT, y);
2018  if (Dimension > 2)
2019  fprintf(output, FORMAT, z);
2020  }
2021 
2022  for (int AxisNo = 1; AxisNo <= Dimension; AxisNo++)
2023  FileWrite(output, FORMAT,MyTimeAverageGrid->velocity(i,j,k,AxisNo));
2024 
2025  for (int AxisNo = 1; AxisNo <= (Dimension*(Dimension+1))/2; AxisNo++)
2026  FileWrite(output, FORMAT,MyTimeAverageGrid->stress(i,j,k,AxisNo));
2027 
2028  if (!DataIsBinary)
2029  fprintf(output,"\n");
2030 
2031  if (PostProcessing == 1)
2032  {
2033  if (j==(1<<ScaleNb)-1)
2034  fprintf(output,"\n");
2035 
2036  if (k==(1<<ScaleNb)-1)
2037  fprintf(output,"\n");
2038  }
2039  }
2040  fclose(output);
2041  }
2042  else
2043  {
2044  cout << "FineMesh.cpp: In method `void FineMesh::writeTimeAverage()':\n";
2045  cout << "FineMesh.cpp: cannot open file " << FileName << '\n';
2046  cout << "carmen: *** [FineMesh.o] Execution error\n";
2047  cout << "carmen: abort execution.\n";
2048  exit(1);
2049  }
2050 }
int ScaleNb
Definition: Parameters.cpp:87
real center(const int AxisNo) const
Returns the component no. AxisNo of the cell-center position.
Definition: Cell.h:1112
real XMax[4]
Definition: Parameters.cpp:77
int FileWrite(FILE *f, const char *format, real arg)
Writes in binary or ASCII mode the real number arg into the file f with the format format...
Definition: FileWrite.cpp:22
real velocity(const int i, const int j, const int k, const int AxisNo) const
Get velocity at the position i,j,k.
Definition: TimeAverageGrid.h:183
int Dimension
Definition: Parameters.cpp:74
real CarmenVersion
Definition: Parameters.cpp:28
int PostProcessing
Definition: Parameters.cpp:144
real stress(const int i, const int j, const int k, const int No) const
Definition: TimeAverageGrid.cpp:190
real XMin[4]
Definition: Parameters.cpp:76
bool DataIsBinary
Definition: Parameters.cpp:145
#define FORMAT
Definition: PreProcessor.h:32
#define REAL
Definition: PreProcessor.h:34
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

Member Data Documentation

Cell* FineMesh::MeshCell

Array of cells

Cell*** FineMesh::Neighbour_iL

Parallel variable

Cell *** FineMesh::Neighbour_iU

Parallel variable

Cell *** FineMesh::Neighbour_jL

Parallel variable

Cell *** FineMesh::Neighbour_jU

Parallel variable

Cell *** FineMesh::Neighbour_kL

Parallel variable

Cell *** FineMesh::Neighbour_kU

Parallel variable


The documentation for this class was generated from the following files: