/* See figs1d.h. */ /* Last edited on 2024-12-21 14:02:41 by stolfi */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define DIM 1 #define MAXTAGSZ 200 void fig_1d_mother_pulse ( PlotOptions *o, char *tag, /* Tag for figure/file dg. */ udg_pulse_kind_t pkind, /* Kind of element. */ udg_cont_t c, /* Continuity order of element. */ udg_degree_t g, /* Degree of element. */ udg_pulse_mother_index_t pix, /* Index of element in set. */ udg_grid_size_t gsz, /* Domain period (number of grid intervals). */ interval_t fr[] /* Arg and function ranges of interest. */ ) { if (! check_pulse_index(pkind, c, g, pix)) { return; } /* Nominal plot scale (client coords to mm): */ double scale = o->scale; double mag[2]; /* Graphing scales (client uns per function un). */ double tstep[2]; /* Major tick spacing. */ double sstep[2]; /* Minor tick spacing. */ mag[0] = 1.0; tstep [0]= 1.0; sstep [0]= 0.5; /* For function argument. */ mag[1] = 0.5; tstep [1]= 1.0; sstep [1]= 0.5; /* For function values. */ interval_t gr[2]; /* Slightly widened ranges for plot/clip. */ interval_t win[2]; /* Plot window (in client coords). */ /* Start figure, plot axes etc: */ compute_1d_plot_scales(ps, o, fr, scale, mag, /* OUT */ gr, win); start_figure(o, tag, tag, win, scale); plot_1d_graph_decoration ( ps, o, scale, mag, fr, tstep, sstep, gr, win ); /* Plot the function: */ if (o->color) { pswr_set_pen(ps, 0.0,0.0,0.5, 0.15, 0.0, 0.0); } else { pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.0, 0.0); } auto double func(double x); double func(double x) { double fx; udg_pulse_eval(pkind, c, g, pix, gsz, (double)gsz, 0, x, 0, &fx); return fx; } plot_1d_function(ps, o, func, 0.002, gr[0], mag[0], gr[1], mag[1] ); finish_figure(o); } void fig_1d_mother_pulse_set ( PlotOptions *o, char *tag, /* Tag for figure/file name. */ udg_pulse_kind_t pkind, /* Kind of element. */ udg_cont_t c, /* Continuity order of element. */ udg_degree_t g, /* Degree of element. */ udg_grid_size_t gsz, /* Domain period (number of grid intervals). */ interval_t fr[] /* Arg and function ranges of interest. */ ) { /* Get max valid pulse index {mix}: */ int mix = udg_pulse_max_index(pkind, c, g); if (mix < 0) { fprintf ( stderr, "** invalid combination (pkind = %d, c = %d, g = %d)\n", udg_pulse_kind_to_char(pkind), c, g ); return; } /* Nominal plot scale (client coords to mm): */ double scale = o->scale; double mag[2]; /* Graphing scales (client uns per function un). */ double tstep[2]; /* Major tick spacing. */ double sstep[2]; /* Minor tick spacing. */ mag[0] = 1.0; tstep [0]= 1.0; sstep [0]= 0.5; /* For function argument. */ mag[1] = 0.5; tstep [1]= 1.0; sstep [1]= 0.5; /* For function values. */ interval_t gr[2]; /* Slightly widened ranges for plot/clip. */ interval_t win[2]; /* Plot window (in client coords). */ /* Start figure, plot axes etc: */ compute_1d_plot_scales(ps, o, fr, scale, mag, /* OUT */ gr, win); start_figure(o, tag, tag, win, scale); plot_1d_graph_decoration ( ps, o, scale, mag, fr, tstep, sstep, gr, win ); /* Plot the function: */ if (o->color) { pswr_set_pen(ps, 0.0,0.0,0.5, 0.15, 0.0, 0.0); } else { pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.0, 0.0); } udg_pulse_mother_index_t pix; for (pix = 0; pix <= mix; pix++) { auto double func(double x); double func(double x) { double fx; udg_pulse_eval(pkind, c, g, pix, gsz, (double)gsz, 0, x, 0, &fx); return fx; } plot_1d_function(ps, o, func, 0.002, gr[0], mag[0], gr[1], mag[1] ); } finish_figure(o); } void figs_1d_basis ( PlotOptions *o, char *tag, /* Tag for figure/file name. */ b1d_basis_t *bas /* The basis to plot. */ ) { /* Old arguments: udg_tree_node_t *G, // Root node of grid. interval_t rootCell[], // Root interval. udg_pulse_kind_t pkind, // Kind of element. udg_cont_t c, // Continuity order of element. udg_degree_t g, // Degree of element. bool_t superior // TRUE for maximal-support elements. */ /* !!! Remove this when possible: !!! */ if (superior) { fprintf(stderr, "** superior basis not implemented yet\n"); return; } /* Get max valid pulse index {mix}: */ int mix = udg_pulse_max_index(pkind, c, g); if (mix < 0) { fprintf ( stderr, "** invalid combination (pkind = %d, c = %d, g = %d)\n", udg_pulse_kind_to_char(pkind), c, g ); return; } int i; /* Assuming that there is no leaf at level 0: */ udg_grid_size_t szMin = (superior ? 1 : 2); double wd = 1.0; /* Obtain the function arg/value ranges of interest: */ interval_t fr[2]; compute_1d_common_pulse_ranges(c, szMin, wd, /*out*/ fr); fr[0] = rootCell[0]; udg_tent_vec_t tv = udg_tent_basis_get(DIM, &pkind, &c, &g, G); fprintf(stderr, " basis has %d tents\n", tv.nel); /* Ensure that the basis starts on a new page: */ pswr_sync_canvas(ps, NULL); /* Plot the tents: */ for (i = 0; i < tv.nel; i++) { udg_tent_t t = tv.el[i]; udg_pulse_mother_index_t pix; udg_tent_pulse_indices(DIM, &mix, t.tix, &pix); udg_rank_t r = udg_cell_rank(t.cell); udg_grid_pos_t pos; udg_cell_position(DIM, t.cell, &pos); fprintf(stderr, "[%03d] ", i); udg_tent_print(stderr, DIM, &pkind, &c, &g, t); fprintf(stderr, "\n"); char *elTag = jsprintf("%s-%05d", tag, i); fig_1d_basis_element(o, elTag, G, rootCell, pkind, c, g, pix, r, pos, fr); free(elTag); } /* Ensure that subsequent pictures will go to the next canvas: */ pswr_fill_canvas(ps); } void fig_1d_element ( PlotOptions *o, char *tag, /* Tag for figure/file name. */ b1d_basis_t *bas, /* The basis to plot. */ int ix, /* Index of element in basis. */ interval_t fr[] /* Arg and function ranges of interest. */ ) { /* Old arguments: udg_tree_node_t *G, // Root node of grid. interval_t rootCell[], // The root cell. udg_pulse_kind_t pkind, // Kind of element. udg_cont_t c, // Continuity order of element. udg_degree_t g, // Degree of element. udg_pulse_mother_index_t pix, // The pulse index udg_rank_t r, // The pulse's rank. udg_grid_pos_t pos, // The pulse's shift. */ if (! check_pulse_index(pkind, c, g, pix)) { return; } /* Nominal plot scale (client coords to mm): */ double scale = o->scale; double mag[2]; /* Graphing scales (client uns per function un). */ double tstep[2]; /* Major tick spacing. */ double sstep[2]; /* Minor tick spacing. */ mag[0] = 1.00; tstep [0]= 1.00; sstep [0]= 0.125; /* For function argument. */ mag[1] = 0.25; tstep [1]= 1.00; sstep [1]= 0.500; /* For function values. */ interval_t gr[2]; /* Slightly widened ranges for plot/clip. */ interval_t win[2]; /* Plot window (in client coords). */ /* Start figure, plot axes etc: */ compute_1d_plot_scales(ps, o, fr, scale, mag, /* OUT */ gr, win); start_figure(o, tag, tag, win, scale); plot_1d_graph_decoration ( ps, o, scale, mag, fr, tstep, sstep, gr, win ); /* Plot the leaf cell boundaries: */ if (o->color) { pswr_set_pen(ps, 0.75,0.75,0.75, 0.15, 0.0,0.0); } else { pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.75,0.75); } plot_1d_tree_leaves(ps, o, G, rootCell, gr[0], mag[0], gr[1], mag[1]); /* Get the grid's size: */ udg_grid_size_t gsz; udg_grid_size(DIM, r, &gsz); /* Get the root cell width: */ double wd = HI(rootCell[0]) - LO(rootCell[0]); /* Get the tent's mother support size: */ udg_grid_size_t psz; udg_tent_mother_supp_size(DIM, &pkind, &c, &g, &pix, &psz); if ((psz % 2) == 0) { /* Even support size, plot the tent's center: */ udg_grid_pos_t ctrpos = (pos + psz/2) % gsz; udg_cell_index_t ucell = udg_cell_from_position(DIM, r, &ctrpos); udg_locus_t E = udg_locus(set32_range(0,DIM-1), ucell); plot_1d_locus(ps, o, E, G, rootCell, gr[0], mag[0]); } /* Plot the function: */ auto double func(double x); double func(double x) { double fx; udg_tent_eval(DIM, &pkind, &c, &g, &pix, &gsz, &wd, &pos, &x, 0, &fx); return fx; } if (o->color) { switch (pix) { case 0: pswr_set_pen(ps, 0.0,0.0,0.6, 0.15, 0.0, 0.0); break; case 1: pswr_set_pen(ps, 0.0,0.3,0.0, 0.15, 0.0, 0.0); break; case 2: pswr_set_pen(ps, 0.5,0.0,0.0, 0.15, 0.0, 0.0); break; default: pswr_set_pen(ps, 0.0,0.0,0.0, 0.15, 0.0, 0.0); } } else { switch(pix) { case 0: pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.0, 0.0); break; case 1: pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.5, 1.0); break; case 2: pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.5, 0.5); break; default: pswr_set_pen(ps, 0.0,0.0,0.0, 0.10, 0.0, 0.0); } } plot_1d_function(ps, o, func, 0.002, gr[0], mag[0], gr[1], mag[1] ); finish_figure(o); }