Streamer fluid modeling - An overview of ARCoS
1.0
|
Function prototypes for exported functions. More...
#include "rz_array.h"
#include "grid.h"
#include "interpol2.h"
#include "mapper.h"
#include "cdr.h"
#include "poisson.h"
#include "photo.h"
#include "reaction.h"
Go to the source code of this file.
Functions | |
rz_array_t * | rz_new_3d_a (int r0, int z0, int r1, int z1, int ntheta) |
Creates a new 3D array structure. | |
rz_array_t * | rz_guest (rz_array_t *host, int r0, int z0, int r1, int z1) |
Creates guest array: This is an array that contains part of another one. | |
void | rz_set_zero (rz_array_t *array) |
Sets the data of an array to zero. | |
void | rz_set_periodic (rz_array_t *array) |
Sets periodic boundary conditions for theta in an array. | |
void | rz_copy_bnd (rz_array_t *from, rz_array_t *to, int sign, REAL *start_from, REAL *start_to, int dim0, int inout_from, int inout_to, int dim1, int dim1_0, int dim1_1, int dim2, int dim2_0, int dim2_1) |
Sets boundaries for one array reading data from other array (but both can be the same: see rz_set_bnd). | |
void | rz_set_bnd (rz_array_t *array, int sign, REAL *start, int dim0, int inout, int dim1, int dim1_from, int dim1_to, int dim2, int dim2_from, int dim2_to) |
Sets boundary conditions (Neumann/Dirichlet) reading from the array itself. | |
void | rz_free (rz_array_t *array) |
Frees an array. | |
void | rz_copy (rz_array_t *fro, int rfro, int zfro, rz_array_t *to, int rto, int zto, int rn, int zn) |
Copies a sub-array of rn x zn from fro (starting at (rfro, zfro)) to to (starting at (rto, zto)). | |
void | rz_copy_modes (rz_array_t *fro, int rfro, int zfro, rz_array_t *to, int rto, int zto, int rn, int zn, int nmode_fro, int nmode_to) |
Copies a sub-array of the mode nmode of rn x zn from fro (starting at (rfro, zfro)) to to (starting at (rto, zto)). | |
void | rz_dump (rz_array_t *rz_array, const char *fname, const char *mode, int r0, int z0, int r1, int z1) |
Reads or writes a rz_array, depending on the string mode, "r" for reading, "w" for writing. | |
void | rz_dump_3d (rz_array_t *rz_array, const char *fname, const char *mode, int r0, int z0, int r1, int z1, int ntheta) |
rz_dump_3d QQQQ | |
void | rz_axis_dump (const char *fname, int x0, int x1, double delta) |
rz_axis_dump QQQQ | |
int | grid_max_depth_r (grid_t *grid) |
Gets the maximum depth of a tree (the level of its deepest node) | |
double | grid_rmin_r (grid_t *grid) |
Gets the minimum r of a grid and all its descendants. | |
void | grid_print_r (grid_t *grid, int indent) |
Recursively prints one grid and all its descendants. | |
int | grid_contains (grid_t *grid, int i, int j, int check) |
Checks whether a point is in the interior or on a given boundary of a grid. | |
int | grid_overlap (grid_t *grid1, grid_t *grid2, int buff1, int buff2, int *left, int *bottom, int *right, int *top, int *level_diff) |
Checks whether two grids overlap and return the rectangle that they in common. | |
int | grid_overlap_with_shifts (grid_t *grid1, grid_t *grid2, int buff1, int buff2, int *left, int *bottom, int *right, int *top, int *level_diff, int shift_r, int shift_z) |
Checks the overlap between two grids. | |
void | grid_inherit_ext_bound (grid_t *grid) |
Makes a grid inherit the ext_bound field of its parent,. | |
grid_t * | grid_finest_containing_r (grid_t *grid, double r, double z) |
Finds the finest descendant of grid that contains the point given by the (r, z) coordinates. | |
int | grid_howmany_children (grid_t *grid) |
How many children does one grid have? | |
grid_t * | grid_get_child (grid_t *grid, int n) |
Finds child number n of the given grid. | |
interpol_t * | interpol_new_a (double Lr, double Lz, interpol_method_t *method) |
Creates a new interpolator that uses a given method. | |
void | interpol_free (interpol_t *this) |
Frees the interpolator. | |
void | interpol_set_stencil (interpol_t *this, double r0, double z0,...) |
Sets the stencil of the interpolation object. | |
void | interpol_set_stencil_at (grid_t *grid, interpol_t *this, double r0, double z0, rz_array_t *ar, int ir, int iz, int itheta) |
Sets the stencil reading from an array. | |
void | interpol_set_coeffs (interpol_t *this) |
Calculates the coefficients of the interpolating polynomial. | |
double | interpol_apply (interpol_t *this, double r, double z) |
Evaluates the interpolating polynomial. | |
void | map_grid (mapper_t **mappers, grid_t *source, grid_t *target, int ntheta, int copy, int interpol, int coarsen, int s_buff, int t_buff) |
Maps two grids. | |
void | map_grid_r (mapper_t **mappers, grid_t *source, grid_t *target, int ntheta, int copy, int interpol, int coarsen, int s_buff, int t_buff) |
Recursive version of map_grid. | |
void | map_trees_r (mapper_t **mappers, grid_t *source, grid_t *target, int ntheta, int copy, int interpol, int coarsen, int s_buff, int t_buff) |
Double-recursive version: | |
void | cdr_init (void) |
Some initialization is needed for this module which has to be inside this function. | |
void | cdr_end (void) |
And the cleaning up has to be here. | |
cdr_grid_t * | cdr_new_3d_a (int r0, int z0, int r1, int z1, int ntheta) |
Creates a new 3D cdr grid. | |
cdr_grid_t * | cdr_like_a (cdr_grid_t *grid) |
Returns a grid with the same dimensions as grid and at the same level. | |
cdr_grid_t * | cdr_clone_a (cdr_grid_t *grid) |
Returns a grid exactly like te one received, with the densities copied. | |
void | cdr_set_periodic (cdr_grid_t *grid) |
Impose periodic boundary conditions in ![]() | |
void | cdr_free (cdr_grid_t *grid) |
void | cdr_free_r (cdr_grid_t *grid) |
Recursive version of cdr_free. | |
void | cdr_calc_charge (cdr_grid_t *grid) |
Calculates the charge in a CDR grid. | |
void | cdr_calc_charge_r (cdr_grid_t *root) |
void | cdr_dft_charge_r (cdr_grid_t *grid, int sign) |
cdr_grid_t * | cdr_create_coarser_a (cdr_grid_t *grid) |
Creates a grid one level coarser than GRID that covers the same area or somewhat more. | |
cdr_grid_t * | cdr_add_coarser_grids_a (cdr_grid_t *prev_root, int n) |
Takes a tree of input nodes and adds n coarser grids, returning a pointer to the root leaf. | |
void | cdr_free_coarser_grids (cdr_grid_t *prev_root, int n) |
Frees the memory allocated by cdr_add_coarser_grids_a. | |
void | cdr_add_ext_field (cdr_grid_t *grid) |
Adds an external electric field to a cdr grid. | |
void | cdr_add_ext_field_r (cdr_grid_t *grid) |
void | cdr_add_inhom_field_r (cdr_grid_t *cdr, double q) |
void | cdr_calc_eabs (cdr_grid_t *grid) |
Calculates the absolute value of the electric field by linear interpolation of its components. | |
void | cdr_calc_eabs_r (cdr_grid_t *grid) |
void | cdr_nonegative (cdr_grid_t *grid) |
void | cdr_nonegative_r (cdr_grid_t *grid) |
pois_grid_t ** | cdr_calc_field_r (cdr_grid_t *grid, int return_pois) |
The interface between the cdr and the poisson parts. | |
void | cdr_set_ext_bnd (cdr_grid_t *grid) |
void | cdr_set_ext_bnd_r (cdr_grid_t *grid) |
void | cdr_calc_d_dens (cdr_grid_t *grid) |
Calculates the derivatives of the densities for each point of the grid. | |
void | cdr_calc_d_dens_r (cdr_grid_t *grid) |
void | cdr_advect_diffu (cdr_grid_t *grid) |
Adds the advection and diffusion terms to the derivatives of the densities. | |
void | cdr_advect_diffu_r (cdr_grid_t *grid) |
double | cdr_courant (cdr_grid_t *grid) |
Returns the minimum tau that satisfies the Courant-Friedrichs-Lewy restriction (CFL). | |
void | cdr_update (cdr_grid_t *orig, cdr_grid_t *dest, double h) |
Writes into the densities of the grid dest the densities of grid orig plus its derivatives times h. | |
void | cdr_rk2_update (cdr_grid_t *dens_0, cdr_grid_t *d_dens_1, cdr_grid_t *d_dens_2, cdr_grid_t *dest, double h) |
Sets dest->dens = dens_0->dens + h/2 * d_dens_1->d_dens + h/2 * d_dens_2->d_dens. | |
void | cdr_rk2_update_r (cdr_grid_t *dens_0, cdr_grid_t *d_dens_1, cdr_grid_t *d_dens_2, cdr_grid_t *dest, double h) |
Recursive version of cdr_rk2_update. | |
void | cdr_self_update_r (cdr_grid_t *grid, double h) |
Recursive version of the former QQQQ, used to implement Euler integration. | |
void | cdr_like_update_ar (cdr_grid_t *grid, cdr_grid_t *new_grid, double h) |
Yet another recursive version of cdr_update, used to implement higher order Runge-Kutta integrations. | |
double | cdr_rk2 (cdr_grid_t *grid, double h, double t) |
Computes the grid error. QQQQ. | |
void | cdr_update_refined (cdr_grid_t **ptree) |
Takes a pointer to a family of cdr grids, creates a new family which is stored in that pointer and takes rid of the initial family. | |
void | cdr_calc_maxs (cdr_grid_t *grid) |
Updates the values of max_dens and max_charge. | |
void | cdr_refine (cdr_grid_t *grid) |
Uses the previous routines to refine (if needed) a cdr grid. | |
void | cdr_refine_r (cdr_grid_t *grid, cdr_grid_t *source) |
Recursively refines a cdr grid and constructs a tree based on it. | |
void | cdr_match_r (cdr_grid_t *grid1, cdr_grid_t *grid2) |
Examines pairs of grids and matches them and all their descendants. | |
void | cdr_set_bnd (cdr_grid_t *grid) |
Sets the boundary conditions of all children of grid by interpolating from grid itself. | |
void | cdr_set_bnd_r (cdr_grid_t *grid) |
void | cdr_restrict (cdr_grid_t *grid) |
Restricts a grid with all its children. | |
void | cdr_restrict_r (cdr_grid_t *grid) |
void | cdr_set_dens (cdr_grid_t *cdr, int species, int mode, double factor, double(*f)(double, double, double)) |
Sets the densities of species species according to the function ![]() | |
void | cdr_init_dens (cdr_grid_t *cdr) |
Inits the densities of all species. | |
cdr_grid_t * | cdr_scratch_init (void) |
Initializes the densities allocating a new grid family. | |
mapper_t ** | cdr_mappers_a (interpol_method_t *interp_method) |
void | cdr_free_mappers (mapper_t **mappers) |
Frees the memory of all mappers QQQQ. | |
void | cdr_dump (cdr_grid_t *grid, const char *prefix, const char *name) |
Dumps all the contents of the given grid into filenames given by prefix and name. | |
void | cdr_dump_r (cdr_grid_t *grid, const char *prefix, const char *name, FILE *infp, double sim_time) |
Dumps all the contents of the given grid into filenames given by prefix and name. | |
cdr_grid_t * | cdr_load_tree_r (const char *prefix, const char *name, FILE *infp) |
Reads the data format produced by cdr_dump_r and creates a complete tree from it. | |
void | cdr_dump_frames (cdr_grid_t *grid, const char *prefix, const char *name) |
Given a grid family, writes in the file named fname the coordinates of the frames that define the grid and his descendants. | |
void | pois_init (void) |
All initialization of the Poisson solver has to be here. | |
pois_grid_t * | pois_new_a (int r0, int z0, int r1, int z1) |
Creates a 2D Poisson grid. | |
pois_grid_t * | pois_new_3d_a (int r0, int z0, int r1, int z1, int ntheta) |
Creates a new 3D Poisson grid. | |
void | pois_free (pois_grid_t *grid) |
Frees the memory allocated by pois_new_a. | |
void | pois_free_r (pois_grid_t *grid) |
Recursively frees a tree of Poisson grids. | |
pois_grid_t * | pois_new_glob_a (int r0, int z0, int r1, int z1, int level) |
Creates a new Poisson grid. | |
pois_grid_t * | pois_init_tree_a (int r0, int z0, int r1, int z1) |
Starts the tree of Poisson grids with the two coarsest ones. | |
REAL * | pois_boundary_a (pois_grid_t *grid, int boundary) |
Is it possible to use a single function to handle all four boundaries? | |
void | pois_solve_grid (pois_grid_t *grid, pois_problem_t *prob, double lambda, double s) |
Solves the Poisson equation, calling the FISHPACK routine. | |
void | pois_set_phi_boundaries (pois_grid_t *grid, REAL *boundaries[], int left_uns, int right_neu, int bottom_neu, int top_neu) |
Uses the boundaries[] vectors to set the boundaries by interpolation for the phi array of a grid. | |
int | pois_map_charge (pois_grid_t *pois, cdr_grid_t *cdr, int mode) |
void | pois_set_error (pois_grid_t *grid) |
Estimates the error on this grid by comparing with the calculations for his parent and performing a Richardson extrapolation. | |
int | pois_refine (pois_grid_t *grid, double threshold) |
The refinement routine. | |
pois_grid_t ** | pois_solve_a (cdr_grid_t *cdr, pois_problem_t *prob) |
Takes a cdr tree and solves the Poisson equation for it. | |
pois_grid_t ** | pois_gen_solve_a (cdr_grid_t *cdr, pois_problem_t *prob, mapper_t **mappers, double es) |
Solves a Poisson/Helmholtz equation with FISHPACK and maps the result using a given set of mapper. | |
pois_grid_t * | pois_solve_mode (cdr_grid_t *tree, cdr_grid_t *cdr, pois_problem_t *prob, int mode, double es) |
Solves a single Fourier mode. | |
void | pois_solve_r (pois_grid_t *pois, cdr_grid_t *cdr, pois_problem_t *prob, int mode, double es, double threshold) |
Recursively solves one Poisson grid. | |
double | pois_phi_at (pois_grid_t *grid, double r, double z, double theta) |
Finds the best-possible approximation for the potential at a given point (r, z, theta) by interpolating from the finest grid that covers that point. | |
void | pois_dump (pois_grid_t *grid, const char *prefix, const char *name) |
Dumps all the contents of the given grid into filenames given by prefix and name. | |
void | pois_dump_r (pois_grid_t *grid, const char *prefix, const char *name) |
Dumps all the contents of the given grid into filenames given by prefix and name. | |
void | pois_write_error_r (pois_grid_t *grid, FILE *fp) |
Writes some error measures of this grid and its descendants into fp. | |
void | pois_error_measures (pois_grid_t *grid, double *L1, double *L2, double *Lmax) |
Calculates the error measure of this grid. | |
void | pois_inhom_init (void) |
pois_inhom_init QQQQ | |
double | pois_inhom_phi (double r, double z) |
Returns the potential created by a unit charge located at pois_inhom_z between an electrode at 0 and a second one at pois_inhom_L. | |
double | pois_inhom_er (double r, double z) |
Radial component of the field. | |
double | pois_inhom_ez (double r, double z) |
Axial component of the field. | |
double | pois_inhom_q_factor (pois_grid_t *pois) |
Once we have the electrostatic potential created by the space charges, we use this function to compute the multiplying factor of the floating charge. | |
void | pois_add_inhom_phi_r (pois_grid_t *grid, double q) |
Adds the potential created by the needle to a Poisson grid and their descendants. | |
void | photo_init () |
Initializes photoionization QQQQ? | |
void | photo_register (double A, double lambda) |
Registers a photoionization term with given A and lambda. | |
void | photo_copy_list (photo_term_t *src, photo_term_t **dest) |
Copies a list of photo terms into *dest. | |
void | photo_unregister_all (void) |
Unregisters all the photoionization terms and frees the allocated space. | |
void | photo_dft_r (cdr_grid_t *grid, int sign) |
Transforms back the photoionization calculation into real space. | |
void | photo_copy_source (cdr_grid_t *grid) |
Copies the derivative of the ion density into cdr->charge. | |
void | photo_add_term (photo_term_t *term, cdr_grid_t *cdr) |
void | photo_add_term_r (photo_term_t *term, cdr_grid_t *cdr) |
...and the recursive version of photo_add_term | |
pois_grid_t ** | photo_calc_term (photo_term_t *term, cdr_grid_t *cdr, int i) |
photo_calc_term QQQQ | |
void | photo_calc (photo_term_t *terms, cdr_grid_t *cdr) |
Calculates the photoionization and adds it to the derivatives of the species densities. | |
void | photo_load_file (char *fname) |
Loads a photoionization file, consisting in a series of rows with A and lambda. | |
void | init_parameters (void) |
Initializes the parameters. | |
void | cstream_init (void) |
Here all the initialization calls. | |
void | cstream_end (void) |
Here all the cleaning and finishing calls. | |
void | cstream_set_field_at_time (double t) |
When we use a time-varying external field, we update the field components at each timesteps. | |
void | dft_transform (rz_array_t *in, rz_array_t *out, int sign) |
Transform the discrete fourier transformations ???? | |
void | dft_diff (grid_t *grid, rz_array_t *f) |
Calculates the Fourier transform of the derivative of a function given its Fourier transform. | |
void | dft_weight (cdr_grid_t *cdr, rz_array_t *var, double weights[], double power) |
Calculates the weight for a given cdr grid and a variable ??? | |
void | dft_out_weights (cdr_grid_t *grid, const char *prefix, double t) |
Outputs to a file 'weights.tsv' the results of dft_weight. | |
void | dft_perturb (cdr_grid_t *cdr, rz_array_t *var, double *epsilon_k) |
Perturbs a FFT-transformed variable. | |
void | dft_dens_perturb_r (cdr_grid_t *grid, int species, double *epsilon_k) |
Takes a density in real space, transforms it to Fourier space, perturbs it and then transforms back to real space. | |
int | find_species_by_name (const char *spec_name) |
Returns the position in the species-array of a given species. | |
void | react_add (reaction_t *react) |
Adds a given reaction to the reaction list. | |
void | react_init () |
Initializes the list of reactions. | |
void | react_apply_r (reaction_t *react, cdr_grid_t *grid, int overwrite) |
Recursive version of react_apply. | |
void | react_apply_all (cdr_grid_t *grid) |
Applies all reactions to the given grid and his descendants. | |
void | kinetic_init (void) |
Any initialization required by the kinetic model, has to be done in this function. | |
double | spr_density_at (double altitude) |
The density at a given height, assuming dens = 1.0 at height = 0.0. | |
void | spr_init () |
Initialize the sprite module. | |
void | spr_hook (cdr_grid_t *grid) |
Hook to update the variables that depend on the head altitude. | |
void | spr_update (double altitude) |
Updates the magnitudes that we are tracking according to a given altitude. | |
double | spr_head_altitude (cdr_grid_t *grid, int sign) |
Finds the position of the streamer head by locating the maximum (or -maximum) of the charge along the streamer axis. | |
void | read_input_file (const char *f_kinetic_name, const char *filename) |
Reads the kinetic parameters (species, reactions) from file filename. | |
Function prototypes for exported functions.
Definition in file proto.h.
rz_array_t* rz_new_3d_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1, | ||
int | ntheta | ||
) |
Creates a new 3D array structure.
Definition at line 23 of file rz_array.c.
rz_array_t* rz_guest | ( | rz_array_t * | host, |
int | r0, | ||
int | z0, | ||
int | r1, | ||
int | z1 | ||
) |
Creates guest array: This is an array that contains part of another one.
We use the memory of the original array and do not allocate new memory.
Definition at line 105 of file rz_array.c.
void rz_set_zero | ( | rz_array_t * | array | ) |
Sets the data of an array to zero.
Definition at line 145 of file rz_array.c.
void rz_set_periodic | ( | rz_array_t * | array | ) |
Sets periodic boundary conditions for theta in an array.
Definition at line 153 of file rz_array.c.
void rz_copy_bnd | ( | rz_array_t * | from, |
rz_array_t * | to, | ||
int | sign, | ||
REAL * | start_from, | ||
REAL * | start_to, | ||
int | dim0, | ||
int | inout_from, | ||
int | inout_to, | ||
int | dim1, | ||
int | dim1_0, | ||
int | dim1_1, | ||
int | dim2, | ||
int | dim2_0, | ||
int | dim2_1 | ||
) |
Sets boundaries for one array reading data from other array (but both can be the same: see rz_set_bnd).
Starting at *start_xxx, it sweeps a 2-dimensional subspace of the grid in dimensions dim1 and dim2 (and perpendicular to dim0). There it sets the boudary conditions.
The value of from is multiplied by sign. Thus, if the boundary is itself, is -1 for homogeneous dirichlet and 1 for homogeneous Neumann (though you should better use BND_CND_HNEUMANN and BND_CND_HDIRICHLET)
inout is -1 if we look/set the values on smaller values of dim0 1 if we look at larger values. (though it is better to use BND_INWARD=-1 and BND_OUTWARD=1).
Note: it is better to call this function before rz_set_periodic.
Definition at line 196 of file rz_array.c.
void rz_set_bnd | ( | rz_array_t * | array, |
int | sign, | ||
REAL * | astart, | ||
int | dim0, | ||
int | inout, | ||
int | dim1, | ||
int | dim1_0, | ||
int | dim1_1, | ||
int | dim2, | ||
int | dim2_0, | ||
int | dim2_1 | ||
) |
Sets boundary conditions (Neumann/Dirichlet) reading from the array itself.
For example, to set Neumann conditions at r = 0 (dim0 = R_INDX), we call it as
rz_set_bnd (array, 1, RZTP (array, 0, 0, 0), R_INDX, 1, Z_INDX, z0, z1, THETA_INDX, 0, ntheta);
Definition at line 229 of file rz_array.c.
void rz_free | ( | rz_array_t * | array | ) |
Frees an array.
Definition at line 240 of file rz_array.c.
void rz_copy | ( | rz_array_t * | fro, |
int | rfro, | ||
int | zfro, | ||
rz_array_t * | to, | ||
int | rto, | ||
int | zto, | ||
int | rn, | ||
int | zn | ||
) |
Copies a sub-array of rn x zn from fro (starting at (rfro, zfro)) to to (starting at (rto, zto)).
Definition at line 252 of file rz_array.c.
void rz_copy_modes | ( | rz_array_t * | fro, |
int | rfro, | ||
int | zfro, | ||
rz_array_t * | to, | ||
int | rto, | ||
int | zto, | ||
int | rn, | ||
int | zn, | ||
int | nmode_fro, | ||
int | nmode_to | ||
) |
Copies a sub-array of the mode nmode of rn x zn from fro (starting at (rfro, zfro)) to to (starting at (rto, zto)).
Definition at line 277 of file rz_array.c.
void rz_dump | ( | rz_array_t * | rz_array, |
const char * | fname, | ||
const char * | mode, | ||
int | r0, | ||
int | z0, | ||
int | r1, | ||
int | z1 | ||
) |
Reads or writes a rz_array, depending on the string mode, "r" for reading, "w" for writing.
Note however that we must already have the dimensions of the array in it.
Definition at line 305 of file rz_array.c.
void rz_dump_3d | ( | rz_array_t * | rz_array, |
const char * | fname, | ||
const char * | mode, | ||
int | r0, | ||
int | z0, | ||
int | r1, | ||
int | z1, | ||
int | ntheta | ||
) |
rz_dump_3d QQQQ
Definition at line 354 of file rz_array.c.
void rz_axis_dump | ( | const char * | fname, |
int | x0, | ||
int | x1, | ||
double | delta | ||
) |
rz_axis_dump QQQQ
Definition at line 411 of file rz_array.c.
int grid_max_depth_r | ( | grid_t * | grid | ) |
double grid_rmin_r | ( | grid_t * | grid | ) |
void grid_print_r | ( | grid_t * | grid, |
int | indent | ||
) |
int grid_contains | ( | grid_t * | grid, |
int | i, | ||
int | j, | ||
int | check | ||
) |
Checks whether a point is in the interior or on a given boundary of a grid.
Does the grid contain the point (i, j) (in its own coordinates)?
check has the following meaning:
GRID_INSIDE : Checks if the point is in the interior of the grid
BND_MASK_* : Checks if it is on the given boundary (BND_MASK_ALL checks for any boundary).
Definition at line 73 of file grid.c.
int grid_overlap | ( | grid_t * | grid1, |
grid_t * | grid2, | ||
int | buff1, | ||
int | buff2, | ||
int * | left, | ||
int * | bottom, | ||
int * | right, | ||
int * | top, | ||
int * | level_diff | ||
) |
Checks whether two grids overlap and return the rectangle that they in common.
Checks whether two grids overlap and return the rectangle that they have in common in the coordinates of the finest grid in (*left, *bottom) - (*right, *top)
Note that *left, *bottom... can be modified even if the two grids do not overlap. buff1 and buff2 are integers that specify the numbers of cells that are taken as buffer in the boundaries for grid1 and grid2.
Definition at line 124 of file grid.c.
int grid_overlap_with_shifts | ( | grid_t * | grid1, |
grid_t * | grid2, | ||
int | buff1, | ||
int | buff2, | ||
int * | left, | ||
int * | bottom, | ||
int * | right, | ||
int * | top, | ||
int * | level_diff, | ||
int | shift_r, | ||
int | shift_z | ||
) |
Checks the overlap between two grids.
Checks the overlap between two grids before it shifts the coarser grid by (shift_r << (level_diff - 1), shift_z << (level_diff - 1) (in finer grid coordinates).
Q: WTF! WHY!!!?
A: We use this to implement the mapping between electric fields. Since The electric field is evaluated not in the cell centers but in the borders, when we interpolate we have to take a shift into account. See mapper.c and mapper.h for more info.
Definition at line 145 of file grid.c.
void grid_inherit_ext_bound | ( | grid_t * | grid | ) |
Finds the finest descendant of grid that contains the point given by the (r, z) coordinates.
Or NULL if the point is not contained in grid. We assume that only ONE sub-grid can contain a given point.
Definition at line 245 of file grid.c.
int grid_howmany_children | ( | grid_t * | grid | ) |
interpol_t* interpol_new_a | ( | double | Lr, |
double | Lz, | ||
interpol_method_t * | method | ||
) |
Creates a new interpolator that uses a given method.
Definition at line 49 of file interpol2.c.
void interpol_free | ( | interpol_t * | this | ) |
Frees the interpolator.
Definition at line 70 of file interpol2.c.
void interpol_set_stencil | ( | interpol_t * | this, |
double | r0, | ||
double | z0, | ||
... | |||
) |
Sets the stencil of the interpolation object.
r0 and z0 are the coordinates of the bottom-left corner of the stencil (the [0,0] point).
Definition at line 83 of file interpol2.c.
void interpol_set_stencil_at | ( | grid_t * | grid, |
interpol_t * | this, | ||
double | r0, | ||
double | z0, | ||
rz_array_t * | ar, | ||
int | ir, | ||
int | iz, | ||
int | itheta | ||
) |
Sets the stencil reading from an array.
ir, iz give the index of the cell in the array corresponding to the stencil origin.
Definition at line 116 of file interpol2.c.
void interpol_set_coeffs | ( | interpol_t * | this | ) |
Calculates the coefficients of the interpolating polynomial.
Has to be called after interpol_set_stencil.
Definition at line 161 of file interpol2.c.
double interpol_apply | ( | interpol_t * | this, |
double | r, | ||
double | z | ||
) |
Evaluates the interpolating polynomial.
Definition at line 190 of file interpol2.c.
void cdr_init | ( | void | ) |
void cdr_end | ( | void | ) |
cdr_grid_t* cdr_new_3d_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1, | ||
int | ntheta | ||
) |
cdr_grid_t* cdr_like_a | ( | cdr_grid_t * | grid | ) |
cdr_grid_t* cdr_clone_a | ( | cdr_grid_t * | grid | ) |
void cdr_set_periodic | ( | cdr_grid_t * | grid | ) |
void cdr_free | ( | cdr_grid_t * | grid | ) |
void cdr_free_r | ( | cdr_grid_t * | grid | ) |
void cdr_calc_charge | ( | cdr_grid_t * | grid | ) |
Calculates the charge in a CDR grid.
Important Note: The charge is here divided by ntheta because our FFT functions are unnormalized and hence when they are applied forth and back they return the initial value multiplied by ntheta. I believe that this is the best point to normalize the data.
Definition at line 361 of file cdr.c.
void cdr_calc_charge_r | ( | cdr_grid_t * | root | ) |
void cdr_dft_charge_r | ( | cdr_grid_t * | grid, |
int | sign | ||
) |
cdr_grid_t* cdr_create_coarser_a | ( | cdr_grid_t * | grid | ) |
Creates a grid one level coarser than GRID that covers the same area or somewhat more.
Note: The new grid contains information only about the charge, not the other functions. That's why we don't use cdr_restrict.
Note that here we may be going one cell out of the aparent boundaries of the input grids but we allocated enough memory for that.
Definition at line 435 of file cdr.c.
cdr_grid_t* cdr_add_coarser_grids_a | ( | cdr_grid_t * | prev_root, |
int | n | ||
) |
void cdr_free_coarser_grids | ( | cdr_grid_t * | prev_root, |
int | n | ||
) |
Frees the memory allocated by cdr_add_coarser_grids_a.
Note: be careful to pass here only a tree returned by cdr_add_coarser_grids_a, since some grids may lose their references and stay allocated forever otherwise. (see assert below).
Definition at line 508 of file cdr.c.
void cdr_add_ext_field | ( | cdr_grid_t * | grid | ) |
Adds an external electric field to a cdr grid.
Really, it would be more efficient to include that field in some other routine and we will avoid one more grid sweep. However, for the sake of code clarity, extendability and maintenability I prefer to add it here.
ext_e_r, ext_e_z and ext_e_theta are functions of three real numbers (r, z, ) that return each of the components of the electric field.
Note that it is the responsibility of e_theta to behave correctly (i.e. periodically) when it receives thetas outside .
void cdr_add_ext_field_r | ( | cdr_grid_t * | grid | ) |
void cdr_add_inhom_field_r | ( | cdr_grid_t * | cdr, |
double | q | ||
) |
void cdr_calc_eabs | ( | cdr_grid_t * | grid | ) |
void cdr_calc_eabs_r | ( | cdr_grid_t * | grid | ) |
void cdr_nonegative | ( | cdr_grid_t * | grid | ) |
void cdr_nonegative_r | ( | cdr_grid_t * | grid | ) |
pois_grid_t** cdr_calc_field_r | ( | cdr_grid_t * | cdr, |
int | return_pois | ||
) |
The interface between the cdr and the poisson parts.
If return_pois is true, returns the Poisson trees and they have to be de-allocated by the calling program. If not, takes care himself of deallocation and returns NULL.
Definition at line 532 of file cdr.c.
void cdr_set_ext_bnd | ( | cdr_grid_t * | grid | ) |
void cdr_set_ext_bnd_r | ( | cdr_grid_t * | grid | ) |
void cdr_calc_d_dens | ( | cdr_grid_t * | grid | ) |
void cdr_calc_d_dens_r | ( | cdr_grid_t * | grid | ) |
void cdr_advect_diffu | ( | cdr_grid_t * | grid | ) |
void cdr_advect_diffu_r | ( | cdr_grid_t * | grid | ) |
double cdr_courant | ( | cdr_grid_t * | grid | ) |
void cdr_update | ( | cdr_grid_t * | orig, |
cdr_grid_t * | dest, | ||
double | h | ||
) |
Writes into the densities of the grid dest the densities of grid orig plus its derivatives times h.
If orig = dest, this implements an Euler step. But it can also be used as a tool to implement a RK
Definition at line 1075 of file cdr.c.
void cdr_rk2_update | ( | cdr_grid_t * | dens_0, |
cdr_grid_t * | d_dens_1, | ||
cdr_grid_t * | d_dens_2, | ||
cdr_grid_t * | dest, | ||
double | h | ||
) |
void cdr_rk2_update_r | ( | cdr_grid_t * | dens_0, |
cdr_grid_t * | d_dens_1, | ||
cdr_grid_t * | d_dens_2, | ||
cdr_grid_t * | dest, | ||
double | h | ||
) |
void cdr_self_update_r | ( | cdr_grid_t * | grid, |
double | h | ||
) |
void cdr_like_update_ar | ( | cdr_grid_t * | grid, |
cdr_grid_t * | new_grid, | ||
double | h | ||
) |
double cdr_rk2 | ( | cdr_grid_t * | grid, |
double | h, | ||
double | t | ||
) |
Computes the grid error. QQQQ.
Recursive version of cdr_grid_error. QQQQ Makes a full second order Runge-Kutta step.
Returns the timestep actually performed, which can be smaller that h if it does not satisfy the Courant criterium.
Definition at line 1262 of file cdr.c.
void cdr_update_refined | ( | cdr_grid_t ** | ptree | ) |
Takes a pointer to a family of cdr grids, creates a new family which is stored in that pointer and takes rid of the initial family.
This function is the entry point of the refinement code.
Definition at line 1363 of file cdr.c.
void cdr_calc_maxs | ( | cdr_grid_t * | grid | ) |
void cdr_refine | ( | cdr_grid_t * | grid | ) |
void cdr_refine_r | ( | cdr_grid_t * | grid, |
cdr_grid_t * | source | ||
) |
Recursively refines a cdr grid and constructs a tree based on it.
if source == NULL
then uses the initial densities
else sets the densities of the newly created grids by interpolating and copying from the tree source.
Definition at line 1720 of file cdr.c.
void cdr_match_r | ( | cdr_grid_t * | grid1, |
cdr_grid_t * | grid2 | ||
) |
Examines pairs of grids and matches them and all their descendants.
If grid2 == NULL, matches only the descendats of grid1. Hence, this routine is usually called as cdr_match_r (root, NULL).
Definition at line 1763 of file cdr.c.
void cdr_set_bnd | ( | cdr_grid_t * | grid | ) |
void cdr_set_bnd_r | ( | cdr_grid_t * | grid | ) |
void cdr_restrict | ( | cdr_grid_t * | grid | ) |
void cdr_restrict_r | ( | cdr_grid_t * | grid | ) |
void cdr_set_dens | ( | cdr_grid_t * | cdr, |
int | species, | ||
int | mode, | ||
double | factor, | ||
double(*)(double, double, double) | f | ||
) |
Sets the densities of species species according to the function .
mode can be one of the following:
SET_DENS_OVERWRITE: Set the dens to f(x, y, x), ignoring what was there before.
SET_DENS_ADD: Adds f to the former density.
SET_DENS_SUB: Substracts f from the former density.
Definition at line 2126 of file cdr.c.
void cdr_init_dens | ( | cdr_grid_t * | cdr | ) |
cdr_grid_t* cdr_scratch_init | ( | void | ) |
mapper_t** cdr_mappers_a | ( | interpol_method_t * | interp_method | ) |
void cdr_free_mappers | ( | mapper_t ** | mappers | ) |
void cdr_dump | ( | cdr_grid_t * | grid, |
const char * | prefix, | ||
const char * | name | ||
) |
void cdr_dump_r | ( | cdr_grid_t * | grid, |
const char * | prefix, | ||
const char * | name, | ||
FILE * | infp, | ||
double | sim_time | ||
) |
Dumps all the contents of the given grid into filenames given by prefix and name.
It also writes in tree.NAME.dat the tree structure of grid, in a format appropiate for cdr_load_tree to understand.
infp has to be NULL when called from outside.
The format of a tree.NAME.dat is as follows. Each line is composed by a "command" and some parameters. the "commands" can be
time parameter: sim_time Writes the current simulation time, as received in sim_time
open parameters: gridname r0 z0 r1 z1 level ext_bound margin
Reads the densities from the files given by gridname, with the corresponding values of the grid parameters. Leaves the grid open to add childrens to it. Those children will be all the grids read until the grid is closed.
close parameters: gridname
Closes the latest opened grid. All subsequent grids will be regarded as brothers of gridname.
Definition at line 2360 of file cdr.c.
cdr_grid_t* cdr_load_tree_r | ( | const char * | prefix, |
const char * | name, | ||
FILE * | infp | ||
) |
Reads the data format produced by cdr_dump_r and creates a complete tree from it.
This function is really quick-and-dirty: one should check the fscanfs and do everything cleanlier.
Definition at line 2425 of file cdr.c.
void cdr_dump_frames | ( | cdr_grid_t * | grid, |
const char * | prefix, | ||
const char * | name | ||
) |
void pois_init | ( | void | ) |
pois_grid_t* pois_new_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1 | ||
) |
pois_grid_t* pois_new_3d_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1, | ||
int | ntheta | ||
) |
void pois_free | ( | pois_grid_t * | grid | ) |
void pois_free_r | ( | pois_grid_t * | grid | ) |
pois_grid_t* pois_new_glob_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1, | ||
int | level | ||
) |
pois_grid_t* pois_init_tree_a | ( | int | r0, |
int | z0, | ||
int | r1, | ||
int | z1 | ||
) |
REAL* pois_boundary_a | ( | pois_grid_t * | grid, |
int | boundary | ||
) |
void pois_solve_grid | ( | pois_grid_t * | grid, |
pois_problem_t * | prob, | ||
double | lambda, | ||
double | s | ||
) |
void pois_set_phi_boundaries | ( | pois_grid_t * | grid, |
REAL * | boundaries[], | ||
int | left_neu, | ||
int | right_neu, | ||
int | bottom_neu, | ||
int | top_neu | ||
) |
Uses the boundaries[] vectors to set the boundaries by interpolation for the phi array of a grid.
(in the extra space we allocated when we created the array). xxx_neu tells us if the xxx boundary has Neumann b.c. (or unspecified, as FISHPACK calls them if they are applied in the axis)
TODO: Please rewrite this mess.
Definition at line 465 of file poisson.c.
int pois_map_charge | ( | pois_grid_t * | pois, |
cdr_grid_t * | cdr, | ||
int | mode | ||
) |
void pois_set_error | ( | pois_grid_t * | grid | ) |
int pois_refine | ( | pois_grid_t * | grid, |
double | threshold | ||
) |
The refinement routine.
Threshold is initially pois_max_error, but if we get too large refinement it can be increased (after warning the user that we are not reaching the accuracy that he asked for).
Definition at line 606 of file poisson.c.
pois_grid_t** pois_solve_a | ( | cdr_grid_t * | cdr, |
pois_problem_t * | prob | ||
) |
pois_grid_t** pois_gen_solve_a | ( | cdr_grid_t * | cdr, |
pois_problem_t * | prob, | ||
mapper_t ** | mappers, | ||
double | es | ||
) |
Solves a Poisson/Helmholtz equation with FISHPACK and maps the result using a given set of mapper.
From this method downwards (in the sense of calling order, not file organization), all the code is shared by the Poisson solver and the Photoionization (Helmholtz) solver.
Definition at line 777 of file poisson.c.
pois_grid_t* pois_solve_mode | ( | cdr_grid_t * | tree, |
cdr_grid_t * | cdr, | ||
pois_problem_t * | prob, | ||
int | mode, | ||
double | es | ||
) |
Solves a single Fourier mode.
tree is the root of the cdr tree with extra_pois_levels added. cdr is the cdr grid at level 0, contained in tree:
cdr = tree->first_child->firts_child...->first_child _________ extra_pois_levels __________/
Definition at line 836 of file poisson.c.
void pois_solve_r | ( | pois_grid_t * | pois, |
cdr_grid_t * | cdr, | ||
pois_problem_t * | prob, | ||
int | mode, | ||
double | es, | ||
double | threshold | ||
) |
double pois_phi_at | ( | pois_grid_t * | grid, |
double | r, | ||
double | z, | ||
double | theta | ||
) |
void pois_dump | ( | pois_grid_t * | grid, |
const char * | prefix, | ||
const char * | name | ||
) |
void pois_dump_r | ( | pois_grid_t * | grid, |
const char * | prefix, | ||
const char * | name | ||
) |
void pois_write_error_r | ( | pois_grid_t * | grid, |
FILE * | fp | ||
) |
void pois_error_measures | ( | pois_grid_t * | grid, |
double * | L1, | ||
double * | L2, | ||
double * | Lmax | ||
) |
void pois_inhom_init | ( | void | ) |
double pois_inhom_phi | ( | double | r, |
double | z | ||
) |
double pois_inhom_er | ( | double | r, |
double | z | ||
) |
double pois_inhom_ez | ( | double | r, |
double | z | ||
) |
double pois_inhom_q_factor | ( | pois_grid_t * | pois | ) |
Once we have the electrostatic potential created by the space charges, we use this function to compute the multiplying factor of the floating charge.
One can also forget about keeping the potential fixed somewhere and impose a constant (non-floating, but may depend on time) charge pois_inhom_fixed_q, which is used if nonzero. The use of that is to simulate a charged cloud close to the earth, which acts as an electrode: usually you would also combine that with the sprite module, that allows varing neutral densities.
Definition at line 1067 of file poisson.c.
void pois_add_inhom_phi_r | ( | pois_grid_t * | grid, |
double | q | ||
) |
Adds the potential created by the needle to a Poisson grid and their descendants.
Note that here is in Fourier space and the Laplacian potential is always axi-symmetric, so you only have to call this function with the zero-mode of the Poisson grids.
The reason that it is better to add the inhomogeneous field to the potential and not later to the electric fields is that if we do that, we will have to substract two large and very curved functions that give something close to zero: the error we make then will be comparable to the result.
Definition at line 1101 of file poisson.c.
void photo_init | ( | ) |
void photo_register | ( | double | A, |
double | lambda | ||
) |
void photo_copy_list | ( | photo_term_t * | src, |
photo_term_t ** | dest | ||
) |
void photo_unregister_all | ( | void | ) |
void photo_dft_r | ( | cdr_grid_t * | grid, |
int | sign | ||
) |
void photo_copy_source | ( | cdr_grid_t * | grid | ) |
void photo_add_term | ( | photo_term_t * | term, |
cdr_grid_t * | cdr | ||
) |
void photo_add_term_r | ( | photo_term_t * | term, |
cdr_grid_t * | cdr | ||
) |
pois_grid_t** photo_calc_term | ( | photo_term_t * | term, |
cdr_grid_t * | cdr, | ||
int | i | ||
) |
void photo_calc | ( | photo_term_t * | terms, |
cdr_grid_t * | cdr | ||
) |
void photo_load_file | ( | char * | fname | ) |
void init_parameters | ( | void | ) |
void cstream_init | ( | void | ) |
void cstream_end | ( | void | ) |
void cstream_set_field_at_time | ( | double | t | ) |
void dft_transform | ( | rz_array_t * | in, |
rz_array_t * | out, | ||
int | sign | ||
) |
void dft_diff | ( | grid_t * | grid, |
rz_array_t * | f | ||
) |
void dft_weight | ( | cdr_grid_t * | cdr, |
rz_array_t * | var, | ||
double | weights[], | ||
double | power | ||
) |
Calculates the weight for a given cdr grid and a variable ???
For a given cdr grid and a variable, calculates its "weight": the integral of the variable raised to power for each Fourier mode. weights[] must be able to contain at least cdr->ntheta values.
Definition at line 143 of file dft.c.
void dft_out_weights | ( | cdr_grid_t * | grid, |
const char * | prefix, | ||
double | t | ||
) |
Outputs to a file 'weights.tsv' the results of dft_weight.
Assumes that grid->charge is calculated but in real space then it transforms it to Fourier space and leaves it like that: so do not assume that grid->charge is unchanged.
grid->dens[electrons], on the other hand, is transformed forth and back.
Definition at line 177 of file dft.c.
void dft_perturb | ( | cdr_grid_t * | cdr, |
rz_array_t * | var, | ||
double * | epsilon_k | ||
) |
Perturbs a FFT-transformed variable.
Assumes that the unperturbed variable is axi-symmetrical and hence all modes are zero except k=0. The perturbation is then selected as a Gaussian random number epsilon_k times the zero-mode value of the variable. epsilon_k is distributed as epsilon_k = N(0, perturb_epsilon).
Definition at line 246 of file dft.c.
void dft_dens_perturb_r | ( | cdr_grid_t * | grid, |
int | species, | ||
double * | epsilon_k | ||
) |
int find_species_by_name | ( | const char * | spec_name | ) |
Returns the position in the species-array of a given species.
Returns -1 if not found.
Definition at line 28 of file reaction.c.
void react_add | ( | reaction_t * | react | ) |
Adds a given reaction to the reaction list.
Definition at line 48 of file reaction.c.
void react_init | ( | ) |
Initializes the list of reactions.
Definition at line 221 of file reaction.c.
void react_apply_r | ( | reaction_t * | react, |
cdr_grid_t * | grid, | ||
int | overwrite | ||
) |
Recursive version of react_apply.
Definition at line 167 of file reaction.c.
void react_apply_all | ( | cdr_grid_t * | grid | ) |
Applies all reactions to the given grid and his descendants.
Definition at line 192 of file reaction.c.
void kinetic_init | ( | void | ) |
double spr_density_at | ( | double | altitude | ) |
void spr_init | ( | ) |
void spr_hook | ( | cdr_grid_t * | grid | ) |
void spr_update | ( | double | altitude | ) |
double spr_head_altitude | ( | cdr_grid_t * | grid, |
int | sign | ||
) |
Finds the position of the streamer head by locating the maximum (or -maximum) of the charge along the streamer axis.
sign has to be +1 for positive streamers and -1 for negative streamers.
Definition at line 101 of file sprites.c.