コード例 #1
0
ファイル: sweep.C プロジェクト: i-maruyama/Block
double SweepOnepdm::do_one(SweepParams &sweepParams, const bool &warmUp, const bool &forward, const bool &restart, const int &restartSize)
{

  SpinBlock system;
  const int nroots = dmrginp.nroots();
  std::vector<double> finalEnergy(nroots,0.);
  std::vector<double> finalEnergy_spins(nroots,0.);
  double finalError = 0.;

  Matrix onepdm(2*dmrginp.last_site(), 2*dmrginp.last_site());onepdm=0.0;
  for (int i=0; i<nroots; i++)
    for (int j=0; j<=i; j++)      
      save_onepdm_binary(onepdm, i ,j);

  sweepParams.set_sweep_parameters();
  // a new renormalisation sweep routine
  pout << ((forward) ? "\t\t\t Starting renormalisation sweep in forwards direction" : "\t\t\t Starting renormalisation sweep in backwards direction") << endl;
  pout << "\t\t\t ============================================================================ " << endl;
  
  InitBlocks::InitStartingBlock (system,forward, sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), restartSize, restart, warmUp);

  sweepParams.set_block_iter() = 0;
 
  pout << "\t\t\t Starting block is :: " << endl << system << endl;

  SpinBlock::store (forward, system.get_sites(), system); // if restart, just restoring an existing block --
  sweepParams.savestate(forward, system.get_sites().size());
  bool dot_with_sys = true;

  sweepParams.set_guesstype() = TRANSPOSE;
	  
  SpinBlock newSystem;
  BlockAndDecimate (sweepParams, system, newSystem, warmUp, dot_with_sys);
  pout.precision(12);
  pout << "\t\t\t The lowest sweep energy : "<< sweepParams.get_lowest_energy()[0]+dmrginp.get_coreenergy()<<endl;
  pout << "\t\t\t ============================================================================ " << endl;

  for (int i=0; i<nroots; i++)
    for (int j=0; j<=i; j++) {
      load_onepdm_binary(onepdm, i ,j);
      accumulate_onepdm(onepdm);
      save_onepdm_spatial_text(onepdm, i ,j);
      save_onepdm_text(onepdm, i ,j);
      save_onepdm_spatial_binary(onepdm, i ,j);
    }
  return sweepParams.get_lowest_energy()[0];
}
コード例 #2
0
ファイル: sweep.C プロジェクト: matk86/Block
double SweepTwopdm::do_one(SweepParams &sweepParams, const bool &warmUp, const bool &forward, const bool &restart, const int &restartSize, int state)
{
  Timer sweeptimer;
  int integralIndex = 0;
  if (dmrginp.hamiltonian() == BCS) {
    pout << "Two PDM with BCS calculations is not implemented" << endl;
    exit(0);
  }
  pout.precision(12);
  SpinBlock system;
  const int nroots = dmrginp.nroots();
  std::vector<double> finalEnergy(nroots,0.);
  std::vector<double> finalEnergy_spins(nroots,0.);
  double finalError = 0.;

  sweepParams.set_sweep_parameters();
  // a new renormalisation sweep routine
  pout << ((forward) ? "\t\t\t Starting renormalisation sweep in forwards direction" : "\t\t\t Starting renormalisation sweep in backwards direction") << endl;
  pout << "\t\t\t ============================================================================ " << endl;
  
  InitBlocks::InitStartingBlock (system,forward, sweepParams.current_root(), sweepParams.current_root(), sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), restartSize, restart, warmUp, integralIndex);
  if(!restart)
    sweepParams.set_block_iter() = 0;
 
  pout << "\t\t\t Starting block is :: " << endl << system << endl;
  if (!restart) 
    SpinBlock::store (forward, system.get_sites(), system, sweepParams.current_root(), sweepParams.current_root()); // if restart, just restoring an existing block --
  sweepParams.savestate(forward, system.get_sites().size());
  bool dot_with_sys = true;

  array_4d<double> twopdm(2*dmrginp.last_site(), 2*dmrginp.last_site(), 2*dmrginp.last_site(), 2*dmrginp.last_site());
  twopdm.Clear();

  save_twopdm_binary(twopdm, state, state); 


  for (; sweepParams.get_block_iter() < sweepParams.get_n_iters(); )
    {
      pout << "\n\t\t\t Block Iteration :: " << sweepParams.get_block_iter() << endl;
      pout << "\t\t\t ----------------------------" << endl;
      if (forward)
	p1out << "\t\t\t Current direction is :: Forwards " << endl;
      else
	p1out << "\t\t\t Current direction is :: Backwards " << endl;

      //if (SHOW_MORE) pout << "system block" << endl << system << endl;
  
      if (dmrginp.no_transform())
	      sweepParams.set_guesstype() = BASIC;
      else if (!warmUp && sweepParams.get_block_iter() != 0) 
  	    sweepParams.set_guesstype() = TRANSFORM;
      else if (!warmUp && sweepParams.get_block_iter() == 0 && 
                ((dmrginp.algorithm_method() == TWODOT_TO_ONEDOT && dmrginp.twodot_to_onedot_iter() != sweepParams.get_sweep_iter()) ||
                  dmrginp.algorithm_method() != TWODOT_TO_ONEDOT))
        sweepParams.set_guesstype() = TRANSPOSE;
      else
        sweepParams.set_guesstype() = BASIC;
      
      p1out << "\t\t\t Blocking and Decimating " << endl;
	  
      SpinBlock newSystem;

      BlockAndDecimate (sweepParams, system, newSystem, warmUp, dot_with_sys, state);

      for(int j=0;j<nroots;++j)
        pout << "\t\t\t Total block energy for State [ " << j << 
	  " ] with " << sweepParams.get_keep_states()<<" :: " << sweepParams.get_lowest_energy()[j] <<endl;              

      finalEnergy_spins = ((sweepParams.get_lowest_energy()[0] < finalEnergy[0]) ? sweepParams.get_lowest_energy_spins() : finalEnergy_spins);
      finalEnergy = ((sweepParams.get_lowest_energy()[0] < finalEnergy[0]) ? sweepParams.get_lowest_energy() : finalEnergy);
      finalError = max(sweepParams.get_lowest_error(),finalError);

      system = newSystem;

      pout << system<<endl;
      
      SpinBlock::store (forward, system.get_sites(), system, sweepParams.current_root(), sweepParams.current_root());	 	

      p1out << "\t\t\t saving state " << system.get_sites().size() << endl;
      ++sweepParams.set_block_iter();
      //sweepParams.savestate(forward, system.get_sites().size());
    }
  //for(int j=0;j<nroots;++j)
  {int j = state;
    pout << "\t\t\t Finished Sweep with " << sweepParams.get_keep_states() << " states and sweep energy for State [ " << j 
	 << " ] with Spin [ " << dmrginp.molecule_quantum().get_s()  << " ] :: " << finalEnergy[j] << endl;
  }
  pout << "\t\t\t Largest Error for Sweep with " << sweepParams.get_keep_states() << " states is " << finalError << endl;
  pout << "\t\t\t ============================================================================ " << endl;

  int i = state, j = state;
  //for (int j=0; j<=i; j++) {
  load_twopdm_binary(twopdm, i, j); 
  //calcenergy(twopdm, i);
  save_twopdm_text(twopdm, i, j);
  save_spatial_twopdm_text(twopdm, i, j);
  save_spatial_twopdm_binary(twopdm, i, j);
  

  // update the static number of iterations

  ++sweepParams.set_sweep_iter();

  ecpu = sweeptimer.elapsedcputime(); ewall = sweeptimer.elapsedwalltime();
  pout << "\t\t\t Elapsed Sweep CPU  Time (seconds): " << setprecision(3) << ecpu << endl;
  pout << "\t\t\t Elapsed Sweep Wall Time (seconds): " << setprecision(3) << ewall << endl;


  return finalEnergy[0];
}
コード例 #3
0
ファイル: PeaksWorkspace.cpp プロジェクト: trnielsen/mantid
    void PeaksWorkspace::saveNexus(::NeXus::File * file) const
    {

      //Number of Peaks
      const size_t np(peaks.size());

      // Column vectors for peaks table
      std::vector<int> detectorID(np);
      std::vector<double> H(np);
      std::vector<double> K(np);
      std::vector<double> L(np);
      std::vector<double> intensity(np);
      std::vector<double> sigmaIntensity(np);
      std::vector<double> binCount(np);
      std::vector<double> initialEnergy(np);
      std::vector<double> finalEnergy(np);
      std::vector<double> waveLength(np);
      std::vector<double> scattering(np);
      std::vector<double> dSpacing(np);
      std::vector<double> TOF(np);
      std::vector<int> runNumber(np);
      std::vector<double> goniometerMatrix(9 * np);

      // Populate column vectors from Peak Workspace
      for (size_t i = 0; i < np; i++)
      {
        Peak p = peaks[i];
        detectorID[i] = p.getDetectorID();
        H[i] = p.getH();
        K[i] = p.getK();
        L[i] = p.getL();
        intensity[i] = p.getIntensity();
        sigmaIntensity[i] = p.getSigmaIntensity();
        binCount[i] = p.getBinCount();
        initialEnergy[i] = p.getInitialEnergy();
        finalEnergy[i] = p.getFinalEnergy();
        waveLength[i] = p.getWavelength();
        scattering[i] = p.getScattering();
        dSpacing[i] = p.getDSpacing();
        TOF[i] = p.getTOF();
        runNumber[i] = p.getRunNumber();
        {
          Matrix<double> gm = p.getGoniometerMatrix();
          goniometerMatrix[9 * i] = gm[0][0];
          goniometerMatrix[9 * i + 1] = gm[1][0];
          goniometerMatrix[9 * i + 2] = gm[2][0];
          goniometerMatrix[9 * i + 3] = gm[0][1];
          goniometerMatrix[9 * i + 4] = gm[1][1];
          goniometerMatrix[9 * i + 5] = gm[2][1];
          goniometerMatrix[9 * i + 6] = gm[0][2];
          goniometerMatrix[9 * i + 7] = gm[1][2];
          goniometerMatrix[9 * i + 8] = gm[1][2];
        }
        // etc.
      }

      // Start Peaks Workspace in Nexus File
      std::string specifyInteger = "An integer";
      std::string specifyDouble = "A double";
      file->makeGroup("peaks_workspace", "NXentry", true);  // For when peaksWorkspace can be loaded

      // Detectors column
      file->writeData("column_1", detectorID);
      file->openData("column_1");
      file->putAttr("name", "Dectector ID");
      file->putAttr("interpret_as", specifyInteger);
      file->putAttr("units", "Not known");
      file->closeData();

      // H column
      file->writeData("column_2", H);
      file->openData("column_2");
      file->putAttr("name", "H");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // K column
      file->writeData("column_3", K);
      file->openData("column_3");
      file->putAttr("name", "K");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // L column
      file->writeData("column_4", L);
      file->openData("column_4");
      file->putAttr("name", "L");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Intensity column
      file->writeData("column_5", intensity);
      file->openData("column_5");
      file->putAttr("name", "Intensity");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Sigma Intensity column
      file->writeData("column_6", sigmaIntensity);
      file->openData("column_6");
      file->putAttr("name", "Sigma Intensity");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Bin Count column
      file->writeData("column_7", binCount);
      file->openData("column_7");
      file->putAttr("name", "Bin Count");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Initial Energy column
      file->writeData("column_8", initialEnergy);
      file->openData("column_8");
      file->putAttr("name", "Initial Energy");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Final Energy column
      file->writeData("column_9", finalEnergy);
      file->openData("column_9");
      file->putAttr("name", "Final Energy");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Wave Length Column
      file->writeData("column_10", waveLength);
      file->openData("column_10");
      file->putAttr("name", "Wave Length");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Scattering Column
      file->writeData("column_11", scattering);
      file->openData("column_11");
      file->putAttr("name", "Scattering");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // D Spacing Column
      file->writeData("column_12", dSpacing);
      file->openData("column_12");
      file->putAttr("name", "D Spacing");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // TOF Column
      file->writeData("column_13", TOF);
      file->openData("column_13");
      file->putAttr("name", "TOF");
      file->putAttr("interpret_as", specifyDouble);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      //Run Number column
      file->writeData("column_14", runNumber);
      file->openData("column_14");
      file->putAttr("name", "Run Number");
      file->putAttr("interpret_as", specifyInteger);
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // Goniometer Matrix Column
      std::vector<int> array_dims;
      array_dims.push_back(static_cast<int>(peaks.size()));
      array_dims.push_back(9);
      file->writeData("column_15", goniometerMatrix, array_dims);
      file->openData("column_15");
      file->putAttr("name", "Goniometer Matrix");
      file->putAttr("interpret_as", "A matrix of 3x3 doubles");
      file->putAttr("units", "Not known");  // Units may need changing when known
      file->closeData();

      // QLab & QSample are calculated and do not need to be saved

      file->closeGroup(); // end of peaks workpace

    }
コード例 #4
0
ファイル: sweep.C プロジェクト: matk86/Block
double SweepOnepdm::do_one(SweepParams &sweepParams, const bool &warmUp, const bool &forward, const bool &restart, const int &restartSize, int state)
{
  Timer sweeptimer;
  int integralIndex = 0;
  SpinBlock system;
  const int nroots = dmrginp.nroots();
  std::vector<double> finalEnergy(nroots,0.);
  std::vector<double> finalEnergy_spins(nroots,0.);
  double finalError = 0.;

  int pdmsize = dmrginp.spinAdapted() ? 2*dmrginp.last_site() : dmrginp.last_site();
  Matrix onepdm(pdmsize, pdmsize);onepdm=0.0;
  Matrix pairmat;
  if (dmrginp.hamiltonian() == BCS) {
    pairmat.ReSize(pdmsize, pdmsize);
    pairmat = 0.0;
    save_pairmat_binary(pairmat, state, state);
  }

  save_onepdm_binary(onepdm, state ,state);

  sweepParams.set_sweep_parameters();
  // a new renormalisation sweep routine
  pout << ((forward) ? "\t\t\t Starting renormalisation sweep in forwards direction" : "\t\t\t Starting renormalisation sweep in backwards direction") << endl;
  pout << "\t\t\t ============================================================================ " << endl;
  
  InitBlocks::InitStartingBlock (system,forward, sweepParams.current_root(), sweepParams.current_root(), sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), restartSize, restart, warmUp, integralIndex);

  sweepParams.set_block_iter() = 0;
 
  pout << "\t\t\t Starting block is :: " << endl << system << endl;

  SpinBlock::store (forward, system.get_sites(), system, sweepParams.current_root(), sweepParams.current_root()); // if restart, just restoring an existing block --
  sweepParams.savestate(forward, system.get_sites().size());
  bool dot_with_sys = true;

  sweepParams.set_guesstype() = TRANSPOSE;
  for (; sweepParams.get_block_iter() < sweepParams.get_n_iters(); )
    {
      pout << "\n\t\t\t Block Iteration :: " << sweepParams.get_block_iter() << endl;
      pout << "\t\t\t ----------------------------" << endl;
      if (forward)
	p1out << "\t\t\t Current direction is :: Forwards " << endl;
      else
	p1out << "\t\t\t Current direction is :: Backwards " << endl;

      if (sweepParams.get_block_iter() == 0)
	sweepParams.set_guesstype() = TRANSPOSE;
      else
	sweepParams.set_guesstype() = TRANSFORM;

      p1out << "\t\t\t Blocking and Decimating " << endl;

      SpinBlock newSystem;
      BlockAndDecimate (sweepParams, system, newSystem, warmUp, dot_with_sys, state);
      pout.precision(12);

      system = newSystem;

      pout << system<<endl;
      
      SpinBlock::store (forward, system.get_sites(), system, sweepParams.current_root(), sweepParams.current_root());	 	

      p1out << "\t\t\t saving state " << system.get_sites().size() << endl;
      ++sweepParams.set_block_iter();
      //sweepParams.savestate(forward, system.get_sites().size());
    }
  pout << "\t\t\t The lowest sweep energy : "<< sweepParams.get_lowest_energy()[0] << endl;
  pout << "\t\t\t ============================================================================ " << endl;


  load_onepdm_binary(onepdm, state ,state);
  accumulate_onepdm(onepdm);
  save_onepdm_spatial_text(onepdm, state, state);
  save_onepdm_text(onepdm, state, state);
  save_onepdm_spatial_binary(onepdm, state, state);

  if (dmrginp.hamiltonian() == BCS) {
    load_pairmat_binary(pairmat, state, state);
    accumulate_onepdm(pairmat);
    // FIXME write out text version
    // only <D{ia}D{jb}> is in the matrix
    save_pairmat_text(pairmat , state, state);
  }

  ecpu = sweeptimer.elapsedcputime(); ewall = sweeptimer.elapsedwalltime();
  pout << "\t\t\t Elapsed Sweep CPU  Time (seconds): " << setprecision(3) << ecpu << endl;
  pout << "\t\t\t Elapsed Sweep Wall Time (seconds): " << setprecision(3) << ewall << endl;

  return sweepParams.get_lowest_energy()[0];
}
コード例 #5
0
ファイル: sweep.C プロジェクト: chrinide/Block
double SweepGenblock::do_one(SweepParams &sweepParams, const bool &warmUp, const bool &forward, const bool &restart, const int &restartSize, int stateA, int stateB)
{
  Timer sweeptimer;
  int integralIndex = 0;

  SpinBlock system;
  const int nroots = dmrginp.nroots();
  std::vector<double> finalEnergy(nroots,0.);
  std::vector<double> finalEnergy_spins(nroots,0.);
  double finalError = 0.;

  sweepParams.set_sweep_parameters();
  // a new renormalisation sweep routine
  pout << ((forward) ? "\t\t\t Starting renormalisation sweep in forwards direction" : "\t\t\t Starting renormalisation sweep in backwards direction") << endl;
  pout << "\t\t\t ============================================================================ " << endl;
  
  InitBlocks::InitStartingBlock (system,forward, stateA, stateB, sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), restartSize, restart, warmUp, integralIndex);
  if(!restart)
    sweepParams.set_block_iter() = 0;

  p2out << "\t\t\t Starting block is :: " << endl << system << endl;
  //if (!restart) 
  SpinBlock::store (forward, system.get_sites(), system, stateA, stateB); // if restart, just restoring an existing block --
  sweepParams.savestate(forward, system.get_sites().size());
  bool dot_with_sys = true;
  if (restart)
  {
    if (forward && system.get_complementary_sites()[0] >= dmrginp.last_site()/2)
      dot_with_sys = false;
    if (!forward && system.get_sites()[0]-1 < dmrginp.last_site()/2)
      dot_with_sys = false;
  }

  for (; sweepParams.get_block_iter() < sweepParams.get_n_iters(); )
    {
      pout << "\n\t\t\t Block Iteration :: " << sweepParams.get_block_iter() << endl;
      pout << "\t\t\t ----------------------------" << endl;
      if (forward)
	{ p1out << "\t\t\t Current direction is :: Forwards " << endl; }
      else
	{ p1out << "\t\t\t Current direction is :: Backwards " << endl; }
      //if (SHOW_MORE) pout << "system block" << endl << system << endl;
  
      if (dmrginp.no_transform())
	      sweepParams.set_guesstype() = BASIC;
      else if (!warmUp && sweepParams.get_block_iter() != 0) 
  	    sweepParams.set_guesstype() = TRANSFORM;
      else if (!warmUp && sweepParams.get_block_iter() == 0 && 
                ((dmrginp.algorithm_method() == TWODOT_TO_ONEDOT && dmrginp.twodot_to_onedot_iter() != sweepParams.get_sweep_iter()) ||
                  dmrginp.algorithm_method() != TWODOT_TO_ONEDOT))
        sweepParams.set_guesstype() = TRANSPOSE;
      else
        sweepParams.set_guesstype() = BASIC;
      
      p1out << "\t\t\t Blocking and Decimating " << endl;
	  
      SpinBlock newSystem;

      BlockAndDecimate (sweepParams, system, newSystem, warmUp, dot_with_sys, stateA, stateB);

      
      system = newSystem;

      //system size is going to be less than environment size
      if (forward && system.get_complementary_sites()[0] >= dmrginp.last_site()/2)
	dot_with_sys = false;
      if (!forward && system.get_sites()[0]-1 < dmrginp.last_site()/2)
	dot_with_sys = false;

      SpinBlock::store (forward, system.get_sites(), system, stateA, stateB);	 	

      p1out << "\t\t\t saving state " << system.get_sites().size() << endl;
      ++sweepParams.set_block_iter();
      //if (sweepParams.get_onedot())
      //pout << "\t\t\tUsing one dot algorithm!!"<<endl; 
      sweepParams.savestate(forward, system.get_sites().size());
    }
  pout << "\t\t\t Finished Generate-Blocks Sweep. " << endl;
  pout << "\t\t\t ============================================================================ " << endl;

  // update the static number of iterations

  ++sweepParams.set_sweep_iter();

  ecpu = sweeptimer.elapsedcputime(); ewall = sweeptimer.elapsedwalltime();
  pout << "\t\t\t Elapsed Sweep CPU  Time (seconds): " << setprecision(3) << ecpu << endl;
  pout << "\t\t\t Elapsed Sweep Wall Time (seconds): " << setprecision(3) << ewall << endl;

  return finalEnergy[0];
}