コード例 #1
0
ファイル: pack_strain.C プロジェクト: cageo/Landry-2016
void
Elastic::FAC::pack_strain(double* buffer,
                          const SAMRAI::hier::Patch& patch,
                          const SAMRAI::hier::Box& region,
                          const int &depth) const
{
  boost::shared_ptr<SAMRAI::pdat::SideData<double> > v_ptr=
    boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
    (patch.getPatchData(v_id));
  SAMRAI::pdat::SideData<double>& v = *v_ptr;

  boost::shared_ptr<SAMRAI::pdat::CellData<double> > dv_diagonal;
  boost::shared_ptr<SAMRAI::pdat::SideData<double> > dv_mixed;
  if(!faults.empty())
    {
      dv_diagonal=boost::dynamic_pointer_cast<SAMRAI::pdat::CellData<double> >
        (patch.getPatchData(dv_diagonal_id));
      dv_mixed=boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
        (patch.getPatchData(dv_mixed_id));
    }

  const Gamra::Dir dim=d_dim.getValue();
  if(have_embedded_boundary())
    {
      boost::shared_ptr<SAMRAI::pdat::SideData<double> > level_set_ptr;
      if(have_embedded_boundary())
        level_set_ptr=boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
          (patch.getPatchData(level_set_id));
    }

  Gamra::Dir ix(Gamra::Dir::from_int(depth/dim)),
    iy(Gamra::Dir::from_int(depth%dim));
  const SAMRAI::hier::Index zero(SAMRAI::hier::Index::getZeroIndex(d_dim));
  SAMRAI::hier::Index ip(zero), jp(zero);
  ip[ix]=1;
  jp[iy]=1;

  const double *dx(boost::dynamic_pointer_cast
                   <SAMRAI::geom::CartesianPatchGeometry>
                   (patch.getPatchGeometry())->getDx());

  SAMRAI::pdat::CellIterator iend(SAMRAI::pdat::CellGeometry::end(region));
  for(SAMRAI::pdat::CellIterator
        icell(SAMRAI::pdat::CellGeometry::begin(region));
      icell!=iend; ++icell)
    {
      const SAMRAI::pdat::SideIndex
        s(*icell,ix,SAMRAI::pdat::SideIndex::Lower);
      if(ix==iy)
        {
          double diff(v(s+ip)-v(s));
          if(!faults.empty())
            diff-=(*dv_diagonal)(*icell,ix);
          *buffer=diff/dx[ix];
        }
      else
        {
          const int ix_iy(index_map(ix,iy,dim));
          double diff(- v(s-jp) - v(s+ip-jp) + v(s+jp)  + v(s+ip+jp));

          if(!faults.empty())
            diff+=(*dv_mixed)(s,ix_iy+1) - (*dv_mixed)(s-jp,ix_iy)
              + (*dv_mixed)(s+ip,ix_iy+1) - (*dv_mixed)(s+ip-jp,ix_iy)
              + (*dv_mixed)(s+jp,ix_iy+1) - (*dv_mixed)(s,ix_iy)
              + (*dv_mixed)(s+ip+jp,ix_iy+1) - (*dv_mixed)(s+ip,ix_iy);
          *buffer=diff/(4*dx[iy]);
        }
      ++buffer;
    }
}
コード例 #2
0
void Elastic::Boundary_Conditions::set_embedded_boundary
(const SAMRAI::hier::Patch& patch, const int &level_set_id,
 const int &dv_mixed_id)
{
  boost::shared_ptr<SAMRAI::pdat::SideData<double> > level_set_ptr=
    boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
    (patch.getPatchData(level_set_id));
  SAMRAI::pdat::SideData<double> &level_set(*level_set_ptr);

  boost::shared_ptr<SAMRAI::pdat::SideData<double> > dv_mixed_ptr;
  if(dv_mixed_id!=invalid_id)
    dv_mixed_ptr=boost::dynamic_pointer_cast
      <SAMRAI::pdat::SideData<double> >(patch.getPatchData(dv_mixed_id));

  const SAMRAI::tbox::Dimension dimension(patch.getDim());
  const Gamra::Dir dim(dimension.getValue());

  const SAMRAI::hier::Box gbox=level_set.getGhostBox();
  const SAMRAI::hier::Box box=level_set.getBox();

  boost::shared_ptr<SAMRAI::geom::CartesianPatchGeometry> geom =
    boost::dynamic_pointer_cast<SAMRAI::geom::CartesianPatchGeometry>
    (patch.getPatchGeometry());

  /* Corners are not synced, so we set the level set to a generic
   * negative value and dv_mixed to zero.  Setting dv_mixed to zero
   * implies that we do not care about faults that intersect that
   * corner (nor should we). */
  for(Gamra::Dir ix=0; ix<dim; ++ix)
    {
      const Gamra::Dir iy(ix.next(dim));
      const Gamra::Dir iz(iy.next(dim));

      std::vector<std::vector<int> > corners(dim);
      corners[ix].push_back(box.lower(ix));
      corners[ix].push_back(box.upper(ix)+1);

      if(geom->getTouchesRegularBoundary(iy,0))
        corners[iy].push_back(gbox.lower(iy));
      if(geom->getTouchesRegularBoundary(iy,1))
        corners[iy].push_back(gbox.upper(iy));

      if(dim==3)
        {
          if(geom->getTouchesRegularBoundary(iz,0))
            corners[iz].push_back(gbox.lower(iz));
          if(geom->getTouchesRegularBoundary(iz,1))
            corners[iz].push_back(gbox.upper(iz));
        }

      SAMRAI::pdat::SideIndex x(SAMRAI::hier::Index(dimension),ix,
                                SAMRAI::pdat::SideIndex::Lower);
      for(std::vector<int>::iterator i=corners[ix].begin();
          i!=corners[ix].end(); ++i)
        {
          x[ix]=*i;
          if(dim==2)
            {
              for(std::vector<int>::iterator j=corners[iy].begin();
                  j!=corners[iy].end();++j)
                {
                  x[iy]=*j;
                  set_embedded_values(x,dim,level_set,dv_mixed_ptr);
                }
            }
          else
            {
              for(std::vector<int>::iterator j=corners[iy].begin();
                  j!=corners[iy].end();++j)
                for(int kk=gbox.lower(iz); kk<=gbox.upper(iz); ++kk)
                  {
                    x[iy]=*j;
                    x[iz]=kk;
                    set_embedded_values(x,dim,level_set,dv_mixed_ptr);
                  }
              for(std::vector<int>::iterator k=corners[iz].begin();
                  k!=corners[iz].end();++k)
                {
                  for(int jj=gbox.lower(iy); jj<=gbox.upper(iy); ++jj)
                    {
                      x[iy]=jj;
                      x[iz]=*k;
                      set_embedded_values(x,dim,level_set,dv_mixed_ptr);
                    }
                }
            }
        }
    }
}