Collection of general-purpose functions.
More...
Go to the source code of this file.
|
int | CheckNaN (double **u, int is, int ie, int id) |
|
int | IsLittleEndian (void) |
|
void | MakeState (State_1D *state) |
|
void | PlutoError (int condition, char *str) |
|
void | Show (double **a, int ip) |
|
void | ShowVector (double *v, int n) |
|
void | ShowMatrix (double **A, int n, double eps) |
|
void | SwapEndian (void *x, const int nbytes) |
|
void | Trace (double xx) |
|
void | Where (int i, Grid *grid) |
|
int | SetLogFile (char *output_dir, Cmd_Line *cmd) |
|
void | print (const char *fmt,...) |
|
void | print1 (const char *fmt,...) |
|
void | WriteAsciiFile (char *fname, double *q, int nvar) |
|
Collection of general-purpose functions.
This file contains some miscellaneous tools for
- Debugging / printing / error functions such as Trace(), Show(), Where(), PlutoError
- function for swapping/detecting endianity
- Author
- A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
- Date
- Sept 1, 2014
Definition in file tools.c.
int CheckNaN |
( |
double ** |
u, |
|
|
int |
is, |
|
|
int |
ie, |
|
|
int |
id |
|
) |
| |
Cheeck whether the array u
contains Not-a-Number (NaN)
Definition at line 19 of file tools.c.
28 for (ii = is; ii <= ie; ii++) {
29 for (nv = 0; nv <
NVAR; nv++) {
30 if (u[ii][nv] != u[ii][nv]) {
31 print (
" > NaN found (%d), |",
id);
#define QUIT_PLUTO(e_code)
int IsLittleEndian |
( |
void |
| ) |
|
Return 1 if the current architecture has little endian order
Definition at line 40 of file tools.c.
47 return *(
char*)&TestEndian;
Allocate memory areas for arrays inside the state structure.
Definition at line 51 of file tools.c.
100 state->
vL = state->
vp;
101 state->
vR = state->
vm + 1;
103 state->
uL = state->
up;
104 state->
uR = state->
um + 1;
106 #if (TIME_STEPPING == HANCOCK) || (TIME_STEPPING == CHARACTERISTIC_TRACING)
109 state->
vh = state->
v;
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
double * lmax
Define the maximum k-characteristic speed over the domain.
double ** vh
Primitive state at n+1/2 (only for one step method)
double ** flux
upwind flux computed with the Riemann solver
double ** visc_src
Viscosity source term.
double ** rhs
Conservative right hand side.
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
double ** res_flux
Resistive flux (current)
double ** vR
Primitive variables to the right of the interface, .
#define ARRAY_3D(nx, ny, nz, type)
double ** visc_flux
Viscosity flux.
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
double * SL
Leftmost velocity in the Riemann fan at i+1/2.
double ** lambda
Characteristic speed associated to Lp and Rp.
double ** tc_flux
Thermal conduction flux.
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
double ** uR
same as vR, in conservative vars
#define ARRAY_1D(nx, type)
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
double * bn
Face magentic field, bn = bx(i+1/2)
double ** um
same as vm, in conservative vars
double ** vL
Primitive variables to the left of the interface, .
double * a2
Sound speed squared.
double * press
Upwind pressure term computed with the Riemann solver.
double ** up
same as vp, in conservative vars
#define ARRAY_2D(nx, ny, type)
double *** Rp
Left and right primitive eigenvectors.
double ** uL
same as vL, in conservative vars
void PlutoError |
( |
int |
condition, |
|
|
char * |
str |
|
) |
| |
If condition is true, issue an error and quit the code.
Definition at line 115 of file tools.c.
121 char *str_err=
"! Error: ";
#define QUIT_PLUTO(e_code)
void print |
( |
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Define print function for the static grid version of PLUTO. The Chombo version is defined in Chombo/amrPLUTO.cpp
Definition at line 367 of file tools.c.
379 #if PRINT_TO_FILE == YES
381 vfprintf(fl, fmt, args);
void print1 |
( |
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Define print1 function
Definition at line 390 of file tools.c.
402 #if PRINT_TO_FILE == YES
405 vfprintf(fl,fmt, args);
409 if (
prank == 0) vprintf(fmt, args);
int SetLogFile |
( |
char * |
output_dir, |
|
|
Cmd_Line * |
cmd |
|
) |
| |
Set the name of the log file and open in write or append mode depending on whether restart is enabled or not.
- Parameters
-
[in] | output_dir | the name of the output directory |
[in] | cmd | pointer to cmd line option structure. |
Definition at line 321 of file tools.c.
331 #if PRINT_TO_FILE == YES
356 printf (
"! SetLogFile: pluto.log cannot be written.\n");
#define QUIT_PLUTO(e_code)
void Show |
( |
double ** |
a, |
|
|
int |
ip |
|
) |
| |
Print the component of the array a
at grid index ip
Definition at line 132 of file tools.c.
157 D_SELECT(
print (
" (%d)> ", ix); ,
158 print (
" (%d,%d)> ", ix, iy); ,
159 print (
" (%d,%d,%d)> ", ix, iy, iz); )
162 for (nv = 0; nv <
NVAR; nv++) {
163 print (
"%12.6e ",
a[ip][nv]);
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
int g_dir
Specifies the current sweep or direction of integration.
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
void ShowMatrix |
( |
double ** |
A, |
|
|
int |
n, |
|
|
double |
eps |
|
) |
| |
Make a nice printing of a 2D matrix A
[0..n-1][0..n-1] Entries with values below eps will display "0.0"
Definition at line 182 of file tools.c.
192 print (
"----------------------------------------------------------------\n");
193 for (k1 = 0; k1 <
n; k1++){
194 for (k2 = 0; k2 <
n; k2++){
195 print (
"%12.3e ", fabs(
A[k1][k2]) >
eps ?
A[k1][k2]:0.0);
199 print (
"----------------------------------------------------------------\n");
double * A
Right interface area, A[i] = .
void ShowVector |
( |
double * |
v, |
|
|
int |
n |
|
) |
| |
Print the component of the array a
at grid index ip
Definition at line 169 of file tools.c.
177 for (k = 0; k <
n; k++)
print (
"%12.6e ", v[k]);
void SwapEndian |
( |
void * |
x, |
|
|
const int |
nbytes |
|
) |
| |
Swap the byte order of x.
- Parameters
-
[in] | x | pointer to the variable being swapped |
[in] | nbytes | data type size |
- Returns
- This function has no return value.
Definition at line 203 of file tools.c.
213 static char Swapped[16];
218 for (k = nbytes; k--; ) Swapped[k] = *(c + nbytes - 1 - k);
219 for (k = nbytes; k--; ) c[k] = Swapped[k];
Print a number xx and the number of times it has been called.
Definition at line 223 of file tools.c.
231 printf (
"Trace ------> %f , %d\n", xx, ++ik);
void Where |
( |
int |
i, |
|
|
Grid * |
grid |
|
) |
| |
Print the location of a particular zone (i,j,k) in the computational domain.
- Note
- This function must be initialized before using it to store grid information. This is done by calling Where(i, grid) the very first time. Subsequent calls can be then done by simply using Where(i,NULL).
Definition at line 235 of file tools.c.
247 int ii=0, jj=0, kk=0;
249 static Grid *grid1, *grid2, *grid3;
284 print ("zone [x1(%d) = %f]",
287 print ("zone [x1(%d) = %f, x2(%d) = %f]",
291 print ("zone [x1(%d) = %f, x2(%d) = %f, x3(%d) = %f]",
int level
The current refinement level (chombo only).
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
int g_dir
Specifies the current sweep or direction of integration.
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
void WriteAsciiFile |
( |
char * |
fname, |
|
|
double * |
q, |
|
|
int |
nvar |
|
) |
| |
Write one row a multi-column ascii file
Definition at line 416 of file tools.c.
423 static char old_file[64] =
"\0";
431 if (strcmp (fname,old_file) == 0){
432 fp = fopen(fname,
"a");
434 fp = fopen(fname,
"w");
435 sprintf (old_file,
"%s",fname);
438 for (n = 0; n < nvar; n++) fprintf (fp,
"%12.6e ",
q[n]);