void SpinAdapted::InitBlocks::InitStartingBlock (SpinBlock& startingBlock, const bool &forward, int leftState, int rightState, const int & forward_starting_size, const int &backward_starting_size, const int& restartSize, const bool &restart, const bool& warmUp, int integralIndex, const vector<SpinQuantum>& braquanta, const vector<SpinQuantum>& ketquanta) { if (restart && restartSize != 1) { int len = restart? restartSize : forward_starting_size; vector<int> sites(len); if (forward) for (int i=0; i<len; i++) sites[i] = i; else for (int i=0; i<len; i++) sites[i] = dmrginp.last_site() - len +i ; if (restart) SpinBlock::restore (forward, sites, startingBlock, leftState, rightState); else SpinBlock::restore (true, sites, startingBlock, leftState, rightState); } else if (forward) { if(startingBlock.nonactive_orb().size()!=0) startingBlock = SpinBlock(0, forward_starting_size - 1,startingBlock.nonactive_orb() , true); else startingBlock = SpinBlock(0, forward_starting_size - 1, integralIndex, leftState==rightState, true); if (dmrginp.add_noninteracting_orbs() && dmrginp.molecule_quantum().get_s().getirrep() != 0 && dmrginp.spinAdapted()) { SpinQuantum s = dmrginp.molecule_quantum(); s = SpinQuantum(s.get_s().getirrep(), s.get_s(), IrrepSpace(0)); int qs = 1, ns = 1; StateInfo addstate(ns, &s, &qs); SpinBlock dummyblock(addstate, integralIndex); SpinBlock newstartingBlock; newstartingBlock.set_integralIndex() = integralIndex; newstartingBlock.default_op_components(false, startingBlock, dummyblock, true, true, leftState==rightState); newstartingBlock.setstoragetype(LOCAL_STORAGE); if( braquanta.size()!= 0) newstartingBlock.BuildSumBlock(NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, startingBlock, dummyblock,braquanta,ketquanta); else newstartingBlock.BuildSumBlock(NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, startingBlock, dummyblock); startingBlock.clear(); startingBlock = newstartingBlock; } } else { std::vector<int> backwardSites; if(dmrginp.spinAdapted()) { for (int i = 0; i < backward_starting_size; ++i) backwardSites.push_back (dmrginp.last_site() - i - 1); } else { for (int i = 0; i < backward_starting_size; ++i) backwardSites.push_back (dmrginp.last_site()/2 - i - 1); } sort (backwardSites.begin (), backwardSites.end ()); startingBlock.set_integralIndex() = integralIndex; startingBlock.default_op_components(false, leftState==rightState); startingBlock.BuildTensorProductBlock (backwardSites); } }
void SpinAdapted::mps_nevpt::type1::BlockDecimateAndCompress (SweepParams &sweepParams, SpinBlock& system, SpinBlock& newSystem, const bool &useSlater, const bool& dot_with_sys, perturber& pb, int baseState) { int sweepiter = sweepParams.get_sweep_iter(); if (dmrginp.outputlevel() > 0) { mcheck("at the start of block and decimate"); pout << "\t\t\t dot with system "<<dot_with_sys<<endl; pout <<endl<< "\t\t\t Performing Blocking"<<endl; } // figure out if we are going forward or backwards dmrginp.guessgenT -> start(); bool forward = (system.get_sites() [0] == 0); SpinBlock systemDot; SpinBlock environment, environmentDot, newEnvironment; SpinBlock big; environment.nonactive_orb() = pb.orb(); newEnvironment.nonactive_orb() = pb.orb(); int systemDotStart, systemDotEnd; int environmentDotStart, environmentDotEnd, environmentStart, environmentEnd; int systemDotSize = sweepParams.get_sys_add() - 1; int environmentDotSize = sweepParams.get_env_add() -1; if (forward) { systemDotStart = dmrginp.spinAdapted() ? *system.get_sites().rbegin () + 1 : (*system.get_sites().rbegin ())/2 + 1 ; systemDotEnd = systemDotStart + systemDotSize; environmentDotStart = systemDotEnd + 1; environmentDotEnd = environmentDotStart + environmentDotSize; } else { systemDotStart = dmrginp.spinAdapted() ? system.get_sites()[0] - 1 : (system.get_sites()[0])/2 - 1 ; systemDotEnd = systemDotStart - systemDotSize; environmentDotStart = systemDotEnd - 1; environmentDotEnd = environmentDotStart - environmentDotSize; } systemDot = SpinBlock(systemDotStart, systemDotEnd, pb.orb()); environmentDot = SpinBlock(environmentDotStart, environmentDotEnd, pb.orb()); Sweep::makeSystemEnvironmentBigBlocks(system, systemDot, newSystem, environment, environmentDot, newEnvironment, big, sweepParams, dot_with_sys, useSlater, system.get_integralIndex(), pb.wavenumber(), baseState,pb.braquanta,pb.ketquanta); //analyse_operator_distribution(big); dmrginp.guessgenT -> stop(); dmrginp.multiplierT -> start(); std::vector<Matrix> rotatematrix; if (dmrginp.outputlevel() > 0) mcheck(""); if (dmrginp.outputlevel() > 0) { if (!dot_with_sys && sweepParams.get_onedot()) { pout << "\t\t\t System Block"<<system; } else pout << "\t\t\t System Block"<<newSystem; pout << "\t\t\t Environment Block"<<newEnvironment<<endl; pout << "\t\t\t Solving wavefunction "<<endl; } std::vector<Wavefunction> solution; solution.resize(1); std::vector<Wavefunction> outputState; outputState.resize(1); DiagonalMatrix e; //read the 0th wavefunction which we keep on the ket side because by default the ket stateinfo is used to initialize wavefunction //also when you use spinblock operators to multiply a state, it does so from the ket side i.e. H|ket> //GuessWave::guess_wavefunctions(solution, e, big, sweepParams.set_guesstype(), sweepParams.get_onedot(), dot_with_sys, 0.0, baseState); GuessWave::guess_wavefunctions(solution[0], e, big, sweepParams.set_guesstype(), sweepParams.get_onedot(), baseState, dot_with_sys, 0.0); #ifndef SERIAL mpi::communicator world; broadcast(world, solution, 0); #endif outputState[0].AllowQuantaFor(big.get_leftBlock()->get_braStateInfo(), big.get_rightBlock()->get_braStateInfo(),pb.braquanta); outputState[0].set_onedot(sweepParams.get_onedot()); outputState[0].Clear(); if (pb.type() == TwoPerturbType::Va) big.multiplyCDD_sum(solution[0],&(outputState[0]),MAX_THRD); if (pb.type() == TwoPerturbType::Vi) big.multiplyCCD_sum(solution[0],&(outputState[0]),MAX_THRD); //davidson_f(solution[0], outputState[0]); SpinBlock newbig; if (sweepParams.get_onedot() && !dot_with_sys) { InitBlocks::InitNewSystemBlock(system, systemDot, newSystem, baseState, pb.wavenumber(), systemDot.size(), dmrginp.direct(), system.get_integralIndex(), DISTRIBUTED_STORAGE, false, true,NO_PARTICLE_SPIN_NUMBER_CONSTRAINT,pb.braquanta,pb.ketquanta); InitBlocks::InitBigBlock(newSystem, environment, newbig,pb.braquanta,pb.ketquanta); Wavefunction tempwave = outputState[0]; GuessWave::onedot_shufflesysdot(big.get_braStateInfo(), newbig.get_braStateInfo(), outputState[0], tempwave); outputState[0] = tempwave; tempwave = solution[0]; GuessWave::onedot_shufflesysdot(big.get_ketStateInfo(), newbig.get_ketStateInfo(), solution[0], tempwave); solution[0] = tempwave; big.get_rightBlock()->clear(); big.clear(); } else newbig = big; DensityMatrix bratracedMatrix(newSystem.get_braStateInfo()); bratracedMatrix.allocate(newSystem.get_braStateInfo()); //bratracedMatrix.makedensitymatrix(outputState, newbig, dmrginp.weights(sweepiter), 0.0, 0.0, true); bratracedMatrix.makedensitymatrix(outputState, newbig, std::vector<double>(1,1.0), 0.0, 0.0, true); if (sweepParams.get_noise() > NUMERICAL_ZERO) { pout << "adding noise "<<trace(bratracedMatrix)<<" "<<sweepiter<<" "<<dmrginp.weights(sweepiter)[0]<<endl; bratracedMatrix.add_onedot_noise_forCompression(solution[0], newbig, sweepParams.get_noise()*max(1.0,trace(bratracedMatrix))); if (trace(bratracedMatrix) <1e-14) bratracedMatrix.SymmetricRandomise(); pout << "after noise "<<trace(bratracedMatrix)<<" "<<sweepParams.get_noise()<<endl; } environment.clear(); newEnvironment.clear(); std::vector<Matrix> brarotateMatrix, ketrotateMatrix; LoadRotationMatrix (newSystem.get_sites(), ketrotateMatrix, baseState); double braerror; if (!mpigetrank()) { braerror = makeRotateMatrix(bratracedMatrix, brarotateMatrix, sweepParams.get_keep_states(), sweepParams.get_keep_qstates()); } #ifndef SERIAL broadcast(world, ketrotateMatrix, 0); broadcast(world, brarotateMatrix, 0); #endif if (dmrginp.outputlevel() > 0) pout << "\t\t\t Total bra discarded weight "<<braerror<<endl<<endl; sweepParams.set_lowest_error() = braerror; SaveRotationMatrix (newbig.get_leftBlock()->get_sites(), brarotateMatrix, pb.wavenumber()); //FIXME //It is neccessary for twodot algorithm to save baseState wavefuntion. //I do not know why. solution[0].SaveWavefunctionInfo (newbig.get_ketStateInfo(), newbig.get_leftBlock()->get_sites(), baseState); outputState[0].SaveWavefunctionInfo (newbig.get_braStateInfo(), newbig.get_leftBlock()->get_sites(), pb.wavenumber()); //TODO //Why do I need this? //They should have been consistent. // solution[0].SaveWavefunctionInfo (newbig.get_ketStateInfo(), newbig.get_leftBlock()->get_sites(), baseState); // SaveRotationMatrix (newbig.get_leftBlock()->get_sites(), ketrotateMatrix, baseState); if (dmrginp.outputlevel() > 0) pout <<"\t\t\t Performing Renormalization "<<endl; newSystem.transform_operators(brarotateMatrix, ketrotateMatrix); if (dmrginp.outputlevel() > 0) mcheck("after rotation and transformation of block"); if (dmrginp.outputlevel() > 0){ pout << *dmrginp.guessgenT<<" "<<*dmrginp.multiplierT<<" "<<*dmrginp.operrotT<< " "<<globaltimer.totalwalltime()<<" timer "<<endl; pout << *dmrginp.makeopsT<<" makeops "<<endl; pout << *dmrginp.datatransfer<<" datatransfer "<<endl; pout <<"oneindexopmult twoindexopmult Hc couplingcoeff"<<endl; pout << *dmrginp.oneelecT<<" "<<*dmrginp.twoelecT<<" "<<*dmrginp.hmultiply<<" "<<*dmrginp.couplingcoeff<<" hmult"<<endl; pout << *dmrginp.buildsumblock<<" "<<*dmrginp.buildblockops<<" build block"<<endl; pout << "addnoise S_0_opxop S_1_opxop S_2_opxop"<<endl; pout << *dmrginp.addnoise<<" "<<*dmrginp.s0time<<" "<<*dmrginp.s1time<<" "<<*dmrginp.s2time<<endl; } }