Move read_splines and write_splines to the adoptors.

git-svn-id: https://subversion.assembla.com/svn/qmcdev/trunk@5738 e5b18d87-469d-4833-9cc0-8cdfa06e9491
This commit is contained in:
Jeongnim Kim 2013-02-25 17:55:11 +00:00
parent bc787cc763
commit 83c69b755d
5 changed files with 104 additions and 33 deletions

View File

@ -236,10 +236,7 @@ namespace qmcplusplus {
foundspline = (sizeD == sizeof(typename adoptor_type::DataType));
}
if(foundspline)
{
einspline_engine<SplineType> bigtable(bspline->MultiSpline);
foundspline=h5f.read(bigtable,"spline_0");
}
bspline->read_splines(h5f);
}
myComm->bcast(foundspline);
t_h5 = now.elapsed();
@ -331,11 +328,10 @@ namespace qmcplusplus {
{
hdf_archive h5f;
h5f.create(splinefile);
einspline_engine<SplineType> bigtable(bspline->MultiSpline);
h5f.write(bspline->AdoptorName,"adoptor_name");
int sizeD=sizeof(typename adoptor_type::DataType);
h5f.write(sizeD,"sizeof");
h5f.write(bigtable,"spline_0");
bspline->write_splines(h5f);
}
}

View File

@ -84,6 +84,18 @@ namespace qmcplusplus {
einspline::set(MultiSpline, 2*ival+1,spline_i, BaseOffset, BaseN);
}
bool read_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.read(bigtable,"spline_0");
}
bool write_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.write(bigtable,"spline_0");
}
inline int convertPos(const PointType& r, PointType& ru)
{
ru=PrimLattice.toUnit(r);
@ -239,7 +251,6 @@ namespace qmcplusplus {
}
}
void set_spline(ST* restrict psi_r, ST* restrict psi_i, int ival)
{
einspline::set(MultiSpline, 2*ival, psi_r);
@ -251,6 +262,18 @@ namespace qmcplusplus {
einspline::set(MultiSpline, 2*ival,spline_r, BaseOffset, BaseN);
einspline::set(MultiSpline, 2*ival+1,spline_i, BaseOffset, BaseN);
}
bool read_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.read(bigtable,"spline_0");
}
bool write_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.write(bigtable,"spline_0");
}
inline int convertPos(const PointType& r, PointType& ru)
{

View File

@ -14,6 +14,48 @@
namespace qmcplusplus {
template<typename SMA>
struct hdf_dual_grid
{
static bool read(SMA* bspline, hdf_archive& h5f)
{
TinyVector<double,3> lower_in;
TinyVector<double,3> upper_in;
h5f.read(lower_in,"lower_bound");
h5f.read(upper_in,"upper_bound");
bool foundspline=true;
lower_in-=bspline->Lower; upper_in-=bspline->Upper;
if(dot(lower_in,lower_in)<1e-12 &&dot(upper_in,upper_in)<1e-12)
{
einspline_engine<typename SMA::SplineType> bigtable(bspline->MultiSpline);
einspline_engine<typename SMA::SplineType> smalltable(bspline->smallBox);
foundspline=h5f.read(bigtable,"spline_0");
foundspline=h5f.read(smalltable,"spline_1");
}
else
{
app_log() << " The upper/lower bound of the input is different from the current value."<< endl;
foundspline=0;
}
return foundspline;
}
static bool write(SMA* bspline, hdf_archive& h5f)
{
einspline_engine<typename SMA::SplineType> bigtable(bspline->MultiSpline);
einspline_engine<typename SMA::SplineType> smalltable(bspline->smallBox);
TinyVector<double,3> lower(bspline->Lower);
TinyVector<double,3> upper(bspline->Upper);
int doneit=1;
doneit=h5f.write(lower,"lower_bound");
doneit=h5f.write(upper,"upper_bound");
doneit=h5f.write(bigtable,"spline_0");
doneit=h5f.write(smalltable,"spline_1");
return doneit;
}
};
/** adoptor class to match ST real spline with TT real SPOs
* @tparam ST precision of spline
* @tparam TT precision of SPOs
@ -26,6 +68,7 @@ namespace qmcplusplus {
typedef typename einspline_traits<ST,D>::BCType BCType;
typedef typename einspline_traits<ST,D>::DataType DataType;
typedef typename SplineAdoptorBase<ST,D>::PointType PointType;
typedef SplineMixedAdoptor<ST,TT,D> ThisType;
using SplineAdoptorBase<ST,D>::HalfG;
using SplineAdoptorBase<ST,D>::GGt;
@ -79,6 +122,16 @@ namespace qmcplusplus {
MultiSpline=einspline::create(dummy,xyz_grid,xyz_bc,n);
}
bool read_splines(hdf_archive& h5f)
{
return hdf_dual_grid<ThisType>::read(this,h5f);
}
bool write_splines(hdf_archive& h5f)
{
return hdf_dual_grid<ThisType>::write(this,h5f);
}
template <typename UBspline, typename PT>
void add_box(UBspline* dense, PT& lower, PT& upper)
{
@ -147,6 +200,7 @@ namespace qmcplusplus {
typedef typename einspline_traits<ST,D>::BCType BCType;
typedef typename einspline_traits<ST,D>::DataType DataType;
typedef typename SplineAdoptorBase<ST,D>::PointType PointType;
typedef SplineOpenAdoptor<ST,TT,D> ThisType;
using SplineAdoptorBase<ST,D>::SuperLattice;
@ -242,6 +296,16 @@ namespace qmcplusplus {
einspline::set(smallBox,ival,dense,gTransform.Offset,gTransform.N);
}
bool read_splines(hdf_archive& h5f)
{
return hdf_dual_grid<ThisType>::read(this,h5f);
}
bool write_splines(hdf_archive& h5f)
{
return hdf_dual_grid<ThisType>::write(this,h5f);
}
inline bool isready()
{
return true;

View File

@ -163,26 +163,7 @@ namespace qmcplusplus {
}
if(foundspline)
{
TinyVector<double,3> lower_in(end);
TinyVector<double,3> upper_in(start);
h5f.read(lower_in,"lower_bound");
h5f.read(upper_in,"upper_bound");
lower_in-=lower; upper_in-=upper;
if(dot(lower_in,lower_in)<1e-12 &&dot(upper_in,upper_in)<1e-12)
{
einspline_engine<typename adoptor_type::SplineType> bigtable(bspline->MultiSpline);
einspline_engine<typename adoptor_type::SplineType> smalltable(bspline->smallBox);
foundspline=h5f.read(bigtable,"spline_0");
foundspline=h5f.read(smalltable,"spline_1");
}
else
{
app_log() << " The upper/lower bound of the input is different from the current value."<< endl;
foundspline=0;
}
}
foundspline=bspline->read_splines(h5f);
}
myComm->bcast(foundspline);
@ -265,15 +246,10 @@ namespace qmcplusplus {
{
hdf_archive h5f;
h5f.create(splinefile);
einspline_engine<typename adoptor_type::SplineType> bigtable(bspline->MultiSpline);
einspline_engine<typename adoptor_type::SplineType> smalltable(bspline->smallBox);
h5f.write(bspline->AdoptorName,"adoptor_name");
int sizeD=sizeof(typename adoptor_type::DataType);
h5f.write(sizeD,"sizeof");
h5f.write(lower,"lower_bound");
h5f.write(upper,"upper_bound");
h5f.write(bigtable,"spline_0");
h5f.write(smalltable,"spline_1");
bspline->write_splines(h5f);
}
}

View File

@ -96,6 +96,18 @@ namespace qmcplusplus {
einspline::set(MultiSpline, ival,spline_r, BaseOffset,BaseN);
}
bool read_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.read(bigtable,"spline_0");
}
bool write_splines(hdf_archive& h5f)
{
einspline_engine<SplineType> bigtable(MultiSpline);
return h5f.write(bigtable,"spline_0");
}
/** convert postion in PrimLattice unit and return sign */
inline int convertPos(const PointType& r, PointType& ru)
{