Пример #1
0
/**
 * SPHSaverへのセーブ
 * @param filename セーブファイル名
 * @retval true  セーブ成功
 * @retval false セーブ失敗
 */
bool SPHSaver::Save(const char* filename){
    // @todo { double precision. }

    SphHeaderTop headerTop;
    SphHeaderSingle headerSingle;

    assert(m_volumeData->Component() == 1 || m_volumeData->Component() == 3);

    headerTop.svType = m_volumeData->Component() == 1 ? 1 : 2;
    headerTop.dType = 1; // float

    headerSingle.size[0] = static_cast<int>(m_volumeData->Width());
    headerSingle.size[1] = static_cast<int>(m_volumeData->Height());
    headerSingle.size[2] = static_cast<int>(m_volumeData->Depth());
    headerSingle.org[0]   = 0.0f;
    headerSingle.org[1]   = 0.0f;
    headerSingle.org[2]   = 0.0f;
    headerSingle.pitch[0] = 1.0f;
    headerSingle.pitch[1] = 1.0f;
    headerSingle.pitch[2] = 1.0f;
    headerSingle.step = 0;
    headerSingle.time = 0.0f;

    SphData sph(headerTop, headerSingle, m_volumeData->Buffer()->GetBuffer());

    std::string fname(filename);
    bool byteSwap = IsBigEndian();
    bool ret = SaveSphFile(&sph, fname, byteSwap);

	return ret;
}
Пример #2
0
//--------------------------------------------------------------------------------------------------
// MAIN
int main(int argc, char* argv[])
{
    // Validate arguments
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " OutputDirectory" << std::endl;
        return -1;
    }

    std::string outputPath(argv[1]);


    // Init simulator
    std::cout << "Initializing simulator..." << std::endl;
    const Vec3d volumeMin(-3,   0, -1);
    const Vec3d volumeMax( 3,   3,  1);
    const double mass = 1.0;
    const double restDensity = 998.23;
    const double h = 0.2;
    const double k = 100.0;
    const double dt = 0.001;
    BasicSPH sph(volumeMin, volumeMax, mass, restDensity, h, k, dt);
    sph.enableAdaptiveTimeStep();

    // Init particles
    std::cout << "Initializing particles" << std::endl;
    Vec3d boxMin(-3, 0, -1);
    Vec3d boxMax(-1, 2,  1);
    initParticlesBox(boxMin, boxMax, 0.1, sph.particles());

    // Output first frame (initial frames)
    const std::string filePrefix("particles_");
    SPHParticleHoudiniIO::outputParticles(sph.particles(), outputPath, filePrefix, 1);

    // Run simulation and output a frame every 1/24 second
    std::cout << "Running simulation!" << std::endl;
    const double frameTime = 1.0/24.0;
    const double totalSimulationTime = 10.0;
    double time = 0.0;
    int currentFrame = 2;
    while (time < totalSimulationTime)
    {
        std::cout << "Simulating frame " << currentFrame << " (" << (frameTime+time) << "s)";
        std::cout << std::endl;

        // Run simulation
        sph.run(frameTime);

        // Output particles
        SPHParticleHoudiniIO::outputParticles(sph.particles(), outputPath, filePrefix, currentFrame);

        // Update simulation time
        time += frameTime;
        ++currentFrame;
    }

    std::cout << "Done!" << std::endl;

    return 0;
}
void
nsChromeRegistryContent::RegisterSubstitution(const SubstitutionMapping& aSubstitution)
{
  nsCOMPtr<nsIIOService> io (do_GetIOService());
  if (!io)
    return;

  nsCOMPtr<nsIProtocolHandler> ph;
  nsresult rv = io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
  if (NS_FAILED(rv))
    return;

  nsCOMPtr<nsISubstitutingProtocolHandler> sph (do_QueryInterface(ph));
  if (!sph)
    return;

  nsCOMPtr<nsIURI> resolvedURI;
  if (aSubstitution.resolvedURI.spec.Length()) {
    rv = NS_NewURI(getter_AddRefs(resolvedURI),
                   aSubstitution.resolvedURI.spec,
                   aSubstitution.resolvedURI.charset.get(),
                   nullptr, io);
    if (NS_FAILED(rv))
      return;
  }

  rv = sph->SetSubstitution(aSubstitution.path, resolvedURI);
  if (NS_FAILED(rv))
    return;
}
   void AABoxContainTest::testMakeVolumeSphere()
   {
      gmtl::Spheref sph(gmtl::Point3f(1,1,1), 2);
      gmtl::AABoxf box;

      gmtl::Point3f expected_min(-1,-1,-1);
      gmtl::Point3f expected_max( 3, 3, 3);

      gmtl::makeVolume(box, sph);
      CPPUNIT_ASSERT(box.getMin() == expected_min);
      CPPUNIT_ASSERT(box.getMax() == expected_max);
      CPPUNIT_ASSERT(! box.isEmpty());
   }
Пример #5
0
 ///Randomly rotate sgrid_m
 void NonLocalECPComponent::randomize_grid(ParticleSet::ParticlePos_t& sphere, bool randomize)
 {
   if(randomize) {
     //const RealType twopi(6.28318530718);
     //RealType phi(twopi*Random()),psi(twopi*Random()),cth(Random()-0.5),
     RealType phi(TWOPI*((*myRNG)())), psi(TWOPI*((*myRNG)())), cth(((*myRNG)())-0.5);
     RealType sph(std::sin(phi)),cph(std::cos(phi)),
     sth(std::sqrt(1.0-cth*cth)),sps(std::sin(psi)),
     cps(std::cos(psi));
     TensorType rmat( cph*cth*cps-sph*sps, sph*cth*cps+cph*sps,-sth*cps,
         -cph*cth*sps-sph*cps,-sph*cth*sps+cph*cps, sth*sps,
         cph*sth,             sph*sth,             cth     );
     SpherGridType::iterator it(sgridxyz_m.begin());
     SpherGridType::iterator it_end(sgridxyz_m.end());
     SpherGridType::iterator jt(rrotsgrid_m.begin());
     int ic=0;
     while(it != it_end) {*jt = dot(rmat,*it); ++it; ++jt;}
     //copy the radomized grid to sphere
     std::copy(rrotsgrid_m.begin(), rrotsgrid_m.end(), sphere.begin());
   } else {
     //copy sphere to the radomized grid
     std::copy(sphere.begin(), sphere.end(), rrotsgrid_m.begin());
   }
 }
Пример #6
0
int main()
{

vector v1,v2,v3;
    
vec(&v1,0,-10004,-20);
vec(&v2,0.20,0.20,0.20);
vec(&v3,0,0,0);

sph(v1,10000,v2,0,0,v3,sp);

vec(&v1,0,0,-20);
vec(&v2,1,0.32,0.36);

sph(v1,4,v2,1,0.5,v3,sp+1);

vec(&v1,5,-1,-15);
vec(&v2,0.90,0.76,0.46);

sph(v1,2,v2,1,0,v3,sp+2);

vec(&v1,5,0,-25);
vec(&v2,0.65,0.77,0.97);

sph(v1,3,v2,1,0,v3,sp+3);

vec(&v1,-5.5,0,-15);
vec(&v2,0.90,0.90,0.90);

sph(v1,3,v2,1,0,v3,sp+4);

vec(&v1,0,20,-30);
vec(&v2,0,0,0);
vec(&v3,3,3,3);

sph(v1,3,v2,0,0,v3,sp+5);

rendering();
}
Пример #7
0
bool CollisionTester::FrustumCircleXZTest( const Frustum& frus, const Circle& cirXZ )
{
	Sphere sph( CVector3( cirXZ.mCenter.GetX(), frus.mCenter.GetY(), cirXZ.mCenter.GetY() ), cirXZ.mRadius );
	return FrustumSphereTest( frus, sph );
}
Пример #8
0
void Input::reader(const std::string & filename) {
  Getkw input_ = Getkw(filename, false, true);
  units_ = input_.getStr("UNITS");
  CODATAyear_ = input_.getInt("CODATA");
  initBohrToAngstrom(bohrToAngstrom, CODATAyear_);

  const Section & mol = input_.getSect("MOLECULE");
  MEPfromMolecule_ = true;
  if (mol.isDefined()) {
    geometry_ = mol.getDblVec("GEOMETRY");
    MEPfromMolecule_ = mol.getBool("MEP");
  }

  const Section & cavity = input_.getSect("CAVITY");

  cavityType_ = cavity.getStr("TYPE");
  area_ = cavity.getDbl("AREA");
  if (cavityType_ == "RESTART") {
    cavFilename_ = cavity.getStr("NPZFILE");
  }

  scaling_ = cavity.getBool("SCALING");
  radiiSet_ = detail::uppercase(cavity.getStr("RADIISET"));
  minimalRadius_ = cavity.getDbl("MINRADIUS");
  mode_ = detail::uppercase(cavity.getStr("MODE"));
  if (mode_ == "EXPLICIT") {
    std::vector<double> spheresInput = cavity.getDblVec("SPHERES");
    int j = 0;
    int nAtoms = int(spheresInput.size() / 4);
    for (int i = 0; i < nAtoms; ++i) {
      Eigen::Vector3d center;
      center = (Eigen::Vector3d() << spheresInput[j],
                spheresInput[j + 1],
                spheresInput[j + 2])
                   .finished();
      Sphere sph(center, spheresInput[j + 3]);
      spheres_.push_back(sph);
      j += 4;
    }
    // Initialize molecule from spheres only when molecule section is absent
    if (!mol.isDefined())
      molecule_ = Molecule(spheres_);
  } else if (mode_ == "ATOMS") {
    atoms_ = cavity.getIntVec("ATOMS");
    radii_ = cavity.getDblVec("RADII");
  }

  // Get the contents of the Medium section
  const Section & medium = input_.getSect("MEDIUM");
  // Get the name of the solvent
  std::string name = medium.getStr("SOLVENT");
  if (name == "EXPLICIT") {
    hasSolvent_ = false;
    // Get the probe radius
    probeRadius_ = medium.getDbl("PROBERADIUS");
    // Get the contents of the Green<inside> section...
    const Section & inside = medium.getSect("GREEN<INSIDE>");
    // ...and initialize the data members
    greenInsideType_ = inside.getStr("TYPE") + "_" + inside.getStr("DER");
    epsilonInside_ = inside.getDbl("EPS");
    // Get the contents of the Green<outside> section...
    const Section & outside = medium.getSect("GREEN<OUTSIDE>");
    // ...and initialize the data members
    greenOutsideType_ = outside.getStr("TYPE") + "_" + outside.getStr("DER");
    epsilonStaticOutside_ = outside.getDbl("EPS");
    epsilonDynamicOutside_ = outside.getDbl("EPSDYN");
    epsilonStatic1_ = outside.getDbl("EPS1");
    epsilonDynamic1_ = outside.getDbl("EPSDYN1");
    epsilonStatic2_ = outside.getDbl("EPS2");
    epsilonDynamic2_ = outside.getDbl("EPSDYN2");
    center_ = outside.getDbl("CENTER");
    width_ = outside.getDbl("WIDTH");
    origin_ = outside.getDblVec("INTERFACEORIGIN");
    if (outside.getStr("TYPE") == "SPHERICALDIFFUSE") {
      greenOutsideType_ += "_" + outside.getStr("PROFILE");
    }
    maxL_ = outside.getInt("MAXL");
  } else { // This part must be reviewed!! Some data members are not initialized...
    // Just initialize the solvent object in this class
    hasSolvent_ = true;
    if (solvents().find(name) == solvents().end()) {
      PCMSOLVER_ERROR("Solvent " + name + " NOT found!");
    } else {
      solvent_ = solvents()[name];
    }
    probeRadius_ = solvent_.probeRadius * angstromToBohr();
    // Specification of the solvent by name means isotropic PCM
    // We have to initialize the Green's functions data here, Solvent class
    // is an helper class and should not be used in the core classes.
    greenInsideType_ = "VACUUM_DERIVATIVE";
    epsilonInside_ = 1.0;
    greenOutsideType_ = "UNIFORMDIELECTRIC_DERIVATIVE";
    epsilonStaticOutside_ = solvent_.epsStatic;
    epsilonDynamicOutside_ = solvent_.epsDynamic;
  }
  integratorType_ = medium.getStr("DIAGONALINTEGRATOR");
  integratorScaling_ = medium.getDbl("DIAGONALSCALING");

  solverType_ = medium.getStr("SOLVERTYPE");
  correction_ = medium.getDbl("CORRECTION");
  hermitivitize_ = medium.getBool("MATRIXSYMM");
  isDynamic_ = medium.getBool("NONEQUILIBRIUM");

  const Section & chgdist = input_.getSect("CHARGEDISTRIBUTION");
  if (chgdist.isDefined()) {
    // Set monopoles
    if (chgdist.getKey<std::vector<double> >("MONOPOLES").isDefined()) {
      std::vector<double> mono = chgdist.getDblVec("MONOPOLES");
      int j = 0;
      int n = int(mono.size() / 4);
      multipoles_.monopoles = Eigen::VectorXd::Zero(n);
      multipoles_.monopolesSites = Eigen::Matrix3Xd::Zero(3, n);
      for (int i = 0; i < n; ++i) {
        multipoles_.monopolesSites.col(i) =
            (Eigen::Vector3d() << mono[j], mono[j + 1], mono[j + 2]).finished();
        multipoles_.monopoles(i) = mono[j + 3];
        j += 4;
      }
    }
    // Set dipoles
    if (chgdist.getKey<std::vector<double> >("DIPOLES").isDefined()) {
      std::vector<double> dipo = chgdist.getDblVec("DIPOLES");
      int j = 0;
      int n = int(dipo.size() / 6);
      multipoles_.dipoles = Eigen::Matrix3Xd::Zero(3, n);
      multipoles_.dipolesSites = Eigen::Matrix3Xd::Zero(3, n);
      for (int i = 0; i < n; ++i) {
        multipoles_.dipolesSites.col(i) =
            (Eigen::Vector3d() << dipo[j], dipo[j + 1], dipo[j + 2]).finished();
        multipoles_.dipoles.col(i) =
            (Eigen::Vector3d() << dipo[j + 3], dipo[j + 4], dipo[j + 5]).finished();
        j += 6;
      }
    }
  }

  providedBy_ = std::string("API-side");
}
Пример #9
0
GridMolecularOrbitals::BasisSetType*
GridMolecularOrbitals::addBasisSet(xmlNodePtr cur)
{
  if(!BasisSet)
    BasisSet = new BasisSetType(IonSys.getSpeciesSet().getTotalNum());
  QuantumNumberType nlms;
  string rnl;
  //current number of centers
  int ncenters = CenterID.size();
  int activeCenter;
  int gridmode = -1;
  bool addsignforM = false;
  string  sph("default"), Morder("gaussian");
  //go thru the tree
  cur = cur->xmlChildrenNode;
  map<string,RGFBuilderBase*> rbuilderlist;
  while(cur!=NULL)
  {
    string cname((const char*)(cur->name));
    if(cname == basis_tag || cname == "atomicBasisSet")
    {
      int expandlm = GAUSSIAN_EXPAND;
      string abasis("invalid"), btype("Numerical");
      //Register valid attributes attributes
      OhmmsAttributeSet aAttrib;
      aAttrib.add(abasis,"elementType");
      aAttrib.add(abasis,"species");
      aAttrib.add(btype,"type");
      aAttrib.add(sph,"angular");
      aAttrib.add(addsignforM,"expM");
      aAttrib.add(Morder,"expandYlm");
      aAttrib.put(cur);
      if(abasis == "invalid")
        continue;
      if(sph == "spherical")
        addsignforM=1; //include (-1)^m
      if(Morder == "gaussian")
      {
        expandlm = GAUSSIAN_EXPAND;
      }
      else
        if(Morder == "natural")
        {
          expandlm = NATURAL_EXPAND;
        }
        else
          if(Morder == "no")
          {
            expandlm = DONOT_EXPAND;
          }
      if(addsignforM)
        LOGMSG("Spherical Harmonics contain (-1)^m factor")
            else
              LOGMSG("Spherical Harmonics  DO NOT contain (-1)^m factor")
              //search the species name
              map<string,int>::iterator it = CenterID.find(abasis);
      if(it == CenterID.end())
        //add the name to the map CenterID
      {
        if(btype == "Numerical" || btype == "NG" || btype == "HFNG")
        {
          rbuilder = new NumericalRGFBuilder(cur);
        }
        else
        {
          rbuilder = new Any2GridBuilder(cur);
        }
        //CenterID[abasis] = activeCenter = ncenters++;
        CenterID[abasis]=activeCenter=IonSys.getSpeciesSet().findSpecies(abasis);
        int Lmax(0); //maxmimum angular momentum of this center
        int num(0);//the number of localized basis functions of this center
        //process the basic property: maximun angular momentum, the number of basis functions to be added
        vector<xmlNodePtr> radGroup;
        xmlNodePtr cur1 = cur->xmlChildrenNode;
        xmlNodePtr gptr=0;
        while(cur1 != NULL)
        {
          string cname1((const char*)(cur1->name));
          if(cname1 == basisfunc_tag || cname1 == "basisGroup")
          {
            radGroup.push_back(cur1);
            int l=atoi((const char*)(xmlGetProp(cur1, (const xmlChar *)"l")));
            Lmax = max(Lmax,l);
            //expect that only Rnl is given
            if(expandlm)
              num += 2*l+1;
            else
              num++;
          }
          else
            if(cname1 == "grid")
            {
              gptr = cur1;
            }
          cur1 = cur1->next;
        }
        XMLReport("Adding a center " << abasis << " centerid "<< CenterID[abasis])
        XMLReport("Maximum angular momentum    = " << Lmax)
        XMLReport("Number of centered orbitals = " << num)
        //create a new set of atomic orbitals sharing a center with (Lmax, num)
        //if(addsignforM) the basis function has (-1)^m sqrt(2)Re(Ylm)
        CenteredOrbitalType* aos = new CenteredOrbitalType(Lmax,addsignforM);
        aos->LM.resize(num);
        aos->NL.resize(num);
        //Now, add distinct Radial Orbitals and (l,m) channels
        num=0;
        rbuilder->setOrbitalSet(aos,abasis); //assign radial orbitals for the new center
        rbuilder->addGrid(gptr); //assign a radial grid for the new center
        vector<xmlNodePtr>::iterator it(radGroup.begin());
        vector<xmlNodePtr>::iterator it_end(radGroup.end());
        while(it != it_end)
        {
          cur1 = (*it);
          xmlAttrPtr att = cur1->properties;
          while(att != NULL)
          {
            string aname((const char*)(att->name));
            if(aname == "rid" || aname == "id")
              //accept id/rid
            {
              rnl = (const char*)(att->children->content);
            }
            else
            {
              map<string,int>::iterator iit = nlms_id.find(aname);
              if(iit != nlms_id.end())
                //valid for n,l,m,s
              {
                nlms[(*iit).second] = atoi((const char*)(att->children->content));
              }
            }
            att = att->next;
          }
          XMLReport("\n(n,l,m,s) " << nlms[0] << " " << nlms[1] << " " << nlms[2] << " " << nlms[3])
          //add Ylm channels
          num = expandYlm(rnl,nlms,num,aos,cur1,expandlm);
          ++it;
        }
        //add the new atomic basis to the basis set
        BasisSet->add(aos,activeCenter);
#if !defined(HAVE_MPI)
        rbuilder->print(abasis,1);
#endif
        if(rbuilder)
        {
          delete rbuilder;
          rbuilder=0;
        }
      }
      else
      {
        WARNMSG("Species " << abasis << " is already initialized. Ignore the input.")
      }
    }
    cur = cur->next;
  }
Пример #10
0
  GTOMolecularOrbitals::BasisSetType* 
  GTOMolecularOrbitals::addBasisSet(xmlNodePtr cur) {

    if(!BasisSet) 
      BasisSet = new BasisSetType(IonSys.getSpeciesSet().getTotalNum());

    QuantumNumberType nlms;
    string rnl;

    //current number of centers
    int ncenters = CenterID.size();
    int activeCenter;
    int gridmode = -1;
    bool addsignforM = true;
    string  sph("spherical"), Morder("gaussian");

    //go thru the tree
    cur = cur->xmlChildrenNode;
    while(cur!=NULL) {
      string cname((const char*)(cur->name));
      if(cname == basis_tag || cname == "atomicBasisSet") {
        int expandlm = GAUSSIAN_EXPAND;
        string abasis("invalid"), norm("no");

        //Register valid attributes attributes
        OhmmsAttributeSet aAttrib;
        aAttrib.add(abasis,"elementType"); aAttrib.add(abasis,"species");
        aAttrib.add(sph,"angular"); aAttrib.add(addsignforM,"expM"); 
        aAttrib.add(Morder,"expandYlm"); 
        aAttrib.add(norm,"normalized"); 
        aAttrib.put(cur);

        if(norm == "yes") Normalized=true;
        else Normalized=false;

        if(abasis == "invalid") continue;
        if(sph == "spherical") addsignforM=true; //include (-1)^m
        if(sph == "cartesian") addsignforM=false;

        if(Morder == "gaussian") {
          expandlm = GAUSSIAN_EXPAND;
        } else if(Morder == "natural"){
          expandlm = NATURAL_EXPAND;
        } else if(Morder == "no") {
          expandlm = DONOT_EXPAND;
        }

        if(addsignforM) 
          LOGMSG("Spherical Harmonics contain (-1)^m factor")
        else
          LOGMSG("Spherical Harmonics  DO NOT contain (-1)^m factor")

	map<string,int>::iterator it = CenterID.find(abasis); //search the species name
	if(it == CenterID.end()) {//add the name to the map CenterID

	  //CenterID[abasis] = activeCenter = ncenters++;
          CenterID[abasis]=activeCenter=IonSys.getSpeciesSet().findSpecies(abasis);
	  int Lmax(0); //maxmimum angular momentum of this center
          int num(0);//the number of localized basis functions of this center

	  //process the basic property: maximun angular momentum, the number of basis functions to be added
          vector<xmlNodePtr> radGroup;
	  xmlNodePtr cur1 = cur->xmlChildrenNode;
          xmlNodePtr gptr=0;
	  while(cur1 != NULL) {
	    string cname1((const char*)(cur1->name));
	    if(cname1 == basisfunc_tag || cname1 == "basisGroup") {
              radGroup.push_back(cur1);
    	      int l=atoi((const char*)(xmlGetProp(cur1, (const xmlChar *)"l")));
	      Lmax = max(Lmax,l);
	      if(expandlm) 
                num += 2*l+1;
	      else
                num++;
	    } 
	    cur1 = cur1->next;
	  }
	  LOGMSG("Adding a center " << abasis << " centerid "<< CenterID[abasis])
          LOGMSG("Maximum angular momentum    = " << Lmax)
          LOGMSG("Number of centered orbitals = " << num)

	  //create a new set of atomic orbitals sharing a center with (Lmax, num)
          //if(addsignforM) the basis function has (-1)^m sqrt(2)Re(Ylm)
	  CenteredOrbitalType* aos = new CenteredOrbitalType(Lmax,addsignforM);
	  aos->LM.resize(num);
	  aos->NL.resize(num);

          //Now, add distinct Radial Orbitals and (l,m) channels
	  num=0;
          vector<xmlNodePtr>::iterator it(radGroup.begin());
          vector<xmlNodePtr>::iterator it_end(radGroup.end());
          while(it != it_end) {
            cur1 = (*it);
	    xmlAttrPtr att = cur1->properties;
	    while(att != NULL) {
	      string aname((const char*)(att->name));
	      if(aname == "rid" || aname == "id") { //accept id/rid
	        rnl = (const char*)(att->children->content);
	      } else { 
	        map<string,int>::iterator iit = nlms_id.find(aname);
	        if(iit != nlms_id.end()) { //valid for n,l,m,s
	          nlms[(*iit).second] = atoi((const char*)(att->children->content));
	        } 
	      }
	      att = att->next;
	    }
	    LOGMSG("\n(n,l,m,s) " << nlms[0] << " " << nlms[1] << " " << nlms[2] << " " << nlms[3])

            //add Ylm channels
            num = expandYlm(rnl,nlms,num,aos,cur1,expandlm);
            ++it;
          }

          LOGMSG("Checking the order of angular momentum ")
          std::copy(aos->LM.begin(), aos->LM.end(), ostream_iterator<int>(app_log()," "));
          app_log() << endl;

	  //add the new atomic basis to the basis set
	  BasisSet->add(aos,activeCenter);
	}else {
	  WARNMSG("Species " << abasis << " is already initialized. Ignore the input.")
	}
      }
      cur = cur->next;
    }
Пример #11
0
int main(int argc, char *argv[]) {

   if (argc != 4) {
      cout << "Usage: run infilename intimestep outfilename" << endl;
      return(-1);
   }
   cout << "Ran program with argv = ";
   for (int i=0;i<argc;i++) {
      cout << argv[i];
   }
   cout << endl;

   CglobalVars globals;
   particleContainer ps;

   //get rank and init all MPI stuff. Put rank in globals
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &(globals.mpiSize));
   MPI_Comm_rank(MPI_COMM_WORLD, &(globals.mpiRank));

   if (globals.mpiRank==0) cout << "Reading input file..." <<endl;
   string filename = argv[1];
   Cio_data_vtk io_data(filename,&globals);
   io_data.readDomain(atoi(argv[2]),&globals);
   io_data.readGlobals(atoi(argv[2]),&globals);
   io_data.readRestart(atoi(argv[2]),&ps,&globals);

   
   if (globals.mpiRank==0) cout << "after read, n = "<<ps.size()<<endl;
   
   int outstep = atoi(argv[2]);

   if (TIME_OVERIDE) {
      if (globals.mpiRank==0) cout << "time was set to time = "<<globals.time<<endl;
      globals.time = START_TIME;
      if (globals.mpiRank==0) cout << "Overiding time, time = "<<globals.time<<endl;
   }
   if (NSTEP_OVERIDE) {
      outstep = START_NSTEP;
      if (globals.mpiRank==0) cout << "Overiding output timestep  = "<<outstep<<endl;
   }
   
   string outFilename = argv[3];
   if (globals.mpiRank==0) cout << "Setting output filename as: "<<outFilename<<endl;
   io_data.setFilename(outFilename,&globals);


   if (globals.mpiRank==0) cout << "1time was set to time = "<<globals.time<<endl;

   if (globals.mpiRank==0) cout << "Creating data structure..." <<endl;

   /*
   CdataLL<sphParticle> *data = new CdataLL<sphParticle>(ps,globals,true);
#ifdef LIQ_DEM
   CdataLL<demParticle> *dataDem = new CdataLL<demParticle>(ps,globals,true);
   CsphLiqDem sph(data,dataDem);
   CcustomSim customSim(data,dataDem,globals.time);
   CcustomOutput customOutput(data,dataDem);
#else
   CsphIncompress sph(data);
   CcustomSim customSim(data,globals.time);
   CcustomOutput customOutput(data);
#endif
*/
   CdataLL *data = new CdataLL(ps,globals,true);
   CsphIncompress sph(data);
   CcustomSim customSim(data,globals.time);
   CcustomOutput customOutput(data);

   if (globals.mpiRank==0) cout << "2time was set to time = "<<globals.time<<endl;

   globals.maxdt = MAXTIME/OUTSTEP;

   if (globals.mpiRank==0) cout << "Starting simulation..."<<endl;
#ifndef START_WRITE_TIME
   double nextWriteTime = globals.time+MAXTIME/OUTSTEP;
#else
   double nextWriteTime = START_WRITE_TIME
#endif

   timeval wtStartSphStep,wtStartOutStep,wtStartSim,wtCurrTime;
   gettimeofday(&wtStartSim,NULL);
   wtStartOutStep = wtStartSim;
   wtStartSphStep = wtStartSim;
   globals.startOutStep();

   while ((globals.time <= MAXTIME) && (outstep <= OUTSTEP)) {

      globals.sphStep++;
      

      gettimeofday(&wtCurrTime,NULL);
      double simTimeSPHStep = wtCurrTime.tv_sec-wtStartSim.tv_sec+(wtCurrTime.tv_usec-wtStartSim.tv_usec)/1000000.0;
      //if (globals.mpiRank==0) cout << "\r#"<<globals.sphStep<<". Time = "<<globals.time<<". Simulation "<<globals.time/MAXTIME*100<<"\% complete. "<<wtCurrTime.tv_sec-wtStartSphStep.tv_sec+(wtCurrTime.tv_usec-wtStartSphStep.tv_usec)/1000000.0<<" sec per SPH step. Time taken = "<<simTimeSPHStep/(60*60)<<flush;
      wtStartSphStep = wtCurrTime;

      customSim.beforeStart(globals.time);
      sph.start();
      customSim.beforeMiddle(globals.time);
      sph.middle();
      customSim.beforeEnd(globals.time);
      sph.end();
      customSim.afterEnd(globals.time);
      
      if (globals.time>= nextWriteTime) {
      //if(globals.sphStep%10==0){
      //if (1) {
         cout << endl;
         outstep++;
         globals.outstep = outstep;
         globals.endOutStep();
         

         if (globals.mpiRank==0) cout << "\tWriting output at time = "<<globals.time<<". Simulation is "<<globals.time/MAXTIME*100<<"\% complete"<<endl;

         sph.calcOutputVars();
         customOutput.calcOutput(outstep,&customSim,&io_data);
         io_data.writeOutput(outstep,ps,&globals);
         io_data.writeGlobals(outstep,&globals);

         if (outstep%RESTART_EVERY_N_STEPS==0) {
            io_data.writeRestart(outstep,ps,&globals);
            io_data.writeDomain(outstep,&globals);
         }

         data->calcTraverseOrder();    //arrange traverse order spatially

         nextWriteTime = globals.time+MAXTIME/OUTSTEP;
         globals.maxdt = MAXTIME/OUTSTEP;


         gettimeofday(&wtCurrTime,NULL);
         double oSTime = wtCurrTime.tv_sec-wtStartOutStep.tv_sec+(wtCurrTime.tv_usec-wtStartOutStep.tv_usec)/1000000.0;
         double simTime = wtCurrTime.tv_sec-wtStartSim.tv_sec+(wtCurrTime.tv_usec-wtStartSim.tv_usec)/1000000.0;
         if (globals.mpiRank==0) cout <<'\t'<<oSTime<< " seconds per output timestep, "<<oSTime*(OUTSTEP-outstep)/(60.0*60.0)<<" hours remaining. "<<simTime/(60.0*60.0)<<" hours since start"<<endl;
         wtStartOutStep = wtCurrTime;

         if (globals.mpiRank==0) cout <<'\t'<<"Step profile: Total time = "<<globals.wtTotalOutStep.tv_sec+globals.wtTotalOutStep.tv_usec/1000000.0<<" Force = "<<globals.wtTotalForceCalc.tv_sec+globals.wtTotalForceCalc.tv_usec/1000000.0<<" dddt = "<<globals.wtTotalDddtCalc.tv_sec+globals.wtTotalDddtCalc.tv_usec/1000000.0<<" reset = "<<globals.wtTotalReset.tv_sec+globals.wtTotalReset.tv_usec/1000000.0<<" update domain = "<<globals.wtTotalUpdateDomain.tv_sec+globals.wtTotalUpdateDomain.tv_usec/1000000.0<<" MPI = "<<globals.wtTotalMPI.tv_sec+globals.wtTotalMPI.tv_usec/1000000.0;
#ifdef SMOOTHING
         if (globals.mpiRank==0) cout <<" Smooth = "<<globals.wtTotalSmooth.tv_sec+globals.wtTotalSmooth.tv_usec/1000000.0<<" SmoothMPI = "<<globals.wtTotalSmoothMPI.tv_sec+globals.wtTotalSmoothMPI.tv_usec/1000000.0<<endl;
#else
         if (globals.mpiRank==0) cout <<endl;
#endif
         globals.startOutStep();
         //exit(-1);
      }
   }
   MPI_Finalize();
}
Пример #12
0
class timingData {
   timingData() {
      gettimeofday(&wtStartSim,NULL);
      wtStartOutStep = wtStartSim;
      wtStartSphStep = wtStartSim;
   }
   outputStartTimestep() {
      gettimeofday(&wtCurrTime,NULL);
      double simTimeSPHStep = wtCurrTime.tv_sec-wtStartSim.tv_sec+(wtCurrTime.tv_usec-wtStartSim.tv_usec)/1000000.0;
      //if (globals.mpiRank==0) cout << "\r#"<<globals.sphStep<<". Time = "<<globals.time<<". Simulation "<<globals.time/MAXTIME*100<<"\% complete. "<<wtCurrTime.tv_sec-wtStartSphStep.tv_sec+(wtCurrTime.tv_usec-wtStartSphStep.tv_usec)/1000000.0<<" sec per SPH step. Time taken = "<<simTimeSPHStep/(60*60)<<flush;
      wtStartSphStep = wtCurrTime;
   }
   outputStartOutputstep() {
      cout << endl;
   }


   private:
      timeval wtStartSphStep,wtStartOutStep,wtStartSim,wtCurrTime;
}


int main(int argc, char *argv[]) {

   CglobalVars globalsSPH;
   vector<sphParticles> psSPH;

   init(argc,argv,globalsSPH);

   Cio_data_vtk<sphParticles> io_dataSPH(atoi(argv[2]),argv[1],&psSPH,&globalsSPH);

   if (globals.mpiRank==0) cout << "Creating data structure..." <<endl;

   CdataLL *dataSPH = new CdataLL(psSPH,globalsSPH,true);
   CsphIncompress sph(dataSPH);

   CcustomSim customSim(data,globals.time);
   CcustomOutput customOutput(data);


   if (globals.mpiRank==0) cout << "Starting simulation..."<<endl;

   runUntilOutput(sph
   
   double nextWriteTime = globals.time+MAXTIME/OUTSTEP;

   
   globals.startOutStep();
   timingData timing;
   while ((globals.time <= MAXTIME) && (outstep <= OUTSTEP)) {

      globals.sphStep++;
      
      timing.outputStartTimestep();

      customSim.beforeStart(globals.time);
      sph.start();
      customSim.beforeMiddle(globals.time);
      sph.middle();
      customSim.beforeEnd(globals.time);
      sph.end();
      customSim.afterEnd(globals.time);
      
      if (globals.time>= nextWriteTime) {
      //if(globals.sphStep%10==0){
      //if (1) {
         cout << endl;
         outstep++;
         globals.outstep = outstep;
         globals.endOutStep();
         

         if (globals.mpiRank==0) cout << "\tWriting output at time = "<<globals.time<<". Simulation is "<<globals.time/MAXTIME*100<<"\% complete"<<endl;

         sph.calcOutputVars();
         customOutput.calcOutput(outstep,&customSim,&io_data);
         io_data.writeOutput(outstep,ps,customSim,&globals);
         io_data.writeGlobals(outstep,&globals);

         if (outstep%RESTART_EVERY_N_STEPS==0) {
            io_data.writeRestart(outstep,ps,&globals);
            io_data.writeDomain(outstep,&globals);
         }

         data->calcTraverseOrder();    //arrange traverse order spatially

         //vector<Cparticle> psGrid;
         //vectInt gridDims;
         //sph.renderToGrid(psGrid,gridDims);
         //io_data.writeGrid(outstep,psGrid,gridDims);

         nextWriteTime = globals.time+MAXTIME/OUTSTEP;
         globals.maxdt = MAXTIME/OUTSTEP;


         gettimeofday(&wtCurrTime,NULL);
         double oSTime = wtCurrTime.tv_sec-wtStartOutStep.tv_sec+(wtCurrTime.tv_usec-wtStartOutStep.tv_usec)/1000000.0;
         double simTime = wtCurrTime.tv_sec-wtStartSim.tv_sec+(wtCurrTime.tv_usec-wtStartSim.tv_usec)/1000000.0;
         if (globals.mpiRank==0) cout <<'\t'<<oSTime<< " seconds per output timestep, "<<oSTime*(OUTSTEP-outstep)/(60.0*60.0)<<" hours remaining. "<<simTime/(60.0*60.0)<<" hours since start"<<endl;
         wtStartOutStep = wtCurrTime;

         if (globals.mpiRank==0) cout <<'\t'<<"Step profile: Total time = "<<globals.wtTotalOutStep.tv_sec+globals.wtTotalOutStep.tv_usec/1000000.0<<" Force = "<<globals.wtTotalForceCalc.tv_sec+globals.wtTotalForceCalc.tv_usec/1000000.0<<" dddt = "<<globals.wtTotalDddtCalc.tv_sec+globals.wtTotalDddtCalc.tv_usec/1000000.0<<" reset = "<<globals.wtTotalReset.tv_sec+globals.wtTotalReset.tv_usec/1000000.0<<" update domain = "<<globals.wtTotalUpdateDomain.tv_sec+globals.wtTotalUpdateDomain.tv_usec/1000000.0<<" MPI = "<<globals.wtTotalMPI.tv_sec+globals.wtTotalMPI.tv_usec/1000000.0;
#ifdef SMOOTHING
         if (globals.mpiRank==0) cout <<" Smooth = "<<globals.wtTotalSmooth.tv_sec+globals.wtTotalSmooth.tv_usec/1000000.0<<" SmoothMPI = "<<globals.wtTotalSmoothMPI.tv_sec+globals.wtTotalSmoothMPI.tv_usec/1000000.0<<endl;
#else
         if (globals.mpiRank==0) cout <<endl;
#endif
         globals.startOutStep();
         //exit(-1);
      }
   }
   MPI_Finalize();
}