MeshDisplacement.cc 4.97 KB
Newer Older
1 2 3 4 5
/* 
    This file is a part of eXlibris C++ Library
    under the GNU General Public License:
    See the LICENSE.md files for terms and 
    conditions.
6
*/
7 8


9
// DamageBandDyn
10
#include "MeshDisplacement.h"
11 12 13 14 15
// Xfem
#include "xEntityFilter.h"
#include "xEval.h"
// AOMD
#include "mEntity.h"
16

17
using namespace xfem;
18

19 20 21
void MoveMeshToDeformed(const xEval<xVector>& eval_disp,
                        xMesh* mesh, const std::vector<xMesh*>& bnd_meshes,
                        xEntityToEntity upper_creator, xEntityToEntity upper_adjacent)
22
{
23 24
  typedef eXlibris_types::hash_map<mVertex*,mEntity*, EntityHashKey, EntityEqualKey> HashMapEntity;
  typedef eXlibris_types::hash_map<mVertex*,xVector, EntityHashKey, EntityEqualKey> HashMapVector;
25 26

  HashMapEntity move_mesh_map;
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
  for (std::vector<xMesh*>::const_iterator itsm=bnd_meshes.begin(); itsm!=bnd_meshes.end(); ++itsm)
  {
    xMesh* bnd_mesh = *itsm;
    for (xIter it=bnd_mesh->begin(1); it!=bnd_mesh->end(1); ++it)
    {
      mEntity* e = *it;
      mEntity* elt = upper_creator(e);
      if (elt)
      {
        for (int i=0; i<e->size(0); ++i)
          move_mesh_map[(mVertex*)e->get(0,i)] = elt; // add new vertex to map
        set<mEntity*> partition;
        mesh->getPartition(elt, partition);
        if (partition.size())
        {
          for (xPartition::iterator itp=partition.begin(); itp!=partition.end(); ++itp)
          {
            mEntity* eltp = *itp;
            for (int i=0; i<eltp->size(0); ++i)
              move_mesh_map[(mVertex*)eltp->get(0,i)] = elt; // add duplicated vertex to map
          }
        }
      }
    }
  }
  for (xIter itn=mesh->begin(0); itn!=mesh->end(0); ++itn)
  {
    mVertex* n = (mVertex*) *itn;
    mEntity* elt = upper_adjacent(n);
    if (elt)
      move_mesh_map[n] = elt;
  }
59 60
  HashMapVector displacement_map;
  for (HashMapEntity::iterator it=move_mesh_map.begin(); it!=move_mesh_map.end(); ++it)
61 62 63 64 65 66 67 68 69 70
  {
    mVertex* n = it->first;
    mEntity* elt = it->second;
    xGeomElem geom_appro(elt);
    Trellis_Util::mPoint pt = n->point();
    geom_appro.setUVWForXYZ(pt);
    xVector val;
    eval_disp(&geom_appro, &geom_appro, val);
    displacement_map[n] = val;
  }
71
  for (HashMapVector::iterator it=displacement_map.begin(); it!=displacement_map.end(); ++it)
72 73 74 75 76 77 78
  {
    mVertex* n = it->first;
    xVector disp = it->second;
    Trellis_Util::mPoint pt = n->point();
    Trellis_Util::mPoint pt_trans(disp(0), disp(1), disp(2));
    n->move(pt+pt_trans);
  }
79 80
}

81
void StoreInitialPos(xMesh* mesh)
82
{
83 84 85 86 87 88 89 90
  unsigned int init_tag = AOMD_Util::Instance()->lookupMeshDataId("initial_config");

  for (xIter itn=mesh->begin(0); itn!=mesh->end(0); ++itn)
  {
    mVertex* n = (mVertex*) *itn;
    const Trellis_Util::mPoint& pt = n->point();
    n->attachVector(init_tag, Trellis_Util::mVector(pt(0),pt(1),pt(2)));
  }
91 92
}

93 94 95
void MoveMeshToInitial(const xEval<xVector>& eval_disp,
                       xMesh* mesh, const std::vector<xMesh*>& bnd_meshes,
                       xEntityToEntity upper_creator)
96
{
97 98
  typedef eXlibris_types::hash_map<mVertex*,mEntity*, EntityHashKey, EntityEqualKey> HashMapEntity;
  typedef eXlibris_types::hash_map<mVertex*,xVector, EntityHashKey, EntityEqualKey> HashMapVector;
99

100 101
  unsigned int init_tag = AOMD_Util::Instance()->lookupMeshDataId("initial_config");

102
  HashMapEntity move_mesh_map;
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
  for (std::vector<xMesh*>::const_iterator itsm=bnd_meshes.begin(); itsm!=bnd_meshes.end(); ++itsm)
  {
    xMesh* bnd_mesh = *itsm;
    for (xIter it=bnd_mesh->begin(1); it!=bnd_mesh->end(1); ++it)
    {
      mEntity* e = *it;
      mEntity* elt = upper_creator(e);
      if (elt)
      {
        for (int i=0; i<e->size(0); ++i)
          move_mesh_map[(mVertex*)e->get(0,i)] = elt; // add new vertex to map
        set<mEntity*> partition;
        mesh->getPartition(elt, partition);
        if (partition.size())
        {
          for (xPartition::iterator itp=partition.begin(); itp!=partition.end(); ++itp)
          {
            mEntity* eltp = *itp;
            for (int i=0; i<eltp->size(0); ++i)
              move_mesh_map[(mVertex*)eltp->get(0,i)] = elt; // add duplicated vertex to map
          }
        }
      }
    }
  }
128 129
  HashMapVector displacement_map;
  for (HashMapEntity::iterator it=move_mesh_map.begin(); it!=move_mesh_map.end(); ++it)
130 131 132 133 134 135 136 137 138 139
  {
    mVertex* n = it->first;
    mEntity* elt = it->second;
    xGeomElem geom_appro(elt);
    Trellis_Util::mPoint pt = n->point();
    geom_appro.setUVWForXYZ(pt);
    xVector val;
    eval_disp(&geom_appro, &geom_appro, val);
    displacement_map[n] = val;
  }
140
  for (HashMapVector::iterator it=displacement_map.begin(); it!=displacement_map.end(); ++it)
141 142 143 144 145 146 147 148 149 150 151 152 153 154
  {
    mVertex* n = it->first;
    xVector disp = it->second;
    Trellis_Util::mPoint pt = n->point();
    Trellis_Util::mPoint pt_trans(disp(0), disp(1), disp(2));
    n->move(pt-pt_trans);
  }
  for (xIter itn=mesh->begin(0); itn!=mesh->end(0); ++itn)
  {
    mVertex* n = (mVertex*) *itn;
    const Trellis_Util::mVector& pos = n->getAttachedVector(init_tag);
    Trellis_Util::mPoint pt(pos(0), pos(1), pos(2));
    n->move(pt);
  }
155
}