Plotter¶
MRCPP comes with its own plotter class which can be used by the host program to generate data files for visualization using e.g. gnuplot, paraview, blob and geomview. These features are available by including:
#include "MRCPP/Plotter"
-
template<int
D
>
classmrcpp
::
Plotter
¶ Class for plotting multivariate functions.
This class will generate an equidistant grid in one (line), two (surf) or three (cube) dimensions, and subsequently evaluate the function on this grid.
The grid is generated from the vectors A, B and C, relative to the origin O:
a linePlot will plot the line spanned by A, starting from O
a surfPlot will plot the area spanned by A and B, starting from O
a cubePlot will plot the volume spanned by A, B and C, starting from O
The vectors A, B and C do not necessarily have to be orthogonal.
The parameter
D
refers to the dimension of the function, not the dimension of the plot.Public Functions
-
Plotter
(const Coord<D> &o = {})¶ - Return
New Plotter object
- Parameters
[in] o
: Plot origin, default(0, 0, ... , 0)
-
void
setSuffix
(int t, const std::string &s)¶ Set file extension for output file.
The file name you decide for the output will get a predefined suffix that differentiates between different types of plot.
- Parameters
[in] t
: Plot type (Plotter<D>::Line
,::Surface
,::Cube
,::Grid
)[in] s
: Extension string, default.line
,.surf
,.cube
,.grid
-
void
setOrigin
(const Coord<D> &o)¶ Set the point of origin for the plot.
- Parameters
[in] o
: Plot origin, default(0, 0, ... , 0)
-
void
setRange
(const Coord<D> &a, const Coord<D> &b = {}, const Coord<D> &c = {})¶ Set boundary vectors A, B and C for the plot.
- Parameters
[in] a
: A vector[in] b
: B vector[in] c
: C vector
-
void
gridPlot
(const MWTree<D> &tree, const std::string &fname)¶ Grid plot of a MWTree.
Writes a file named fname + file extension (“.grid” as default) to be read by geomview to visualize the grid (of endNodes) where the multiresolution function is defined. In MPI, each process will write a separate file, and will print only nodes owned by itself (pluss the rootNodes).
- Parameters
[in] tree
: MWTree to plot[in] fname
: File name for output, without extension
-
void
linePlot
(const std::array<int, 1> &npts, const RepresentableFunction<D> &func, const std::string &fname)¶ Parametric plot of a function.
Plots the function func parametrically with npts[0] along the vector A starting from the origin O to a file named fname + file extension (“.line” as default).
- Parameters
[in] npts
: Number of points along A[in] func
: Function to plot[in] fname
: File name for output, without extension
-
void
surfPlot
(const std::array<int, 2> &npts, const RepresentableFunction<D> &func, const std::string &fname)¶ Surface plot of a function.
Plots the function func in 2D on the area spanned by the two vectors A (npts[0] points) and B (npts[1] points), starting from the origin O, to a file named fname + file extension (“.surf” as default).
- Parameters
[in] npts
: Number of points along A and B[in] func
: Function to plot[in] fname
: File name for output, without extension
-
void
cubePlot
(const std::array<int, 3> &npts, const RepresentableFunction<D> &func, const std::string &fname)¶ Cubic plot of a function.
Plots the function func in 3D in the volume spanned by the three vectors A (npts[0] points), B (npts[1] points) and C (npts[2] points), starting from the origin O, to a file named fname + file extension (“.cube” as default).
- Parameters
[in] npts
: Number of points along A, B and C[in] func
: Function to plot[in] fname
: File name for output, without extension
Note
When plotting a FunctionTree
, only the scaling part of the
leaf nodes will be evaluated, which means that the function
values will not be fully accurate. This is done to allow a
fast and const
function evaluation that can be done in
OMP parallel. If you want to include also the final wavelet
corrections to your function values, you’ll have to manually
extend the MW grid by one level before plotting using
mrcpp::refine_grid(tree, 1)
.
Examples¶
A parametric line plot of a three-dimensional function along the z axis [-1, 1]:
mrcpp::FunctionTree<3> f_tree(MRA); // Function to be plotted
int nPts = 1000; // Number of points
mrcpp::Coord<3> o{ 0.0, 0.0,-1.0}; // Origin vector
mrcpp::Coord<3> a{ 0.0, 0.0, 2.0}; // Boundary vector
mrcpp::Plotter<3> plot(o); // Plotter of 3D functions
plot.setRange(a); // Set plot range
plot.linePlot({nPts}, f_tree, "f_tree"); // Write to file f_tree.line
A surface plot of a three-dimensional function in the x=[-2,2], y=[-1,1], z=0 plane:
int aPts = 2000; // Number of points in a
int bPts = 1000; // Number of points in b
mrcpp::Coord<3> o{-2.0,-1.0, 0.0}; // Origin vector
mrcpp::Coord<3> a{ 4.0, 0.0, 0.0}; // Boundary vector A
mrcpp::Coord<3> b{ 0.0, 2.0, 0.0}; // Boundary vector B
mrcpp::Plotter<3> plot(o); // Plotter of 3D functions
plot.setRange(a, b); // Set plot range
plot.surfPlot({aPts, bPts}, f_tree, "f_tree"); // Write to file f_tree.surf
A cube plot of a three-dimensional function in the volume x=[-2,2], y=[-1,1], z=[0,2]:
int aPts = 200; // Number of points in a
int bPts = 100; // Number of points in b
int cPts = 100; // Number of points in c
mrcpp::Coord<3> o{-2.0,-1.0, 0.0}; // Origin vector
mrcpp::Coord<3> a{ 4.0, 0.0, 0.0}; // Boundary vector A
mrcpp::Coord<3> b{ 0.0, 2.0, 0.0}; // Boundary vector B
mrcpp::Coord<3> b{ 0.0, 0.0, 2.0}; // Boundary vector C
mrcpp::Plotter<3> plot(o); // Plotter of 3D functions
plot.setRange(a, b, c); // Set plot range
plot.cubePlot({aPts, bPts, cPts}, f_tree, "f_tree"); // Write to file f_tree.cube
A grid plot of a three-dimensional FunctionTree:
mrcpp::Plotter<3> plot; // Plotter of 3D functions
plot.gridPlot(f_tree, "f_tree"); // Write to file f_tree.grid