void
BlockFileReader::loadDict()
{
  QString dictFile = m_baseFilename + ".dict";
  QFile dfile(dictFile);
  dfile.open(QIODevice::ReadOnly);
  QDataStream in(&dfile);
  in >> m_minLevel;
  for(int ib=0; ib<m_minLevel; ib++)
    {
      in >> m_uniform[ib];
      in >> m_fileBlocks[ib];
      in >> m_blockOffset[ib]; 
    }
  dfile.close();

  QString lowresFile = m_baseFilename + ".lowres";
  QFile lfile(lowresFile);
  lfile.open(QIODevice::ReadOnly);
  lfile.read((char*)&m_sslevel, 1);
  lfile.read((char*)&m_ssd, 4);
  lfile.read((char*)&m_ssw, 4);
  lfile.read((char*)&m_ssh, 4);
  m_ssvol = new uchar[m_ssd*m_ssw*m_ssh*m_bytesPerVoxel];
  lfile.read((char*)m_ssvol, m_ssd*m_ssw*m_ssh*m_bytesPerVoxel);
  lfile.close();

//  QMessageBox::information(0, "", QString("%1 : %2 %3 %4").\
//			   arg(m_sslevel).arg(m_ssd).arg(m_ssw).arg(m_ssh));

  initializeBlockReader();
}
Example #2
0
void ViewerWindow::openAnimations()
{
#if 0
	QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)");
	if(dialog.exec()) {
		std::ifstream dfile(dialog.selectedFiles().at(0).toStdString().c_str());
		AnimationList anims;

		if(dfile.is_open())
		{
			dfile.seekg(0, std::ios_base::end);
			size_t length = dfile.tellg();
			dfile.seekg(0);
			char *file = new char[length];
			dfile.read(file, length);

			LoaderIFP loader;
			if( loader.loadFromMemory(file) ) {
				for(auto& f : loader.animations) {
					anims.push_back(f);
				}
			}

			delete[] file;
		}

		animationswidget->setAnimations(anims);
	}
#endif
}
Example #3
0
FileHandle FileIndex::openFile(const std::string& filename)
{
	auto iterator = files.find( filename );
	if( iterator == files.end() )
	{
		return nullptr;
	}
	
	IndexData& f = iterator->second;
	bool isArchive = !f.archive.empty();
	
	auto fsName = f.directory + "/" + f.originalName;
	
	char* data = nullptr;
	size_t length = 0;
	
	if( isArchive )
	{
		fsName = f.directory + "/" + f.archive;
		
		LoaderIMG img;
		
		if( ! img.load(fsName) )
		{
			throw std::runtime_error("Failed to load IMG archive: " + fsName);
		}
		
		LoaderIMGFile file;
		if( img.findAssetInfo(f.originalName, file) )
		{
			length = file.size * 2048;
			data = img.loadToMemory(f.originalName);
		}
	}
	else
	{
		std::ifstream dfile(fsName.c_str(), std::ios_base::binary);
		if ( ! dfile.is_open()) {
			throw std::runtime_error("Unable to open file: " + fsName);
		}

		dfile.seekg(0, std::ios_base::end);
		length = dfile.tellg();
		dfile.seekg(0);
		data = new char[length];
		dfile.read(data, length);
	}
	
	if( data == nullptr )
	{
		return nullptr;
	}
	
	return FileHandle( new FileContentsInfo{ data, length } );
}
Example #4
0
int DBInit::copyDB(){
    QFile dfile("assets:/sights.sqlite");
    QFile existFile("./sights.sqlite");
    //Если файл с БД скопирован, то пропускаем следующие шаги
    if (existFile.exists())
        existFile.remove();
  //      return 0;
    if (dfile.exists())
    {
         dfile.copy("./sights.sqlite");
         QFile::setPermissions("./sights.sqlite",QFile::WriteOwner | QFile::ReadOwner);
    }
    return 1;
}
Example #5
0
int main(int argc, char *argv[])
{

	signal(SIGALRM, sig_alarm);

	if ((argc < 2) || (argc > 2 && argc < 5) || (argc > 5)) {
		fprintf(stderr, "Error args!\n");
		print_usage();
		return -1;
	}

	strcpy(root_dir, argv[1]);
	if (root_dir[strlen(root_dir)-1] == '/') {
		root_dir[strlen(root_dir)-1] = '\0';	
	}
	if (argc == 5) {
		file_size = atol(argv[2])*1024*1024;
		thread_n = atoi(argv[3]);
		time_s = atoi(argv[4]);
	}
	if ((n = parse_args()) <= 0) {
		openlog("fs_write", LOG_CONS|LOG_PID, 0);
		syslog(LOG_USER|LOG_ERR, "parse_args error!\n");
		print_usage();
		return -1;
	}
	strcpy(_dirname, root_dir);
	strcat(_dirname, "/");
	strcat(_dirname, dirs_name[now]);
	if (init_time(time_s) < 0) {
		openlog("fs_write", LOG_CONS|LOG_PID, 0);
		syslog(LOG_USER|LOG_ERR, "init_time error!\n");
		return -1;
	}

	if (w_thread() < 0) {
		return -1;
	}
	if (dfile() < 0) {
		return -1;
	}
}
void SimpleTaskManager::loadInitData(QString dir)
{
    QDirIterator *dirIt;
    dirIt = new QDirIterator(dir, QDirIterator::NoIteratorFlags);

    while (dirIt->hasNext())
    {
        dirIt->next();
        QString _f = dirIt->filePath();
        QFileInfo f(_f);

        if(f.suffix() == "stb")
        {
            QFile dfile(dirIt->filePath());
            dfile.open(QIODevice::ReadOnly);

            SimpleTask *st = STFromBinary(dfile.readAll());
            this->addTask(st);
        }
    }
}
void
CameraCalib::read3dPoints(std::string filename, std::vector<cv::Point3f> *list) {
	std::ifstream dfile(filename);
	std::string line;
	int n;
	std::stringstream stream;
	if (dfile.is_open()) {
		while (getline(dfile, line)) {
			cv::Point3f point;
			stream = std::stringstream(line);
			stream >> n;
			point.x = n;

			stream >> n;
			point.y = n;

			stream >> n;
			point.z = n;
			list->push_back(point);
		}
	dfile.close();
	}
}
Example #8
0
void ModelViewer::loadAnimations(const QString& file) {
    std::ifstream dfile(file.toStdString().c_str(), std::ios_base::binary);
    AnimationList anims;

    if (dfile.is_open()) {
        dfile.seekg(0, std::ios_base::end);
        size_t length = dfile.tellg();
        dfile.seekg(0);
        char* file = new char[length];
        dfile.read(file, length);

        LoaderIFP loader;
        if (loader.loadFromMemory(file)) {
            for (auto& f : loader.animations) {
                anims.push_back(f);
            }
        }

        delete[] file;
    }

    animationWidget->setAnimations(anims);
}
Example #9
0
// Function to load the runInfo structure with all runID's on local disk
void US_XpnRunAuc::load_runs( void )
{
   impdir         = US_Settings::importDir();  // Imports directory
   impdir.replace( "\\", "/" );                // Possible Windows issue

   if ( impdir.right( 1 ) != "/" )
      impdir         = impdir + "/";           // Insure trailing slash

   // Set up to load either from a raw DB file or from openAUC files
   QStringList efilt( "*.auc" );

   QStringList runids;
   QStringList rdirs = QDir( impdir ).entryList(
         QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );
qDebug() << "LdDk:  rdirs count" << rdirs.count() << "impdir" << impdir
 << "efilt" << efilt;

   // Get the list of all Run IDs with data in their work directories
   for ( int ii = 0; ii < rdirs.count(); ii++ )
   {
      QString runID  = rdirs[ ii ];
      QString wdir   = impdir + runID + "/";
      QStringList efiles = QDir( wdir ).entryList( efilt, QDir::Files,
                                                   QDir::Name );
      int nfiles     = efiles.count();
qDebug() << "LdDk:   ii" << ii << "run" << rdirs[ii]
 << "count" << nfiles;

      if ( nfiles < 1 )              // Definitely not Optima
         continue;

      QString rfn    = wdir + efiles[ 0 ];
      QString date   = US_Util::toUTCDatetimeText(
                          QFileInfo( rfn ).lastModified().toUTC()
                          .toString( Qt::ISODate ), true )
                          .section( " ", 0, 0 ).simplified();

      // Look for TMST definition file and test import origin
      QString dfname = runID + ".time_state.xml";
      QString dpath  = wdir + dfname;
      QFile dfile( dpath );

      if ( ! dfile.exists()  ||
           ! dfile.open( QIODevice::ReadOnly ) )
         continue;  // Skip if TMST def file does not exist or can't be opened
qDebug() << "LdDk:    dfname -- exists/opened";

      QTextStream fsi( &dfile );
      QString pmatch( "import_type=\"Optima\"" );
      QString pmatch2( "import_type=\"XPN\"" );
      QString xmli   = fsi.readAll();
      dfile.close();
qDebug() << "LdDk:     pmatch" << pmatch;

      if ( ! xmli.contains( pmatch )  &&
           ! xmli.contains( pmatch2 ) )
         continue;  // Skip if TMST def has no import_type="Optima"


      // Add an eligible run directory to the list
//qDebug() << "LdDk:   ii" << ii << "  rfn" << rfn;
      RunInfo rr;
      rr.runID       = runID;
      rr.date        = date;
      rr.ntriple     = nfiles;
//qDebug() << "LdDk:   ii" << ii << "     runID date count"
// << rr.runID << rr.date << rr.nfiles;

      runInfo << rr;
   }

   if ( runInfo.size() < 1 )
   {
      QMessageBox::information( this,
             tr( "Error" ),
             tr( "There are no US3 runs on the local Disk to load.\n" ) );
   }

   return;
}
Example #10
0
dispnoerr(char *s)
{
dfile(s,2);
}
Example #11
0
dispfile(char *s)
{
dfile(s,0);
}
Example #12
0
regdispfile(char *s)
{
dfile(s,1);
}
Example #13
0
/** create a SlaterDeterminant
 * @param cur xmlnode containing \<slaterdeterminant\>
 * @return a SlaterDeterminant
 *
 * @warning MultiSlaterDeterminant is not working yet.
 */
SPOSetBase*
SplineSetBuilder::createSPOSet(xmlNodePtr cur)
{
  string hrefname("NONE");
  int norb(0);
  int degeneracy(1);
  OhmmsAttributeSet aAttrib;
  aAttrib.add(norb,"orbitals");
  aAttrib.add(degeneracy,"degeneracy");
  aAttrib.add(hrefname,"href");
  aAttrib.put(cur);
  if(norb ==0)
  {
    app_error() << "SplineSetBuilder::createSPOSet failed. Check the attribte orbitals." << endl;
    return 0;
  }
  app_log() << "    Degeneracy = " << degeneracy << endl;
  std::vector<int> npts(3);
  npts[0]=GridXYZ->nX;
  npts[1]=GridXYZ->nY;
  npts[2]=GridXYZ->nZ;
  std::vector<RealType> inData(npts[0]*npts[1]*npts[2]);
  SPOSetType* psi= new SPOSetType(norb);
  vector<int> occSet(norb);
  for(int i=0; i<norb; i++)
    occSet[i]=i;
  cur=cur->children;
  while(cur != NULL)
  {
    string cname((const char*)(cur->name));
    if(cname == "occupation")
    {
      string occ_mode("ground");
      const xmlChar* o=xmlGetProp(cur,(const xmlChar*)"mode");
      if(o!= NULL)
        occ_mode = (const char*)o;
      //Do nothing if mode == ground
      if(occ_mode == "excited")
      {
        vector<int> occ_in, occRemoved;
        putContent(occ_in,cur);
        for(int k=0; k<occ_in.size(); k++)
        {
          if(occ_in[k]<0)
            occRemoved.push_back(-occ_in[k]-1);
        }
        int kpopd=0;
        for(int k=0; k<occ_in.size(); k++)
        {
          if(occ_in[k]>0)
            occSet[occRemoved[kpopd++]]=occ_in[k]-1;
        }
      }
      hid_t h_file = H5Fopen(hrefname.c_str(),H5F_ACC_RDWR,H5P_DEFAULT);
      const xmlChar* h5path = xmlGetProp(cur,(const xmlChar*)"h5path");
      string hroot("/eigenstates_3/twist_0");
      if(h5path != NULL)
        hroot=(const char*)h5path;
      char wfname[128],wfshortname[16];
      for(int iorb=0; iorb<norb; iorb++)
      {
        sprintf(wfname,"%s/band_%d/eigenvector",hroot.c_str(),occSet[iorb]/degeneracy);
        sprintf(wfshortname,"b%d",occSet[iorb]/degeneracy);
        SPOType* neworb=0;
        map<string,SPOType*>::iterator it(NumericalOrbitals.find(wfshortname));
        if(it == NumericalOrbitals.end())
        {
          neworb=new SPOType(GridXYZ);
          HDFAttribIO<std::vector<RealType> > dummy(inData,npts);
          dummy.read(h_file,wfname);
          //neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.BoxBConds[0]);
          neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.SuperCellEnum);
          NumericalOrbitals[wfshortname]=neworb;
          app_log() << "   Reading spline function " << wfname << endl;
        }
        else
        {
          neworb = (*it).second;
          app_log() << "   Reusing spline function " << wfname << endl;
        }
        psi->add(neworb);
      }
      H5Fclose(h_file);
    }
    cur=cur->next;
  }
  SPOType* aorb=(*NumericalOrbitals.begin()).second;
  string fname("spline3d.vti");
  std::ofstream dfile(fname.c_str());
  dfile.setf(ios::scientific, ios::floatfield);
  dfile.setf(ios::left,ios::adjustfield);
  dfile.precision(10);
  dfile << "<?xml version=\"1.0\"?>" << endl;
  dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl;
  dfile << "  <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2
        << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl;
  dfile << "    <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl;
  dfile << "       <PointData Scalars=\"wfs\">" << endl;
  dfile << "          <DataArray type=\"Float32\" Name=\"wfs\">" << endl;
  int ng=0;
  GradType grad;
  ValueType lap;
  for(int ix=0; ix<npts[0]-1; ix++)
  {
    double x(GridXYZ->gridX->operator()(ix));
    for(int iy=0; iy<npts[1]-1; iy++)
    {
      double y(GridXYZ->gridY->operator()(iy));
      for(int iz=0; iz<npts[2]-1; iz++, ng++)
      {
        PosType p(x,y,GridXYZ->gridZ->operator()(iz));
        //aorb.setgrid(p);
        //Timing with the ofstream is not correct.
        //Uncomment the line below and comment out the next two line.
        //double t=aorb.evaluate(p,grad,lap);
        dfile << setw(20) << aorb->evaluate(p,grad,lap);
        if(ng%5 == 4)
          dfile << endl;
      }
    }
  }
  dfile << "          </DataArray>" << endl;
  dfile << "       </PointData>" << endl;
  dfile << "    </Piece>" << endl;
  dfile << "  </ImageData>" << endl;
  dfile << "</VTKFile>" << endl;
  abort();
  return psi;
}
Example #14
0
// Scan database for reports
void US_SyncWithDB::scan_db_reports()
{
//qDebug() << "ScDB:TM:00: " << QTime::currentTime().toString("hh:mm:ss:zzzz");
   US_Passwd   pw;
   US_DB2      db( pw.getPasswd() );

   if ( db.lastErrno() != US_DB2::OK )
   {
      QMessageBox::information( this,
         tr( "DB Connection Problem" ),
         tr( "There was an error connecting to the database:\n" )
         + db.lastError() );
      return;
   }

   QString desc = tr(
      "<b>Note:</b> Proceeding may result in local reports<br/>"
      "being replaced from the database.<ul>"
      "<li><b>Cancel</b>   to abort synchronizing from the DB.</li>"
      "<li><b>Download</b> to proceed with DB synchronization.</li>"
      "<li><b>New Only</b> to only download new DB records.</li></ul>"
      "<b>Downloading report records from the database...</b>" );
   te_desc->setHtml( desc );
   qApp->processEvents();
   QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );

   QStringList query;
   QString     invID  = QString::number( US_Settings::us_inv_ID() );

   setWindowTitle( tr( "Download Report Data from the Database" ) );

   query.clear();
   query << "count_reports" << invID;
   int nreports = db.functionQuery( query );
qDebug() << "Reports count" << nreports;
   desc         = desc + "<br/>&nbsp;&nbsp;&nbsp;";
   int nbdchr   = desc.length();
   desc         = desc.left( nbdchr )
                  + tr( "Total DB run reports is %1" ).arg( nreports );
   te_desc->setHtml( desc );
   qApp->processEvents();

   // Determine runIDs of existing local results
   QString resdir = US_Settings::resultDir() + "/";
   QDir dirres( resdir );
   QStringList resruns = dirres.entryList(
         QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );

   query.clear();
   query << "get_report_desc" << invID;
   db.query( query );
   QStringList runids;
   int kreports = 0;
   int jreports = 0;
   nrunrpl = nrunadd = ndocrpl = ndocadd = 0;
   QString rptdir = US_Settings::reportDir() + "/";
   QDir dirrpt( rptdir );

   while ( db.next() )
   {
      QString runid    = db.value( 4 ).toString();
      jreports++;
      if ( resruns.contains( runid ) )
      {
         runids   << runid;
qDebug() << "  report id" << db.value(0).toString() << "runID" << runid;
         kreports++;
      }
   }
qDebug() << "Report descs count" << kreports;

   desc         = desc.left( nbdchr )
                  + tr( "DB reports for local runIDs is %1" ).arg( kreports );
   te_desc->setHtml( desc );
   qApp->processEvents();

   for ( int ii = 0; ii < kreports; ii++ )
   {
      QString runid    = runids[ ii ];
      QString rundir   = rptdir + runid;
      QString runresd  = resdir + runid;

      US_Report freport;
      freport.readDB( runid, &db );

      int ntriples     = freport.triples.count();
qDebug() << "  Report" << ii << "triples count" << ntriples << "runID" << runid;

      if ( ntriples > 0 )
      {
         if ( QDir( rundir ).exists() )
         {
            if ( newonly )  continue;
            nrunrpl++;
         }

         else
         {
            nrunadd++;
            dirrpt.mkdir( runid );
         }
      }

      int kdocadd = 0;

      for ( int jj = 0; jj < ntriples; jj++ )
      {
         US_Report::ReportTriple* tripl = &freport.triples[ jj ];
         int ndocs        = tripl->docs.count();
qDebug() << "    Triple" << jj << "docs count" << ndocs;

         desc         = desc.left( nbdchr )
                        + tr( "Run %1, Triple %2: comparing %3 documents...")
                        .arg( ii + 1 ).arg( jj + 1 ).arg( ndocs );
         te_desc->setHtml( desc );
         qApp->processEvents();

         for ( int kk = 0; kk < ndocs; kk++ )
         {
            US_Report::ReportDocument* doc = &tripl->docs[ kk ];
            QString fname = doc->filename;
qDebug() << "      Doc" << kk << "filename" << fname << "ID" << doc->documentID;
            QString fpath = rundir + "/" + fname;
            if ( fname.endsWith( ".csv" ) )
               fpath         = runresd + "/" + fname;

            QFile dfile( fpath );

            if ( dfile.exists() )
            {
               if ( newonly )  continue;
               ndocrpl++;
            }

            else
            {
               ndocadd++;
            }

            int st = doc->readDB( rundir, &db );

            if ( st != US_DB2::OK )
            {
               qDebug() << "ReportDoc read ERROR: status" << st << fpath;
            }
         }
      }

      if ( newonly  &&  kdocadd != ndocadd )
         nrunrpl++;

   }
   QApplication::restoreOverrideCursor();
        
   QMessageBox::information( this,
         tr( "DB Reports Downloaded" ),
         tr( "Run IDs: %1 updated, %2 added.\n"
             "Documents: %3 replaced, %4 added." )
         .arg( nrunrpl ).arg( nrunadd ).arg( ndocrpl ).arg( ndocadd ) );
qDebug() << "nrunrpl nrunadd ndocrpl ndocadd" << nrunrpl << nrunadd
   << ndocrpl << ndocadd;
}
Example #15
0
void ExportEPUB::SaveFolderAsEpubToLocation(const QString &fullfolderpath, const QString &fullfilepath)
{
    QString tempFile = fullfolderpath + "-tmp.epub";
    QDateTime timeNow = QDateTime::currentDateTime();
    zip_fileinfo fileInfo;
#ifdef Q_OS_WIN32
    zlib_filefunc64_def ffunc;
    fill_win32_filefunc64W(&ffunc);
    zipFile zfile = zipOpen2_64(Utility::QStringToStdWString(QDir::toNativeSeparators(tempFile)).c_str(), APPEND_STATUS_CREATE, NULL, &ffunc);
#else
    zipFile zfile = zipOpen64(QDir::toNativeSeparators(tempFile).toUtf8().constData(), APPEND_STATUS_CREATE);
#endif

    if (zfile == NULL) {
        boost_throw(CannotOpenFile() << errinfo_file_fullpath(tempFile.toStdString()));
    }

    memset(&fileInfo, 0, sizeof(fileInfo));
    fileInfo.tmz_date.tm_sec = timeNow.time().second();
    fileInfo.tmz_date.tm_min = timeNow.time().minute();
    fileInfo.tmz_date.tm_hour = timeNow.time().hour();
    fileInfo.tmz_date.tm_mday = timeNow.date().day();
    fileInfo.tmz_date.tm_mon = timeNow.date().month() - 1;
    fileInfo.tmz_date.tm_year = timeNow.date().year();

    // Write the mimetype. This must be uncompressed and the first entry in the archive.
    if (zipOpenNewFileInZip64(zfile, "mimetype", &fileInfo, NULL, 0, NULL, 0, NULL, Z_NO_COMPRESSION, 0, 0) != Z_OK) {
        zipClose(zfile, NULL);
        QFile::remove(tempFile);
        boost_throw(CannotStoreFile() << errinfo_file_fullpath("mimetype"));
    }

    if (zipWriteInFileInZip(zfile, EPUB_MIME_DATA, (unsigned int)strlen(EPUB_MIME_DATA)) != Z_OK) {
        zipCloseFileInZip(zfile);
        zipClose(zfile, NULL);
        QFile::remove(tempFile);
        boost_throw(CannotStoreFile() << errinfo_file_fullpath("mimetype"));
    }

    zipCloseFileInZip(zfile);
    // Write all the files in our directory path to the archive.
    QDirIterator it(fullfolderpath, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden, QDirIterator::Subdirectories);

    while (it.hasNext()) {
        it.next();
        QString relpath = it.filePath().remove(fullfolderpath);

        while (relpath.startsWith("/")) {
            relpath = relpath.remove(0, 1);
        }

        // Add the file entry to the archive.
        // We should check the uncompressed file size. If it's over >= 0xffffffff the last parameter (zip64) should be 1.
        if (zipOpenNewFileInZip4_64(zfile, relpath.toUtf8().constData(), &fileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 8, 0, 15, 8, Z_DEFAULT_STRATEGY, NULL, 0, 0x0b00, 1<<11, 0) != Z_OK) {
            zipClose(zfile, NULL);
            QFile::remove(tempFile);
            boost_throw(CannotStoreFile() << errinfo_file_fullpath(relpath.toStdString()));
        }

        // Open the file on disk. We will read this and write what we read into
        // the archive.
        QFile dfile(it.filePath());

        if (!dfile.open(QIODevice::ReadOnly)) {
            zipCloseFileInZip(zfile);
            zipClose(zfile, NULL);
            QFile::remove(tempFile);
            boost_throw(CannotOpenFile() << errinfo_file_fullpath(it.fileName().toStdString()));
        }

        // Write the data from the file on disk into the archive.
        char buff[BUFF_SIZE] = {0};
        qint64 read = 0;

        while ((read = dfile.read(buff, BUFF_SIZE)) > 0) {
            if (zipWriteInFileInZip(zfile, buff, read) != Z_OK) {
                dfile.close();
                zipCloseFileInZip(zfile);
                zipClose(zfile, NULL);
                QFile::remove(tempFile);
                boost_throw(CannotStoreFile() << errinfo_file_fullpath(relpath.toStdString()));
            }
        }

        dfile.close();

        // There was an error reading the file on disk.
        if (read < 0) {
            zipCloseFileInZip(zfile);
            zipClose(zfile, NULL);
            QFile::remove(tempFile);
            boost_throw(CannotStoreFile() << errinfo_file_fullpath(relpath.toStdString()));
        }

        if (zipCloseFileInZip(zfile) != Z_OK) {
            zipClose(zfile, NULL);
            QFile::remove(tempFile);
            boost_throw(CannotStoreFile() << errinfo_file_fullpath(relpath.toStdString()));
        }
    }

    zipClose(zfile, NULL);
    // Overwrite the contents of the real file with the contents from the temp
    // file we saved the data do. We do this instead of simply copying the file
    // because a file copy will lose extended attributes such as labels on OS X.
    QFile temp_epub(tempFile);

    if (!temp_epub.open(QFile::ReadOnly)) {
        boost_throw(CannotOpenFile() << errinfo_file_fullpath(tempFile.toStdString()));
    }

    QFile real_epub(fullfilepath);

    if (!real_epub.open(QFile::WriteOnly | QFile::Truncate)) {
        temp_epub.close();
        boost_throw(CannotWriteFile() << errinfo_file_fullpath(fullfilepath.toStdString()));
    }

    // Copy the contents from the temp file to the real file.
    char buff[BUFF_SIZE] = {0};
    qint64 read = 0;
    qint64 written = 0;

    while ((read = temp_epub.read(buff, BUFF_SIZE)) > 0) {
        written = real_epub.write(buff, read);

        if (written != read) {
            temp_epub.close();
            real_epub.close();
            QFile::remove(tempFile);
            boost_throw(CannotCopyFile() << errinfo_file_fullpath(fullfilepath.toStdString()));
        }
    }

    if (read == -1) {
        temp_epub.close();
        real_epub.close();
        QFile::remove(tempFile);
        boost_throw(CannotCopyFile() << errinfo_file_fullpath(fullfilepath.toStdString()));
    }

    temp_epub.close();
    real_epub.close();
    QFile::remove(tempFile);
}
Example #16
0
int main(int argc, char** argv) {

  double ri = 0.0;
  double rf = 1.0;
  std::vector<int> npts(3);
  npts[0]=51;npts[1]=51;npts[2]=51;

  double xcut=0.23;
  double ycut=0.67;

  const int nk0=1;
  const int nk1=1;
  const int nk2=1;

  //Create one-dimensional grids for three orthogonal directions
  typedef LinearGrid<double> GridType;
  GridType gridX, gridY, gridZ;
  gridX.set(ri,rf,npts[0]);
  gridY.set(ri,rf,npts[1]);
  gridZ.set(ri,rf,npts[2]);

  //Create an analytic function for assignment
  ComboFunc infunc;
  infunc.push_back(0.5,new TestFunc(1,1,1));
  //infunc.push_back(0.3,new TestFunc(1,1,2));
  //infunc.push_back(0.1,new TestFunc(1,2,1));
  //infunc.push_back(0.01,new TestFunc(2,1,1));
  //infunc.push_back(0.01,new TestFunc(2,2,1));
  //infunc.push_back(0.001,new TestFunc(2,1,2));
  //infunc.push_back(0.001,new TestFunc(2,2,2));
  //infunc.push_back(0.001,new TestFunc(5,5,5));
  //infunc.push_back(-0.3,new TestFunc(7,2,3));
  //infunc.push_back(0.01,new TestFunc(7,7,7));
  //infunc.push_back(0.001,new TestFunc(5,5,5));

  //Write to an array
  std::vector<double> inData(npts[0]*npts[1]*npts[2]);
  std::vector<double>::iterator it(inData.begin());

  Pooma::Clock timer;
  timer.start();
  //Assign the values
  for(int ix=0; ix<npts[0]; ix++) {
    double x(gridX(ix));
    for(int iy=0; iy<npts[1]; iy++) {
      double y(gridY(iy));
      for(int iz=0; iz<npts[2]; iz++) {
        (*it)=infunc.f(x,y,gridZ(iz));++it;
      }
    }
  }
  timer.stop();
  cout << "Time to evaluate " << timer.cpu_time() << endl;


  //Test TriCubicSplineT function
  //Create XYZCubicGrid
  XYZCubicGrid<double> grid3(&gridX,&gridY,&gridZ);
  //Create a TriCubicSpline with PBC: have to think more about fixed-boundary conditions
  TriCubicSplineT<double> aorb(&grid3);

  //Reset the coefficients
  aorb.reset(inData.begin(), inData.end());

  double lap,val;
  TinyVector<double,3> grad;

  //aorb.reset();
  //Write for vtk ImageData
  string fname("spline3d.vti");
  std::ofstream dfile(fname.c_str());
  dfile.setf(ios::scientific, ios::floatfield);
  dfile.setf(ios::left,ios::adjustfield);
  dfile.precision(10);

  dfile << "<?xml version=\"1.0\"?>" << endl;
  dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl;
  dfile << "  <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 
    << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl;
  dfile << "    <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl;
  dfile << "       <PointData Scalars=\"wfs\">" << endl;
  dfile << "          <DataArray type=\"Float32\" Name=\"wfs\">" << endl;
  timer.start();
  int ng=0;
  for(int ix=0; ix<npts[0]-1; ix++) {
    double x(gridX(ix));
    for(int iy=0; iy<npts[1]-1; iy++) {
      double y(gridY(iy));
      for(int iz=0; iz<npts[2]-1; iz++, ng++) {
         TinyVector<double,3> p(x,y,gridZ(iz));
         //aorb.setgrid(p);
         //Timing with the ofstream is not correct. 
         //Uncomment the line below and comment out the next two line.
         //double t=aorb.evaluate(p,grad,lap);
         dfile << setw(20) << aorb.evaluate(p,grad,lap);
         if(ng%5 == 4) dfile << endl;
      }
    }
  }
  timer.stop();
  cout << "Time to evaluate with spline " << timer.cpu_time() << endl;
  dfile << "          </DataArray>" << endl;
  dfile << "       </PointData>" << endl;
  dfile << "    </Piece>" << endl;
  dfile << "  </ImageData>" << endl;
  dfile << "</VTKFile>" << endl;

  hid_t h_file = H5Fcreate("spline3d.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
  HDFAttribIO<std::vector<double> > dump(inData,npts);
  dump.write(h_file,"orb0000");
  HDFAttribIO<TriCubicSplineT<double> > dump1(aorb);
  dump1.write(h_file,"spline0000");
  H5Fclose(h_file);

  //double lap;
  //TinyVector<double,3> grad;
  //for(int k=0; k<nptY-1; k++) {
  //  //TinyVector<double,3> p(xcut,ycut,gridZ(k)+0.11*gridZ.dr(k));
  //  TinyVector<double,3> p(xcut,gridY(k)+0.11*gridY.dr(k),ycut);
  //  aorb.setgrid(p);
  //  double y=aorb.evaluate(p,grad,lap);
  //  dfile << setw(30) << p[1] << setw(30) << infunc.f(p) << setw(30) << y << setw(30) << infunc.d2f(p) << setw(30) << lap << endl;
  //}

  return 0;
}
Example #17
0
int main(){

   sky sky;

   double hbarc = 197.327;

   double Mu = M;   //Mass in MeV
   cout<<Mu<<endl;
   complex <double> M_I(0,1);

   // Create momentum space grid
   std::vector<double> kmesh;
   std::vector<double> kweights;
   double const kmax = 5.0;
   int const kpts = 170;
   kmesh.resize( kpts );
   kweights.resize( kpts );
   GausLeg( 0., kmax, kmesh, kweights );

   ////////Input Parameters of the potential (fit parameters) /////
   std::string parameters_filename="Input.inp";

   NuclearParameters Nu = read_nucleus_parameters( "Input/pca40.inp" );

   //I'm altering the potential to represent ca40 after a proton is removed (i.e. the potential for K39)
   /*Nu.A = 39.0;
     Nu.Z = 19.0;

     cout<<Nu.Z<<" "<<Nu.A<<endl;
     */

   double Ef=Nu.Ef;
   int lmax=20;
   double zp0;
   double tz=0.5;

   int type=1;
   int mvolume = 4;
   int AsyVolume = 1;

   double A = Nu.A;

   double  mu = (A)/((A-1.));

   if (tz>0) { zp0=1;}
   else {zp0=0;}

   double ph_gap = Nu.ph_gap;
   cout<<"ph_gap = "<<Nu.ph_gap<<endl;
   double  rStart = .05;
   double  rmax = 13.51999;
   int  ham_pts = 340; //300 for highR 

   double  rdelt = rmax / (ham_pts-2);
   cout<<"rdelt = "<<rdelt<<endl;

   vector<double> dr;
   dr.assign(ham_pts,rdelt);

   // Construct Parameters Object
   Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );
   // Construct Potential Object
   pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
   pot * pott = &pottt;
   cout<<"kconstant = "<<pott->kconstant<<endl;

   boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A, pott);

   double Elower = -11.61818;
   double Eupper = -9.4;
   double jj = .5;
   int ll = 0;
   int Ifine = 1;
   initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
   initiate.exteriorWaveFunct(ll);
   initiate.normalizeWF();


   double tol=.01;
   double estart=Ef;

   ///// Making rmesh///

   std::vector<double> rmesh_p= initiate.make_rmesh_point();
   std::vector<double> rmesh= initiate.make_rmesh();

   //int J=0.5;
   //lmax=6;
   //for(int L=0;L<lmax+1;L++){
   //	for(int s=0;s<2;s++){	
   //		J=L-0.5+s;
   //		if(J<0){
   //			J=0.5;
   //			s=1;
   //		}	
   //
   //		string slab;
   //		ostringstream convert;
   //		convert << s;
   //		slab = convert.str();
   //
   //		string jlab = sky.jlab(J);
   //		string llab = sky.llab(L);
   //	
   //		cout<<endl;
   //		cout<<"L = "<<L<<" J = "<<J<<endl;
   //		cout<<endl;
   //
   //		int N = 0;
   //
   //            string preq = "waves/partials/dom/eep100";
   //            string instring = preq + sky.Nlab(L) + sky.Nlab(s+1) + ".txt"; 
   //            cout<<instring<<endl;
   //	ifstream filein(instring.c_str());
   //      cout<<filein<<endl;
   //	vector <double> par;
   //	par.assign(rmesh.size(),0);
   //	std::string line;
   //	int i;
   //	i=0;
   //	while(getline(filein,line)){
   //		par[i] = atof(line.c_str());
   //            cout<<par[i]<<endl;
   //		i++;
   //	}
   //      cout<<"i = "<<i<<endl;
   //	filein.close();		
   //            vector<double> park = sky.four(L,par,rmesh,kmesh);
   //
   //            
   //		string fname = "waves/kwave/dom/" + llab +  slab + ".txt";
   //		ofstream ffile(fname.c_str());
   //            
   //            for(int i=0;i<kmesh.size();i++){
   //                  ffile<<kmesh[i]<<" "<<park[i]<<endl;
   //            }
   //
   //      }
   //}
   //
   //cout<<"done fourier transforming"<<endl;

   matrix_t test(rmesh.size(),rmesh.size());

   test = initiate.re_hamiltonian(rmesh,Ef,ll,jj); 

   eigen_t dom_wf_s = initiate.find_boundstate(rmesh, Ef, 1, 0, 0.5, tol);
   eigen_t dom_wf_d = initiate.find_boundstate(rmesh, Ef, 0, 2, 1.5, tol);

   ofstream dfile("wfdomd32.txt");
   ofstream sfile("wfdoms12.txt");

   double sf = initiate.sfactor(rmesh,dom_wf_d.first,2,1.5,dom_wf_d.second);

   sfile<<rmesh[0]<<" "<<dom_wf_s.second[0]<<endl;
   dfile<<"0.0 0.0"<<endl;
   for(int i=0;i<rmesh.size()-1;i++){
      if(i%2==1){
         dfile<<rmesh[i]<<" "<<dom_wf_d.second[i]<<endl;
         sfile<<rmesh[i]<<" "<<dom_wf_s.second[i]<<endl;
      }
   }

   double rms = 0.0;
   for(int i=0;i<rmesh.size();i++){
      rms += pow(dom_wf_d.second[i]*rmesh[i]*rmesh[i],2) * rdelt;
   }
   rms = sqrt(rms);

   cout<<"rms = "<<rms<<endl;

   cout<<"d3/2 spectroscopic factor = "<<sf<<endl;
   cout<<"d3/2 bound energy = "<<dom_wf_d.first<<endl;

   double  rdelt_p = rdelt / 1.025641026;

   double Emax = 2*Ef;
   double Emin=-200.0 + Emax;

   string title = "pca40";
   string* title0 = &title;

   double E0 = 0.52;

   ofstream rfile("react2.txt");

   //for(int j=1;j<201;j++){
   //      double Elab = E0 + j;

   double Elab = 100.0;

   /*
      if (Ecm < 0.) return Ecm/A*(1.+A);

   //find momentum of projecile, also momentum of target
   double pc = sqrt(Ecm)*sqrt((Ecm+2.*Mu)*(Ecm+2.*A*
   Mu)*
   (Ecm+2.*(A+1.)*scatterRspace::m0))/2./(Ecm+(A+1)
    *Mu);
   //velocity of target in units of c
   double vtarget = pc/sqrt(pow(pc,2)+pow(A*Mu,2));
   //gamma factor for this velocity
   double gam = 1./sqrt(1.-pow(vtarget,2));
   // tot energy of projectile (neutron or proton in com frame)
   double Eproj = sqrt(pow(Mu,2)+pow(pc,2));
   double Elab = (Eproj + vtarget*pc)*gam;
   //this energy contains rest mass , so remove it 
   Elab -= Mu;
   */

   //  A = Nu.A-1;

   if (Elab < 0.) return Elab*A/(1.+A);
   // center of mass velocity in units of c
   double vcm = sqrt(Elab*(Elab+2.*scatterRspace::m0))/(Elab+(1.+A)*
         scatterRspace::m0);
   //gamma factor for this velocity
   double gam = 1./sqrt(1.-std::pow(vcm,2));
   double Ecm = (gam-1.)*(1.+A)*scatterRspace::m0 +
      gam*Elab*(A-1.)*scatterRspace::m0/((A+1.)*
            scatterRspace::m0+Elab);


   //Just using the exact same com energy from e'p code...
   //Ecm = 96.4967424;


   //cout<<"A = "<<Nu.A<<" Z = "<<Nu.Z<<endl;
   //Doing the scattering from an N-1,A-1 nucleus
   scatterRspace scat(Nu.Z,1,Nu.A,pott,title0);

   scat.getSmatrix(Ecm,Elab);


   // testing out differential cross section

   //ofstream cfile("cross.txt");
   //
   //int count = 1000;
   //for(int i=0;i<count;i++){
   //double angle = i *(3.14159/count/2);
   //double cross = scat.DifferentialXsection(angle);
   //angle = angle * (180.0/3.14159);
   //cfile<<angle<<" "<<cross<<endl;
   //}
   string Estring;
   ostringstream convert;
   convert << Elab ;
   Estring = convert.str();

   double react = scat.AbsorptionXsection();

   rfile<<Elab<<" "<<react<<endl;

   //}
} //end of main
Example #18
0
int main(int argc, char** argv)
{
  double ri = 0.0;
  double rf = 1.0;
  int npts = 101;
  const double nk=2;
  const double twopi = 8.0*atan(1.0)*nk;
  LinearGrid<double> agrid;
  agrid.set(ri,rf,npts);
#if defined(USE_PBC)
  typedef OneDimCubicSplinePBC<double> OrbitalType;
#else
  typedef OneDimCubicSplineFirst<double> OrbitalType;
#endif
  OrbitalType aorb(&agrid);
  aorb.resize(agrid.size());
  for(int i=0; i<agrid.size(); i++)
  {
    aorb(i)=FUNCTION(twopi*agrid(i));
  }
  aorb.spline(0,twopi*DFUNCTION(twopi*agrid.rmin()),agrid.size()-1, twopi*DFUNCTION(twopi*agrid.rmax()));
  string fname("testpbc.dat");
  std::ofstream dfile(fname.c_str());
  dfile.setf(ios::scientific, ios::floatfield);
  dfile.setf(ios::left,ios::adjustfield);
  dfile.precision(15);
  const double c1=1.0/twopi;
  const double c2=c1*c1;
  double du,d2u,_r,_rinv,y;
#if defined(USE_PBC)
  for(int ig=agrid.size()/2; ig<agrid.size() ; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig)-agrid.rmax();
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#endif
  for(int ig=0; ig<agrid.size()-1; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig);
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y
          << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#if defined(USE_PBC)
  for(int ig=0; ig<agrid.size()/2; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig)+agrid.rmax();
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#endif
  dfile << endl;
  return 0;
}
Example #19
0
int main(){

   sky sky;

   double hbarc = 197.327;

   double Mu = M;   //Mass in MeV
   cout<<Mu<<endl;
   complex <double> M_I(0,1);

   // Create momentum space grid
   std::vector<double> kmesh;
   std::vector<double> kweights;
   double const kmax = 5.0;
   int const kpts = 170;
   kmesh.resize( kpts );
   kweights.resize( kpts );
   GausLeg( 0., kmax, kmesh, kweights );

   ////////Input Parameters of the potential (fit parameters) /////
   std::string parameters_filename="Input.inp";

   NuclearParameters Nu = read_nucleus_parameters( "Input/pca40.inp" );

   //I'm altering the potential to represent ca40 after a proton is removed (i.e. the potential for K39)
   /*Nu.A = 39.0;
     Nu.Z = 19.0;

     cout<<Nu.Z<<" "<<Nu.A<<endl;
     */

   double Ef=Nu.Ef;
   int lmax=20;
   double zp0;
   double tz=+0.5;

   int type=1;
   int mvolume = 4;
   int AsyVolume = 1;

   double A = Nu.A;

   double  mu = (A)/((A-1.));

   if (tz>0) { zp0=1;}
   else {zp0=0;}

   double ph_gap = Nu.ph_gap;
   cout<<"ph_gap = "<<Nu.ph_gap<<endl;
   double  rStart = .05;
   double  rmax = 13.51999;
   int  ham_pts = 340; //300 for highR 

   double  rdelt = rmax / (ham_pts-1);
   cout<<"rdelt = "<<rdelt<<endl;

   vector<double> dr;
   dr.assign(ham_pts,rdelt);

   // Construct Parameters Object
   Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );
   // Construct Potential Object
   pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
   pot * pott = &pottt;
   cout<<"kconstant = "<<pott->kconstant<<endl;

   boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A, pott);

   double Elower = -11.61818;
   double Eupper = -9.4;
   double jj = .5;
   int ll = 0;
   int Ifine = 1;
   initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
   initiate.exteriorWaveFunct(ll);
   initiate.normalizeWF();


   double tol=.01;
   double estart=Ef;

   ///// Making rmesh///

   std::vector<double> rmesh_p= initiate.make_rmesh_point();
   std::vector<double> rmesh= initiate.make_rmesh();

   matrix_t test(rmesh.size(),rmesh.size());

   test = initiate.re_hamiltonian(rmesh,Ef,ll,jj); 

   eigen_t dom_wf_s = initiate.find_boundstate(rmesh, Ef, 1, 0, 0.5, tol);
   eigen_t dom_wf_d = initiate.find_boundstate(rmesh, Ef, 0, 2, 1.5, tol);

   ofstream dfile("wfdomd32.txt");
   ofstream sfile("wfdoms12.txt");

   double sf = initiate.sfactor(rmesh,dom_wf_d.first,2,1.5,dom_wf_d.second);

   //dfile<<"0.0 0.0"<<endl;
   //Going to start from 0.08, since this is what dweepy does for BSWF
   //even though the partial wave starts from 0 in dweepy...
   for(int i=0;i<rmesh.size();i++){
      if(i%2==1){
         dfile<<rmesh[i]<<" "<<dom_wf_d.second[i]<<endl;
         sfile<<rmesh[i]<<" "<<dom_wf_s.second[i]<<endl;
      }
   }

   double rms = 0.0;
   for(int i=0;i<rmesh.size();i++){
      rms += pow(dom_wf_d.second[i]*rmesh[i]*rmesh[i],2) * rdelt;
   }
   rms = sqrt(rms);

   cout<<"rms = "<<rms<<endl;

   cout<<"d3/2 spectroscopic factor = "<<sf<<endl;
   cout<<"d3/2 bound energy = "<<dom_wf_d.first<<endl;
   cout<<"s1/2 bound energy = "<<dom_wf_s.first<<endl;
   cout<<"Fermi Energy = "<<Ef<<endl;

   double  rdelt_p = rdelt / 1.025641026;

   double Emax = 2*Ef;
   double Emin=-200.0 + Emax;

   string title = "pca40";
   string* title0 = &title;

   double E0 = 0.52;

   ofstream rfile("react2.txt");

   //for(int j=1;j<201;j++){
   //      double Elab = E0 + j;

   double Elab = 100.0;

   /*
      if (Ecm < 0.) return Ecm/A*(1.+A);

   //find momentum of projecile, also momentum of target
   double pc = sqrt(Ecm)*sqrt((Ecm+2.*Mu)*(Ecm+2.*A*
   Mu)*
   (Ecm+2.*(A+1.)*scatterRspace::m0))/2./(Ecm+(A+1)
    *Mu);
   //velocity of target in units of c
   double vtarget = pc/sqrt(pow(pc,2)+pow(A*Mu,2));
   //gamma factor for this velocity
   double gam = 1./sqrt(1.-pow(vtarget,2));
   // tot energy of projectile (neutron or proton in com frame)
   double Eproj = sqrt(pow(Mu,2)+pow(pc,2));
   double Elab = (Eproj + vtarget*pc)*gam;
   //this energy contains rest mass , so remove it 
   Elab -= Mu;
   */

   //  A = Nu.A-1;

   if (Elab < 0.) return Elab*A/(1.+A);
   // center of mass velocity in units of c
   double vcm = sqrt(Elab*(Elab+2.*scatterRspace::m0))/(Elab+(1.+A)*
         scatterRspace::m0);
   //gamma factor for this velocity
   double gam = 1./sqrt(1.-std::pow(vcm,2));
   double Ecm = (gam-1.)*(1.+A)*scatterRspace::m0 +
      gam*Elab*(A-1.)*scatterRspace::m0/((A+1.)*
            scatterRspace::m0+Elab);


   ////Just using the exact same com energy from e'p code...
   ////Ecm = 96.4967424;


   //scatterRspace scat(Nu.Z,1,Nu.A,pott,title0);

   //scat.getSmatrix(Ecm,Elab);

   
   //ofstream eout("elast.txt");
   //ofstream rout("ruth.txt");
   //ifstream din("cross.dat");
   //ofstream dout("cross.txt");
   ////ofstream eout("anal.txt");
   //double ruth,cross,angle;
   //double data,error,theta;
   //int count = 22;
   
   ////Just needed to run this once to adjust the data by dividing out rutherford
   //for(int i=0;i<count;i++){
      //din >> theta >> data >> error;
      //ruth = scat.Rutherford(theta*3.14159/180);
      //data = data / ruth;
      //error = error / ruth;
      //dout << theta << " " << data << " " << error << endl;
   //}
   //din.close();
   //dout.close();

   //// testing out differential cross section

   //count = 1000;
   //for(int i=1;i<count;i++){
      //angle = i *(3.14159/count/2);
      //cross = scat.DifferentialXsection(angle);
      //ruth = scat.Rutherford(angle);
      //angle = angle * (180.0/3.14159);
      //eout<<angle<<" "<<cross/ruth<<endl;
      //rout<<angle<<" "<<ruth<<endl;
   //}
   //eout.close();

   //string Estring;
   //ostringstream convert;
   //convert << Elab ;
   //Estring = convert.str();

   //double react = scat.AbsorptionXsection();

   //rfile<<Elab<<" "<<react<<endl;

   //}
} //end of main
Example #20
0
// #include"reaction.h"
int main(){

sky sky;

////////Input Parameters of the potential (fit parameters) /////
std::string parameters_filename="Input.inp";

//change this for neutron or proton
NuclearParameters Nu = read_nucleus_parameters( "Input/nca40.inp" );

double Ef=Nu.Ef;
//lmax can't be 6 for high r value
int lmax = 6;
double z0=20.0;
double zp0;
double A0=40.0;
// +1/2 for proton, -1/2 for neutron
double tz=-0.5;

int type=1;
int mvolume = 4;
int AsyVolume = 1;

double A = 40.0;

if (tz>0) { zp0=1;}
else {zp0=0;}

double ph_gap = Nu.ph_gap;
cout<<"ph_gap = "<<Nu.ph_gap<<endl;
double  rStart = .05;
double  rmax = 20.;
double  ham_pts = 300; 

double  rdelt = rmax / ham_pts;

        // Construct Parameters Object
        Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );

        // Construct Potential Object
        pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
	pot * pott = &pottt;

        // store coulomb potential in order to compare with




 boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A , pott);


  
 double Elower = -11.61818;
 double Eupper = -9.4;
 double jj = .5;
 int ll = 0;
 int Ifine = 1;
 initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
 initiate.exteriorWaveFunct(ll);
 initiate.normalizeWF();


double tol=.01;
double estart=Ef;

///// Making rmesh///

std::vector<double> rmesh_p= initiate.make_rmesh_point();
std::vector<double> rmesh= initiate.make_rmesh();
//std::vector<double> rmesh = initiate.make_rmesh_point();
double rdelt_p = rdelt * 39.0/40.0;

// Create momentum space grid
std::vector<double> kmesh;
std::vector<double> kweights;
double const kmax = 5.0;
int const kpts = rmesh.size();
kmesh.resize( kpts );
kweights.resize( kpts );
GausLeg( 0., kmax, kmesh, kweights );



////////////////////////////
//// s and d wave functions////
///////////////////////////
double J = 0.5;

double Emax=-0.005;
//double Emax = 2.0*Ef;
double Emin=-200.0;
//double Emin=-200.0 + Emax;

std::ofstream filee("waves/wave.out");
std::cout<<Elower<<std::endl;

//Generating the propagator

std::vector< lj_eigen_t > bound_levels = initiate.get_bound_levels( rmesh, tol );

cout<<"energy = "<<bound_levels[1][0].first<<endl;

ofstream boundf("waves/bound.txt");
for(int i=0;i<rmesh.size();i++){
	boundf<<rmesh[i]<<" "<<bound_levels[1][0].second[i]*rmesh[i]<<endl;
}

std::vector< mesh_t > emesh_vec =
        initiate.get_emeshes( rmesh, Emin, Emax, bound_levels );

cout<<"emesh_vec = "<<emesh_vec.size()<<endl;

std::vector< prop_t > prop_vec = initiate.get_propagators( rmesh, emesh_vec );

vector <double> pdist = initiate.point_distribution(rmesh,Emax,emesh_vec,prop_vec,bound_levels);

double occ[7];
double onum=0.0;
double num=0.0;

double part=0;
double kpart=0;
vector<double> p_dist;
p_dist.assign( rmesh.size(), 0 );
vector<double> k_dist;
k_dist.assign( kmesh.size(), 0 );

matrix_t d_mtx( rmesh.size(), rmesh.size() ); // density matrix
d_mtx.clear();


//Starting loop over L and J to go through all the orbitals
//THESE ARE CHANGED TO PRODUCE A SPECIFIC RESULT, CHANGE THEM BACK FOR GENERAL USE
lmax=3;
for(int L=3;L<lmax+1;L++){
	for(int s=0;s<2;s++){	
		J=L-0.5+s;
		if(J<0){
			J=0.5;
			s=1;
		}	
	
		cout<<"L = "<<L<<" J = "<<J<<endl;

		string jlab = sky.jlab(J);
		
		string llab = sky.llab(L);

		string dest = "waves/neutron/occ/";

		int index=initiate.index_from_LJ(L,J);

		const prop_t &propE = prop_vec.at(index);

		const mesh_t &emesh = emesh_vec.at(index);

		int Nmax = sky.Nmax(L,J);

		double socc[Nmax];

		string occlab =  dest + "sky" + llab + jlab + ".txt";
		ofstream focc(occlab.c_str());

// Create Bessel Function matrix in k and r
  /*  matrix_t bess_mtx( kmesh.size(), rmesh.size() );
		bess_mtx.clear();
		matrix_t bess_mtx_sky( kmesh.size(), rmesh.size() );
		bess_mtx_sky.clear();
    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
	    for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {
	      double rho = kmesh[nk] * rmesh[nr];
        bess_mtx( nk, nr ) = gsl_sf_bessel_jl( L, kmesh[nk] * rmesh_p[nr]);
				bess_mtx_sky( nk, nr ) = gsl_sf_bessel_jl( L, rho );
      }
    }	*/	

//Starting loop over N
		for(int N=0;N<Nmax;N++){
			d_mtx.clear();
			cout << "N = "<<N<<endl;
			string Nlab;
			ostringstream convert;
			convert << N;
			Nlab = convert.str();

			vector<double> wf = sky.read_q(N,L,J,rmesh.size());
			vector<double> skyrme = sky.read(N,L,J,rmesh.size());

			std::vector<double> spec;
			std::vector<double> spec0;

//Folding wave functions with S(r,r';E) to get S(E), does it for dom and skyrme wavefunctions
			double spf = 0;
			occ[N]=0;
			socc[N]=0;
			//cout<<"emesh size = "<<emesh.size()<<endl;
			for(unsigned int n=0;n<emesh.size();++n){
			  spf=0.0;
				double spf0=0;
				double Edelt=emesh[n].second;
			 for( unsigned int i = 0; i < rmesh.size(); ++i ) {
					for( unsigned int j = 0; j < rmesh.size(); ++j ) { 
						spf -= rdelt * skyrme[i] * skyrme[j] *imag( propE[n]( i, j ) ) / M_PI;
						d_mtx(i,j) -= imag(propE[n](i,j)) / M_PI / (rmesh[i] * rmesh[j] * rdelt) * Edelt;
					} 
				} 
			//WANT TO ADD A COUPLE MORE CATCHES IN HERE FOR VARIOUS OTHER ORBITALS!!!!!!!!!!!!!!!!
				if(L==0 && N==1 && emesh[n].first > -9){
					spf=0;
				}else if(L==2 && N==0 && J==1.5 && emesh[n].first > -10){
					spf=0;
				}else if(L==3 && N==0 && emesh[n].first > -9){
					spf=0;
				}
				
				spec.push_back(spf);
				spec0.push_back(spf0);
				occ[N] += spf0*Edelt;
				socc[N] += spf*Edelt;
			}

//creating the skyrme density
			for(int i=0;i<rmesh.size();i++){
				p_dist[i] += socc[N] * (2*J+1) * pow(skyrme[i]/rmesh[i],2) / (4*M_PI);
			//	k_dist[i] += socc[N] * (2*J+1) * pow(ksky[i],2) / (4*M_PI);
			}


//this adds the QP peaks to the particle number
			if(L==0 && N==1){
				const lj_eigen_t &levels = bound_levels.at(index);
        double QPE = levels[N].first;
        const std::vector<double> &QPF = levels[N].second;
        double S = initiate.sfactor( rmesh, QPE, L, J, QPF );
				onum += S*(2*J+1);
				occ[N] += S;
				for(int i=0;i<rmesh.size();i++){
					p_dist[i] += S * (2*J+1) * pow(QPF[i],2) / (4*M_PI);
				}
				//Transforming QPF to k-space
				/* vector <double> kqpf;
				kqpf.assign(kmesh.size(),0);
				for(int ik=0;ik<kmesh.size();ik++){
					double kq=0;
					for(int ir=0;ir<rmesh.size();ir++){
						kq += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * QPF[ir] * pow(rmesh_p[ir],2);
					}
					kqpf[ik] = kq;		
				}
				for(int i=0;i<rmesh.size();i++){
					k_dist[i] += S * (2*J+1) * pow(kqpf[i],2) / (4*M_PI);
				} */
			}else if(L==2 && J==1.5 && N==0){
				const lj_eigen_t &levels = bound_levels.at(index);
        double QPE = levels[N].first;
        const std::vector<double> &QPF = levels[N].second;
        double S = initiate.sfactor( rmesh, QPE, L, J, QPF );
				onum += S*(2*J+1);
				occ[N] += S;
				for(int i=0;i<rmesh.size();i++){
					p_dist[i] += S * (2*J+1) * pow(QPF[i],2) / (4*M_PI);
				}
			//see what happens if I find QPE using this self energy
				//Transforming QPF to k-space
				/* vector <double> kqpf;
				kqpf.assign(kmesh.size(),0);
				for(int ik=0;ik<kmesh.size();ik++){
					double kq=0;
					for(int ir=0;ir<rmesh.size();ir++){
						kq += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * QPF[ir] * pow(rmesh_p[ir],2);
					}
					kqpf[ik] = kq;		
				}
				for(int i=0;i<rmesh.size();i++){
					k_dist[i] += S * (2*J+1) * pow(kqpf[i],2) / (4*M_PI);
				} */
			}
			
			/* if(L ==3 && N == 0){
				//double QPEf = initiate.find_level(rmesh, -2.0, N, L, J, tol);
				eigen_t forbit = initiate.find_boundstate(rmesh, -2.0, N, L, J, tol);
				cout <<"QPE "<<llab<<jlab<<" = "<<forbit.first<<endl;
				double fs = initiate.sfactor(rmesh, forbit.first, L, J, forbit.second);
				cout <<"S "<<llab<<jlab<<" = "<<fs<<endl;
			}	*/	



			string speclab =   dest + "spec" + llab + jlab + Nlab + ".out";

			speclab = "waves/neutron/occ/new/spec" + llab + jlab + Nlab + ".out";

			ofstream fspec(speclab.c_str());
	
			for(int i=0;i<emesh.size();i++){
				fspec<<emesh[i].first<<" "<<emesh[i].second<<" "<<spec[i]<<endl;
				//fspec<<emesh[i].first<<" "<<spec[i]<<endl;
			}

//change this to occ if you want dom occupation numbers
			focc<<socc[N]<<endl;
			onum += socc[N]*(2*J+1);
			num += occ[N]*(2*J+1);		

		} //ending loop over N
	}		//ending loop over j
} 		//ending loop over L

ofstream sdenr("waves/skydenr.txt");
ofstream sdenk("waves/skydenk.txt");

for(int i=0;i<rmesh.size();i++){
	part += p_dist[i] * pow(rmesh_p[i],2) * rdelt_p * 4 * M_PI;
}

for(int i=0;i<rmesh.size();i++){
	sdenr<<rmesh_p[i]<<" "<<p_dist[i]/part<<endl;
}

cout<<"particle number from sky occ = "<<onum<<endl;
cout<<"particle number from sky density (r) = "<<part<<endl;
//out<<"particle number from sky density (k) = "<<kpart<<endl;

ofstream dfile("waves/background/wavedmtxt.txt");

for(int i=0;i<rmesh.size();i++){
	for(int j=0;j<rmesh.size();j++){
		dfile<<d_mtx(i,j)<<" ";
	}
	dfile<<endl;
}




}
Example #21
0
int main(int argc, char** argv){
	QStringList arg;
	for(int i=0; i<argc; ++i){
		arg.append(argv[i]);
	}
	
	if(arg.length() != 4){
		help();
		return -1;
	}
	
	const QString sfile = arg[1];
	QFile ffile(sfile);
	if(!ffile.open(QIODevice::ReadOnly)){
		qerr << "Unable to open input file "<<sfile<<endl;
		help();
		return -1;
	}
	QTextStream tfile(&ffile);
	
	const QString slfile = arg[2];
	QFile flfile(slfile);
	if(!flfile.open(QIODevice::WriteOnly)){
		qerr << "Unable to open input file "<<slfile<<endl;
		help();
		return -1;
	}
	QTextStream lfile(&flfile);
	
	const QString sdfile = arg[3];
	QFile fdfile(sdfile);
	if(!fdfile.open(QIODevice::WriteOnly)){
		qerr << "Unable to open input file "<<sdfile<<endl;
		help();
		return -1;
	}
	QTextStream dfile(&fdfile);
	
	// read in transactions from file
	QList<Transaction> tlist = readTransactionFile(tfile);
	
	// create a map of transactions searchable by name
	QHash<QString,Transaction> tname = mapNameTransaction(tlist);
	
	// create the intermediate transaction states
	QHash<TransactionStateHead,TransactionState> tstate = generateTransactionState(tlist);
	
	// create a map of dependencies
	QHash<TransactionStateHead,QSet<TransactionEdge> > tgraph = generateStateMap(tstate);
	
	// create a reveresed set of dependencies
	QHash<TransactionStateHead,QSet<TransactionEdge> > reverse = reverseStateMap(tgraph);
	
	// create a trimmed set of dependencies
	PeerMap trimLive = trimStateMapLive(tgraph, reverse);
	PeerMap trimDead = trimStateMapDead(tgraph, reverse);
	
//	printTransactions(qout, tlist);
//	printTransactionRoot(qout, tstate);
	printTransactionGraph(lfile, trimLive, true);
	printTransactionGraph(dfile, trimDead, false);
	
	ffile.close();
	flfile.close();
	fdfile.close();
	
	return 0;
}