LRTwoBodyJastrow::ValueType LRTwoBodyJastrow::logRatio(ParticleSet& P, int iat, ParticleSet::ParticleGradient_t& dG, ParticleSet::ParticleLaplacian_t& dL) { NeedToRestore=true; const KContainer::VContainer_t& kpts(P.SK->KLists.kpts_cart); const KContainer::SContainer_t& ksq(P.SK->KLists.ksq); const Vector<ComplexType>& eikr1(P.SK->eikr_new); const Vector<ComplexType>& del_eikr(P.SK->delta_eikr); //add the difference Rhok += del_eikr; curVal=0.0; curLap=0.0; curGrad=0.0; for(int jat=0;jat<NumPtcls; jat++) { if(iat==jat) { for(int ki=0; ki<NumKpts; ki++) { //ComplexType rhok_new(Rhok[ki]+del_eikr[ki]); //ComplexType skp((Fk[ki]*conj(eikr1[ki])*rhok_new)); ComplexType skp((Fk[ki]*conj(eikr1[ki])*Rhok[ki])); #if defined(QMC_COMPLEX) curVal += skp; curGrad += ComplexType(skp.imag(),-skp.real())*kpts[ki]; curLap += ksq[ki]*(Fk[ki]-skp); #else curVal += skp.real(); curGrad += kpts[ki]*skp.imag(); curLap += ksq[ki]*(Fk[ki]-skp.real()); #endif } } else { const ComplexType* restrict eikrj(P.SK->eikr[jat]); GradType g; ValueType l(0.0), v(0.0); for(int ki=0; ki<NumKpts; ki++) { ComplexType skp(Fk[ki]*del_eikr[ki]*conj(eikrj[ki])); GradType dg(skp.imag()*kpts[ki]); ValueType dl(skp.real()*ksq[ki]); v += skp.real(); g +=dg; l -= dl; //dG[jat] += Fk[ki]*skp.imag()*kpts[ki]; //dL[jat] -= Fk[ki]*skp.real()*ksq[ki]; } offU[jat]=v; offdU[jat]=g; offd2U[jat]=l; dG[jat] += g; dL[jat] += l; } } dG[iat] += offdU[iat] = curGrad-dU[iat]; dL[iat] += offd2U[iat] = curLap-d2U[iat]; return offU[iat] = curVal-U[iat]; }
void onDrawContent(SkCanvas* canvas) override { GraphicsPort skp(canvas); doDraw(&skp); const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); std::unique_ptr<SkCanvas> c2 = SkRasterHandleAllocator::MakeCanvas(skstd::make_unique<MyAllocator>(), info); MyPort cgp(c2.get()); doDraw(&cgp); SkPixmap pm; c2->peekPixels(&pm); SkBitmap bm; bm.installPixels(pm); canvas->drawBitmap(bm, 280, 0, nullptr); }
LRTwoBodyJastrow::ValueType LRTwoBodyJastrow::ratio(ParticleSet& P, int iat) { //restore, if called should do nothing NeedToRestore=false; curVal=0.0; const KContainer::VContainer_t& kpts(P.SK->KLists.kpts_cart); const Vector<ComplexType>& eikr1(P.SK->eikr_new); const Vector<ComplexType>& del_eikr(P.SK->delta_eikr); //Rhok += del_eikr; for(int ki=0; ki<NumKpts; ki++) { //ComplexType skp((Fk[ki]*conj(eikr1[ki])*Rhok[ki])); ComplexType skp((Fk[ki]*conj(eikr1[ki])*(Rhok[ki]+del_eikr[ki]))); #if defined(QMC_COMPLEX) curVal += skp; #else curVal += skp.real(); #endif } return std::exp(curVal-U[iat]); }
LRTwoBodyJastrow::ValueType LRTwoBodyJastrow::evaluateLog(ParticleSet& P, ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) { Rhok=0.0; for(int spec1=0; spec1<NumSpecies; spec1++) { const ComplexType* restrict rhok(P.SK->rhok[spec1]); for(int ki=0; ki<NumKpts; ki++) { Rhok[ki] += rhok[ki]; } } const KContainer::VContainer_t& kpts(P.SK->KLists.kpts_cart); const KContainer::SContainer_t& ksq(P.SK->KLists.ksq); ValueType sum(0.0); for(int iat=0; iat<NumPtcls; iat++) { ValueType res(0.0),l(0.0); GradType g; const ComplexType* restrict eikr(P.SK->eikr[iat]); for(int ki=0; ki<NumKpts; ki++) { ComplexType skp((Fk[ki]*conj(eikr[ki])*Rhok[ki])); #if defined(QMC_COMPLEX) res += skp; l += ksq[ki]*(Fk[ki]-skp); g += ComplexType(skp.imag(),-skp.real())*kpts[ki]; #else res += skp.real(); g += kpts[ki]*skp.imag(); l += ksq[ki]*(Fk[ki]-skp.real()); #endif } sum+=(U[iat]=res); G[iat]+=(dU[iat]=g); L[iat]+=(d2U[iat]=l); } return sum*0.5; }
static void client(const char* skpPath, const char* dataEndpoint) { // Read the .skp. SkAutoTUnref<const SkData> skp(SkData::NewFromFileName(skpPath)); if (!skp) { SkDebugf("Couldn't read %s\n", skpPath); exit(1); } SkMemoryStream stream(skp->data(), skp->size()); sk_sp<SkPicture> picture(SkPicture::MakeFromStream(&stream)); PictureHeader header; SkRandom rand(picture->cullRect().width() * picture->cullRect().height()); SkScalar r = rand.nextRangeScalar(0, picture->cullRect().width()), b = rand.nextRangeScalar(0, picture->cullRect().height()), l = rand.nextRangeScalar(0, r), t = rand.nextRangeScalar(0, b); header.clip.setLTRB(l,t,r,b); header.matrix.setTranslate(-l, -t); header.matrix.postRotate(rand.nextRangeScalar(-25, 25)); header.alpha = 0x7F; //Clients use NN_REQ (request) type sockets. int socket = nn_socket(AF_SP, NN_REQ); // Clients connect a socket to an endpoint. nn_connect(socket, dataEndpoint); // Send the picture and its header. SkDebugf("Sending %s (%d bytes)...", skpPath, skp->size()); send_picture(socket, header, *skp); // Wait for ack. uint8_t ack; nn_recv(socket, &ack, sizeof(ack), 0/*flags*/); SkDebugf(" ok.\n"); }