/* Last edited on 2024-11-20 06:06:37 by stolfi */ /* * spr2D.c * 29/11/2006 * * Demonstrates sparse decompositions based on iterated * interpolation in 2D Gaussian * Available geometries: empty domain, closed box, open horn. */ /* We need to define _GNU_SOURCE to get {asprintf}. */ #define _GNU_SOURCE #include #include #include #include #include "int2d.h" #include "mwplot.h" /* The maximum number of samples that we can have: */ #define NPx 100 #define NPy 100 #define SIGMA_MAX (1e7) /* Nominal conductivity {sigma} of metals. */ void fatal(char* s); double** dvector(int nl, int nc); /* Allocates an array with {nl} rows and {nc} columns. */ void wait_for_user(void); /* Writes "Hit return to continue" and waits for user to do so. */ /* NON-HOMOGENEOUS MEDIUM Non-homogeneous media are simulated by setting the appropriate elements of the {sigma} field. */ void setup_geometry_box(int n, double **sigma); /* Draws into {sigma} the outline of a microwave horn, with open mouth and impervious sides. */ void setup_geometry_horn(int n, double **sigma); /* Draws into {sigma} a square box, with empty interior and impervious walls. */ void show_field ( mwplot_t *wp, int nx, int ny, double dx, double dy, double **A, double vMax, char *zLabel, double time ); /* Plots on {wp} the field {A}, assumed to be an array of samples with {nx} rows and {ny} columns, with step sizes {dx} and {dy}, respectively. The vertical scale is set assuming the values of {A} are in {[-vMax _ +vmax]}. The Z axis will be labeled with {zLabel}, and the plot will have a title showing the specified {time}, assumed to be in nanoseconds. If the plotter {wp} is configured to write to disk instead of the screen, the plot file will be called "{zLabel}-{NNNNNN}.{ext}", where {NNNNNN} is the {time} value rounded to integer, and {ext} is the appropriate extension ("eps", "png", etc.) */ int main() { /* Fundamental constants */ double cc = 2.99792458e8; /* speed of light in free space */ double muz = 4.0 * M_PI * 1.0e-7; /* permeability of free space */ double epsz =1.0 / (cc*cc*muz); /* permittivity of free space */ /* double aimp = sqrt(muz/epsz); */ /* wave impedance in free space */ int interp_points; /* 2 or 4 point interpolation (linear or cubic) */ double eps; /* error / threshold for the sparse representation */ double eps1; /* error / threshold for the sparse representation */ int n0; /* number of samples in the coarse level */ int ell; int ell_atual; /* actual number of decomp levels with significant wavelet coeffs */ int level_max; /* number of decomposition levels */ int n; int npontos; char buf[1024]; int i, j, k; /* Starts the gnuplot process, sets some unchanging plot options: */ mwplot_t *wp = mwplot_start_gnuplot(0); mwplot_set_terminal(wp, /*x11*/ 0); mwplot_set_palette(wp, /*blue--red*/ 20); n0 = 8; printf("Enter the number of samples in the coarse level, up to %d: [%d] ", NPx, n0); fgets(buf, sizeof(buf), stdin); if (buf[0] != '\n') n0 = atoi(buf); ell = 4; printf("Enter the number of decompositions levels: [%d] ", ell); fgets(buf, sizeof(buf), stdin); if (buf[0] != '\n') ell = atoi(buf); ell_atual = ell; eps = 1e-6; printf("Epsilon: [%g] ", eps); fgets(buf, sizeof(buf), stdin); if (buf[0] != '\n') eps = atof(buf); eps1=eps/10; interp_points = 4; printf("Enter the number of interpolation points: [%d]", interp_points); fgets(buf, sizeof(buf), stdin); if (buf[0] != '\n') interp_points = atoi(buf); n = n0 * (1<