33 #ifndef MADNESS_MRA_FUNCPLOT_H__INCLUDED
34 #define MADNESS_MRA_FUNCPLOT_H__INCLUDED
66 template <
typename T, std::
size_t NDIM>
67 void plotdx(
const Function<T,NDIM>&
f,
69 const Tensor<double>& cell = FunctionDefaults<NDIM>::get_cell(),
70 const std::vector<long>& npt = std::vector<long>(
NDIM,201L),
96 template<std::
size_t NDIM>
104 Tensor<double> cell(
NDIM, 2);
106 for(i = 0; i <
NDIM; ++i) {
107 cell(i, 0) = plotlo[i];
108 cell(i, 1) = plothi[i];
112 if(world.
rank() == 0) {
113 f = fopen(filename,
"w");
117 fprintf(f,
"<VTKFile type=\"StructuredGrid\" version=\"0.1\"" \
118 " byte_order=\"LittleEndian\" compressor=\"" \
119 "vtkZLibDataCompressor\">\n");
120 fprintf(f,
" <StructuredGrid WholeExtent=\"");
121 for(i = 0; i <
NDIM; ++i)
122 fprintf(f,
"0 %ld ", npt[i]-1);
126 fprintf(f,
" <Piece Extent=\"");
127 for(i = 0; i <
NDIM; ++i)
128 fprintf(f,
"0 %ld ", npt[i]-1);
132 fprintf(f,
" <Points>\n");
133 fprintf(f,
" <DataArray NumberOfComponents=\"3\" " \
134 "type=\"Float32\" format=\"ascii\">\n");
137 for(i = 0; i <
NDIM; ++i) {
141 space[i] = (cell(i, 1) - cell(i, 0)) / (npt[i] - 1);
146 for(i = 0; i <
NDIM; ++i)
147 fprintf(f,
"%f ", plotlo[i] + it[i]*space[i]);
153 fprintf(f,
" </DataArray>\n");
154 fprintf(f,
" </Points>\n");
155 fprintf(f,
" <PointData>\n");
175 template<
typename T, std::
size_t NDIM>
179 bool binary =
false) {
188 template<
typename T, std::
size_t NDIM>
192 bool binary =
false,
bool plot_refine =
false) {
197 Tensor<double> cell(
NDIM, 2);
199 for(i = 0; i <
NDIM; ++i) {
200 cell(i, 0) = plotlo[i];
201 cell(i, 1) = plothi[i];
203 std::vector<long> numpt(NDIM);
204 for(i = 0; i <
NDIM; ++i)
211 if(world.
rank() == 0) {
212 f = fopen(filename,
"a");
216 fprintf(f,
" <DataArray Name=\"%s\" format=\"ascii\" " \
217 "type=\"Float32\" NumberOfComponents=\"1\">\n", fieldname);
221 Tensor<T> tmpr =
function.eval_cube(cell, numpt, plot_refine);
224 if(world.
rank() == 0) {
226 fprintf(f,
"%.6e\n", tmpr(*it));
228 fprintf(f,
" </DataArray>\n");
241 template<
typename T, std::
size_t NDIM>
243 const char *fieldname,
World &world,
const char *filename,
246 bool plot_refine =
false) {
255 Tensor<double> cell(
NDIM, 2);
257 for(i = 0; i <
NDIM; ++i) {
258 cell(i, 0) = plotlo[i];
259 cell(i, 1) = plothi[i];
261 std::vector<long> numpt(NDIM);
262 for(i = 0; i <
NDIM; ++i)
269 if(world.
rank() == 0) {
270 f = fopen(filename,
"a");
274 fprintf(f,
" <DataArray Name=\"%s\" format=\"ascii\" " \
275 "type=\"Float32\" NumberOfComponents=\"2\">\n", fieldname);
279 Tensor<std::complex<T> > tmpr =
function.eval_cube(cell, numpt,
283 if(world.
rank() == 0) {
285 fprintf(f,
"%.6e %.6e\n",
real(tmpr(*it)),
imag(tmpr(*it)));
287 fprintf(f,
" </DataArray>\n");
299 template<std::
size_t NDIM>
305 if(world.
rank() == 0) {
306 f = fopen(filename,
"a");
310 fprintf(f,
" </PointData>\n");
311 fprintf(f,
" <CellData>\n");
312 fprintf(f,
" </CellData>\n");
313 fprintf(f,
" </Piece>\n");
314 fprintf(f,
" </StructuredGrid>\n");
315 fprintf(f,
"</VTKFile>\n");
323 return (a>>8) | (a<<8);
332 template <
typename T>
333 static void plotpovray(
const Function<T,3>&
function,
334 const char* filename,
335 const Tensor<double>& cell = FunctionDefaults<3>::get_cell(),
336 const std::vector<long>& npt = std::vector<long>(3,201L))
340 MADNESS_ASSERT(npt.size() == 3);
343 World& world =
const_cast< Function<T,3>&
>(
function).world();
345 if (world.rank() == 0) {
346 f = fopen(filename,
"w");
348 fwrite((
void*) dims,
sizeof(
short), 3, f);
350 Tensor<T> r =
function.eval_cube(cell, npt);
351 if (world.rank() == 0) {
352 double rmax = r.max();
353 double rmin = r.min();
354 double rrange = rmax + rmin;
355 double rmean = rrange*0.5;
356 double fac = 65535.0/rrange;
358 printf(
"plot_povray: %s: min=%.2e(0.0) mean=%.2e(0.5) max=%.2e(1.0) range=%.2e\n",
359 filename,rmin,rmean,rmax,rrange);
361 std::vector<unsigned short> d(npt[0]);
362 for (
unsigned int i2=0; i2<npt[2]; ++i2) {
363 for (
unsigned int i1=0; i1<npt[1]; ++i1) {
364 for (
unsigned int i0=0; i0<npt[0]; ++i0) {
365 d[i0] = (
unsigned short)(
htons_x((
unsigned short)(fac*(r(i0,i1,i2) - rmin))));
368 fwrite((
void*) &d[0],
sizeof(
short), npt[0], f);
376 static inline void plot_line_print_value(FILE* f,
double_complex v) {
377 fprintf(f,
" %.14e %.14e ",
real(v),
imag(v));
380 static inline void plot_line_print_value(FILE* f,
double v) {
381 fprintf(f,
" %.14e", v);
387 template <
typename T, std::
size_t NDIM>
391 coordT h = (hi - lo)*(1.0/(npt-1));
394 for (std::size_t i=0; i<
NDIM; ++i) sum += h[i]*h[i];
399 if (world.
rank() == 0) {
400 FILE* file = fopen(filename,
"w");
403 for (
int i=0; i<npt; ++i) {
404 coordT r = lo + h*double(i);
405 fprintf(file,
"%.14e ", i*sum);
406 plot_line_print_value(file, f.
eval(r));
417 template <
typename T,
typename U, std::
size_t NDIM>
421 coordT h = (hi - lo)*(1.0/(npt-1));
424 for (std::size_t i=0; i<
NDIM; ++i) sum += h[i]*h[i];
430 if (world.
rank() == 0) {
431 FILE* file = fopen(filename,
"w");
434 for (
int i=0; i<npt; ++i) {
435 coordT r = lo + h*double(i);
436 fprintf(file,
"%.14e ", i*sum);
437 plot_line_print_value(file, f.
eval(r));
438 plot_line_print_value(file, g.
eval(r));
450 template <
typename T,
typename U,
typename V, std::
size_t NDIM>
454 coordT h = (hi - lo)*(1.0/(npt-1));
457 for (std::size_t i=0; i<
NDIM; ++i) sum += h[i]*h[i];
464 if (world.
rank() == 0) {
465 FILE* file = fopen(filename,
"w");
468 for (
int i=0; i<npt; ++i) {
469 coordT r = lo + h*double(i);
470 fprintf(file,
"%.14e ", i*sum);
471 plot_line_print_value(file, f.
eval(r));
472 plot_line_print_value(file, g.
eval(r));
473 plot_line_print_value(file, a.
eval(r));
484 template <
typename T,
typename U,
typename V,
typename W, std::
size_t NDIM>
488 coordT h = (hi - lo)*(1.0/(npt-1));
491 for (std::size_t i=0; i<
NDIM; ++i) sum += h[i]*h[i];
499 if (world.
rank() == 0) {
500 FILE* file = fopen(filename,
"w");
501 for (
int i=0; i<npt; ++i) {
502 coordT r = lo + h*double(i);
503 fprintf(file,
"%.14e ", i*sum);
504 plot_line_print_value(file, f.
eval(r));
505 plot_line_print_value(file, g.
eval(r));
506 plot_line_print_value(file, a.
eval(r));
507 plot_line_print_value(file, b.
eval(r));
530 template<
size_t NDIM>
534 if (world.
size()>1)
return;
551 std::ifstream
f(
"input");
557 }
else if (s ==
"plane") {
559 }
else if (s ==
"zoom") {
561 }
else if (s ==
"output") {
563 }
else if (s ==
"points") {
565 }
else if (s ==
"origin") {
566 for (std::size_t i=0; i<NDIM; ++i) f >> origin[i];
569 double scale=1.0/zoom;
595 if(world.
rank() == 0) {
599 f=fopen(filename.c_str(),
"w");
602 for (
int i0=0; i0<npoints; i0++) {
603 for (
int i1=0; i1<npoints; i1++) {
605 coord[cc1]=lo+origin[cc1]+i0*stepsize;
606 coord[cc2]=lo+origin[cc2]+i1*stepsize;
609 fprintf(f,
"%12.6f %12.6f %12.6f\n",coord[cc1],coord[cc2],
614 if (output_type==
"gnuplot") fprintf(f,
"\n");
621 filename=
"mra_structure_"+c1+c2+
"_"+name;
622 function.get_impl()->print_plane(filename.c_str(),cc1,cc2,coord);
627 std::ostringstream o;
638 template<
size_t NDIM>
655 const double maxrank=40.0;
656 double hue=0.7-(0.7/maxrank)*(rank);
662 static void print_psdot(FILE *f,
double x,
double y,
double color) {
663 fprintf(f,
"\\newhsbcolor{mycolor}{%8.4f 1.0 0.7}\n",color);
664 fprintf(f,
"\\psdot[linecolor=mycolor](%12.8f,%12.8f)\n",x,y);
668 static coord_3d
circle2(
double lo,
double hi,
double radius, coord_3d el2,
long npt,
long ipt) {
670 double phi=ipt*stepsize;
674 coord[0]=radius *
sin(phi);
675 coord[1]=radius *
cos(phi);
680 static coord_6d
circle_6d(
const coord_6d& lo,
const coord_6d& hi,
double radius, coord_3d el2,
long npt,
long ipt) {
688 coord[0]=radius *
sin(phi);
689 coord[1]=radius *
cos(phi);
717 const coordT step=(hi-
lo)*(1.0/npt);
718 coordT coord=lo+step*ipt;
737 coordT
lo(0.0),
hi(0.0);
744 return curve(start,end,radius,el2,npt,ipt);
752 template<
size_t NDIM>
755 const int npt=traj.
npt;
757 const bool psdot=
false;
759 if(world.
rank() == 0) {
760 f = fopen(filename.c_str(),
"w");
765 fprintf(f,
"\\psset{xunit=0.1cm}\n");
766 fprintf(f,
"\\psset{yunit=10cm}\n");
767 fprintf(f,
"\\begin{pspicture}(0,-0.3)(100,1.0)\n");
768 fprintf(f,
"\\pslinewidth=0.05pt\n");
772 for (
int ipt=0; ipt<npt; ipt++) {
775 long rank=
function.evalR(coord);
778 fprintf(f,
"%4i %12.6f\n",ipt,
function(coord));
783 if (psdot) fprintf(f,
"\\end{pspicture}\n");
793 template<
size_t NDIM>
796 const int npt=traj.
npt;
798 const bool psdot=
false;
800 if(world.
rank() == 0) {
801 f = fopen(filename.c_str(),
"w");
805 fprintf(f,
"\\psset{xunit=0.05cm}\n");
806 fprintf(f,
"\\psset{yunit=100cm}\n");
807 fprintf(f,
"\\begin{pspicture}(0,0.25)(100,0.3)\n");
808 fprintf(f,
"\\pslinewidth=0.005pt\n");
813 for (
int ipt=0; ipt<npt; ipt++) {
822 fprintf(f,
"%4i %12.6f\n",ipt, ff(coord));
827 if (psdot) fprintf(f,
"\\end{pspicture}\n");
840 #endif // MADNESS_MRA_FUNCPLOT_H__INCLUDED
WorldGopInterface & gop
Global operations.
Definition: worldfwd.h:462
trajectory(double radius, long npt)
Definition: funcplot.h:708
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
const double pi
Mathematical constant pi.
Definition: constants.h:44
std::complex< double > double_complex
Definition: lineplot.cc:16
double imag(double x)
Definition: complexfun.h:56
double radius
Definition: funcplot.h:645
coord_3d el2
Definition: funcplot.h:648
const int NDIM
Definition: tdse1.cc:44
Definition: funcplot.h:639
Future< T > eval(const coordT &xuser) const
Evaluates the function at a point in user coordinates. Possible non-blocking comm.
Definition: mra.h:185
std::istream & position_stream(std::istream &f, const std::string &tag)
Definition: position_stream.cc:37
trajectory(double radius, coord_3d el2, long npt)
Definition: funcplot.h:712
const double L
Definition: 3dharmonic.cc:123
void plotdx(const Function< T, NDIM > &f, const char *filename, const Tensor< double > &cell=FunctionDefaults< NDIM >::get_cell(), const std::vector< long > &npt=std::vector< long >(NDIM, 201L), bool binary=true)
Writes an OpenDX format file with a cube/slice of points on a uniform grid.
Definition: mraimpl.h:3228
::std::string string
Definition: gtest-port.h:872
Defines common mathematical and physical constants.
const mpreal cos(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2255
Definition: indexit.h:180
Vector< double, 3 > coord_3d
Definition: funcplot.h:634
NDIM & f
Definition: mra.h:2179
ProcessID size() const
Returns the number of processes in this world (same as MPI_Comm_size())
Definition: worldfwd.h:533
Vector< double, NDIM > operator()(int ipt)
Definition: funcplot.h:743
Vector< double, 3 > coordT
Definition: chem/corepotential.cc:57
void plot_plane(World &world, const Function< double, NDIM > &function, const std::string name)
Definition: funcplot.h:531
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only) ...
Definition: tensor.h:2429
double lo
Definition: funcplot.h:643
coordT start
Definition: funcplot.h:647
static double hueCode(const int rank)
some tools for plotting MRA ranks of low order tensors
Definition: funcplot.h:654
static coord_3d circle2(double lo, double hi, double radius, coord_3d el2, long npt, long ipt)
Definition: funcplot.h:668
void plot_along(World &world, trajectory< NDIM > traj, const Function< double, NDIM > &function, std::string filename)
Definition: funcplot.h:753
Vector< double, NDIM > coordT
Definition: funcplot.h:641
World & world() const
Returns the world.
Definition: mra.h:622
static Vector< double, NDIM > line_internal(const coordT &lo, const coordT &hi, double radius, coord_3d el2, long npt, long ipt)
Definition: funcplot.h:716
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
#define max(a, b)
Definition: lda.h:53
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition: vmra.h:290
void reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm...
Definition: mra.h:737
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
coordT(* curve)(const coordT &lo, const coordT &hi, double radius, coord_3d el2, long npt, long ipt)
Definition: funcplot.h:649
static void print_psdot(FILE *f, double x, double y, double color)
Definition: funcplot.h:662
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
void plotvtk_begin(World &world, const char *filename, const Vector< double, NDIM > &plotlo, const Vector< double, NDIM > &plothi, const Vector< long, NDIM > &npt, bool binary=false)
Definition: funcplot.h:97
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
void fence()
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition: worldgop.cc:52
A multiresolution adaptive numerical function.
Definition: derivative.h:61
Vector< double, 6 > coord_6d
Definition: funcplot.h:635
void barrier()
Synchronizes all processes in communicator ... does NOT fence pending AM or tasks.
Definition: worldgop.h:657
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
const mpreal sin(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2262
ProcessID rank() const
Returns the process rank in this world (same as MPI_Comm_rank()))
Definition: worldfwd.h:526
double real(double x)
Definition: complexfun.h:52
static trajectory line_xyz(const int xyz, const long npt)
EZ ctor for a line a direction xyz={0,1,2,..,NDIM-1} thru the origin.
Definition: funcplot.h:735
void plot_line(const char *filename, int npt, const Vector< double, NDIM > &lo, const Vector< double, NDIM > &hi, const Function< T, NDIM > &f)
Generates ASCII file tabulating f(r) at npoints along line r=lo,...,hi.
Definition: funcplot.h:388
static trajectory line2(const coordT start, const coordT end, const long npt)
constructor for a line
Definition: funcplot.h:725
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition: funcdefaults.h:391
static coord_6d circle_6d(const coord_6d &lo, const coord_6d &hi, double radius, coord_3d el2, long npt, long ipt)
Definition: funcplot.h:680
long npt
Definition: funcplot.h:646
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
unsigned short htons_x(unsigned short a)
Definition: funcplot.h:322
void plotvtk_end(World &world, const char *filename, bool binary=false)
Definition: funcplot.h:300
coordT end
Definition: funcplot.h:647
double hi
Definition: funcplot.h:644
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
trajectory()
Definition: funcplot.h:702
void plotvtk_data(const T &function, const char *fieldname, World &world, const char *filename, const Vector< double, NDIM > &plotlo, const Vector< double, NDIM > &plothi, const Vector< long, NDIM > &npt, bool binary=false)
Definition: funcplot.h:176
#define PROFILE_FUNC
Definition: worldprofile.h:198