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

An object Node is an element of a graded tree structure, used for multiresolution computations. Its contains the following informations: More...

#include <Node.h>

Public Member Functions

 Node (const int l=0, const int i=0, const int j=0, const int k=0)
 Constructor of Node class. Generates a new node at the position (l, i, j, k) in the tree structure. A new node is always a leaf. The array of pointers to the children is allocated, together with the informations on the corresponding cell: cell-center position and cell size. More...
 
 ~Node ()
 Distructor of Node class. Removes the node from the tree structure. If the node is not a leaf, all the children are also removed. More...
 
int cells () const
 Returns the number of cells in the tree. More...
 
int leaves () const
 Returns the number of leaves in the tree. More...
 
int adapt ()
 Computes the details in the leaves and its parent nodes and, in function of the threshold Tolerance, adapt the tree structure. More...
 
void checkGradedTree ()
 Checks if the tree is graded. If not, an error is emitted. Only for debugging. More...
 
void initValue ()
 Computes the initial value. More...
 
void addLevel ()
 Adds levels when needed. More...
 
Cellproject ()
 Computes the cell-average values of all nodes that are not leaves by projection from the cell-averages values of the leaves. This procedure is required after a time evolution to refresh the internal nodes of the tree. More...
 
void fillVirtualChildren ()
 Fills the cell-average values of every virtual leaf with values predicted from its parent and uncles. This procedure is required after a time evolution to refresh the virtual leaves of the tree. 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 ()
 Computes the divergence vector with the space discretization scheme. More...
 
void RungeKutta ()
 Computes one Runge-Kutta step. More...
 
void computeIntegral ()
 Computes integral values like e.g. flame velocity, global error, etc. More...
 
void computeGradient ()
 Computes velocity gradient (only for Navier-Stokes). More...
 
void computeCorrection ()
 Computes velocity gradient (only for Navier-Stokes). More...
 
void checkStability ()
 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 writeTree (const char *FileName) const
 Writes tree structure into file FileName. Only for debugging. More...
 
void writeAverage (const char *FileName)
 Writes cell-average values in multiresolution representation and the corresponding mesh into file FileName. More...
 
void writeMesh (const char *FileName) const
 Writes mesh data for Gnuplot into file FileName. More...
 
void writeHeader (const char *FileName) const
 Writes header for Data Explorer into file FileName. More...
 
void writeFineGrid (const char *FileName, const int L=ScaleNb) const
 Writes cell-average values on a regular grid of level L 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...
 
void restoreFineMesh ()
 Restores the tree structure and the cell-averages from the file carmen.bak in FineMesh format. More...
 
void smooth ()
 Deletes the details in the highest level. More...
 

Detailed Description

An object Node is an element of a graded tree structure, used for multiresolution computations. Its contains the following informations:

A leaf is a node without children, a virtual leaf is an artificial leaf created only for the flux computations. No time evolution is made on virtual leaves.

Constructor & Destructor Documentation

Node::Node ( const int  l = 0,
const int  i = 0,
const int  j = 0,
const int  k = 0 
)

Constructor of Node class. Generates a new node at the position (l, i, j, k) in the tree structure. A new node is always a leaf. The array of pointers to the children is allocated, together with the informations on the corresponding cell: cell-center position and cell size.

Parameters
lLevel
iPosition x
jPosition y
kPosition z
39 {
40  // Set Nl, Ni, Nj, Nk
41  Nl = l;
42  Ni = i;
43  Nj = j;
44  Nk = k;
45 
46  // --- If l = 0, then node is root ---
47 
48  if (Nl == 0)
49  {
50  Root = this;
51  CellNb = 1;
52  LeafNb = 1;
53  }
54 // else if(CellNb<(power2(1<<ScaleNb))) CellNb++;
55 // else CellNb--;
56  // --- Increase the total number of cells ---
57 
58  CellNb ++;
59 
60  // --- Allocate array of pointers to children ---
61 
62  Child = new Node* [ChildNb];
63 
64  // --- A new node is a simple leaf ---
65 
66  setSimpleLeaf();
67 
68  // --- Set the coordinates and the size of the cell ---
69 
70  // x-direction
71  ThisCell.setSize( 1, (XMax[1]-XMin[1])/(1<<Nl) );
72  ThisCell.setCenter( 1, XMin[1] + (Ni + .5)*ThisCell.size(1) );
73 
74  // y-direction
75  if (Dimension > 1)
76  {
77  ThisCell.setSize( 2, (XMax[2]-XMin[2])/(1<<Nl) );
78  ThisCell.setCenter( 2, XMin[2] + (Nj + .5)*ThisCell.size(2) );
79  }
80 
81  // z-direction
82  if (Dimension > 2)
83  {
84  ThisCell.setSize( 3, (XMax[3]-XMin[3])/(1<<Nl) );
85  ThisCell.setCenter( 3, XMin[3] + (Nk + .5)*ThisCell.size(3) );
86  }
87 }
An object Node is an element of a graded tree structure, used for multiresolution computations...
Definition: Node.h:38
real XMax[4]
Definition: Parameters.cpp:77
int LeafNb
Definition: Parameters.cpp:175
int ChildNb
Definition: Parameters.cpp:213
int Dimension
Definition: Parameters.cpp:74
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
int CellNb
Definition: Parameters.cpp:174
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
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
Node::~Node ( )

Distructor of Node class. Removes the node from the tree structure. If the node is not a leaf, all the children are also removed.

96 {
97  // --- Local variables --------------------------------------------------------------------
98 
99  int n=0; // Counter on children
100 
101  // --- Distructor procedure ---------------------------------------------------------------
102 
103  // --- Decrease the total number of cells ---
104 
105  CellNb --;
106 
107  // --- If the node has children, delete them ---
108 
109  if (hasChildren())
110  for (n = 0; n < ChildNb; n++) delete Child[n];
111 
112  // --- Delete array of pointers to children ---
113 
114  delete[] Child;
115 }
int ChildNb
Definition: Parameters.cpp:213
int CellNb
Definition: Parameters.cpp:174

Member Function Documentation

int Node::adapt ( )

Computes the details in the leaves and its parent nodes and, in function of the threshold Tolerance, adapt the tree structure.

Returns
int
692 {
693  // --- Local variables ---
694 
695  int n; // Counter on children
696  int isDeletable; // Test if children are deletable (0 = all children are deletable)
697 
698  // --- In case of time adaptivity, only remesh when a complete time evolution has been done ---
699 
700  // --- Init ---
701 
702  isDeletable = 0;
703 
704  // --- Test to stop recursion ---
705 
706  // If the node is not an internal node, this node can be deleted
707  if (!isInternalNode() || Nl >= ScaleNb) return 0;
708 
709  // --- Recursion ---
710 
711  // Test if children are deletable
712  for (n = 0; n < ChildNb; n++)
713  isDeletable += Child[n]->adapt();
714 
715  // If all children are deletable, test if this node is also deletable
716 
717  if (isDeletable == 0)
718  {
719  if (detailIsSmall())
720  {
721  if (!TimeAdaptivity || (TimeAdaptivity && isEndTimeCycle()))
722  for (n = 0; n < ChildNb; n++) Child[n]->combine();
723 
724  // Add value 0 to variable isDeletable of the parent
725  return 0;
726 
727  }
728  else
729  {
730  if (!TimeAdaptivity || (TimeAdaptivity && isEndTimeCycle()))
731  for (n = 0; n < ChildNb; n++) Child[n]->split();
732 
733  return 1;
734  }
735  }
736  // Add value 1 to variable Deletable of the parent
737  return 1;
738 }
bool TimeAdaptivity
Definition: Parameters.cpp:85
int ScaleNb
Definition: Parameters.cpp:87
int ChildNb
Definition: Parameters.cpp:213
int adapt()
Computes the details in the leaves and its parent nodes and, in function of the threshold Tolerance...
Definition: Node.cpp:691

Here is the caller graph for this function:

void Node::addLevel ( )

Adds levels when needed.

Returns
void
192 {
193  // --- Local variables --------------------------------------------------------------------
194 
195  int n=0; // Counter on children
196 
197  // --- If level higher or equal to maximum scale number allowed, do not split
198 
199  if ( Nl >= ScaleNb ) return;
200 
201  // --- If node is not a leaf, recurse on children
202 
203  if (isInternalNode())
204  {
205  for (n = 0 ; n < ChildNb; n++)
206  Child[n]->addLevel();
207  }
208  else
209  {
210  // If it is a virtual leaf, no splitting
211  if (isVirtualLeaf()) return;
212 
213  // If it is on the wall, always split
214  if (UseBoundaryRegions && isOnBoundary())
215  split(true);
216 
217  // Test on prediction error (always split on levels 0 and 1)
218  if (!detailIsSmall() || Nl <= 1)
219  split(true);
220 
221  }
222 }
int ScaleNb
Definition: Parameters.cpp:87
int ChildNb
Definition: Parameters.cpp:213
bool UseBoundaryRegions
Definition: Parameters.cpp:80
void addLevel()
Adds levels when needed.
Definition: Node.cpp:191

Here is the caller graph for this function:

void Node::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
2717 {
2718  int n; // Counter on children
2719  FILE* output; // Output file
2720  int QuantityNo; // Counter on quantities
2721 
2722  // --- Init ---
2723 
2724  if (Nl==0)
2725  {
2726  output = fopen("carmen.bak","w");
2727 
2728  // --- Write header ---
2729 
2730  fprintf(output, "Backup at iteration %i, physical time %e\n", IterationNo, ElapsedTime);
2731  }
2732  else
2733  output = fopen("carmen.bak","a");
2734 
2735  // --- If node is not a leaf, recurse to children ---
2736 
2737  if (isInternalNode())
2738  {
2739  fprintf(output,"N\n");
2740  fclose(output);
2741  for (n = 0; n < ChildNb; n++)
2742  Child[n]->backup();
2743  }
2744  else
2745  {
2746  for (QuantityNo=1; QuantityNo <= QuantityNb; QuantityNo++)
2747  {
2748  fprintf(output, FORMAT, ThisCell.average(QuantityNo));
2749  fprintf(output, "\n");
2750  }
2751  fclose(output);
2752  }
2753 }
int QuantityNb
Definition: Parameters.cpp:171
int ChildNb
Definition: Parameters.cpp:213
void backup()
Backs up the tree structure and the cell-averages into a file carmen.bak. In further computations...
Definition: Node.cpp:2716
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
#define FORMAT
Definition: PreProcessor.h:32

Here is the caller graph for this function:

int Node::cells ( ) const
inline

Returns the number of cells in the tree.

Returns
int
685 {
686  return CellNb;
687 }
int CellNb
Definition: Parameters.cpp:174
void Node::checkGradedTree ( )

Checks if the tree is graded. If not, an error is emitted. Only for debugging.

Returns
void
2631 {
2632  // --- Local variables ---
2633 
2634  int n; // Counter on children
2635  int i, j, k; // Counter in directions
2636  int ej, ek; // 1 if this dimension is existing, 0 else.
2637 
2638  // --- Init ---
2639  ej = (Dimension > 1)? 1:0;
2640  ek = (Dimension > 2)? 1:0;
2641 
2642 
2643  if (Nl == 0)
2644  {
2645  cout << "carmen: testing tree structure ...\n";
2646  for (n = 0; n < ChildNb; n++)
2647  Child[n]->checkGradedTree();
2648  cout << "carmen: tree structure OK. \n";
2649  return;
2650  }
2651 
2652  // --- Test if neighbours are existing (eventually virtual) ---
2653 
2654  for (i = -1; i <= 1; i+=1)
2655  for (j = -1*ej; j <= 1*ej; j+=1)
2656  for (k = -1*ek; k <= 1*ek; k+=1)
2657  {
2658  if (cell(Nl, Ni+i, Nj+j, Nk+k)==0)
2659  {
2660  cout << "carmen: Tree not graded':\n";
2661  cout << "carmen: Node (" << Nl << ", " << Ni << ", "<< Nj << ", "<< Nk << ") \n";
2662  cout << "carmen: has missing neighbour (" << Nl << ", " << Ni+i << ", "<< Nj+j << ", "<< Nk+k << ") \n";
2663  cout << "carmen: abort execution.\n";
2664  exit(1);
2665  }
2666  }
2667 
2668  // --- Recurse if it is a node ---
2669 
2670  if (isInternalNode())
2671  {
2672  for (n = 0; n < ChildNb; n++)
2673  Child[n]->checkGradedTree();
2674  }
2675 }
int ChildNb
Definition: Parameters.cpp:213
int Dimension
Definition: Parameters.cpp:74
void checkGradedTree()
Checks if the tree is graded. If not, an error is emitted. Only for debugging.
Definition: Node.cpp:2630

Here is the caller graph for this function:

void Node::checkStability ( )

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
2431 {
2432  // --- Local variables ---
2433 
2434  int n, iaux; // Counter on children
2435  real x=0., y=0., z=0.; // Real position
2436 
2437  // --- Recursion ---
2438 
2439  if (isInternalNode())
2440  {
2441  for (n = 0; n < ChildNb; n++)
2442  Child[n]->checkStability();
2443  }
2444  else
2445  {
2446  // --- Compute x, y, z ---
2447 
2448  x = ThisCell.center(1);
2449  if (Dimension > 1) y = ThisCell.center(2);
2450  if (Dimension > 2) z = ThisCell.center(3);
2451 
2452  if (ThisCell.isOverflow())
2453  {
2454  iaux=system("echo Unstable computation.>> carmen.prf");
2455  if (Cluster == 0) iaux=system("echo carmen: unstable computation. >> OUTPUT");
2456  cout << "carmen: instability detected at iteration no. "<< IterationNo <<"\n";
2457  cout << "carmen: position ("<< x <<", "<<y<<", "<<z<<")\n";
2458  cout << "carmen: abort execution.\n";
2459  exit(1);
2460  }
2461  }
2462 }
real center(const int AxisNo) const
Returns the component no. AxisNo of the cell-center position.
Definition: Cell.h:1112
int ChildNb
Definition: Parameters.cpp:213
int Cluster
Definition: Parameters.cpp:170
int Dimension
Definition: Parameters.cpp:74
int IterationNo
Definition: Parameters.cpp:168
bool isOverflow() const
Return true if one of the cell-average quantities is greater than the maximum. This usually means the...
Definition: Cell.cpp:382
void checkStability()
Checks if the computation is numerically unstable, i.e. if one of the cell-averages is overflow...
Definition: Node.cpp:2430
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void Node::computeCorrection ( )

Computes velocity gradient (only for Navier-Stokes).

Returns
void
2189 {
2190  // --- Local variables ---
2191 
2192  int n=0; // Counter on children
2193  real rho=0., psi=0.; // Variables density and psi
2194  int q=0, p=0; // Counter
2195  real Bx=0.; // Magnetic field
2196  real neweta=0.;
2197  real B1=0., B2=0., V=0., dx=0., DB=0., BR=0., BL=0., GB=0.;
2198  int ei=0, ej=0, ek=0;
2199  real udotB=0.;
2200 
2201 
2202  // --- Computation ---
2203 
2204  if (requiresDivergenceComputation())
2205  {
2206  if(DivClean==1) // EGLM
2207  {
2208 
2209  rho = ThisCell.density();
2210  psi = ThisCell.psi();
2211 
2212  for (q=1; q <= 3; q++)
2213  {
2214  Bx = ThisCell.magField(q);
2215  ThisCell.setAverage(q+1, ThisCell.average(q+1) - TimeStep*Bx*Bdivergence/(ch*ch));
2216  }
2217 
2218  ThisCell.setAverage(5, ThisCell.average(5) - TimeStep*PsiGrad);
2219  ThisCell.setAverage(6, ThisCell.average(6)*exp(-(cr*ch*TimeStep/SpaceStep)));
2220 
2221  }else if(DivClean==2)//GLM
2222  {
2223  psi = ThisCell.psi();
2224  ThisCell.setAverage(6, psi*exp(-(cr*ch*TimeStep/SpaceStep)));
2225  }else if(DivClean==3)
2226  {
2227  Bdivergence=0.;
2228  for (q=1; q <= Dimension; q++)
2229  {
2230  dx = ThisCell.size(q);
2231  dx *= 2.;
2232  B1=cell(Nl, Ni+ei, Nj+ej, Nk+ek)->magField(q);
2233  B2=cell(Nl, Ni-ei, Nj-ej, Nk-ek)->magField(q);
2234  Bdivergence += (B1-B2)/dx;
2235  udotB += ThisCell.velocity(q)*ThisCell.magField(q);
2236  }
2237 
2238  ThisCell.setAverage(2, ThisCell.average(2) - TimeStep*Bdivergence*ThisCell.magField(1));
2239  ThisCell.setAverage(3, ThisCell.average(3) - TimeStep*Bdivergence*ThisCell.magField(2));
2240  ThisCell.setAverage(4, ThisCell.average(4) - TimeStep*Bdivergence*ThisCell.magField(3));
2241  ThisCell.setAverage(5, ThisCell.average(5) - TimeStep*Bdivergence*udotB);
2242  ThisCell.setAverage(7, ThisCell.average(7) - TimeStep*Bdivergence*ThisCell.velocity(1));
2243  ThisCell.setAverage(8, ThisCell.average(8) - TimeStep*Bdivergence*ThisCell.velocity(2));
2244  ThisCell.setAverage(9, ThisCell.average(9) - TimeStep*Bdivergence*ThisCell.velocity(3));
2245 
2246 
2247  }
2248  }
2249 
2250  // --- Recurse on children ---
2251 
2252  if (isInternalNode())
2253  for (n = 0; n < ChildNb; n++){
2254  Child[n]->computeCorrection();
2255  }
2256 }
real ch
Definition: Parameters.cpp:140
real density() const
Returns the cell-average density.
Definition: Cell.h:1262
int ChildNb
Definition: Parameters.cpp:213
real SpaceStep
Definition: Parameters.cpp:156
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
void computeCorrection()
Computes velocity gradient (only for Navier-Stokes).
Definition: Node.cpp:2188
real cr
Definition: Parameters.cpp:194
int DivClean
Definition: Parameters.cpp:70
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
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
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 Node::computeDivergence ( )

Computes the divergence vector with the space discretization scheme.

Returns
void

2D resistive part of the model added to the Flux

1978 {
1979  // --- Local variables ---
1980 
1981  int n=0; // Counter on children
1982  Vector FluxIn, FluxOut; // Ingoing and outgoing flux
1983  Vector InitAverage0; // Cell-average value of the initial condition
1984  Vector clean;
1985  real divCor=0.;
1986  // --- Computation ---
1987 
1988  if (requiresDivergenceComputation())
1989  {
1990  // --- Compute source term -------------------------------------------------------------
1991 
1992  ThisCell.setDivergence(Source(ThisCell));
1993 
1994  // --- Add flux in x-direction ---------------------------------------------------------
1995 
1996  // If the cell is a leaf with virtual children and its left cousin is a node, compute flux on upper level
1997 
1998  if (isLeafWithVirtualChildren() && node(Nl, Ni-1, Nj, Nk) != 0 && node(Nl, Ni-1, Nj, Nk)->isInternalNode() && FluxCorrection)
1999  {
2000  FluxIn = Flux( *childCell(-2,0,0), *childCell(-1,0,0), *childCell(0,0,0) , *childCell(1,0,0), 1 );
2001 
2002  if (Dimension > 1)
2003  FluxIn += Flux( *childCell(-2,1,0), *childCell(-1,1,0), *childCell(0,1,0), *childCell(1,1,0), 1 );
2004 
2005  if (Dimension > 2)
2006  {
2007  FluxIn += Flux( *childCell(-2,0,1), *childCell(-1,0,1), *childCell(0,0,1), *childCell(1,0,1), 1 );
2008  FluxIn += Flux( *childCell(-2,1,1), *childCell(-1,1,1), *childCell(0,1,1), *childCell(1,1,1), 1 );
2009  }
2010 
2011  // Average flux
2012  FluxIn *= 1./(1<<(Dimension-1));
2013 
2014  }
2015  else
2016  FluxIn = Flux( *cousinCell(-2,0,0), *cousinCell(-1,0,0), ThisCell, *cousinCell(1,0,0), 1 );
2017 
2018  divCor = -auxvar;
2019  // If the cell is a leaf with virtual children and its right cousin is a node, compute flux on upper level
2020 
2021  if (isLeafWithVirtualChildren() && node(Nl, Ni+1, Nj, Nk) != 0 && node(Nl, Ni+1, Nj, Nk)->isInternalNode() && FluxCorrection)
2022  {
2023  FluxOut = Flux( *childCell(0,0,0), *childCell(1,0,0), *childCell(2,0,0), *childCell(3,0,0), 1 );
2024 
2025  if (Dimension > 1)
2026  FluxOut += Flux( *childCell(0,1,0), *childCell(1,1,0), *childCell(2,1,0), *childCell(3,1,0), 1 );
2027 
2028  if (Dimension > 2)
2029  {
2030  FluxOut += Flux( *childCell(0,0,1), *childCell(1,0,1), *childCell(2,0,1), *childCell(3,0,1), 1 );
2031  FluxOut += Flux( *childCell(0,1,1), *childCell(1,1,1), *childCell(2,1,1), *childCell(3,1,1), 1 );
2032  }
2033 
2034  // Average flux
2035  FluxOut *= 1./(1<<(Dimension-1));
2036 
2037  }
2038  else
2039  FluxOut = Flux( *cousinCell(-1,0,0), ThisCell, *cousinCell(1,0,0), *cousinCell(2,0,0), 1 );
2040 
2041  divCor += auxvar;
2043  if(Resistivity){
2044  FluxIn = FluxIn - ResistiveTerms(ThisCell, *cousinCell(-1,0,0), *cousinCell(0,-1,0), *cousinCell(0,0,-1), 1);
2045  FluxOut = FluxOut - ResistiveTerms(*cousinCell(1,0,0), ThisCell , *cousinCell(1,-1,0), *cousinCell(1,0,-1), 1);
2046  }
2047 
2048  // Add divergence in x-direction
2049  ThisCell.setDivergence( ThisCell.divergence() + (FluxIn - FluxOut)/(ThisCell.size(1)));
2050 
2051  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
2052  PsiGrad = ThisCell.average(7)*(FluxOut.value(7) - FluxIn.value(7) - divCor)/(ThisCell.size(1));
2053  Bdivergence = ((FluxOut.value(6) - FluxIn.value(6))/(ThisCell.size(1)));
2054 
2055  // --- Add flux in y-direction ---------------------------------------------------------
2056 
2057  if (Dimension > 1)
2058  {
2059  // If the cell is a leaf with virtual children and its front cousin is a node, compute flux on upper level
2060 
2061  if (isLeafWithVirtualChildren() && node(Nl, Ni, Nj-1, Nk) != 0 && node(Nl, Ni, Nj-1, Nk)->isInternalNode() && FluxCorrection)
2062  {
2063  FluxIn = Flux( *childCell(0,-2,0), *childCell(0,-1,0), *childCell(0,0,0), *childCell(0,1,0), 2 );
2064  FluxIn += Flux( *childCell(1,-2,0), *childCell(1,-1,0), *childCell(1,0,0) , *childCell(1,1,0), 2 );
2065 
2066  if (Dimension > 2)
2067  {
2068  FluxIn += Flux( *childCell(0,-2,1), *childCell(0,-1,1), *childCell(0,0,1), *childCell(0,1,1), 2 );
2069  FluxIn += Flux( *childCell(1,-2,1), *childCell(1,-1,1), *childCell(1,0,1), *childCell(1,1,1), 2 );
2070  }
2071 
2072  // Average flux
2073  FluxIn *= 1./(1<<(Dimension-1));
2074 
2075  }
2076  else
2077  FluxIn = Flux( *cousinCell(0,-2,0), *cousinCell(0,-1,0), ThisCell, *cousinCell(0,1,0), 2 );
2078 
2079  divCor = -auxvar;
2080  // If the cell is a leaf with virtual children and its back cousin is a node, compute flux on upper level
2081 
2082  if (isLeafWithVirtualChildren() && node(Nl, Ni, Nj+1, Nk) != 0 && node(Nl, Ni, Nj+1, Nk)->isInternalNode() && FluxCorrection)
2083  {
2084  FluxOut = Flux( *childCell(0,0,0), *childCell(0,1,0), *childCell(0,2,0), *childCell(0,3,0), 2 );
2085  FluxOut += Flux( *childCell(1,0,0), *childCell(1,1,0), *childCell(1,2,0), *childCell(1,3,0), 2 );
2086 
2087  if (Dimension > 2)
2088  {
2089  FluxOut += Flux( *childCell(0,0,1), *childCell(0,1,1), *childCell(0,2,1), *childCell(0,3,1), 2 );
2090  FluxOut += Flux( *childCell(1,0,1), *childCell(1,1,1), *childCell(1,2,1), *childCell(1,3,1), 2 );
2091  }
2092 
2093  // Average flux
2094  FluxOut *= 1./(1<<(Dimension-1));
2095 
2096  }
2097  else
2098  FluxOut = Flux( *cousinCell(0,-1,0), ThisCell, *cousinCell(0,1,0), *cousinCell(0,2,0), 2 );
2099 
2100  divCor += auxvar;
2101 
2102  if(Resistivity){
2103  FluxIn = FluxIn - ResistiveTerms(ThisCell, *cousinCell(-1,0,0), *cousinCell(0,-1,0), *cousinCell(0,0,-1), 2);
2104  FluxOut = FluxOut - ResistiveTerms(*cousinCell(0,1,0), *cousinCell(-1,1,0), ThisCell , *cousinCell(0,1,-1), 2);
2105  }
2106 
2107  // Add divergence in y-direction
2108  ThisCell.setDivergence( ThisCell.divergence() + (FluxIn - FluxOut)/(ThisCell.size(2)));
2109 
2110  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
2111  PsiGrad += ThisCell.average(8)*(FluxOut.value(8) - FluxIn.value(8) - divCor)/(ThisCell.size(2));
2112  Bdivergence += ((FluxOut.value(6) - FluxIn.value(6))/(ThisCell.size(2)));
2113 
2114 
2115  }
2116 
2117 
2118  // --- Add flux in z-direction ---------------------------------------------------------
2119 
2120  if (Dimension > 2)
2121  {
2122  // If the cell is a leaf with virtual children and its lower cousin is a node, compute flux on upper level
2123 
2124  if (isLeafWithVirtualChildren() && node(Nl, Ni, Nj, Nk-1) != 0 && node(Nl, Ni, Nj, Nk-1)->isInternalNode() && FluxCorrection)
2125  {
2126  FluxIn = Flux( *childCell(0,0,-2), *childCell(0,0,-1), *childCell(0,0,0), *childCell(0,0,1), 3 );
2127  FluxIn += Flux( *childCell(1,0,-2), *childCell(1,0,-1), *childCell(1,0,0), *childCell(1,0,1), 3 );
2128  FluxIn += Flux( *childCell(0,1,-2), *childCell(0,1,-1), *childCell(0,1,0), *childCell(0,1,1), 3 );
2129  FluxIn += Flux( *childCell(1,1,-2), *childCell(1,1,-1), *childCell(1,1,0), *childCell(1,1,1), 3 );
2130 
2131  // Average flux
2132  FluxIn *= 0.25;
2133 
2134  }
2135  else
2136  FluxIn = Flux( *cousinCell(0,0,-2), *cousinCell(0,0,-1), ThisCell, *cousinCell(0,0,1), 3 );
2137 
2138  divCor = -auxvar;
2139 
2140  // If the cell is a leaf with virtual children and its upper cousin is a node, compute flux on upper level
2141 
2142  if (isLeafWithVirtualChildren() && node(Nl, Ni, Nj, Nk+1) != 0 && node(Nl, Ni, Nj, Nk+1)->isInternalNode() && FluxCorrection)
2143  {
2144  FluxOut = Flux( *childCell(0,0,0), *childCell(0,0,1), *childCell(0,0,2), *childCell(0,0,3), 3 );
2145  FluxOut += Flux( *childCell(1,0,0), *childCell(1,0,1), *childCell(1,0,2), *childCell(1,0,3), 3 );
2146  FluxOut += Flux( *childCell(0,1,0), *childCell(0,1,1), *childCell(0,1,2), *childCell(0,1,3), 3 );
2147  FluxOut += Flux( *childCell(1,1,0), *childCell(1,1,1), *childCell(1,1,2), *childCell(1,1,3), 3 );
2148 
2149  // Average flux
2150  FluxOut *= 0.25;
2151 
2152  }
2153  else
2154  FluxOut = Flux( *cousinCell(0,0,-1), ThisCell, *cousinCell(0,0,1), *cousinCell(0,0,2), 3 );
2155 
2156  divCor += auxvar;
2157 
2158  if(Resistivity){
2159  FluxIn = FluxIn - ResistiveTerms(ThisCell, *cousinCell(-1,0,0), *cousinCell(0,-1,0), *cousinCell(0,0,-1), 3);
2160  FluxOut = FluxOut - ResistiveTerms(*cousinCell(0,0,1), *cousinCell(-1,0,1), *cousinCell(0,-1,1), ThisCell , 3);
2161  }
2162 
2163  // Add divergence in z-direction
2164  ThisCell.setDivergence( ThisCell.divergence() + (FluxIn - FluxOut)/(ThisCell.size(3)));
2165 
2166  // Variables \grad(psi) and \div(B) to evaluate GLM and EGLM divergence cleaning
2167  PsiGrad += ThisCell.average(9)*(FluxOut.value(9) - FluxIn.value(9) - divCor)/(ThisCell.size(3));
2168  Bdivergence += ((FluxOut.value(6) - FluxIn.value(6))/(ThisCell.size(3)));
2169 
2170  }
2171  }
2172 
2173  // --- Recurse on children ---
2174 
2175  if (isInternalNode())
2176  for (n = 0; n < ChildNb; n++)
2177  Child[n]->computeDivergence();
2178 }
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
int ChildNb
Definition: Parameters.cpp:213
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
bool FluxCorrection
Definition: Parameters.cpp:143
real divergence(const int QuantityNo) const
Returns the component no. QuantityNo of the divergence vector.
Definition: Cell.h:1192
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
void computeDivergence()
Computes the divergence vector with the space discretization scheme.
Definition: Node.cpp:1977
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
real Bdivergence
Definition: Parameters.cpp:138
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

void Node::computeGradient ( )

Computes velocity gradient (only for Navier-Stokes).

Returns
void
2267 {
2268  // --- Local variables ---
2269 
2270  int n=0; // Counter on children
2271  real rho1=0., rho2=0.; // Densities
2272  real rhoE1=0., rhoE2=0.; // Energies
2273  real V1=0., V2=0.; // Velocity
2274  real dx=0.; // Cell size
2275  real dxV=0.; // Correction of dx for the computation of GradV close to solid walls
2276  int p=0, q=0; // Counters
2277  int ei=0, ej=0, ek=0; // 1 if this direction is chosen, 0 elsewhere
2278 
2279  // --- Computation ---
2280 
2281 // if (requiresDivergenceComputation() || (CVS && isParentOfLeaf()))
2282 
2283  if (requiresDivergenceComputation())
2284  {
2285  if (EquationType != 6)
2286  {
2287  cout << "Node.cpp: In method `void Node::computeGradient()':\n";
2288  cout << "Node.cpp: EquationType not equal to 6 \n";
2289  cout << "carmen: *** [Node.o] Execution error\n";
2290  cout << "carmen: abort execution.\n";
2291  exit(1);
2292  }
2293 
2294  for (p=1;p <= Dimension; p++)
2295  {
2296  ei = (p==1)? 1:0;
2297  ej = (p==2)? 1:0;
2298  ek = (p==3)? 1:0;
2299 
2300  dx = ThisCell.size(p);
2301  dx *= 2.;
2302 
2303  // dxV = correction on dx for the computation of GradV close to solid walls
2304 
2305  if (BoundaryRegion(cell(Nl, Ni+ei,Nj+ej,Nk+ek)->center()) > 3 ||
2306  BoundaryRegion(cell(Nl, Ni-ei,Nj-ej,Nk-ek)->center()) > 3 )
2307  dxV = 0.75*dx;
2308  else
2309  dxV = dx;
2310 
2311  rho1 = cell(Nl, Ni+ei,Nj+ej,Nk+ek)->density();
2312  rho2 = cell(Nl, Ni-ei,Nj-ej,Nk-ek)->density();
2313 
2314  ThisCell.setGradient(p, 1, (rho1-rho2)/dx);
2315 
2316  for (q=1; q <= Dimension; q++)
2317  {
2318  V1=cell(Nl, Ni+ei, Nj+ej, Nk+ek)->velocity(q);
2319  V2=cell(Nl, Ni-ei, Nj-ej, Nk-ek)->velocity(q);
2320  ThisCell.setGradient(p, q+1, (V1-V2)/dxV);
2321  }
2322 
2323  rhoE1 = cell(Nl, Ni+ei, Nj+ej, Nk+ek)->energy();
2324  rhoE2 = cell(Nl, Ni-ei, Nj-ej, Nk-ek)->energy();
2325 
2326  ThisCell.setGradient(p, Dimension+2, (rhoE1-rhoE2)/dx);
2327  }
2328  }
2329 
2330  // --- Recurse on children ---
2331 
2332  if (isInternalNode())
2333  for (n = 0; n < ChildNb; n++)
2334  Child[n]->computeGradient();
2335 }
void computeGradient()
Computes velocity gradient (only for Navier-Stokes).
Definition: Node.cpp:2266
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 ChildNb
Definition: Parameters.cpp:213
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
void Node::computeIntegral ( )

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

Returns
void
2471 {
2472  // --- Local variables ---
2473 
2474  int QuantityNo; // Quantity number (0 to QuantityNb)
2475  int n; // Counter on children
2476  int AxisNo; // Counter on dimension
2477  real dx, dy=0., dz=0.; // Cell size
2478  Vector Center(Dimension); // local center of the flame ball
2479  real VelocityMax; // local maximum of the velocity
2480  real MaxSpeed;
2481  real MemoryCompression = 0.; // Memory compression
2482 
2483  Vector GradDensity(Dimension); // gradient of density
2484  Vector GradPressure(Dimension); // gradient of pressure
2485  real divB=0;
2486  real modB=0.;
2487 
2488  real B1=0., B2=0.; // Left and right magnetic field cells
2489 
2490  int ei=0, ej=0, ek=0; // 1 if this direction is chosen, 0 elsewhere
2491 
2492 
2493  // --- Init ---
2494 
2495  if (Nl == 0)
2496  {
2497  // Only if ExpectedCompression not equal to zero => variable tolerance
2498 
2499  if (ExpectedCompression != 0.)
2500  {
2501  MemoryCompression = (1.*CellNb)/(1<<(ScaleNb*Dimension));
2502  Tolerance = Tolerance*(1.- (ExpectedCompression-MemoryCompression));
2503  if (Tolerance > 1E+10)
2504  {
2505  printf("carmen: ExpectedCompression unreachable\n");
2506  printf("carmen: maximal compression is %5.2f %%", MemoryCompression*100.);
2507  printf("carmen: abort execution.\n");
2508  exit(1);
2509  }
2510  }
2511 
2512  // Init integral values
2513 // DIVB = 0.;
2514  //DIVBMax = 0.;
2515  FlameVelocity = 0.;
2516  GlobalMomentum = 0.;
2517  GlobalEnergy = 0.;
2518  GlobalEnstrophy = 0.;
2519  ExactMomentum = 0.;
2520  ExactEnergy = 0.;
2521 
2522  GlobalReactionRate = 0.;
2523  AverageRadius = 0.;
2524  ReactionRateMax = 0.;
2525 
2526  for (AxisNo=1; AxisNo <= Dimension; AxisNo++)
2527  Center.setValue(AxisNo,XCenter[AxisNo]);
2528 
2529  ErrorMax = 0.;
2530  ErrorMid = 0.;
2531  ErrorL2 = 0.;
2532  ErrorNb = 0;
2533 
2534  RKFError = 0.;
2535 
2536  //Eigenvalue = 0.;
2537  QuantityMax.setZero();
2539 
2540  IntVorticity=0.;
2541  IntDensity=0.;
2542  IntMomentum.setZero();
2543  BaroclinicEffect=0.;
2544 
2545  }
2546 
2547  // --- Recursion ---
2548 
2549  if (isInternalNode())
2550  {
2551  for (n = 0; n < ChildNb; n++)
2552  Child[n]->computeIntegral();
2553  }
2554  else if (isLeaf())
2555  {
2556  // Whatever the equation, if ConstantTimeStep is false, compute RKFError
2557 
2558  if (!ConstantTimeStep && StepNb == 3)
2559  {
2560  for (QuantityNo = 1; QuantityNo <= QuantityNb; QuantityNo++)
2561  {
2562  if (Abs(ThisCell.average(QuantityNo)) > RKFAccuracyFactor)
2563  RKFError = Max(RKFError, Abs(1.-ThisCell.lowAverage(QuantityNo)/ThisCell.average(QuantityNo)));
2564  }
2565  }
2566 
2567  dx = ThisCell.size(1);
2568  dy = (Dimension > 1) ? ThisCell.size(2) : 1.;
2569  dz = (Dimension > 2) ? ThisCell.size(3) : 1.;
2570 
2571  // --- Compute the global momentum, global energy and global enstrophy ---
2572 
2573  GlobalMomentum += ThisCell.average(2)*dx*dy*dz;
2574  GlobalEnergy += .5*(ThisCell.magField()*ThisCell.magField() + ThisCell.density()*(ThisCell.velocity()*ThisCell.velocity())) + ThisCell.pressure()/(Gamma-1.0);
2575  GlobalEnergy *= dx*dy*dz;
2576  Helicity += (ThisCell.magField(2)*ThisCell.velocity(3) - ThisCell.magField(3)*ThisCell.velocity(2))*ThisCell.magField(1) +
2577  (ThisCell.magField(3)*ThisCell.velocity(1) - ThisCell.magField(1)*ThisCell.velocity(3))*ThisCell.magField(2) +
2578  (ThisCell.magField(1)*ThisCell.velocity(2) - ThisCell.magField(2)*ThisCell.velocity(1))*ThisCell.magField(3);
2579  Helicity *= 2*dx*dy*dz;
2580 
2581  // --- Compute maximum of the conservative quantities ---
2582 
2583  for (QuantityNo=1; QuantityNo <=QuantityNb; QuantityNo++)
2584  {
2585  if ( QuantityMax.value(QuantityNo) < fabs(ThisCell.average(QuantityNo)) )
2586  QuantityMax.setValue(QuantityNo, fabs(ThisCell.average(QuantityNo)) );
2587  }
2588 
2589  // --- Compute the maximal eigenvalue ---
2590 
2591  VelocityMax = 0.;
2592  MaxSpeed = 0.;
2593  for (AxisNo=1; AxisNo <= Dimension; AxisNo ++){
2594  VelocityMax = Max( VelocityMax, fabs(ThisCell.velocity(AxisNo)));
2595  MaxSpeed = Max( MaxSpeed , fabs(ThisCell.fastSpeed(AxisNo)));
2596  }
2597 
2598  VelocityMax += MaxSpeed;
2599 
2600  EigenvalueMax = Max (EigenvalueMax, VelocityMax);
2601 
2602 
2603 
2604  for (AxisNo = 1; AxisNo <= Dimension; AxisNo++)
2605  {
2606  ei = (AxisNo == 1)? 1:0;
2607  ej = (AxisNo == 2)? 1:0;
2608  ek = (AxisNo == 3)? 1:0;
2609 
2610  dx = ThisCell.size(AxisNo);
2611  //dx *= 2.;
2612 
2613  B1 = cell(Nl, Ni+ei, Nj+ej, Nk+ek)->magField(AxisNo);
2614  B2 = cell(Nl, Ni-ei, Nj-ej, Nk-ek)->magField(AxisNo);
2615  modB += (B1 + B2)/dx;
2616  divB += (B1-B2)/dx;
2617  }
2618  modB += 1.120e-13;
2619  DIVBMax = Max(DIVBMax,Abs(0.5*divB));
2620  DIVB = DIVBMax/modB;
2621  }
2622 }
real DIVB
Definition: Parameters.cpp:136
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
real lowAverage(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value with low precision in the Runge-Kutta-...
Definition: Cell.h:1160
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 density() const
Returns the cell-average density.
Definition: Cell.h:1262
int ChildNb
Definition: Parameters.cpp:213
real fastSpeed(const int AxisNo) const
Returns the fast speed vector.
Definition: Cell.cpp:340
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 ExpectedCompression
Definition: Parameters.cpp:96
real ExactMomentum
Definition: Parameters.cpp:199
real RKFAccuracyFactor
Definition: Parameters.cpp:191
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
int StepNb
Definition: Parameters.cpp:36
int CellNb
Definition: Parameters.cpp:174
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
Vector QuantityAverage
Definition: Parameters.cpp:163
real pressure() const
Returns the cell-average pressure.
Definition: Cell.cpp:84
void computeIntegral()
Computes integral values like e.g. flame velocity, global error, etc.
Definition: Node.cpp:2470
bool ConstantTimeStep
Definition: Parameters.cpp:94
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
real Tolerance
Definition: Parameters.cpp:91
#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 Node::fillVirtualChildren ( )

Fills the cell-average values of every virtual leaf with values predicted from its parent and uncles. This procedure is required after a time evolution to refresh the virtual leaves of the tree.

Returns
void
625 {
626  // --- Local variables ---
627 
628  int n=0; // Counter on children
629 
630  // --- Recursion ---
631 
632  switch(Flag)
633  {
634  // If node is not a leaf or leaf with virtual children, recurse on children
635  case 0:
636  case 2:
637  for (n = 0; n < ChildNb; n++)
638  Child[n]->fillVirtualChildren();
639  break;
640 
641  // If node is a simple leaf, stop procedure
642  case 1:
643  return;
644  break;
645 
646  // If node is a virtual leaf, compute value with prediction
647  case 3:
648  ThisCell.setAverage(predict());
649  if (EquationType==6) ThisCell.setGradient(parentCell()->gradient());
650  break;
651 
652  };
653 }
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
int ChildNb
Definition: Parameters.cpp:213
void fillVirtualChildren()
Fills the cell-average values of every virtual leaf with values predicted from its parent and uncles...
Definition: Node.cpp:624
int EquationType
Definition: Parameters.cpp:66
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921

Here is the caller graph for this function:

void Node::initValue ( )

Computes the initial value.

Returns
void
125 {
126  int i,j,k; // Counters on directions
127 
128  ThisCell.setAverageZero();
129 
130  if (UseBoundaryRegions && isInsideBoundary())
131  {
132  ThisCell.setAverage(InitAverage( ThisCell.center(1),
133  (Dimension >1)? ThisCell.center(2):0.,
134  (Dimension > 2)? ThisCell.center(3):0. ) );
135  }
136  else
137  {
138  switch (Dimension)
139  {
140  case 1:
141  for (i=0;i<=1;i++)
142  ThisCell.setAverage( ThisCell.average()+.5* InitAverage(
143  ThisCell.center(1)+(i-0.5)*ThisCell.size(1)
144  ) );
145  break;
146 
147  case 2:
148  if(IcNb){
149  for (i=0;i<=1;i++){
150  for (j=0;j<=1;j++){
151  ThisCell.setAverage( ThisCell.average()+.25* InitAverage(
152  ThisCell.center(1)+(i-0.5)*ThisCell.size(1),
153  ThisCell.center(2)+(j-0.5)*ThisCell.size(2)));
154  ThisCell.setRes(InitResistivity(ThisCell.center(1), ThisCell.center(2)));
155  }
156  }
157  }else{
158  ThisCell.setAverage(InitAverage(ThisCell.center(1), ThisCell.center(2)));
159  ThisCell.setRes(InitResistivity(ThisCell.center(1), ThisCell.center(2)));
160  }
161 
162  break;
163 
164  case 3:
165  if(IcNb){
166  for (i=0;i<=1;i++)
167  for (j=0;j<=1;j++)
168  for (k=0;k<=1;k++){
169  ThisCell.setAverage( ThisCell.average()+.125* InitAverage(
170  ThisCell.center(1)+(i-0.5)*ThisCell.size(1),
171  ThisCell.center(2)+(j-0.5)*ThisCell.size(2),
172  ThisCell.center(3)+(k-0.5)*ThisCell.size(3)) );
173  ThisCell.setRes(InitResistivity(ThisCell.center(1), ThisCell.center(2),ThisCell.center(3)));
174  }
175 
176  }else{
177  ThisCell.setAverage(InitAverage(ThisCell.center(1), ThisCell.center(2),ThisCell.center(3)));
178  ThisCell.setRes(InitResistivity(ThisCell.center(1), ThisCell.center(2),ThisCell.center(3)));
179  }
180  break;
181  };
182  }
183 }
void setAverageZero()
Sets all the cell-average values to zero.
Definition: Cell.h:937
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
int IcNb
Definition: Parameters.cpp:89
int Dimension
Definition: Parameters.cpp:74
void setRes(const real UserAverage)
Set resistivity.
Definition: Cell.h:1011
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
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
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

Here is the caller graph for this function:

int Node::leaves ( ) const
inline

Returns the number of leaves in the tree.

Returns
int
696 {
697  return LeafNb;
698 }
int LeafNb
Definition: Parameters.cpp:175
Cell * Node::project ( )

Computes the cell-average values of all nodes that are not leaves by projection from the cell-averages values of the leaves. This procedure is required after a time evolution to refresh the internal nodes of the tree.

Returns
Cell*
662 {
663  // --- Local variables ---
664 
665  int n=0; // Counter on children
666 
667  // --- If cell is not a leaf, compute projection ie mean value of children ---
668 
669  if (isInternalNode())
670  {
671  // Set value to zero
672  ThisCell.setAverageZero();
673 
674  // Compute the mean value
675  for (n = 0; n < ChildNb; n++)
676  ThisCell.setAverage( ThisCell.average() + Child[n]->project()->average() );
677 
678  ThisCell.setAverage( ThisCell.average() / ChildNb );
679 
680  }
681 
682  return &ThisCell;
683 }
void setAverageZero()
Sets all the cell-average values to zero.
Definition: Cell.h:937
int ChildNb
Definition: Parameters.cpp:213
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921
Cell * project()
Computes the cell-average values of all nodes that are not leaves by projection from the cell-average...
Definition: Node.cpp:661

Here is the caller graph for this function:

void Node::restore ( )

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

Returns
void
2762 {
2763 
2764  int n=0; // Counter on children
2765  int QuantityNo=0; // Counter on quantities
2766  char buf[256]; // Text buffer
2767  char* caux;
2768  // --- Init ---
2769 
2770  if (Nl==0)
2771  {
2772  GlobalFile = fopen("carmen.bak","r");
2773  // fgets(buf, 256, GlobalFile);
2774  }
2775 
2776  caux=fgets(buf,256,GlobalFile);
2777 
2778  // If the first data is not a 'N', it means that the data has been created using FineMesh
2779 
2780  if (buf[0] != 'N' && Nl==0)
2781  {
2782  fclose(GlobalFile);
2783  restoreFineMesh();
2784  return;
2785  }
2786 
2787  // If end of file is reached, close file and return
2788  if (feof(GlobalFile))
2789  {
2790  fclose(GlobalFile);
2791  return;
2792  }
2793 
2794  // --- Recurse : if node is not a leaf, split it and restore children ---
2795 
2796  if (buf[0]=='N')
2797  {
2798  split();
2799  for (n = 0; n < ChildNb; n++)
2800  Child[n]->restore();
2801  }
2802  else
2803  {
2804  ThisCell.setAverage(1,atof(buf));
2805  for (QuantityNo=2; QuantityNo <= QuantityNb; QuantityNo++)
2806  {
2807  caux=fgets(buf,256,GlobalFile);
2808  ThisCell.setAverage(QuantityNo, atof(buf));
2809  }
2810  return;
2811  }
2812 }
int QuantityNb
Definition: Parameters.cpp:171
FILE * GlobalFile
Definition: Parameters.cpp:212
int ChildNb
Definition: Parameters.cpp:213
void restoreFineMesh()
Restores the tree structure and the cell-averages from the file carmen.bak in FineMesh format...
Definition: Node.cpp:2821
void restore()
Restores the tree structure and the cell-averages from the file carmen.bak. This file was created by ...
Definition: Node.cpp:2761
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921

Here is the caller graph for this function:

void Node::restoreFineMesh ( )

Restores the tree structure and the cell-averages from the file carmen.bak in FineMesh format.

Returns
void
2822 {
2823  // --- Local variables ---
2824 
2825  int i=0,j=0,k=0; // Counters in the three directions
2826  int n=0,iaux; // Global counter
2827  int QuantityNo=0; // Counter on quantities
2828  FILE* input; // Input file
2829  real buf;
2830 
2831  // --- Split the whole tree structure ---
2832 
2833  splitAll();
2834 
2835  // --- Get data from carmen.bak in the FineMesh format
2836 
2837 
2838  // -- Open file --
2839 
2840  input = fopen("carmen.bak","r");
2841 
2842  // -- When there is no back-up file, return --
2843 
2844  if (!input) return;
2845 
2846  // -- Loop on fine-grid cells --
2847 
2848  for (n = 0; n < 1<<(ScaleNb*Dimension); n++)
2849  {
2850  // -- Compute i, j, k --
2851 
2852  i = n%(1<<ScaleNb);
2853  if (Dimension > 1) j = (n%(1<<(2*ScaleNb)))/(1<<ScaleNb);
2854  if (Dimension > 2) k = n/(1<<(2*ScaleNb));
2855 
2856  for (QuantityNo=1; QuantityNo <= QuantityNb; QuantityNo++)
2857  {
2858  iaux=fscanf(input,BACKUP_FILE_FORMAT, &buf);
2859  cell(ScaleNb,i,j,k)->setAverage(QuantityNo, buf);
2860  }
2861  }
2862 
2863  fclose(input);
2864 
2865 }
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
int Dimension
Definition: Parameters.cpp:74
#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 Node::RungeKutta ( )

Computes one Runge-Kutta step.

Returns
void
2346 {
2347  // --- Local variables ---
2348 
2349  int n=0; // Counter on children
2350  real c1=0., c2=0., c3=0.; // Runge-Kutta coefficients
2351  real LocalTimeStep=TimeStep; // Local time step
2352 
2353  Vector Q(QuantityNb), Qs(QuantityNb), D(QuantityNb); // Cell-average, temporary cell-average and divergence
2354 
2355  // --- If node is in the tree, recurse on children -----------------------------------------
2356 
2357  if (isInternalNode())
2358  for (n = 0; n < ChildNb; n++)
2359  Child[n]->RungeKutta();
2360 
2361  // --- If the leaf is in the boundary, do not perform time evolution -----------------------
2362 
2363  if (UseBoundaryRegions)
2364  {
2365  if (isLeaf() && isInsideBoundary())
2366  return;
2367  }
2368 
2369  // --- For leaves in the fluid region ------------------------------------------------------
2370 
2371  if (requiresDivergenceComputation())
2372  {
2373  // --- Compute local time step in function of the scale ---
2374 
2375  if (TimeAdaptivity)
2376  {
2377  // Compute local time step
2378  LocalTimeStep = TimeStep*(1<<(TimeAdaptivityFactor*(ScaleNb-Nl)));
2379 
2380  // At the end of the time cycle, Q <- Qlow (solution at end of cycle)
2381  if (isEndTimeCycle() && StepNo == 1 && Nl < ScaleNb)
2382  ThisCell.setAverage( ThisCell.lowAverage());
2383  }
2384  // --- Define Runge-Kutta coefficients ---
2385 
2386  switch(StepNo)
2387  {
2388  case 1:
2389  c1 = 1.; c2 = 0.; c3 = 1.;
2390  break;
2391  case 2:
2392  if (StepNb == 2) {c1 = .5; c2 = .5; c3 = .5; }
2393  if (StepNb == 3) {c1 = .75; c2 = .25; c3 = .25; }
2394  break;
2395  case 3:
2396  c1 = 1./3.; c2 = 2.*c1; c3 = c2;
2397  break;
2398  };
2399 
2400  // --- Runge-Kutta step ---
2401 
2402  Q = ThisCell.average();
2403  Qs = ThisCell.tempAverage();
2404  D = ThisCell.divergence();
2405 
2406  // Perform RK step only in fluid region
2407  ThisCell.setAverage( c1*Qs + c2*Q + (c3 * LocalTimeStep)*D );
2408 
2409  // For the Runge-Kutta-Fehlberg 2(3) method, store second-stage with the RK2 coefficients
2410 
2411  if (!ConstantTimeStep && (StepNo == 2) && (StepNb == 3)) // MODIFIED 10.12.05
2412  ThisCell.setLowAverage(0.5*(Qs + Q + LocalTimeStep*D));
2413 
2414  // Time adaptivity :
2415  if (TimeAdaptivity)
2416  {
2417  if (isBeginTimeCycle() && StepNo == 1 && Nl < ScaleNb)
2418  storeTimeEvolution();
2419  }
2420  }
2421 
2422 }
bool TimeAdaptivity
Definition: Parameters.cpp:85
int ScaleNb
Definition: Parameters.cpp:87
int QuantityNb
Definition: Parameters.cpp:171
real lowAverage(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value with low precision in the Runge-Kutta-...
Definition: Cell.h:1160
Standard class for every vector in Carmen.
Definition: Vector.h:29
int StepNo
Definition: Parameters.cpp:167
void RungeKutta()
Computes one Runge-Kutta step.
Definition: Node.cpp:2345
int ChildNb
Definition: Parameters.cpp:213
real divergence(const int QuantityNo) const
Returns the component no. QuantityNo of the divergence vector.
Definition: Cell.h:1192
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
void setLowAverage(const int QuantityNo, const real UserAverage)
Identical to setAverage (int QuantityNo, real UserAverage), but for the vector of the cell-average va...
Definition: Cell.h:969
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 ConstantTimeStep
Definition: Parameters.cpp:94
bool UseBoundaryRegions
Definition: Parameters.cpp:80
int TimeAdaptivityFactor
Definition: Parameters.cpp:86
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 Node::smooth ( )

Deletes the details in the highest level.

Returns
void
2875 {
2876  int n=0; // Child number
2877 
2878  // --- Recurse on children ---
2879 
2880  if (isInternalNode())
2881  {
2882  for (n = 0; n < ChildNb; n++)
2883  Child[n]->smooth();
2884  }
2885  else
2886  //if (Nl == ScaleNb)
2887  {
2888  if (parentCell()->average() == ThisCell.average())
2889  return;
2890  else
2891  ThisCell.setAverage(SmoothCoeff*predict()+(1.-SmoothCoeff)*ThisCell.average());
2892  }
2893 
2894  return;
2895 }
int ChildNb
Definition: Parameters.cpp:213
real SmoothCoeff
Definition: Parameters.cpp:99
real average(const int QuantityNo) const
Returns the component no. QuantityNo of the cell-average value.
Definition: Cell.h:1128
void smooth()
Deletes the details in the highest level.
Definition: Node.cpp:2874
void setAverage(const int QuantityNo, const real UserAverage)
Sets the cell-average of the quantity QuantityNo to UserAverage. Example:
Definition: Cell.h:921

Here is the caller graph for this function:

void Node::store ( )

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

Returns
void
1914 {
1915  // --- Local variables ---
1916 
1917  int n=0; // Counter on children
1918 
1919  // --- Store cell-average value Q into Qs ---
1920 
1921  if (((EquationType==6) && SchemeNb > 5 ) || requiresTimeEvolution() || IterationNo == 1)
1922  {
1923  if (UseBoundaryRegions)
1924  {
1925  if (IterationNo == 1)
1926  ThisCell.setOldAverage(ThisCell.average());
1927  else
1928  ThisCell.setOldAverage(ThisCell.tempAverage());
1929  }
1930 
1931  ThisCell.setTempAverage(ThisCell.average());
1932  }
1933 
1934  // --- Recursion in nodes that have children (real or virtual) ---
1935 
1936  if (hasChildren())
1937  {
1938  for (n = 0; n < ChildNb; n++)
1939  Child[n]->store();
1940  }
1941 }
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 ChildNb
Definition: Parameters.cpp:213
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
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
int SchemeNb
Definition: Parameters.cpp:67
int EquationType
Definition: Parameters.cpp:66
bool UseBoundaryRegions
Definition: Parameters.cpp:80
void store()
Stores cell-average values into temporary cell-average values.
Definition: Node.cpp:1913

Here is the caller graph for this function:

void Node::storeGrad ( )

Stores gradient values into temporary gradient values.

Returns
void
1951 {
1952  // --- Local variables ---
1953 
1954  int n=0; // Counter on children
1955 
1956  // --- Store gradient-average value Grad into Grads ---
1957 
1958  if (((EquationType==6) && SchemeNb > 5) || requiresTimeEvolution() || IterationNo == 1)
1959  ThisCell.setTempGradient(ThisCell.gradient());
1960 
1961  // --- Recursion in nodes that have children (real or virtual) ---
1962 
1963  if (hasChildren())
1964  {
1965  for (n = 0; n < ChildNb; n++)
1966  Child[n]->storeGrad();
1967  }
1968 }
void storeGrad()
Stores gradient values into temporary gradient values.
Definition: Node.cpp:1950
int ChildNb
Definition: Parameters.cpp:213
int IterationNo
Definition: Parameters.cpp:168
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
int SchemeNb
Definition: Parameters.cpp:67
int EquationType
Definition: Parameters.cpp:66
real gradient(const int i, const int j) const
Returns the component no. i, j of the velocity gradient. Does not work for MHD!
Definition: Cell.h:1225
void Node::writeAverage ( const char *  FileName)

Writes cell-average values in multiresolution representation and the corresponding mesh into file FileName.

Parameters
FileNameName of the file.
Returns
void
1090 {
1091  // --- Local variables ---
1092 
1093  int n ; // Counter on children
1094  FILE *output; // Pointer to output file
1095  Vector Qbuf(QuantityNb); // Buffer of the vector of conservative quantities
1096  real a=1., b=1.; // Weights for the synchronisation of conservative quantities
1097  int Nf=1;
1098 
1099  // --- Open file ---
1100 
1101  if ((output = fopen(FileName,"a")) != NULL)
1102  {
1103  // If node is not a leaf, recurse to children
1104  if (isInternalNode())
1105  {
1106  fclose(output);
1107  for (n = 0; n < ChildNb; n++)
1108  Child[n]->writeAverage(FileName);
1109  }
1110  else
1111  {
1112  // In case of local time stepping, store value and synchronize it
1113  if ( TimeAdaptivity && Dimension == 1 && (Nl < (ScaleNb-1)) )
1114  {
1115  Qbuf = ThisCell.average();
1116 
1117  Nf = 1<<TimeAdaptivityFactor*(ScaleNb-Nl);
1118  a = 1.*(IterationNo%Nf - Nf/2);
1119  b = 1.*(Nf - IterationNo%Nf);
1120 
1121  if ( (a+b) != 0. )
1122  {
1123  // Qbuf2 = ( b/(a+b) )* ThisCell.average()+ ( a/(a+b) )* ThisCell.lowAverage();
1124 
1125  // ThisCell.setAverage(Qbuf2);
1126 
1127  //ThisCell.setAverage(( b/(a+b) )* ThisCell.average()+ ( a/(a+b) )* ThisCell.lowAverage())
1128  }
1129  }
1130 
1131  // write cell-average values and details from parent
1132 
1133  fprintf(output, FORMAT, ThisCell.center(1));
1134  if (Dimension > 1) fprintf(output, FORMAT, ThisCell.center(2));
1135  if (Dimension > 2) fprintf(output, FORMAT, ThisCell.center(3));
1136 
1137  if (Dimension > 1)
1138  fprintf(output, "%i", Nl);
1139 
1140  else{
1141  fprintf(output, FORMAT, ThisCell.density());
1142  fprintf(output, FORMAT, ThisCell.pressure());
1143  fprintf(output, FORMAT, ThisCell.psi());
1144  fprintf(output, FORMAT, ThisCell.energy());
1145  fprintf(output, FORMAT, ThisCell.velocity(1));
1146  fprintf(output, FORMAT, ThisCell.magField(1));
1147  }
1148 
1149  fprintf(output,"\n");
1150 
1151  // In case of local time stepping, return to the previous value
1152  if (TimeAdaptivity && Dimension == 1 && Nl < ScaleNb-1)
1153  ThisCell.setAverage(Qbuf);
1154 
1155  fclose(output);
1156  }
1157  }
1158  else
1159  {
1160  cout << "Node.cpp: In method `void Node::writeAverage()':\n";
1161  cout << "Node.cpp: cannot open file " << FileName << '\n';
1162  cout << "carmen: *** [Node.o] Execution error\n";
1163  cout << "carmen: abort execution.\n";
1164  exit(1);
1165  }
1166 }
bool TimeAdaptivity
Definition: Parameters.cpp:85
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 QuantityNb
Definition: Parameters.cpp:171
Standard class for every vector in Carmen.
Definition: Vector.h:29
real density() const
Returns the cell-average density.
Definition: Cell.h:1262
int ChildNb
Definition: Parameters.cpp:213
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 IterationNo
Definition: Parameters.cpp:168
void writeAverage(const char *FileName)
Writes cell-average values in multiresolution representation and the corresponding mesh into file Fil...
Definition: Node.cpp:1089
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
#define FORMAT
Definition: PreProcessor.h:32
real pressure() const
Returns the cell-average pressure.
Definition: Cell.cpp:84
int TimeAdaptivityFactor
Definition: Parameters.cpp:86
real psi() const
Returns the cell-average density.
Definition: Cell.h:1280
real energy() const
Returns the cell-average energy per unit of volume.
Definition: Cell.h:1307
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 Node::writeFineGrid ( const char *  FileName,
const int  L = ScaleNb 
) const

Writes cell-average values on a regular grid of level L into file FileName.

Parameters
FileNameName of the file
LMaximum level.
Returns
void
1175 {
1176 
1177  // --- Declarations ------------------------------------------------------------------------
1178 
1179  int l=0,i=0,j=0,k=0,n=0; // counters
1180 
1181  int ej = (Dimension > 1)? 1:0;
1182  int ek = (Dimension > 2)? 1:0;
1183 
1184  real x=0., y=0., z=0., t=0.; // Cell centers and time
1185  real dx=0., dy=0., dz=0.; // Cell sizes
1186  int GridPoints; // Grid points
1187  char DependencyType[12]; // positions or connections
1188 
1189  PrintGrid FineGrid(L);
1190 
1191  FILE *output;
1192 
1193  // --- Execution ---------------------------------------------------------------------------
1194 
1195  // --- Compute grid points and set dependency type ---
1196 
1197  if (WriteAsPoints)
1198  {
1199  GridPoints = (1<<L);
1200  sprintf(DependencyType,"positions");
1201  }
1202  else
1203  {
1204  GridPoints = (1<<L)+1;
1205  sprintf(DependencyType,"connections");
1206  }
1207 
1208  // --- Compute t, dx, dy, dz ---
1209 
1210  t = ElapsedTime;
1211 
1212  dx = (XMax[1]-XMin[1])/((1<<L)-1);
1213 
1214  if (Dimension > 1)
1215  dy = (XMax[2]-XMin[2])/((1<<L)-1);
1216 
1217  if (Dimension > 2)
1218  dz = (XMax[3]-XMin[3])/((1<<L)-1);
1219 
1220 
1221  // --- Compute result on fine mesh ---
1222 
1223  for (l=0; l<=L; l++)
1224  {
1225  for (i = 0; i <= ((1<<l)-1); i++)
1226  for (j = 0; j <= ((1<<l)-1)*ej; j++)
1227  for (k = 0; k <= ((1<<l)-1)*ek; k++)
1228  {
1229  if (node(l,i,j,k)==0)
1230  FineGrid.predict(l,i,j,k);
1231  else
1232  FineGrid.setValue(i,j,k,cell(l,i,j,k)->average());
1233  }
1234  FineGrid.refresh();
1235  }
1236 
1237 
1238  // --- Open file ---
1239 
1240  if ((output = fopen(FileName,"w")) != NULL)
1241  {
1242  // --- Header ---
1243 
1244  switch(PostProcessing)
1245  {
1246  // GNUPLOT
1247  case 1:
1248  fprintf(output,"#");
1249  fprintf(output, TXTFORMAT, " x");
1250  fprintf(output, TXTFORMAT, "#Density");
1251  fprintf(output, TXTFORMAT, "#Pressure");
1252  fprintf(output, TXTFORMAT, "#Psi");
1253  fprintf(output, TXTFORMAT, "#Energy");
1254  fprintf(output, TXTFORMAT, "#Velocity");
1255  fprintf(output, TXTFORMAT, "#MagField");
1256  fprintf(output, TXTFORMAT, "#Div B");
1257  fprintf(output, "\n");
1258  break;
1259 
1260  // DATA EXPLOTER
1261  case 2:
1262  // Header for Data explorer
1263 
1264  fprintf(output, "# Data Explorer file\n# generated by Carmen %3.1f\n", CarmenVersion);
1265 
1266  switch(Dimension)
1267  {
1268  case 2:
1269  fprintf(output, "#grid = %d x %d\n", GridPoints, GridPoints);
1270  fprintf(output, "#positions = %f, %f, %f, %f\n#\n", XMin[1], dx, XMin[2], dy);
1271  break;
1272 
1273  case 3:
1274  fprintf(output, "#grid = %d x %d x %d\n", GridPoints, GridPoints, GridPoints);
1275  fprintf(output, "#positions = %f, %f, %f, %f, %f, %f\n#\n", XMin[1], dx, XMin[2], dy, XMin[3], dz );
1276  break;
1277  };
1278  if (DataIsBinary)
1279  fprintf(output, "#format = binary\n");
1280  else
1281  fprintf(output, "#format = ascii\n");
1282 
1283  fprintf(output, "#interleaving = field\n");
1284 
1285  // MHD
1286  fprintf(output, "#field = density, pressure, psi, energy, velocity, magField, Div B\n");
1287  fprintf(output, "#structure = scalar, scalar, scalar, scalar, 3-vector, 3-vector, scalar \n");
1288  fprintf(output, "#type = %s, %s, %s, %s, %s, %s\n", REAL, REAL, REAL, REAL, REAL, REAL, REAL);
1289  fprintf(output, "#dependency = %s, %s, %s, %s, %s, %s\n", DependencyType, DependencyType, DependencyType, DependencyType, DependencyType, DependencyType, DependencyType);
1290 
1291 
1292  fprintf(output, "#header = marker \"START_DATA\\n\" \n");
1293  fprintf(output, "#end\n");
1294  fprintf(output, "#START_DATA\n");
1295 
1296  break;
1297 
1298  // TECPLOT
1299  case 3:
1300  fprintf(output, "VARIABLES = \"x\"\n");
1301  fprintf(output,"\"y\"\n");
1302  if (Dimension > 2)
1303  fprintf(output,"\"z\"\n");
1304 
1305  fprintf(output,"\"RHO\"\n\"P\"\n\"PSI\"\n\"E\"\n\"U\"\n\"V\"\n\"W\"\n\"BX\"\n\"BY\"\n\"BZ\"\n");
1306 
1307  fprintf(output,"ZONE T=\"Carmen %3.1f\"\n",CarmenVersion);
1308  fprintf(output,"I=%i, ",(1<<L));
1309  if (Dimension > 1)
1310  fprintf(output,"J=%i, ",(1<<L));
1311  if (Dimension > 2)
1312  fprintf(output,"K=%i, ",(1<<L));
1313  fprintf(output,"F=POINT\n");
1314  break;
1315 
1316  case 4:
1317  int N=(1<<L);
1318  fprintf(output, "# vtk DataFile Version 2.8\nSolucao MHD\n");
1319  if(DataIsBinary)
1320  fprintf(output, "BINARY\n");
1321  else
1322  fprintf(output, "ASCII\n");
1323 
1324  fprintf(output, "DATASET STRUCTURED_GRID\n");
1325  if (Dimension == 2)
1326  {
1327  fprintf(output, "DIMENSIONS %d %d %d \n", N,N,1);
1328  fprintf(output, "POINTS %d FLOAT\n", N*N);
1329  for (int i = 0; i < N; i++)
1330  for (int j = 0; j < N; j++)
1331  fprintf(output, "%f %f %f \n", XMin[1] + i*dx, XMin[2] + j*dy, 0.0);
1332 
1333  fprintf(output, "\n\nPOINT_DATA %d \n", N*N);
1334  }
1335  if (Dimension == 3)
1336  {
1337  fprintf(output, "DIMENSIONS %d %d %d \n", N,N,N);
1338  fprintf(output, "POINTS %d FLOAT\n", N*N*N);
1339  for (int i = 0; i < N; i++)
1340  for (int j = 0; j < N; j++)
1341  for (int k = 0; k < N; k++)
1342  fprintf(output, "%f %f %f \n", XMin[1] + i*dx, XMin[2] + j*dy, XMin[3] + k*dx);
1343 
1344  fprintf(output, "\n\nPOINT_DATA %d \n", N*N*N);
1345  }
1346 
1347  break;
1348 
1349  };
1350 
1351  // --- write values ---
1352 
1353  for (n=0; n < (1<<(Dimension*L)); n++)
1354  {
1355 
1356  // -- Compute i, j, k --
1357 
1358  // For Gnuplot and DX, loop order: for i... {for j... {for k...} }
1359  if (PostProcessing != 3)
1360  {
1361  switch(Dimension)
1362  {
1363  case 1:
1364  i = n;
1365  j = k = 0;
1366  break;
1367 
1368  case 2:
1369  j = n%(1<<L);
1370  i = n/(1<<L);
1371  k = 0;
1372  break;
1373 
1374  case 3:
1375  k = n%(1<<L);
1376  j = (n%(1<<(2*L)))/(1<<L);
1377  i = n/(1<<(2*L));
1378  break;
1379  };
1380  }
1381  else
1382  {
1383  // For Tecplot, loop order: for k... {for j... {for i...} }
1384  i = n%(1<<L);
1385  if (Dimension > 1)
1386  j = (n%(1<<(2*L)))/(1<<L);
1387  else
1388  j = 0;
1389  if (Dimension > 2)
1390  k = n/(1<<(2*L));
1391  else
1392  k = 0;
1393  }
1394 
1395  // Compute x, y, z
1396  if (PostProcessing == 1 || PostProcessing == 2)
1397  {
1398  x = XMin[1]+i*dx;
1399  if (Dimension > 1) y = XMin[2]+j*dy;
1400  if (Dimension > 2) z = XMin[3]+k*dz;
1401  }
1402  // For Tecplot, write coordinates
1403  if (PostProcessing == 3)
1404  {
1405  FileWrite(output, FORMAT, x);
1406  if (Dimension > 1) FileWrite(output, FORMAT, y);
1407  if (Dimension > 2) FileWrite(output, FORMAT, z);
1408  }
1409 
1410  }
1411  // MHD
1412  if(PostProcessing == 4)
1413  {
1414  /*
1415  fprintf(output, "\n\nSCALARS eta float\nLOOKUP_TABLE default\n");
1416  for (n=0; n < (1<<(Dimension*L)); n++){
1417  switch(Dimension)
1418  {
1419  case 1:
1420  i = n;
1421  j = k = 0;
1422  break;
1423 
1424  case 2:
1425  j = n%(1<<L);
1426  i = n/(1<<L);
1427  k = 0;
1428  break;
1429 
1430  case 3:
1431  k = n%(1<<L);
1432  j = (n%(1<<(2*L)))/(1<<L);
1433  i = n/(1<<(2*L));
1434  break;
1435  };
1436  FileWrite(output, FORMAT, FineGrid.etaConst(i,j,k));
1437  fprintf(output, "\n");
1438  }
1439  */
1440  fprintf(output, "\n\nSCALARS Density float\nLOOKUP_TABLE default\n");
1441  for (n=0; n < (1<<(Dimension*L)); n++){
1442  switch(Dimension)
1443  {
1444  case 1:
1445  i = n;
1446  j = k = 0;
1447  break;
1448 
1449  case 2:
1450  j = n%(1<<L);
1451  i = n/(1<<L);
1452  k = 0;
1453  break;
1454 
1455  case 3:
1456  k = n%(1<<L);
1457  j = (n%(1<<(2*L)))/(1<<L);
1458  i = n/(1<<(2*L));
1459  break;
1460  };
1461  FileWrite(output, FORMAT, FineGrid.density(i,j,k));
1462  fprintf(output, "\n");
1463  }
1464 
1465  fprintf(output, "\n\nSCALARS Pressure float\nLOOKUP_TABLE default\n");
1466  for (n=0; n < (1<<(Dimension*L)); n++){
1467  switch(Dimension)
1468  {
1469  case 1:
1470  i = n;
1471  j = k = 0;
1472  break;
1473 
1474  case 2:
1475  j = n%(1<<L);
1476  i = n/(1<<L);
1477  k = 0;
1478  break;
1479 
1480  case 3:
1481  k = n%(1<<L);
1482  j = (n%(1<<(2*L)))/(1<<L);
1483  i = n/(1<<(2*L));
1484  break;
1485  };
1486  FileWrite(output, FORMAT, FineGrid.pressure(i,j,k));
1487  fprintf(output, "\n");
1488  }
1489 
1490  fprintf(output, "\n\nSCALARS Energy float\nLOOKUP_TABLE default\n");
1491  for (n=0; n < (1<<(Dimension*L)); n++){
1492  switch(Dimension)
1493  {
1494  case 1:
1495  i = n;
1496  j = k = 0;
1497  break;
1498 
1499  case 2:
1500  j = n%(1<<L);
1501  i = n/(1<<L);
1502  k = 0;
1503  break;
1504 
1505  case 3:
1506  k = n%(1<<L);
1507  j = (n%(1<<(2*L)))/(1<<L);
1508  i = n/(1<<(2*L));
1509  break;
1510  };
1511  FileWrite(output, FORMAT, FineGrid.energy(i,j,k));
1512  fprintf(output, "\n");
1513  }
1514 
1515  fprintf(output, "\n\nSCALARS Vx float\nLOOKUP_TABLE default\n");
1516  for (n=0; n < (1<<(Dimension*L)); n++){
1517  switch(Dimension)
1518  {
1519  case 1:
1520  i = n;
1521  j = k = 0;
1522  break;
1523 
1524  case 2:
1525  j = n%(1<<L);
1526  i = n/(1<<L);
1527  k = 0;
1528  break;
1529 
1530  case 3:
1531  k = n%(1<<L);
1532  j = (n%(1<<(2*L)))/(1<<L);
1533  i = n/(1<<(2*L));
1534  break;
1535  };
1536  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,1));
1537  fprintf(output, "\n");
1538  }
1539 
1540  fprintf(output, "\n\nSCALARS Vy float\nLOOKUP_TABLE default\n");
1541  for (n=0; n < (1<<(Dimension*L)); n++){
1542  switch(Dimension)
1543  {
1544  case 1:
1545  i = n;
1546  j = k = 0;
1547  break;
1548 
1549  case 2:
1550  j = n%(1<<L);
1551  i = n/(1<<L);
1552  k = 0;
1553  break;
1554 
1555  case 3:
1556  k = n%(1<<L);
1557  j = (n%(1<<(2*L)))/(1<<L);
1558  i = n/(1<<(2*L));
1559  break;
1560  };
1561  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,2));
1562  fprintf(output, "\n");
1563  }
1564 
1565  fprintf(output, "\n\nSCALARS Vz float\nLOOKUP_TABLE default\n");
1566  for (n=0; n < (1<<(Dimension*L)); n++){
1567  switch(Dimension)
1568  {
1569  case 1:
1570  i = n;
1571  j = k = 0;
1572  break;
1573 
1574  case 2:
1575  j = n%(1<<L);
1576  i = n/(1<<L);
1577  k = 0;
1578  break;
1579 
1580  case 3:
1581  k = n%(1<<L);
1582  j = (n%(1<<(2*L)))/(1<<L);
1583  i = n/(1<<(2*L));
1584  break;
1585  };
1586  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,3));
1587  fprintf(output, "\n");
1588  }
1589 
1590  fprintf(output, "\n\nSCALARS Bx float\nLOOKUP_TABLE default\n");
1591  for (n=0; n < (1<<(Dimension*L)); n++){
1592  switch(Dimension)
1593  {
1594  case 1:
1595  i = n;
1596  j = k = 0;
1597  break;
1598 
1599  case 2:
1600  j = n%(1<<L);
1601  i = n/(1<<L);
1602  k = 0;
1603  break;
1604 
1605  case 3:
1606  k = n%(1<<L);
1607  j = (n%(1<<(2*L)))/(1<<L);
1608  i = n/(1<<(2*L));
1609  break;
1610  };
1611  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,1));
1612  fprintf(output, "\n");
1613  }
1614 
1615  fprintf(output, "\n\nSCALARS By float\nLOOKUP_TABLE default\n");
1616  for (n=0; n < (1<<(Dimension*L)); 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<<L);
1626  i = n/(1<<L);
1627  k = 0;
1628  break;
1629 
1630  case 3:
1631  k = n%(1<<L);
1632  j = (n%(1<<(2*L)))/(1<<L);
1633  i = n/(1<<(2*L));
1634  break;
1635  };
1636  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,2));
1637  fprintf(output, "\n");
1638  }
1639 
1640  fprintf(output, "\n\nSCALARS Bz float\nLOOKUP_TABLE default\n");
1641  for (n=0; n < (1<<(Dimension*L)); n++){
1642  switch(Dimension)
1643  {
1644  case 1:
1645  i = n;
1646  j = k = 0;
1647  break;
1648 
1649  case 2:
1650  j = n%(1<<L);
1651  i = n/(1<<L);
1652  k = 0;
1653  break;
1654 
1655  case 3:
1656  k = n%(1<<L);
1657  j = (n%(1<<(2*L)))/(1<<L);
1658  i = n/(1<<(2*L));
1659  break;
1660  };
1661  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,3));
1662  fprintf(output, "\n");
1663  }
1664 
1665  fprintf(output, "\n\nSCALARS DivB float\nLOOKUP_TABLE default\n");
1666  for (n=0; n < (1<<(Dimension*L)); n++){
1667  switch(Dimension)
1668  {
1669  case 1:
1670  i = n;
1671  j = k = 0;
1672  break;
1673 
1674  case 2:
1675  j = n%(1<<L);
1676  i = n/(1<<L);
1677  k = 0;
1678  break;
1679 
1680  case 3:
1681  k = n%(1<<L);
1682  j = (n%(1<<(2*L)))/(1<<L);
1683  i = n/(1<<(2*L));
1684  break;
1685  };
1686  FileWrite(output, FORMAT, FineGrid.divergenceB(i,j,k));
1687  fprintf(output, "\n");
1688  }
1689  fprintf(output, "\n\nSCALARS DivB2 float\nLOOKUP_TABLE default\n");
1690  for (n=0; n < (1<<(Dimension*L)); n++){
1691  switch(Dimension)
1692  {
1693  case 1:
1694  i = n;
1695  j = k = 0;
1696  break;
1697 
1698  case 2:
1699  j = n%(1<<L);
1700  i = n/(1<<L);
1701  k = 0;
1702  break;
1703 
1704  case 3:
1705  k = n%(1<<L);
1706  j = (n%(1<<(2*L)))/(1<<L);
1707  i = n/(1<<(2*L));
1708  break;
1709  };
1710  FileWrite(output, FORMAT, FineGrid.vorticity(i,j,k));
1711  fprintf(output, "\n");
1712  }
1713 
1714  fprintf(output, "\n\nVECTORS Velocity float\n");
1715  for (n=0; n < (1<<(Dimension*L)); n++){
1716  switch(Dimension)
1717  {
1718  case 1:
1719  i = n;
1720  j = k = 0;
1721  break;
1722 
1723  case 2:
1724  j = n%(1<<L);
1725  i = n/(1<<L);
1726  k = 0;
1727  break;
1728 
1729  case 3:
1730  k = n%(1<<L);
1731  j = (n%(1<<(2*L)))/(1<<L);
1732  i = n/(1<<(2*L));
1733  break;
1734  };
1735 
1736 
1737  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,1));
1738  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,2));
1739  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,3));
1740  }
1741 
1742 
1743  fprintf(output, "\n\nVECTORS MagField float\n");
1744  for (n=0; n < (1<<(Dimension*L)); n++){
1745  switch(Dimension)
1746  {
1747  case 1:
1748  i = n;
1749  j = k = 0;
1750  break;
1751 
1752  case 2:
1753  j = n%(1<<L);
1754  i = n/(1<<L);
1755  k = 0;
1756  break;
1757 
1758  case 3:
1759  k = n%(1<<L);
1760  j = (n%(1<<(2*L)))/(1<<L);
1761  i = n/(1<<(2*L));
1762  break;
1763  };
1764 
1765 
1766  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,1));
1767  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,2));
1768  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,3));
1769  }
1770  }else{
1771  for (n=0; n < (1<<(Dimension*L)); n++)
1772  {
1773  FileWrite(output, FORMAT, FineGrid.density(i,j,k));
1774  FileWrite(output, FORMAT, FineGrid.pressure(i,j,k));
1775  FileWrite(output, FORMAT, FineGrid.psi(i,j,k));
1776  FileWrite(output, FORMAT, FineGrid.energy(i,j,k));
1777 
1778  for (int AxisNo = 1; AxisNo <= 3; AxisNo++){
1779  FileWrite(output, FORMAT, FineGrid.velocity(i,j,k,AxisNo));
1780  FileWrite(output, FORMAT, FineGrid.magField(i,j,k,AxisNo));
1781  }
1782  FileWrite(output, FORMAT, FineGrid.divergenceB(i,j,k));
1783  }
1784  }
1785 
1786  for (n=0; n < (1<<(Dimension*L)); n++){
1787  // For ASCII data, add a return at the end of the line
1788  if (!DataIsBinary)
1789  fprintf(output,"\n");
1790 
1791  // For Gnuplot, add empty lines when j=jmax or k=kmax
1792  if (PostProcessing == 1)
1793  {
1794  if (j==(1<<ScaleNb)-1)
1795  fprintf(output,"\n");
1796 
1797  if (k==(1<<ScaleNb)-1)
1798  fprintf(output,"\n");
1799  }
1800  }
1801 
1802  fclose(output);
1803  }
1804  else
1805  {
1806  cout << "Node.cpp: In method `void writeFineGrid(Node*, char*, int)':\n";
1807  cout << "Node.cpp: cannot open file " << FileName << '\n';
1808  cout << "carmen: *** [Node.o] Execution error\n";
1809  cout << "carmen: abort execution.\n";
1810  exit(1);
1811  }
1812 }/*
int ScaleNb
Definition: Parameters.cpp:87
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
bool WriteAsPoints
Definition: Parameters.cpp:147
#define TXTFORMAT
Definition: PreProcessor.h:33
int Dimension
Definition: Parameters.cpp:74
real ElapsedTime
Definition: Parameters.cpp:95
real CarmenVersion
Definition: Parameters.cpp:28
int PostProcessing
Definition: Parameters.cpp:144
An object PrintGrid is a special regular grid created to write tree-structured data into an output fi...
Definition: PrintGrid.h:38
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:

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

Writes header for Data Explorer into file FileName.

Parameters
FileNameName of the file.
Returns
void
1029 {
1030  // --- Local variables ---
1031 
1032  FILE *output; // Pointer to output file
1033 
1034  // --- Open file ---
1035 
1036  if ((output = fopen(FileName,"w")) != NULL)
1037  {
1038  // --- Header ---
1039 
1040  if (Dimension == 1)
1041  {
1042  // GNUPLOT
1043  fprintf(output,"#");
1044  fprintf(output, TXTFORMAT, " x");
1045  fprintf(output, TXTFORMAT, "Density");
1046  fprintf(output, TXTFORMAT, "Pressure");
1047  fprintf(output, TXTFORMAT, "Psi");
1048  fprintf(output, TXTFORMAT, "Energy");
1049  fprintf(output, TXTFORMAT, "Velocity");
1050  fprintf(output, TXTFORMAT, "MagField");
1051  fprintf(output, "\n");
1052  }
1053  else
1054  {
1055  fprintf(output, "# Data Explorer file\n# generated by Carmen %3.1f\n", CarmenVersion);
1056  fprintf(output, "# points = %d\n",LeafNb);
1057  fprintf(output, "# format = ascii\n");
1058  fprintf(output, "# interleaving = field\n");
1059 
1060  fprintf(output, "# field = locations, Q1\n");
1061  fprintf(output, "# structure = %d-vector, scalar\n", Dimension);
1062  fprintf(output, "# type = %s, %s\n", REAL, REAL);
1063  fprintf(output, "# dependency = positions, positions\n");
1064 
1065  fprintf(output, "# header = marker \"START_DATA\\n\" \n");
1066  fprintf(output, "# end\n");
1067  fprintf(output, "# START_DATA\n");
1068  }
1069 
1070  fclose(output);
1071  return;
1072  }
1073  else
1074  {
1075  cout << "Node.cpp: In method `void Node::writeHeader()':\n";
1076  cout << "Node.cpp: cannot open file " << FileName << '\n';
1077  cout << "carmen: *** [Node.o] Execution error\n";
1078  cout << "carmen: abort execution.\n";
1079  exit(1);
1080  }
1081 }
int LeafNb
Definition: Parameters.cpp:175
#define TXTFORMAT
Definition: PreProcessor.h:33
int Dimension
Definition: Parameters.cpp:74
real CarmenVersion
Definition: Parameters.cpp:28
#define REAL
Definition: PreProcessor.h:34

Here is the caller graph for this function:

void Node::writeMesh ( const char *  FileName) const

Writes mesh data for Gnuplot into file FileName.

Parameters
FileNameName of the file.
Returns
void
1820 {
1821  // --- Local variables ---
1822 
1823  int n; // Counter on children
1824  FILE *output; // Pointer to output file
1825 
1826  // --- Open file ---
1827 
1828  if ( (Nl == 0) ? (output = fopen(FileName,"w")) : (output = fopen(FileName,"a")) )
1829  {
1830  if (isInternalNode())
1831  {
1832  for (n = 0; n < ChildNb; n++)
1833  Child[n]->writeMesh(FileName);
1834  }
1835  else
1836  {
1837  // x-direction
1838  fprintf(output, FORMAT, ThisCell.center(1)-.5*ThisCell.size(1));
1839  if (Dimension >1) fprintf(output, FORMAT, ThisCell.center(2)-.5*ThisCell.size(2));
1840  if (Dimension >2) fprintf(output, FORMAT, ThisCell.center(3)-.5*ThisCell.size(3));
1841  fprintf(output, "%d", Nl);
1842  fprintf(output,"\n");
1843 
1844  fprintf(output, FORMAT, ThisCell.center(1)+.5*ThisCell.size(1));
1845  if (Dimension >1) fprintf(output, FORMAT, ThisCell.center(2)-.5*ThisCell.size(2));
1846  if (Dimension >2) fprintf(output, FORMAT, ThisCell.center(3)-.5*ThisCell.size(3));
1847  fprintf(output, "%d", Nl);
1848  fprintf(output,"\n\n");
1849 
1850  // y-direction
1851  if (Dimension > 1)
1852  {
1853  fprintf(output, FORMAT, ThisCell.center(1)-.5*ThisCell.size(1));
1854  fprintf(output, FORMAT, ThisCell.center(2)+.5*ThisCell.size(2));
1855  if (Dimension >2) fprintf(output, FORMAT, ThisCell.center(3)-.5*ThisCell.size(3));
1856  fprintf(output, "%d", Nl);
1857  fprintf(output,"\n");
1858 
1859  fprintf(output, FORMAT, ThisCell.center(1)+.5*ThisCell.size(1));
1860  fprintf(output, FORMAT, ThisCell.center(2)+.5*ThisCell.size(2));
1861  if (Dimension >2) fprintf(output, FORMAT, ThisCell.center(3)-.5*ThisCell.size(3));
1862  fprintf(output, "%d", Nl);
1863  fprintf(output,"\n\n");
1864  }
1865 
1866  // z-direction
1867  if (Dimension > 2)
1868  {
1869  fprintf(output, FORMAT, ThisCell.center(1)-.5*ThisCell.size(1));
1870  fprintf(output, FORMAT, ThisCell.center(2)-.5*ThisCell.size(2));
1871  fprintf(output, FORMAT, ThisCell.center(3)+.5*ThisCell.size(3));
1872  fprintf(output, "%d", Nl);
1873  fprintf(output,"\n");
1874 
1875  fprintf(output, FORMAT, ThisCell.center(1)+.5*ThisCell.size(1));
1876  fprintf(output, FORMAT, ThisCell.center(2)-.5*ThisCell.size(2));
1877  fprintf(output, FORMAT, ThisCell.center(3)+.5*ThisCell.size(3));
1878  fprintf(output, "%d", Nl);
1879  fprintf(output,"\n\n");
1880 
1881  fprintf(output, FORMAT, ThisCell.center(1)-.5*ThisCell.size(1));
1882  fprintf(output, FORMAT, ThisCell.center(2)+.5*ThisCell.size(2));
1883  fprintf(output, FORMAT, ThisCell.center(3)+.5*ThisCell.size(3));
1884  fprintf(output, "%d", Nl);
1885  fprintf(output,"\n");
1886 
1887  fprintf(output, FORMAT, ThisCell.center(1)+.5*ThisCell.size(1));
1888  fprintf(output, FORMAT, ThisCell.center(2)+.5*ThisCell.size(2));
1889  fprintf(output, FORMAT, ThisCell.center(3)+.5*ThisCell.size(3));
1890  fprintf(output, "%d", Nl);
1891  fprintf(output,"\n\n\n");
1892  }
1893  fprintf(output,"\n");
1894  }
1895  fclose(output);
1896  }
1897  else
1898  {
1899  cout << "Node.cpp: In method `void Node::writeMesh()':\n";
1900  cout << "Node.cpp: cannot open file " << FileName << '\n';
1901  cout << "carmen: *** [Node.o] Execution error\n";
1902  cout << "carmen: abort execution.\n";
1903  exit(1);
1904  }
1905 }
real center(const int AxisNo) const
Returns the component no. AxisNo of the cell-center position.
Definition: Cell.h:1112
int ChildNb
Definition: Parameters.cpp:213
int Dimension
Definition: Parameters.cpp:74
void writeMesh(const char *FileName) const
Writes mesh data for Gnuplot into file FileName.
Definition: Node.cpp:1819
real size(const int AxisNo) const
Returns the cell size in the direction AxisNo.
Definition: Cell.h:1095
#define FORMAT
Definition: PreProcessor.h:32

Here is the caller graph for this function:

void Node::writeTree ( const char *  FileName) const

Writes tree structure into file FileName. Only for debugging.

Parameters
FileNameName of the file.
Returns
void
956 {
957  // --- Local variables ---
958 
959  int n, l; // Counter
960 
961  FILE *output; // Pointer to output file
962 
963  // --- Open file ---
964 
965  if ( (Nl == 0) ? (output = fopen(FileName,"w")) : (output = fopen(FileName,"a")) )
966  {
967  for (l = 1; l <= Nl; l++)
968  fprintf(output, "|" );
969 
970  fprintf(output, "+ ");
971  switch (Dimension)
972  {
973  case 1:
974  fprintf(output, "(%d, %d)", Nl, Ni );
975  break;
976 
977  case 2:
978  fprintf(output, "(%d, %d, %d)", Nl, Ni, Nj);
979  break;
980 
981  case 3:
982  fprintf(output, "(%d, %d, %d, %d)", Nl, Ni, Nj, Nk );
983  break;
984  };
985  switch(Flag)
986  {
987  case 0:
988  fprintf(output," -- node --");
989  break;
990 
991  case 1:
992  fprintf(output," -- leaf --");
993  break;
994 
995  case 2:
996  fprintf(output," -- leaf with virtual children --");
997  break;
998 
999  case 3:
1000  fprintf(output," -- virtual leaf --");
1001  break;
1002 
1003  };
1004  fprintf(output,"\n");
1005  fclose(output);
1006  if (hasChildren())
1007  {
1008  for (n = 0; n < ChildNb; n++)
1009  Child[n]->writeTree(FileName);
1010  }
1011  }
1012  else
1013  {
1014  cout << "Node.cpp: In method `void Node::writeText()':\n";
1015  cout << "Node.cpp: cannot open file " << FileName << '\n';
1016  cout << "carmen: *** [Node.o] Execution error\n";
1017  cout << "carmen: abort execution.\n";
1018  exit(1);
1019  }
1020 }
void writeTree(const char *FileName) const
Writes tree structure into file FileName. Only for debugging.
Definition: Node.cpp:955
int ChildNb
Definition: Parameters.cpp:213
int Dimension
Definition: Parameters.cpp:74

Here is the caller graph for this function:


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