Example #1
0
    boost::shared_ptr<PhotonArray> SBGaussian::SBGaussianImpl::shoot(int N, UniformDeviate u) const
    {
        dbg<<"Gaussian shoot: N = "<<N<<std::endl;
        dbg<<"Target flux = "<<getFlux()<<std::endl;
        boost::shared_ptr<PhotonArray> result(new PhotonArray(N));
        double fluxPerPhoton = _flux/N;
        for (int i=0; i<N; i++) {
            // First get a point uniformly distributed on unit circle
#ifdef USE_COS_SIN
            double theta = 2.*M_PI*u();
            double rsq = u(); // cumulative dist function P(<r) = r^2 for unit circle
            double sint,cost;
            (theta * radians).sincos(sint,cost);
            // Then map radius to the desired Gaussian with analytic transformation
            double rFactor = _sigma * std::sqrt( -2. * std::log(rsq));
            result->setPhoton(i, rFactor*cost, rFactor*sint, fluxPerPhoton);
#else
            double xu, yu, rsq;
            do {
                xu = 2.*u()-1.;
                yu = 2.*u()-1.;
                rsq = xu*xu+yu*yu;
            } while (rsq>=1. || rsq==0.);
            // Then map radius to the desired Gaussian with analytic transformation
            double rFactor = _sigma * std::sqrt( -2. * std::log(rsq) / rsq);
            result->setPhoton(i, rFactor*xu, rFactor*yu, fluxPerPhoton);
#endif
        }
        dbg<<"Gaussian Realized flux = "<<result->getTotalFlux()<<std::endl;
        return result;
    }
Example #2
0
    void SBGaussian::SBGaussianImpl::shoot(PhotonArray& photons, UniformDeviate ud) const
    {
        const int N = photons.size();
        dbg<<"Gaussian shoot: N = "<<N<<std::endl;
        dbg<<"Target flux = "<<getFlux()<<std::endl;
        double fluxPerPhoton = _flux/N;
        for (int i=0; i<N; i++) {
            // First get a point uniformly distributed on unit circle
#ifdef USE_COS_SIN
            double theta = 2.*M_PI*ud();
            double rsq = ud(); // cumulative dist function P(<r) = r^2 for unit circle
            double sint,cost;
            math::sincos(theta, sint, cost);
            // Then map radius to the desired Gaussian with analytic transformation
            double rFactor = _sigma * std::sqrt( -2. * std::log(rsq));
            photons.setPhoton(i, rFactor*cost, rFactor*sint, fluxPerPhoton);
#else
            double xu, yu, rsq;
            do {
                xu = 2.*ud()-1.;
                yu = 2.*ud()-1.;
                rsq = xu*xu+yu*yu;
            } while (rsq>=1. || rsq==0.);
            // Then map radius to the desired Gaussian with analytic transformation
            double rFactor = _sigma * std::sqrt( -2. * std::log(rsq) / rsq);
            photons.setPhoton(i, rFactor*xu, rFactor*yu, fluxPerPhoton);
#endif
        }
        dbg<<"Gaussian Realized flux = "<<photons.getTotalFlux()<<std::endl;
    }
Example #3
0
    boost::shared_ptr<PhotonArray> SBMoffat::SBMoffatImpl::shoot(int N, UniformDeviate u) const
    {
        dbg<<"Moffat shoot: N = "<<N<<std::endl;
        dbg<<"Target flux = "<<getFlux()<<std::endl;
        // Moffat has analytic inverse-cumulative-flux function.
        boost::shared_ptr<PhotonArray> result(new PhotonArray(N));
        double fluxPerPhoton = _flux/N;
        for (int i=0; i<N; i++) {
#ifdef USE_COS_SIN
            // First get a point uniformly distributed on unit circle
            double theta = 2.*M_PI*u();
            double rsq = u(); // cumulative dist function P(<r) = r^2 for unit circle
            double sint,cost;
            (theta * radians).sincos(sint,cost);
            // Then map radius to the Moffat flux distribution
            double newRsq = std::pow(1. - rsq * _fluxFactor, 1. / (1. - _beta)) - 1.;
            double rFactor = _rD * std::sqrt(newRsq);
            result->setPhoton(i, rFactor*cost, rFactor*sint, fluxPerPhoton);
#else
            // First get a point uniformly distributed on unit circle
            double xu, yu, rsq;
            do {
                xu = 2.*u()-1.;
                yu = 2.*u()-1.;
                rsq = xu*xu+yu*yu;
            } while (rsq>=1. || rsq==0.);
            // Then map radius to the Moffat flux distribution
            double newRsq = std::pow(1. - rsq * _fluxFactor, 1. / (1. - _beta)) - 1.;
            double rFactor = _rD * std::sqrt(newRsq / rsq);
            result->setPhoton(i, rFactor*xu, rFactor*yu, fluxPerPhoton);
#endif
        }
        dbg<<"Moffat Realized flux = "<<result->getTotalFlux()<<std::endl;
        return result;
    }
Example #4
0
 std::string SBTopHat::SBTopHatImpl::repr() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBTopHat("<<getRadius()<<", "<<
         getFlux()<<", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
Example #5
0
 std::string SBKolmogorov::SBKolmogorovImpl::repr() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBKolmogorov("<<getLamOverR0()<<", "<<getFlux();
     oss << ", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
Example #6
0
 std::string SBGaussian::SBGaussianImpl::serialize() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBGaussian("<<getSigma()<<", "<<getFlux();
     oss << ", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
Example #7
0
 std::string SBBox::SBBoxImpl::serialize() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBBox("<<getWidth()<<", "<<getHeight()<<", "<<
         getFlux()<<", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
Example #8
0
 std::string SBAiry::SBAiryImpl::repr() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBAiry("<<getLamOverD()<<", "<<getObscuration()<<", "<<
         getFlux()<<", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
 void SBInterpolatedImage::setFlux(double flux) 
 {
     checkReady();
     double factor = flux/getFlux();
     wts *= factor;
     if (xsumValid) *xsum *= factor;
     if (ksumValid) *ksum *= factor;
 }
Example #10
0
 std::string SBSpergel::SBSpergelImpl::serialize() const
 {
     std::ostringstream oss(" ");
     oss.precision(std::numeric_limits<double>::digits10 + 4);
     oss << "galsim._galsim.SBSpergel("<<getNu()<<", "<<getScaleRadius();
     oss << ", None, "<<getFlux();
     oss << ", galsim.GSParams("<<*gsparams<<"))";
     return oss.str();
 }
Example #11
0
 Position<double> SBShapelet::SBShapeletImpl::centroid() const
 {
     std::complex<double> cen(0.);
     double n = 1.;
     for (PQIndex pq(1,0); !pq.pastOrder(_bvec.getOrder()); pq.incN(), n+=2)
         cen += sqrt(n+1.) * _bvec[pq];
     cen *= sqrt(2.)*_sigma/getFlux();
     return Position<double>(real(cen),-imag(cen));
 }
Example #12
0
 boost::shared_ptr<PhotonArray> SBAutoConvolve::SBAutoConvolveImpl::shoot(
     int N, UniformDeviate u) const
 {
     dbg<<"AutoConvolve shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     boost::shared_ptr<PhotonArray> result = _adaptee.shoot(N, u);
     result->convolve(*_adaptee.shoot(N, u), u);
     dbg<<"AutoConvolve Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #13
0
 void SBAutoConvolve::SBAutoConvolveImpl::shoot(PhotonArray& photons, UniformDeviate ud) const
 {
     const int N = photons.size();
     dbg<<"AutoConvolve shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     _adaptee.shoot(photons, ud);
     PhotonArray temp(N);
     _adaptee.shoot(temp, ud);
     photons.convolve(temp, ud);
     dbg<<"AutoConvolve Realized flux = "<<photons.getTotalFlux()<<std::endl;
 }
Example #14
0
 boost::shared_ptr<PhotonArray> SBBox::SBBoxImpl::shoot(int N, UniformDeviate u) const
 {
     dbg<<"Box shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     boost::shared_ptr<PhotonArray> result(new PhotonArray(N));
     double fluxPerPhoton = _flux/N;
     for (int i=0; i<N; i++)
         result->setPhoton(i, _width*(u()-0.5), _height*(u()-0.5), fluxPerPhoton);
     dbg<<"Box Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #15
0
 boost::shared_ptr<PhotonArray> SBAiry::SBAiryImpl::shoot(int N, UniformDeviate u) const
 {
     dbg<<"Airy shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     boost::shared_ptr<PhotonArray> result=_info->shoot(N, u);
     // Then rescale for this flux & size
     result->scaleFlux(_flux);
     result->scaleXY(1./_D);
     dbg<<"Airy Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #16
0
 boost::shared_ptr<PhotonArray> SBKolmogorov::SBKolmogorovImpl::shoot(
     int N, UniformDeviate ud) const
 {
     dbg<<"Kolmogorov shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     // Get photons from the KolmogorovInfo structure, rescale flux and size for this instance
     boost::shared_ptr<PhotonArray> result = _info->shoot(N,ud);
     result->scaleFlux(_flux);
     result->scaleXY(1./_k0);
     dbg<<"Kolmogorov Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #17
0
 void SBAutoCorrelate::SBAutoCorrelateImpl::shoot(PhotonArray& photons, UniformDeviate ud) const
 {
     const int N = photons.size();
     dbg<<"AutoCorrelate shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     _adaptee.shoot(photons, ud);
     PhotonArray temp(N);
     _adaptee.shoot(temp, ud);
     // Flip sign of (x,y) in one of the results
     temp.scaleXY(-1.);
     photons.convolve(temp, ud);
     dbg<<"AutoCorrelate Realized flux = "<<photons.getTotalFlux()<<std::endl;
 }
Example #18
0
    boost::shared_ptr<PhotonArray> SBAdd::SBAddImpl::shoot(int N, UniformDeviate u) const 
    {
        dbg<<"Add shoot: N = "<<N<<std::endl;
        dbg<<"Target flux = "<<getFlux()<<std::endl;
        double totalAbsoluteFlux = getPositiveFlux() + getNegativeFlux();
        double fluxPerPhoton = totalAbsoluteFlux / N;

        // Initialize the output array
        boost::shared_ptr<PhotonArray> result(new PhotonArray(0));

        double remainingAbsoluteFlux = totalAbsoluteFlux;
        int remainingN = N;

        // Get photons from each summand, using BinomialDeviate to
        // randomize distribution of photons among summands
        for (ConstIter pptr = _plist.begin(); pptr!= _plist.end(); ++pptr) {
            double thisAbsoluteFlux = pptr->getPositiveFlux() + pptr->getNegativeFlux();

            // How many photons to shoot from this summand?
            int thisN = remainingN;  // All of what's left, if this is the last summand...
            std::list<SBProfile>::const_iterator nextPtr = pptr;
            ++nextPtr;
            if (nextPtr!=_plist.end()) {
                // otherwise allocate a randomized fraction of the remaining photons to this summand:
                BinomialDeviate bd(u, remainingN, thisAbsoluteFlux/remainingAbsoluteFlux);
                thisN = bd();
            }
            if (thisN > 0) {
                boost::shared_ptr<PhotonArray> thisPA = pptr->shoot(thisN, u);
                // Now rescale the photon fluxes so that they are each nominally fluxPerPhoton
                // whereas the shoot() routine would have made them each nominally 
                // thisAbsoluteFlux/thisN
                thisPA->scaleFlux(fluxPerPhoton*thisN/thisAbsoluteFlux);
                result->append(*thisPA);
            }
            remainingN -= thisN;
            remainingAbsoluteFlux -= thisAbsoluteFlux;
            if (remainingN <=0) break;
            if (remainingAbsoluteFlux <= 0.) break;
        }
        
        dbg<<"Add Realized flux = "<<result->getTotalFlux()<<std::endl;

        // This process produces correlated photons, so mark the resulting array as such.
        if (_plist.size() > 1) result->setCorrelated();
        
        return result;
    }
Example #19
0
 boost::shared_ptr<PhotonArray> SBAutoCorrelate::SBAutoCorrelateImpl::shoot(
     int N, UniformDeviate u) const
 {
     dbg<<"AutoCorrelate shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     boost::shared_ptr<PhotonArray> result = _adaptee.shoot(N, u);
     boost::shared_ptr<PhotonArray> result2 = _adaptee.shoot(N, u);
     // Flip sign of (x,y) in one of the results
     for (int i=0; i<result2->size(); i++) {
         Position<double> negxy = -Position<double>(result2->getX(i), result2->getY(i));
         result2->setPhoton(i, negxy.x, negxy.y, result2->getFlux(i));
     }
     result->convolve(*result2, u);
     dbg<<"AutoCorrelate Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #20
0
/**
  Compute dU = dt*dUdt, the change in the conserved variables over
  the time step. The fluxes are returned are suitable for use in refluxing.
  This has a default implementation but can be redefined as needed.
  */
void LinElastPhysics::computeUpdate(FArrayBox&       a_dU,
    FluxBox&         a_F,
    const FArrayBox& a_U,
    const FluxBox&   a_WHalf,
    const bool&      a_useArtificialViscosity,
    const Real&      a_artificialViscosity,
    const Real&      a_currentTime,
    const Real&      a_dx,
    const Real&      a_dt,
    const Box&       a_box)
{
    CH_assert(isDefined());

    a_dU.setVal(0.0);

    for (int idir = 0; idir < SpaceDim; idir++)
    {
        // Get flux from WHalf
        getFlux(a_F[idir],a_WHalf[idir],idir,a_F[idir].box());

        if (a_useArtificialViscosity)
        {
            artVisc(a_F[idir],a_U,
                a_artificialViscosity,a_currentTime,
                idir,a_box);
        }

        // Compute flux difference fHi-fLo
        FArrayBox diff(a_dU.box(), a_dU.nComp());
        diff.setVal(0.0);

        FORT_FLUXDIFFF(CHF_FRA(diff),
            CHF_CONST_FRA(a_F[idir]),
            CHF_CONST_INT(idir),
            CHF_BOX(a_box));

        // Add flux difference to dU
        a_dU += diff;

        ((LEPhysIBC*)m_bc)->updateBoundary(a_WHalf[idir],idir,a_dt,a_dx,a_currentTime+a_dt,true);
    }

    // Multiply dU by dt/dx because that is what the output expects
    a_dU *= -a_dt / a_dx;
}
Example #21
0
 boost::shared_ptr<PhotonArray> SBConvolve::SBConvolveImpl::shoot(int N, UniformDeviate u) const
 {
     dbg<<"Convolve shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     std::list<SBProfile>::const_iterator pptr = _plist.begin();
     if (pptr==_plist.end())
         throw SBError("Cannot shoot() for empty SBConvolve");
     boost::shared_ptr<PhotonArray> result = pptr->shoot(N, u);
     // It may be necessary to shuffle when convolving because we do
     // do not have a gaurantee that the convolvee's photons are
     // uncorrelated, e.g. they might both have their negative ones
     // at the end.
     // However, this decision is now made by the convolve method.
     for (++pptr; pptr != _plist.end(); ++pptr)
         result->convolve(*pptr->shoot(N, u), u);
     dbg<<"Convolve Realized flux = "<<result->getTotalFlux()<<std::endl;
     return result;
 }
Example #22
0
 void SBConvolve::SBConvolveImpl::shoot(PhotonArray& photons, UniformDeviate ud) const
 {
     const int N = photons.size();
     dbg<<"Convolve shoot: N = "<<N<<std::endl;
     dbg<<"Target flux = "<<getFlux()<<std::endl;
     std::list<SBProfile>::const_iterator pptr = _plist.begin();
     if (pptr==_plist.end())
         throw SBError("Cannot shoot() for empty SBConvolve");
     pptr->shoot(photons, ud);
     // It may be necessary to shuffle when convolving because we do
     // do not have a gaurantee that the convolvee's photons are
     // uncorrelated, e.g. they might both have their negative ones
     // at the end.
     // However, this decision is now made by the convolve method.
     for (++pptr; pptr != _plist.end(); ++pptr) {
         PhotonArray temp(N);
         pptr->shoot(temp, ud);
         photons.convolve(temp, ud);
     }
     dbg<<"Convolve Realized flux = "<<photons.getTotalFlux()<<std::endl;
 }
Example #23
0
bool pkmAudioSpectralFlux::detectOnset(float *magnitudes, int length)
{
    currentFlux = getFlux(magnitudes, length);
    
//    std::cout << "flux: " << currentFlux << " frames since last onset: " << numFramesSinceLastOnset << std::endl;
    
    if (isnan(currentFlux) | isinf(currentFlux)) {
        numFramesSinceLastOnset = 0;
        return false;
    }
    else {
        numFramesSinceLastOnset++;
    }
    
    
    if ((currentFlux > threshold) && (numFramesSinceLastOnset > minSegmentLength)) {
        numFramesSinceLastOnset = 0;
        return true;
    }
    else {
        return false;
    }
}
Example #24
0
 double SBAutoCorrelate::SBAutoCorrelateImpl::xValue(const Position<double>& pos) const
 {
     SBProfile temp = _adaptee.transform(-1., 0., 0., -1.);
     return RealSpaceConvolve(_adaptee,temp,pos,getFlux(),this->gsparams);
 }
Example #25
0
//
// VCAMRPoissonOp2::reflux()
//   There are currently the new version (first) and the old version (second)
//   in this file.  Brian asked to preserve the old version in this way for
//   now. - TJL (12/10/2007)
//
void VCAMRPoissonOp2::reflux(const LevelData<FArrayBox>&        a_phiFine,
                            const LevelData<FArrayBox>&        a_phi,
                            LevelData<FArrayBox>&              a_residual,
                            AMRLevelOp<LevelData<FArrayBox> >* a_finerOp)
{
  CH_TIMERS("VCAMRPoissonOp2::reflux");

  m_levfluxreg.setToZero();
  Interval interv(0,a_phi.nComp()-1);

  CH_TIMER("VCAMRPoissonOp2::reflux::incrementCoarse", t2);
  CH_START(t2);

  DataIterator dit = a_phi.dataIterator();
  for (dit.reset(); dit.ok(); ++dit)
  {
    const FArrayBox& coarfab   = a_phi[dit];
    const FluxBox&   coarBCoef = (*m_bCoef)[dit];
    const Box&       gridBox   = a_phi.getBoxes()[dit];

    if (m_levfluxreg.hasCF(dit()))
    {
      for (int idir = 0; idir < SpaceDim; idir++)
      {
        FArrayBox coarflux;
        Box faceBox = surroundingNodes(gridBox, idir);

        getFlux(coarflux, coarfab, coarBCoef, faceBox, idir);

        Real scale = 1.0;
        m_levfluxreg.incrementCoarse(coarflux, scale,dit(),
            interv, interv, idir);
      }
    }
  }

  CH_STOP(t2);

  // const cast:  OK because we're changing ghost cells only
  LevelData<FArrayBox>& phiFineRef = ( LevelData<FArrayBox>&)a_phiFine;

  VCAMRPoissonOp2* finerAMRPOp = (VCAMRPoissonOp2*) a_finerOp;
  QuadCFInterp& quadCFI = finerAMRPOp->m_interpWithCoarser;

  quadCFI.coarseFineInterp(phiFineRef, a_phi);
  // I'm pretty sure this is not necessary. bvs -- flux calculations use
  // outer ghost cells, but not inner ones
  // phiFineRef.exchange(a_phiFine.interval());
  IntVect phiGhost = phiFineRef.ghostVect();
  int ncomps = a_phiFine.nComp();

  CH_TIMER("VCAMRPoissonOp2::reflux::incrementFine", t3);
  CH_START(t3);

  DataIterator ditf = a_phiFine.dataIterator();
  const DisjointBoxLayout& dblFine = a_phiFine.disjointBoxLayout();
  for (ditf.reset(); ditf.ok(); ++ditf)
    {
      const FArrayBox& phifFab   = a_phiFine[ditf];
      const FluxBox&   fineBCoef = (*(finerAMRPOp->m_bCoef))[ditf];
      const Box&       gridbox   = dblFine.get(ditf());

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          //int normalGhost = phiGhost[idir];
          SideIterator sit;
          for (sit.begin(); sit.ok(); sit.next())
            {
              if (m_levfluxreg.hasCF(ditf(), sit()))
                {
                  Side::LoHiSide hiorlo = sit();
                  Box fluxBox = bdryBox(gridbox,idir,hiorlo,1);

                  FArrayBox fineflux(fluxBox,ncomps);
                  getFlux(fineflux, phifFab, fineBCoef, fluxBox, idir,
                          m_refToFiner);

                  Real scale = 1.0;
                  m_levfluxreg.incrementFine(fineflux, scale, ditf(),
                                             interv, interv, idir, hiorlo);
                }
            }
        }
    }

  CH_STOP(t3);

  Real scale = 1.0/m_dx;
  m_levfluxreg.reflux(a_residual, scale);
}
Example #26
0
void VCAMRPoissonOp2::reflux(const LevelData<FArrayBox>&        a_phiFine,
                            const LevelData<FArrayBox>&        a_phi,
                            LevelData<FArrayBox>&              a_residual,
                            AMRLevelOp<LevelData<FArrayBox> >* a_finerOp)
{
  CH_TIME("VCAMRPoissonOp2::reflux");

  int ncomp = 1;
  ProblemDomain fineDomain = refine(m_domain, m_refToFiner);
  LevelFluxRegister levfluxreg(a_phiFine.disjointBoxLayout(),
                               a_phi.disjointBoxLayout(),
                               fineDomain,
                               m_refToFiner,
                               ncomp);

  levfluxreg.setToZero();
  Interval interv(0,a_phi.nComp()-1);

  DataIterator dit = a_phi.dataIterator();
  for (dit.reset(); dit.ok(); ++dit)
    {
      const FArrayBox& coarfab = a_phi[dit];
      const FluxBox& coarBCoef  = (*m_bCoef)[dit];
      const Box& gridBox = a_phi.getBoxes()[dit];

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          FArrayBox coarflux;
          Box faceBox = surroundingNodes(gridBox, idir);
          getFlux(coarflux, coarfab, coarBCoef , faceBox, idir);

          Real scale = 1.0;
          levfluxreg.incrementCoarse(coarflux, scale,dit(),
                                     interv,interv,idir);
        }
    }
  LevelData<FArrayBox>& p = ( LevelData<FArrayBox>&)a_phiFine;

  // has to be its own object because the finer operator
  // owns an interpolator and we have no way of getting to it
  VCAMRPoissonOp2* finerAMRPOp = (VCAMRPoissonOp2*) a_finerOp;
  QuadCFInterp& quadCFI = finerAMRPOp->m_interpWithCoarser;

  quadCFI.coarseFineInterp(p, a_phi);
  // p.exchange(a_phiFine.interval()); // BVS is pretty sure this is not necesary.
  IntVect phiGhost = p.ghostVect();

  DataIterator ditf = a_phiFine.dataIterator();
  const  DisjointBoxLayout& dblFine = a_phiFine.disjointBoxLayout();
  for (ditf.reset(); ditf.ok(); ++ditf)
    {
      const FArrayBox& phifFab = a_phiFine[ditf];
      const FluxBox& fineBCoef  = (*(finerAMRPOp->m_bCoef))[ditf];
      const Box& gridbox = dblFine.get(ditf());
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          int normalGhost = phiGhost[idir];
          SideIterator sit;
          for (sit.begin(); sit.ok(); sit.next())
            {
              Side::LoHiSide hiorlo = sit();
              Box fabbox;
              Box facebox;

              // assumption here that the stencil required
              // to compute the flux in the normal direction
              // is 2* the number of ghost cells for phi
              // (which is a reasonable assumption, and probably
              // better than just assuming you need one cell on
              // either side of the interface
              // (dfm 8-4-06)
              if (sit() == Side::Lo)
                {
                  fabbox = adjCellLo(gridbox,idir, 2*normalGhost);
                  fabbox.shift(idir, 1);
                  facebox = bdryLo(gridbox, idir,1);
                }
              else
                {
                  fabbox = adjCellHi(gridbox,idir, 2*normalGhost);
                  fabbox.shift(idir, -1);
                  facebox = bdryHi(gridbox, idir, 1);
                }

              // just in case we need ghost cells in the transverse direction
              // (dfm 8-4-06)
              for (int otherDir=0; otherDir<SpaceDim; ++otherDir)
                {
                  if (otherDir != idir)
                    {
                      fabbox.grow(otherDir, phiGhost[otherDir]);
                    }
                }
              CH_assert(!fabbox.isEmpty());

              FArrayBox phifab(fabbox, a_phi.nComp());
              phifab.copy(phifFab);

              FArrayBox fineflux;
              getFlux(fineflux, phifab, fineBCoef, facebox, idir,
                      m_refToFiner);

              Real scale = 1.0;
              levfluxreg.incrementFine(fineflux, scale, ditf(),
                                       interv, interv, idir, hiorlo);
            }
        }
    }

  Real scale =  1.0/m_dx;
  levfluxreg.reflux(a_residual, scale);
}
Example #27
0
    boost::shared_ptr<PhotonArray> SBExponential::SBExponentialImpl::shoot(
        int N, UniformDeviate u) const
    {
        dbg<<"Exponential shoot: N = "<<N<<std::endl;
        dbg<<"Target flux = "<<getFlux()<<std::endl;
#ifdef USE_NEWTON_RAPHSON
        // The cumulative distribution of flux is 1-(1+r)exp(-r).
        // Here is a way to solve for r by an initial guess followed
        // by Newton-Raphson iterations.  Probably not
        // the most efficient thing since there are logs in the iteration.

        // Accuracy to which to solve for (log of) cumulative flux distribution:
        const double Y_TOLERANCE=this->gsparams->shoot_accuracy;

        double fluxPerPhoton = _flux / N;
        boost::shared_ptr<PhotonArray> result(new PhotonArray(N));

        for (int i=0; i<N; i++) {
            double y = u();
            if (y==0.) {
                // In case of infinite radius - just set to origin:
                result->setPhoton(i,0.,0.,fluxPerPhoton);
                continue;
            }
            // Initial guess
            y = -std::log(y);
            double r = y>2. ? y : sqrt(2.*y);
            double dy = y - r + std::log(1.+r);
            while ( std::abs(dy) > Y_TOLERANCE) {
                r = r + (1.+r)*dy/r;
                dy = y - r + std::log(1.+r);
            }
            // Draw another (or multiple) randoms for azimuthal angle 
#ifdef USE_COS_SIN
            double theta = 2. * M_PI * u();
#ifdef _GLIBCXX_HAVE_SINCOS
            // Most optimizing compilers will do this automatically, but just in case...
            double sint,cost;
            sincos(theta,&sint,&cost);
#else
            double cost = std::cos(theta);
            double sint = std::sin(theta);
#endif
            double rFactor = r * _r0;
            result->setPhoton(i, rFactor * cost, rFactor * sint, fluxPerPhoton);
#else
            double xu, yu, rsq;
            do {
                xu = 2. * u() - 1.;
                yu = 2. * u() - 1.;
                rsq = xu*xu+yu*yu;
            } while (rsq >= 1. || rsq == 0.);
            double rFactor = r * _r0 / std::sqrt(rsq);
            result->setPhoton(i, rFactor * xu, rFactor * yu, fluxPerPhoton);
#endif
        }
#else
        // Get photons from the ExponentialInfo structure, rescale flux and size for this instance
        boost::shared_ptr<PhotonArray> result = _info->shoot(N,u);
        result->scaleFlux(_flux_over_2pi);
        result->scaleXY(_r0);
#endif
        dbg<<"Exponential Realized flux = "<<result->getTotalFlux()<<std::endl;
        return result;
    }
Example #28
0
 double SBAutoCorrelate::SBAutoCorrelateImpl::xValue(const Position<double>& pos) const
 {
     SBProfile temp = _adaptee.rotate(180. * degrees);
     return RealSpaceConvolve(_adaptee,temp,pos,getFlux(),this->gsparams);
 }
Example #29
0
 double SBAutoConvolve::SBAutoConvolveImpl::xValue(const Position<double>& pos) const
 { return RealSpaceConvolve(_adaptee,_adaptee,pos,getFlux(),this->gsparams); }
Example #30
0
float pkmAudioSpectralFlux::getFlux(float *audioSignal)
{   
    fft->forward(0, audioSignal, magnitudes.data, phases.data);
    
    return getFlux(magnitudes.data, magnitudes.size());
}