A variety of useful utility functions. More...
Go to the source code of this file.
Functions | |
char * | ath_strdup (const char *in) |
This is really strdup(), but strdup is not available in ANSI (-pendantic or -ansi will leave it undefined in gcc) much like allocate. | |
int | ath_gcd (int a, int b) |
Calculate the Greatest Common Divisor by Euler's method. | |
int | ath_big_endian (void) |
Return 1 if the machine is big endian (e.g. | |
void | ath_bswap (void *vdat, int len, int cnt) |
Swap bytes, code stolen from NEMO. | |
void | ath_error (char *fmt,...) |
Terminate execution and output error message Uses variable-length argument lists provided in <stdarg.h> | |
void | minmax1 (Real *data, int nx1, Real *dmino, Real *dmaxo) |
Return the min and max of a 1D array using registers Works on data of type float, not Real. | |
void | minmax2 (Real **data, int nx2, int nx1, Real *dmino, Real *dmaxo) |
Return the min and max of a 2D array using registers Works on data of type float, not Real. | |
void | minmax3 (Real ***data, int nx3, int nx2, int nx1, Real *dmino, Real *dmaxo) |
Return the min and max of a 3D array using registers Works on data of type float, not Real. | |
void | do_nothing_bc (GridS *pG) |
DOES ABSOLUTELY NOTHING! THUS, WHATEVER THE BOUNDARY ARE SET TO INITIALLY, THEY REMAIN FOR ALL TIME. | |
Real | compute_div_b (GridS *pG) |
COMPUTE THE DIVERGENCE OF THE MAGNETIC FIELD USING FACE-CENTERED FIELDS OVER THE ENTIRE ACTIVE GRID. | |
void | compute_l1_error (const char *problem, const MeshS *pM, const ConsS ***RootSoln, const int errortype) |
COMPUTE THE L1-ERRORS IN ALL VARIABLES AT THE CURRENT (USUALLY THE FINAL) TIMESTEP USING THE INITIAL SOLUTION. | |
int | sign_change (Real(*func)(const Real, const Real), const Real a0, const Real b0, const Real x, Real *a, Real *b) |
SEARCH FOR A SIGN CHANGE. | |
int | bisection (Real(*func)(const Real, const Real), const Real a0, const Real b0, const Real x, Real *root) |
THIS FUNCTION IMPLEMENTS THE BISECTION METHOD FOR ROOT FINDING. | |
Real | trapzd (Real(*func)(Real), const Real a, const Real b, const int n, const Real s) |
THIS ROUTINE COMPUTES THE nTH STAGE OF REFINEMENT OF AN EXTENDED TRAPEZOIDAL RULE. | |
Real | qsimp (Real(*func)(Real), const Real a, const Real b) |
RETURNS THE INTEGRAL OF THE FUNCTION func FROM a TO b. | |
Real | avg1d (Real(*func)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE ONE- DIMENSIONAL GRID CELL (i,j,k). | |
Real | avg2d (Real(*func)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE TWO- DIMENSIONAL GRID CELL (i,j,k). | |
Real | avg3d (Real(*func)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE THREE-DIMENSIONAL GRID CELL (i,j,k). | |
Real | avgXZ (Real(*func)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
Real | fz (Real z) |
Real | fy (Real y) |
Real | fx (Real x) |
Real | fXZ (Real z) |
Real | vecpot2b1i (Real(*A2)(Real, Real, Real), Real(*A3)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
Compute B-field components from a vector potential. | |
Real | vecpot2b2i (Real(*A1)(Real, Real, Real), Real(*A3)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
Compute B-field components from a vector potential. | |
Real | vecpot2b3i (Real(*A1)(Real, Real, Real), Real(*A2)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) |
Compute B-field components from a vector potential. | |
Real | f1 (Real x) |
Real | f2 (Real y) |
Real | f3 (Real z) |
void | ludcmp (Real **a, int n, int *indx, Real *d) |
LU decomposition from Numerical Recipes. | |
void | lubksb (Real **a, int n, int *indx, Real b[]) |
Backward substitution (from numerical recipies). | |
void | InverseMatrix (Real **a, int n, Real **b) |
Inverse matrix solver. | |
void | MatrixMult (Real **a, Real **b, int m, int n, int l, Real **c) |
Matrix multiplication: a(m*n) * b(n*l) = c(m*l). | |
Variables | |
static Real | xsav |
static Real | ysav |
static Real | zsav |
static Real | xmin |
static Real | xmax |
static Real | ymin |
static Real | ymax |
static Real | zmin |
static Real | zmax |
static Real(* | nrfunc )(Real, Real, Real) |
static Real(* | a1func )(Real, Real, Real) |
static Real(* | a2func )(Real, Real, Real) |
static Real(* | a3func )(Real, Real, Real) |
A variety of useful utility functions.
PURPOSE: A variety of useful utility functions.
CONTAINS PUBLIC FUNCTIONS:
Definition in file utils.c.
int ath_big_endian | ( | void | ) |
Return 1 if the machine is big endian (e.g.
Sun, PowerPC) return 0 if not (e.g. Intel)
Definition at line 64 of file utils.c.
References n.
Referenced by dump_vtk(), dump_vtksub(), output_vtk_2d(), and output_vtk_3d().
void ath_bswap | ( | void * | vdat, | |
int | len, | |||
int | cnt | |||
) |
Swap bytes, code stolen from NEMO.
Definition at line 77 of file utils.c.
Referenced by dump_vtk(), dump_vtksub(), output_vtk_2d(), and output_vtk_3d().
void ath_error | ( | char * | fmt, | |
... | ||||
) |
Terminate execution and output error message Uses variable-length argument lists provided in <stdarg.h>
Definition at line 118 of file utils.c.
References atherr_fp().
Referenced by add_par_line(), advect_particles(), allocate(), ath_2d_fft_create_plan(), ath_2d_fft_quick_plan(), ath_3d_fft_create_plan(), baton_start(), baton_stop(), bisection(), bvals_grav_init(), bvals_mhd_init(), calloc_1d_array(), calloc_2d_array(), calloc_3d_array(), change_rundir(), compute_l1_error(), conduction_init(), dump_binary(), dump_history_enroll(), dump_parhistory_enroll(), dump_particle_binary(), dump_restart(), dump_tab_cons(), dump_tab_prim(), dump_vtk(), dump_vtksub(), exchange_feedback(), exchange_feedback_init(), Fargo(), fluxes(), get_gasinfo(), get_myGridIndex(), getPC(), getShockVars(), grav_acc(), grav_pot(), init_grid(), init_mesh(), init_output(), init_particle(), initialize(), integrate_2d_vl(), integrate_3d_vl(), integrate_destruct(), integrate_diff_init(), integrate_init(), integrate_init_1d(), integrate_init_2d(), integrate_init_3d(), Integrate_Particles(), line_block_name(), lr_states_init(), ludcmp(), main(), multig_3d(), my_strdup(), out_ktab(), OutData1(), OutData2(), OutData3(), output_pdf(), output_pgm(), output_ppm(), output_tab_1d(), output_tab_2d(), output_tab_3d(), output_vtk(), output_vtk_2d(), output_vtk_3d(), OutputModeAmplitude(), par_cmdline(), par_dist_mpi(), par_exist(), par_getsl(), par_open(), parse_slice(), particle_realloc(), perturb(), problem(), Prolongate(), qsimp(), realloc_recvbuf(), realloc_sendbuf(), recv_ix1_feedback(), recv_ix2_feedback(), recv_ix3_feedback(), recv_ox1_feedback(), recv_ox2_feedback(), recv_ox3_feedback(), resistivity_init(), restart_grids(), RestrictCorrect(), selfg_fft_obc_3d(), selfg_init(), selfg_multig_1d(), selfg_multig_2d(), selfg_multig_3d(), selfg_multig_3d_init(), send_ix1_feedback(), send_ix2_feedback(), send_ix3_feedback(), send_ox1_feedback(), send_ox2_feedback(), send_ox3_feedback(), set_bvals_particle(), set_mg_bvals(), setFluxes(), shearingbox_ix1_particle(), shearingbox_ox1_particle(), SMR_init(), swap_mg_ix1(), swap_mg_ix2(), swap_mg_ix3(), swap_mg_ox1(), swap_mg_ox2(), swap_mg_ox3(), Userwork_after_loop(), Userwork_in_loop(), and viscosity_init().
int ath_gcd | ( | int | a, | |
int | b | |||
) |
char* ath_strdup | ( | const char * | in | ) |
This is really strdup(), but strdup is not available in ANSI (-pendantic or -ansi will leave it undefined in gcc) much like allocate.
Definition at line 35 of file utils.c.
References ath_perr().
Referenced by dump_history_enroll(), dump_parhistory_enroll(), main(), and my_strdup().
Real avg1d | ( | Real(*)(Real, Real, Real) | func, | |
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE ONE- DIMENSIONAL GRID CELL (i,j,k).
INTEGRATION IS PERFORMED USING qsimp. ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
Definition at line 688 of file utils.c.
References cc_pos(), GridS::dx1, fx(), nrfunc, and qsimp().
Referenced by problem().
Real avg2d | ( | Real(*)(Real, Real, Real) | func, | |
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE TWO- DIMENSIONAL GRID CELL (i,j,k).
INTEGRATION IS PERFORMED USING qsimp. ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
Definition at line 715 of file utils.c.
References cc_pos(), GridS::dx1, GridS::dx2, fy(), nrfunc, and qsimp().
Referenced by cyladvect_ix1(), cyladvect_ox1(), cylbr_ix1(), cylbr_ox1(), and problem().
Real avg3d | ( | Real(*)(Real, Real, Real) | func, | |
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE THREE-DIMENSIONAL GRID CELL (i,j,k).
INTEGRATION IS PERFORMED USING qsimp. ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
Definition at line 742 of file utils.c.
References cc_pos(), GridS::dx1, GridS::dx2, GridS::dx3, fz(), nrfunc, and qsimp().
Real avgXZ | ( | Real(*)(Real, Real, Real) | func, | |
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
Definition at line 761 of file utils.c.
References cc_pos(), GridS::dx1, GridS::dx3, fXZ(), nrfunc, and qsimp().
COMPUTE THE DIVERGENCE OF THE MAGNETIC FIELD USING FACE-CENTERED FIELDS OVER THE ENTIRE ACTIVE GRID.
RETURNS THE MAXIMUM OF |DIV B|.
Definition at line 218 of file utils.c.
References GridS::B1i, GridS::B2i, GridS::B3i, cc_pos(), GridS::dx1, GridS::dx2, GridS::dx3, GridS::ie, GridS::is, GridS::je, GridS::js, GridS::ke, and GridS::ks.
Referenced by problem(), and Userwork_in_loop().
void compute_l1_error | ( | const char * | problem, | |
const MeshS * | pM, | |||
const ConsS *** | RootSoln, | |||
const int | errortype | |||
) |
COMPUTE THE L1-ERRORS IN ALL VARIABLES AT THE CURRENT (USUALLY THE FINAL) TIMESTEP USING THE INITIAL SOLUTION.
THIS MEANS THAT THE SOLUTION MUST EITHER BE STATIC (STEADY-STATE) OR MUST HAVE COMPLETED A FULL PERIOD OF ROTATION, ETC. FOR THE ERRORTYPE FLAG, 0 MEANS ABSOLUTE ERROR, AND 1 MEANS AVERAGE ERROR PER GRID CELL.
Definition at line 269 of file utils.c.
References ath_error(), ath_fname(), ConsS::B1c, ConsS::B2c, ConsS::B3c, cc_pos(), DomainS::Comm_Domain, ConsS::d, MeshS::Domain, DomainS::DomNumber, GridS::dx1, GridS::dx2, GridS::dx3, ConsS::E, error, DomainS::Grid, GridS::ie, GridS::is, GridS::je, GridS::js, GridS::ke, GridS::ks, ConsS::M1, ConsS::M2, ConsS::M3, DomainS::MaxX, DomainS::MinX, n, DomainS::Nx, ConsS::s, and GridS::U.
Referenced by Userwork_after_loop().
void do_nothing_bc | ( | GridS * | pG | ) |
DOES ABSOLUTELY NOTHING! THUS, WHATEVER THE BOUNDARY ARE SET TO INITIALLY, THEY REMAIN FOR ALL TIME.
Definition at line 205 of file utils.c.
Referenced by problem(), and problem_read_restart().
Definition at line 986 of file utils.c.
References a1func.
Referenced by vecpot2b2i(), and vecpot2b3i().
Definition at line 991 of file utils.c.
References a2func.
Referenced by vecpot2b1i(), and vecpot2b3i().
Definition at line 996 of file utils.c.
References a3func.
Referenced by vecpot2b1i(), and vecpot2b2i().
Inverse matrix solver.
a: input matrix; n: matrix size, b: return matrix Note: the input matrix will be DESTROYED
Definition at line 1106 of file utils.c.
References calloc_1d_array(), lubksb(), and ludcmp().
Referenced by MultiNSH().
Backward substitution (from numerical recipies).
a is the input matrix done with LU decomposition, n is the matrix size indx id the history of row permutation b is the vector on the right (AX=b), and is returned with the solution
Definition at line 1077 of file utils.c.
Referenced by InverseMatrix().
LU decomposition from Numerical Recipes.
Using Crout's method with partial pivoting a is the input matrix, and is returned with LU decomposition readily made, n is the matrix size, indx records the history of row permutation, whereas d =1(-1) for even(odd) number of permutations.
Definition at line 1012 of file utils.c.
References ath_error(), and calloc_1d_array().
Referenced by InverseMatrix().
Matrix multiplication: a(m*n) * b(n*l) = c(m*l).
Definition at line 1129 of file utils.c.
Referenced by MultiNSH().
Return the min and max of a 1D array using registers Works on data of type float, not Real.
Definition at line 142 of file utils.c.
Referenced by out_ktab(), and output_tab_1d().
Return the min and max of a 2D array using registers Works on data of type float, not Real.
Definition at line 160 of file utils.c.
Referenced by output_pgm(), output_ppm(), output_tab_2d(), and output_vtk_2d().
Return the min and max of a 3D array using registers Works on data of type float, not Real.
Definition at line 181 of file utils.c.
Referenced by output_tab_3d(), and output_vtk_3d().
RETURNS THE INTEGRAL OF THE FUNCTION func FROM a TO b.
THE PARAMETER EPS CAN BE SET TO THE DESIRED FRACTIONAL ACCURACY AND JMAX SO THAT 2^(JMAX-1) IS THE MAXIMUM ALLOWED NUMBER OF STEPS. INTEGRATION IS PERFORMED BY SIMPSON'S RULE. ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
Definition at line 650 of file utils.c.
References ath_error(), s, and trapzd().
Referenced by avg1d(), avg2d(), avg3d(), avgXZ(), cylbr_ix1(), cylbr_ox1(), fXZ(), fy(), fz(), problem(), vecpot2b1i(), vecpot2b2i(), and vecpot2b3i().
int sign_change | ( | Real(*)(const Real, const Real) | func, | |
const Real | a0, | |||
const Real | b0, | |||
const Real | x, | |||
Real * | a, | |||
Real * | b | |||
) |
SEARCH FOR A SIGN CHANGE.
THIS FUNCTION PARTITIONS THE INTERVAL (a0,b0) INTO 2^k EQUALLY SPACED GRID POINTS, EVALUATES THE FUNCTION f AT THOSE POINTS, AND THEN SEARCHES FOR A SIGN CHANGE IN f BETWEEN ADJACENT GRID POINTS. THE FIRST SUCH INTERVAL FOUND, (a,b), IS RETURNED.
Definition at line 511 of file utils.c.
References n.
Referenced by problem().
THIS ROUTINE COMPUTES THE nTH STAGE OF REFINEMENT OF AN EXTENDED TRAPEZOIDAL RULE.
func IS INPUT AS A POINTER TO THE FUNCTION TO BE INTEGRATED BETWEEN LIMITS a AND b, ALSO INPUT. WHEN CALLED WITH n=1, THE ROUTINE RETURNS THE CRUDEST ESTIMATE OF ^b f(R) R dR. SUBSEQUENT CALLS WITH n=2,3,... (IN THAT SEQUENTIAL ORDER) WILL IMPROVE THE ACCURACY BY ADDING 2n-2 ADDITIONAL INTERIOR POINTS. ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER
Definition at line 617 of file utils.c.
Referenced by qsimp().
Real vecpot2b1i | ( | Real(*)(Real, Real, Real) | A2, | |
Real(*)(Real, Real, Real) | A3, | |||
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
Compute B-field components from a vector potential.
THESE FUNCTIONS COMPUTE MAGNETIC FIELD COMPONENTS FROM COMPONENTS OF A SPECIFIED VECTOR POTENTIAL USING STOKES' THEOREM AND SIMPSON'S QUADRATURE. NOTE: THIS IS ONLY GUARANTEED TO WORK IF THE POTENTIAL IS OF CLASS C^1. WRITTEN BY AARON SKINNER.
Definition at line 831 of file utils.c.
References A2(), a2func, A3(), a3func, cc_pos(), GridS::dx1, GridS::dx2, GridS::dx3, f2(), f3(), and qsimp().
Referenced by problem().
Real vecpot2b2i | ( | Real(*)(Real, Real, Real) | A1, | |
Real(*)(Real, Real, Real) | A3, | |||
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
Compute B-field components from a vector potential.
THESE FUNCTIONS COMPUTE MAGNETIC FIELD COMPONENTS FROM COMPONENTS OF A SPECIFIED VECTOR POTENTIAL USING STOKES' THEOREM AND SIMPSON'S QUADRATURE. NOTE: THIS IS ONLY GUARANTEED TO WORK IF THE POTENTIAL IS OF CLASS C^1. WRITTEN BY AARON SKINNER.
Definition at line 887 of file utils.c.
References A1(), a1func, A3(), a3func, cc_pos(), GridS::dx1, GridS::dx2, GridS::dx3, f1(), f3(), and qsimp().
Referenced by problem().
Real vecpot2b3i | ( | Real(*)(Real, Real, Real) | A1, | |
Real(*)(Real, Real, Real) | A2, | |||
const GridS * | pG, | |||
const int | i, | |||
const int | j, | |||
const int | k | |||
) |
Compute B-field components from a vector potential.
THESE FUNCTIONS COMPUTE MAGNETIC FIELD COMPONENTS FROM COMPONENTS OF A SPECIFIED VECTOR POTENTIAL USING STOKES' THEOREM AND SIMPSON'S QUADRATURE. NOTE: THIS IS ONLY GUARANTEED TO WORK IF THE POTENTIAL IS OF CLASS C^1. WRITTEN BY AARON SKINNER.
Definition at line 939 of file utils.c.
References A1(), a1func, A2(), a2func, cc_pos(), GridS::dx1, GridS::dx2, GridS::dx3, f1(), f2(), and qsimp().
Definition at line 818 of file utils.c.
Referenced by f1(), vecpot2b2i(), and vecpot2b3i().
Definition at line 819 of file utils.c.
Referenced by f2(), vecpot2b1i(), and vecpot2b3i().
Definition at line 820 of file utils.c.
Referenced by f3(), vecpot2b1i(), and vecpot2b2i().
Definition at line 677 of file utils.c.
Referenced by Fargo(), pbc_ix1(), pbc_ox1(), problem(), RemapEy_ix1(), RemapEy_ox1(), ShearingSheet_ix1(), and ShearingSheet_ox1().
Definition at line 677 of file utils.c.
Referenced by Fargo(), pbc_ix1(), pbc_ox1(), problem(), RemapEy_ix1(), RemapEy_ox1(), ShearingSheet_ix1(), and ShearingSheet_ox1().