Contact.h 8.86 KB
Newer Older
1
/*
2 3
    This source code is subject to non-permissive licence,
    see the DamageBandDyn/LICENSE file for conditions.
4
*/
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
#ifndef _Contact_h_
#define _Contact_h_
// Xfem
#include "xAlgorithm.h" //
#include "xBoundary.h"
#include "xData.h"
#include "xEval.h"
#include "xExportGmsh.h" //
// AOMD
#include "AOMD.h"

typedef std::pair<Trellis_Util::mPoint,xfem::xVector> OrientedSurface;
typedef boost::function<OrientedSurface (const Trellis_Util::mPoint&)> PointToOrientedSurface;

class Sphere
{
public:
  Sphere(const Trellis_Util::mPoint& o, const double& r) : origin(o), radius(r) {}
  OrientedSurface operator()(const Trellis_Util::mPoint& p) const;
private:
  Sphere();
  Trellis_Util::mPoint origin;
  double radius;
};

class Plane
{
public:
  Plane(const Trellis_Util::mPoint& p, xfem::xVector n) : point_on_plane(p), normal(n.norm()) {}
  OrientedSurface operator()(const Trellis_Util::mPoint& p) const;
private:
  Plane();
  Trellis_Util::mPoint  point_on_plane;
  xfem::xVector normal;
};

class InterVector
{
public:
  InterVector(const std::vector<PointToOrientedSurface>& ds_) : ds(ds_) {}
  OrientedSurface operator()(const Trellis_Util::mPoint& p)  const;
private:
  std::vector<PointToOrientedSurface> ds;
};

class FreePunch
{
public:
  FreePunch(double radius_) :
    point(0.005,0.,0.),
    origin(0.005-radius_,-radius_,0.),
    normal1(0.,1.,0.),
    normal2(1./sqrt(2.),1./sqrt(2.),0.),
    radius(radius_) {}
  OrientedSurface operator()(const Trellis_Util::mPoint& p) const;
private:
  Trellis_Util::mPoint point;
  Trellis_Util::mPoint origin;
  xVector normal1;
  xVector normal2;
  double radius;
};

class EvalContact : public xfem::xEval<std::pair<double,xfem::xVector> >
{
public:
  typedef boost::function<std::pair<Trellis_Util::mPoint,xfem::xVector> (const Trellis_Util::mPoint&)> PointToOrientedSurface;
  EvalContact(PointToOrientedSurface point_to_oriented_surface_) :
    point_to_oriented_surface(point_to_oriented_surface_) {}
  void operator()(const xfem::xGeomElem* geo_appro, const xfem::xGeomElem* geo_integ, std::pair<double, xfem::xVector>& res) const;
private:
   PointToOrientedSurface point_to_oriented_surface;
};

class Adaptator
{
public:
  Adaptator(PointToOrientedSurface point_to_oriented_surface_) : point_to_oriented_surface(point_to_oriented_surface_) {}
  double operator()(const Trellis_Util::mPoint& p) const;
private:
  PointToOrientedSurface point_to_oriented_surface;
};

template <typename MESHUPDATOR>
class TreatmentOfContact
{
public:
  TreatmentOfContact(MESHUPDATOR& mesh_updator_) :
    mesh_updator(mesh_updator_)
  {}
  void compute(const xfem::xField& displacement_field, const xfem::xField& velocity_field,
               const xfem::xData& data, const xfem::xBoundary& groups, double time_step, const xfem::xEntityFilter filter=xfem::xAcceptAll())
  {
    // HARDCODED
    FreePunch point_to_oriented_surface(0.0003);
    // HARDCODED

    EvalContact eval_contact(point_to_oriented_surface);

    xfem::xDoubleManager* disp_double_manager = displacement_field.getDoubleManager();
    xfem::xDoubleManager* velo_double_manager = velocity_field.getDoubleManager();
    std::map<AOMD::mVertex*, AOMD::mEntity*> vertex_map;
    for (xfem::xPhysicalEnv::const_iterator it = data.PhysicalEnv->begin(); it != data.PhysicalEnv->end(); ++it) {
      const xfem::xEnv& env = *it;
      if (env.Geom==CONTACT_LINE) {
        assert(env.Type==FIX);
        xfem::xClassRegion bc(data.mesh, env.Entity, env.getDimension());
        xfem::xFilteredRegion<xfem::xClassIter, xfem::xEntityFilter> fr_bc(bc.begin(), bc.end(), filter);
        xfem::xFilteredRegion<xfem::xClassIter, xfem::xEntityFilter>::FilterIter itf=fr_bc.begin();
        xfem::xFilteredRegion<xfem::xClassIter, xfem::xEntityFilter>::FilterIter endf=fr_bc.end();
        for (; itf!=endf; ++itf) {
          AOMD::mEntity* e = *itf;
          for (int i=0; i<e->size(0); ++i) {
            AOMD::mVertex* n = static_cast<AOMD::mVertex*>(e->get(0,i));
            vertex_map.insert(std::make_pair(n,e));
          }
        }
      }
    }
    std::map<AOMD::mVertex*, AOMD::mEntity*>::iterator itv=vertex_map.begin();
    std::map<AOMD::mVertex*, AOMD::mEntity*>::iterator endv=vertex_map.end();
    penetration_map.clear();
    for(; itv!=endv; ++itv) {
128 129
      AOMD::mVertex* n = itv->first;
      AOMD::mEntity* e = itv->second;
130 131 132 133 134 135 136 137 138 139 140 141 142
      xfem::xGeomElem geom_elem(e);
      geom_elem.setUVWForXYZ(n->point());
      std::pair<double,xfem::xVector> res;
      eval_contact(&geom_elem, &geom_elem, res);
      penetration_map.insert(std::make_pair(n, res));
    }
    std::map<AOMD::mVertex*, std::pair<double,xfem::xVector> >::iterator itp=penetration_map.begin();
    std::map<AOMD::mVertex*, std::pair<double,xfem::xVector> >::iterator endp=penetration_map.end();
    std::vector<std::pair<xfem::xValue<double>*, double> > disp_map;
    std::vector<std::pair<xfem::xValue<double>*, double> > velo_map;
    for (; itp!=endp; ++itp) {
      double penetration=itp->second.first;
      if (penetration<0.000001) {
143
        AOMD::mVertex* n = itp->first;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
        xfem::xVector normal=itp->second.second;
        std::vector<xfem::xValue<double>*> disp_vals;
        std::vector<xfem::xValue<double>*> velo_vals;
        xfem::xFiniteElement FEM;
        FEM.setKeys(n, displacement_field.begin(), displacement_field.end());
        disp_double_manager->getValPtr(FEM.beginKey(), FEM.endKey(), disp_vals);
        velo_double_manager->getValPtr(FEM.beginKey(), FEM.endKey(), velo_vals);
        std::vector<xfem::xValue<double>*>::const_iterator it_velo=velo_vals.begin();
        xfem::xVector dis, vel;
        for (int j=0; it_velo!=velo_vals.end(); ++it_velo, ++j) {
          vel(j)=(*it_velo)->getVal();
        }
        std::vector<xfem::xValue<double>*>::const_iterator it_disp=disp_vals.begin();
        it_velo=velo_vals.begin();
        dis=penetration*normal;
        xfem::xVector tang_vel=vel-(vel*normal)*normal;
        for (int j=0; it_disp!=disp_vals.end(); ++it_disp, ++it_velo, ++j) {
          disp_map.push_back(std::make_pair(*it_disp,(*it_disp)->getVal()-dis(j)));
          velo_map.push_back(std::make_pair(*it_velo,tang_vel(j)));
        }
      }
    }
    // Here we have to go back to initial config because if there is the
    // iso-zero of ls_in or ls_geo on an element that experiences contact we
    // have to move this iso-zero based on the disp field interpolation.  Note
    // that the following solution is BRUTE FORCE.
    if (!disp_map.empty()) {
      mesh_updator.moveInitial();
      for (std::vector<std::pair<xfem::xValue<double>*,double> >::const_iterator it=disp_map.begin(); it!=disp_map.end(); ++it) {
        (it->first)->setVal(it->second);
      }
      for (std::vector<std::pair<xfem::xValue<double>*,double> >::const_iterator it=velo_map.begin(); it!=velo_map.end(); ++it) {
        (it->first)->setVal(it->second);
      }
      mesh_updator.moveDeformed();
    }
  }
  void updateAccel(const xfem::xField& acceleration_field)
  {
    xfem::xDoubleManager* accel_double_manager = acceleration_field.getDoubleManager();
    std::map<AOMD::mVertex*, std::pair<double,xfem::xVector> >::iterator itp=penetration_map.begin();
    std::map<AOMD::mVertex*, std::pair<double,xfem::xVector> >::iterator endp=penetration_map.end();
    std::vector<std::pair<xfem::xValue<double>*, double> > accel_vec;
    for (; itp!=endp; ++itp) {
      double penetration=itp->second.first;
      if (penetration<0.000001) {
190
        AOMD::mVertex* n = itp->first;
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        xfem::xVector normal=itp->second.second;
        std::vector<xfem::xValue<double>*> accel_vals;
        xfem::xFiniteElement FEM;
        FEM.setKeys(n, acceleration_field.begin(), acceleration_field.end());
        accel_double_manager->getValPtr(FEM.beginKey(), FEM.endKey(), accel_vals);
        std::vector<xfem::xValue<double>*>::const_iterator it_accel=accel_vals.begin();
        xfem::xVector acc;
        for (int j=0; it_accel!=accel_vals.end(); ++it_accel, ++j) {
          acc(j)=(*it_accel)->getVal();
        }
        it_accel=accel_vals.begin();
        xfem::xVector tang_acc=acc-(acc*normal)*normal;
        for (int j=0; it_accel!=accel_vals.end(); ++it_accel, ++j) {
          accel_vec.push_back(std::make_pair(*it_accel,tang_acc(j)));
        }
      }
    }
    // if (!accel_vec.empty()) {
    //   mesh_updator.moveInitial();
    //   for (std::vector<std::pair<xfem::xValue<double>*,double> >::const_iterator it=accel_vec.begin(); it!=accel_vec.end(); ++it) {
    //     (it->first)->setVal(it->second);
    //   }
    //   mesh_updator.moveDeformed();
    // }
  }
private:
  MESHUPDATOR& mesh_updator;
  std::map<AOMD::mVertex*, std::pair<double,xfem::xVector> > penetration_map;
};

struct NoContact
{
  NoContact() {}
  void compute(const xfem::xField& displacement_field, const xfem::xField& velocity_field, const xfem::xData& data, const xfem::xBoundary& groups, double time_step, const xfem::xEntityFilter filter=xfem::xAcceptAll()) {}
  void updateAccel(const xfem::xField& acceleration_field) {}
};

#endif