41 bool SpaceGrid::put(xmlNodePtr cur, std::map<std::string, Point>& points,
bool is_periodic,
bool abort_on_fail)
44 bool succeeded =
true;
48 int npundef = -100000;
55 ga.
add(ref,
"reference");
58 if (
coord ==
"cartesian")
60 else if (
coord ==
"cylindrical")
62 else if (
coord ==
"spherical")
64 else if (
coord ==
"voronoi")
68 app_log() <<
" Coordinate supplied to spacegrid must be cartesian, cylindrical, spherical, or voronoi" 79 else if (ref ==
"vacuum")
81 else if (ref ==
"neutral")
85 app_log() << ref <<
" is not a valid reference, choose vacuum or neutral." << std::endl;
99 APP_ABORT(
"SpaceGrid::put(): A rectilinear grid must be referenced to vacuum");
108 succeeded = succeeded && init_success;
114 if (abort_on_fail && !succeeded)
124 bool succeeded =
true;
128 origin = points[
"center"];
136 for (
int d = 0; d <
DIM; d++)
139 nearcell[i].r = std::numeric_limits<RealType>::max();
150 const std::vector<RealType>& Z = *
Zptcl;
163 app_log() <<
" Pstatic must be specified for a Voronoi grid" << std::endl;
172 bool succeeded =
true;
173 std::string ax_cartesian[
DIM] = {
"x",
"y",
"z"};
174 std::string ax_cylindrical[
DIM] = {
"r",
"phi",
"z"};
175 std::string ax_spherical[
DIM] = {
"r",
"phi",
"theta"};
176 std::map<std::string, int> cmap;
180 for (
int d = 0; d <
DIM; d++)
182 cmap[ax_cartesian[d]] = d;
187 for (
int d = 0; d <
DIM; d++)
189 cmap[ax_cylindrical[d]] = d;
190 axlabel[d] = ax_cylindrical[d];
195 for (
int d = 0; d <
DIM; d++)
197 cmap[ax_spherical[d]] = d;
206 xmlNodePtr element = cur->children;
207 std::string undefined =
"";
210 bool has_origin =
false;
215 std::vector<int> ndu_per_interval[
DIM];
216 while (element != NULL)
218 std::string name = (
const char*)element->name;
220 std::string p1 = undefined;
221 std::string p2 =
"zero";
222 std::string fraction = undefined;
224 std::string scale = undefined;
225 std::string label = undefined;
230 ea->add(fraction,
"fraction");
231 ea->add(scale,
"scale");
232 ea->add(label,
"label");
234 ea->add(agrid,
"grid");
237 if (name ==
"origin")
241 app_log() <<
" p1 must be defined in spacegrid element " << name << std::endl;
246 app_log() <<
" spacegrid must contain at most one origin element" << std::endl;
251 if (fraction == undefined)
255 origin = points[p1] + frac * (points[p2] - points[p1]);
257 else if (name ==
"axis")
261 app_log() <<
" p1 must be defined in spacegrid element " << name << std::endl;
267 app_log() <<
" spacegrid must contain " <<
DIM <<
" axes, " << naxes <<
"provided" << std::endl;
270 if (cmap.find(label) == cmap.end())
272 app_log() <<
" grid label " << label <<
" is invalid for " <<
coord <<
" coordinates" << std::endl;
273 app_log() <<
" valid options are: ";
274 for (
int d = 0; d <
DIM; d++)
280 if (scale == undefined)
284 for (
int d = 0; d <
DIM; d++)
285 axes(d, iaxis) = frac * (points[p1][d] - points[p2][d]);
289 bool inparen =
false;
291 for (
int i = 0; i < grid.size(); i++)
299 if (!(inparen && gc ==
' '))
309 std::vector<std::string> tokens =
split(grid,
" ");
312 for (
int i = 0; i < tokens.size(); i++)
313 if (tokens[i][0] !=
'(')
317 std::vector<int> ndom_int, ndu_int;
318 std::vector<RealType> du_int;
319 ndom_int.resize(nintervals);
320 du_int.resize(nintervals);
321 ndu_int.resize(nintervals);
327 app_log() <<
" interval endparticles cannot be greater than " << 1 << std::endl;
328 app_log() <<
" endpoint provided: " << u1 << std::endl;
332 bool has_paren_val =
false;
336 for (
int i = 1; i < tokens.size(); i++)
338 if (tokens[i][0] !=
'(')
344 has_paren_val =
false;
348 app_log() <<
" interval (" << u1 <<
"," << u2 <<
") is negative" << std::endl;
353 app_log() <<
" interval endparticles cannot be greater than " << 1 << std::endl;
354 app_log() <<
" endpoint provided: " << u2 << std::endl;
359 du_int[interval] = (u2 - u1) / ndom_i;
360 ndom_int[interval] = ndom_i;
364 du_int[interval] = du_i;
365 ndom_int[interval] =
floor((u2 - u1) / du_i + .5);
366 if (
std::abs(u2 - u1 - du_i * ndom_int[interval]) > utol)
368 app_log() <<
" interval (" << u1 <<
"," << u2 <<
") not divisible by du=" << du_i << std::endl;
376 has_paren_val =
true;
377 std::string paren_val = tokens[i].substr(1, tokens[i].length() - 2);
378 is_int = tokens[i].find(
".") == std::string::npos;
393 for (
int i = 0; i < du_int.size(); i++)
394 du_min =
std::min(du_min, du_int[i]);
395 odu[iaxis] = 1.0 / du_min;
397 for (
int i = 0; i < du_int.size(); i++)
399 ndu_int[i] =
floor(du_int[i] / du_min + .5);
400 if (
std::abs(du_int[i] - ndu_int[i] * du_min) > utol)
402 app_log() <<
"interval " << i + 1 <<
" of axis " << iaxis + 1 <<
" is not divisible by smallest subinterval " 403 << du_min << std::endl;
411 for (
int i = 0; i < ndom_int.size(); i++)
412 for (
int j = 0; j < ndom_int[i]; j++)
415 for (
int k = 0; k < ndu_int[i]; k++)
426 for (
int i = 0; i < ndom_int.size(); i++)
427 ndom_tot += ndom_int[i];
428 ndu_per_interval[iaxis].resize(ndom_tot);
430 for (
int i = 0; i < ndom_int.size(); i++)
431 for (
int ii = 0; ii < ndom_int[i]; ii++)
433 ndu_per_interval[iaxis][idom] = ndu_int[i];
438 element = element->next;
442 app_log() <<
" spacegrid must contain " <<
DIM <<
" axes, " << iaxis + 1 <<
"provided" << std::endl;
447 std::map<std::string, int> cartmap;
448 for (
int d = 0; d <
DIM; d++)
450 cartmap[ax_cartesian[d]] = d;
452 for (
int d = 0; d <
DIM; d++)
454 if (cartmap.find(
axlabel[d]) != cartmap.end())
456 if (
umin[d] < -1.0 ||
umax[d] > 1.0)
458 app_log() <<
" grid values for " <<
axlabel[d] <<
" must fall in [-1,1]" << std::endl;
459 app_log() <<
" interval provided: [" <<
umin[d] <<
"," <<
umax[d] <<
"]" << std::endl;
467 app_log() <<
" phi interval cannot be longer than 1" << std::endl;
476 app_log() <<
" grid values for " <<
axlabel[d] <<
" must fall in [0,1]" << std::endl;
477 app_log() <<
" interval provided: [" <<
umin[d] <<
"," <<
umax[d] <<
"]" << std::endl;
497 std::vector<RealType> interval_centers[
DIM];
498 std::vector<RealType> interval_widths[
DIM];
499 for (
int d = 0; d <
DIM; d++)
501 int nintervals = ndu_per_interval[d].size();
502 app_log() <<
"nintervals " << d <<
" " << nintervals << std::endl;
503 interval_centers[d].resize(nintervals);
504 interval_widths[d].resize(nintervals);
505 interval_widths[d][0] = ndu_per_interval[d][0] /
odu[d];
506 interval_centers[d][0] = interval_widths[d][0] / 2.0 +
umin[d];
507 for (
int i = 1; i < nintervals; i++)
509 interval_widths[d][i] = ndu_per_interval[d][i] /
odu[d];
510 interval_centers[d][i] = interval_centers[d][i - 1] + .5 * (interval_widths[d][i] + interval_widths[d][i - 1]);
519 Point du, uc, ubc, rc;
528 int idomain =
dm[0] * i +
dm[1] * j +
dm[2] * k;
529 du[0] = interval_widths[0][i];
530 du[1] = interval_widths[1][j];
531 du[2] = interval_widths[2][k];
532 uc[0] = interval_centers[0][i];
533 uc[1] = interval_centers[1][j];
534 uc[2] = interval_centers[2][k];
538 vol = du[0] * du[1] * du[2];
542 uc[1] = 2.0 * M_PI * uc[1] - M_PI;
543 du[1] = 2.0 * M_PI * du[1];
544 vol = uc[0] * du[0] * du[1] * du[2];
545 ubc[0] = uc[0] *
cos(uc[1]);
546 ubc[1] = uc[0] *
sin(uc[1]);
550 uc[1] = 2.0 * M_PI * uc[1] - M_PI;
551 du[1] = 2.0 * M_PI * du[1];
552 uc[2] = M_PI * uc[2];
553 du[2] = M_PI * du[2];
554 vol = (uc[0] * uc[0] + du[0] * du[0] / 12.0) * du[0]
556 * 2.0 *
sin(uc[2]) *
sin(.5 * du[2]);
557 ubc[0] = uc[0] *
sin(uc[2]) *
cos(uc[1]);
558 ubc[1] = uc[0] *
sin(uc[2]) *
sin(uc[1]);
559 ubc[2] = uc[0] *
cos(uc[2]);
572 for (
int d = 0; d <
DIM; d++)
603 for (
int d = 0; d <
DIM; d++)
611 vol = du[0] * du[1] * du[2];
614 uc[1] = 2.0 * M_PI * uc[1] - M_PI;
615 du[1] = 2.0 * M_PI * du[1];
616 vol = uc[0] * du[0] * du[1] * du[2];
619 uc[1] = 2.0 * M_PI * uc[1] - M_PI;
620 du[1] = 2.0 * M_PI * du[1];
621 uc[2] = M_PI * uc[2];
622 du[2] = M_PI * du[2];
623 vol = (uc[0] * uc[0] + du[0] * du[0] / 12.0) * du[0]
625 * 2.0 *
sin(uc[2]) *
sin(.5 * du[2]);
644 os << indent +
"SpaceGrid" << std::endl;
660 os << indent +
" coordinates = " +
s << std::endl;
661 os << indent +
" buffer_offset = " <<
buffer_offset << std::endl;
662 os << indent +
" ndomains = " <<
ndomains << std::endl;
663 os << indent +
" axes = " <<
axes << std::endl;
664 os << indent +
" axinv = " <<
axinv << std::endl;
665 for (
int d = 0; d <
DIM; d++)
667 os << indent +
" axis " <<
axlabel[d] <<
":" << std::endl;
668 os << indent +
" umin = " <<
umin[d] << std::endl;
669 os << indent +
" umax = " <<
umax[d] << std::endl;
670 os << indent +
" du = " << 1.0 /
odu[d] << std::endl;
671 os << indent +
" dm = " <<
dm[d] << std::endl;
672 os << indent +
" gmap = ";
673 for (
int g = 0; g <
gmap[d].size(); g++)
675 os <<
gmap[d][g] <<
" ";
679 os << indent +
"end SpaceGrid" << std::endl;
689 buf.
add(tmp.begin(), tmp.end());
696 buf.
add(tmp.begin(), tmp.end());
708 std::vector<int> ng(1);
710 std::stringstream ss;
711 ss << grid_index + cshift;
712 std::string name =
"spacegrid" + ss.str();
713 h5desc.push_back({{name}});
714 auto&
oh = h5desc.back();
736 oh.
addProperty(const_cast<iMatrix&>(imat),
"reference_count", file);
745 std::map<std::string, int> axtmap;
753 for (
int d = 0; d <
DIM; d++)
755 axtypes[d] = axtmap[
axlabel[d]];
760 std::string iname[ni];
762 ivar[
n] = (
int*)axtypes;
763 iname[
n] =
"axtypes";
766 iname[
n] =
"dimensions";
773 std::string rname[nr];
785 for (
int i = 0; i < ni; i++)
787 for (
int d = 0; d <
DIM; d++)
788 imat(d, 0) = ivar[i][d];
793 for (
int i = 0; i < nr; i++)
795 for (
int d = 0; d <
DIM; d++)
796 rmat(d, 0) = rvar[i][d];
799 for (
int d = 0; d <
DIM; d++)
801 int gsize =
gmap[d].size();
802 imat.resize(gsize, 1);
803 for (
int i = 0; i < gsize; i++)
805 int gval =
gmap[d][i];
809 std::string gmname =
"gmap" +
int2string(ival);
818 #define SPACEGRID_CHECK 824 std::vector<bool>& particles_outside,
828 int nparticles = values.
size1();
829 int nvalues = values.
size2();
832 const RealType o2pi = 1.0 / (2.0 * M_PI);
840 for (p = 0; p < nparticles; p++)
842 particles_outside[p] =
false;
844 for (
int d = 0; d <
DIM; ++d)
847 for (
int d = 0; d <
DIM; ++d)
848 buf_index += nvalues *
dm[d] * iu[d];
849 for (v = 0; v < nvalues; v++, buf_index++)
850 buf[buf_index] += values(p, v);
855 for (p = 0; p < nparticles; p++)
860 particles_outside[p] =
false;
865 for (v = 0; v < nvalues; v++, buf_index++)
866 buf[buf_index] += values(p, v);
872 for (p = 0; p < nparticles; p++)
880 particles_outside[p] =
false;
885 for (v = 0; v < nvalues; v++, buf_index++)
886 buf[buf_index] += values(p, v);
891 for (p = 0; p < nparticles; p++)
896 u[2] =
acos(
ub[2] /
u[0]) * o2pi * 2.0;
899 particles_outside[p] =
false;
904 for (v = 0; v < nvalues; v++, buf_index++)
905 buf[buf_index] += values(p, v);
927 for (v = 0; v < nvalues; v++, buf_index++)
928 buf[buf_index] += values(p, v);
933 for (v = 0; v < nvalues; v++, buf_index++)
934 buf[buf_index] += values(p, v);
936 for (p = 0; p < nparticles; p++)
937 particles_outside[p] =
false;
940 nearcell[p].r = std::numeric_limits<RealType>::max();
943 app_log() <<
" coordinate type must be cartesian, cylindrical, spherical, or voronoi" << std::endl;
956 for (p = 0; p < nparticles; p++)
961 particles_outside[p] =
false;
965 cell_index =
dm[0] * iu[0] +
dm[1] * iu[1] +
dm[2] * iu[2];
966 for (v = 0; v < nvalues; v++)
973 for (p = 0; p < nparticles; p++)
981 particles_outside[p] =
false;
985 cell_index =
dm[0] * iu[0] +
dm[1] * iu[1] +
dm[2] * iu[2];
986 for (v = 0; v < nvalues; v++)
993 for (p = 0; p < nparticles; p++)
998 u[2] =
acos(
ub[2] /
u[0]) * o2pi * 2.0;
1001 particles_outside[p] =
false;
1005 cell_index =
dm[0] * iu[0] +
dm[1] * iu[1] +
dm[2] * iu[2];
1006 for (v = 0; v < nvalues; v++)
1016 APP_ABORT(
"SoA transformation needed for Voronoi grids")
1031 for (v = 0; v < nvalues; v++)
1036 for (p =
ndparticles, cell_index = 0; p < nparticles; p++, cell_index++)
1038 for (v = 0; v < nvalues; v++)
1043 for (p = 0; p < nparticles; p++)
1044 particles_outside[p] =
false;
1047 nearcell[p].r = std::numeric_limits<RealType>::max();
1050 app_log() <<
" coordinate type must be cartesian, cylindrical, spherical, or voronoi" << std::endl;
1063 for (v = 0; v < nvalues; v++, buf_index++)
1081 vals[v] += buf[
n + v];
1089 app_log() <<
"SpaceGrid::check_grid" << std::endl;
1090 const RealType o2pi = 1.0 / (2.0 * M_PI);
1097 for (
int d = 0; d <
DIM; d++)
1113 u[2] =
acos(
ub[2] /
u[0]) * o2pi * 2.0;
1121 idomain =
dm[0] * iu[0] +
dm[1] * iu[1] +
dm[2] * iu[2];
1124 app_log() <<
" cell mismatch " << i <<
" " << idomain << std::endl;
1130 app_log() <<
" SpaceGrid cells do not map onto themselves" << std::endl;
1132 app_log() <<
"end SpaceGrid::check_grid" << std::endl;
Tensor< RealType, DIM > axinv
Container_t::iterator begin()
size_type size() const
return the size of the data
enum qmcplusplus::SpaceGrid::@61 coordinate
helper functions for EinsplineSetBuilder
std::vector< int > reference_count
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
const DistRow & getDistRow(int iel) const
return a row of distances for a given target particle
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
bool put(xmlNodePtr cur)
assign attributes to the set
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
std::string int2string(const int &i)
void addProperty(T &p, const std::string &pname, hdf_archive &file)
add named property to describe the collectable this helper class handles
void resize(size_type n, size_type m)
Resize the container.
Attaches a unit to a Vector for IO.
Matrix< RealType > cellsamples
void write_description(std::ostream &os, std::string &indent)
void sum(const BufferType &buf, RealType *vals)
void evaluate(const ParticlePos &R, const Matrix< RealType > &values, BufferType &buf, std::vector< bool > &particles_outside, const DistanceTableAB &dtab)
int string2int(const std::string &s)
size_type size() const
return the current size
MakeReturn< UnaryNode< FnCos, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t cos(const Vector< T1, C1 > &l)
std::vector< std::string > split(const std::string &s)
MakeReturn< UnaryNode< FnArcCos, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t acos(const Vector< T1, C1 > &l)
MakeReturn< BinaryNode< FnArcTan2, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t atan2(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
AB type of DistanceTable containing storage.
Matrix< RealType > domain_volumes
class to handle a set of attributes of an xmlNode
double string2real(const std::string &s)
int allocate_buffer_space(BufferType &buf)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
std::vector< int > gmap[DIM]
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file, int grid_index) const
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
std::vector< RealType > * Zptcl
std::vector< irpair > nearcell
Tensor< T, D > inverse(const Tensor< T, D > &a)
void set_dimensions(const std::vector< int > &dims, int first)
set the shape of this observable
enum qmcplusplus::SpaceGrid::@62 reference
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
Container_t::iterator end()
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Matrix< RealType > domain_centers
bool initialize_voronoi(std::map< std::string, Point > &points)
bool initialize_rectilinear(xmlNodePtr cur, std::string &coord, std::map< std::string, Point > &points)
Matrix< RealType > domain_uwidths
Tensor< RealType, DIM > axes
bool put(xmlNodePtr cur, std::map< std::string, Point > &points, ParticlePos &R, std::vector< RealType > &Z, int ndp, bool is_periodic, bool abort_on_fail=true)
MakeReturn< UnaryNode< FnFloor, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t floor(const Vector< T1, C1 > &l)