File: Corner.cpp

package info (click to toggle)
esys-particle 2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,284 kB
  • sloc: cpp: 77,304; python: 5,647; makefile: 1,176; sh: 10
file content (122 lines) | stat: -rw-r--r-- 2,653 bytes parent folder | download
1
2
3
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
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC)      //
// http://www.uq.edu.au/esscc                              //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////

#include "Corner.h"

/*!
  constructor

  \param pos the position of the corner
  \param id the node id
  \param tag the node tag
*/
Corner::Corner(const Vec3& pos,int id, int tag)
{
  m_p=pos;
  m_old_pos=m_p;
  m_id=id;
  m_tag=tag;
}
 
/*!
  add Edge to corner
  
  \param edge a pointer to the edge
*/ 
void Corner::addEdge(Edge* edge)
{
  m_edges.push_back(edge);
}

/*!
  add Triangle to Corner

  \param triangle a pointer to the triangle
*/
void Corner::addTriangle(Triangle* triangle)
{
  m_triangles.push_back(triangle);
}

void Corner::applyForce(const Vec3 &f)
{
  if (m_triangles.size() > 0)
  {
    const Vec3 portionF = f*(1.0/m_triangles.size());
    for (
      std::vector<Triangle *>::iterator it = m_triangles.begin();
      it != m_triangles.end();
      ++it
    ){
      (*it)->applyForce(portionF);
    }
  }
}

/*!
  get distance between corner and point

  \param p the point
*/
double Corner::sep(const Vec3& p) const
{
  return (m_p-p).norm();
}

/*!
  check if the contact between a particle at a point and the 
  corner is valid or if there is a contact between the particle
  and any of the adjacent edges or triangles

  \param p the center of the particle 
*/
bool Corner::isValidContact(const Vec3& p) const
{ 
  bool res=true;
  
  // check vs. Triangles
  vector<Triangle*>::const_iterator titer=m_triangles.begin();
  while((titer!=m_triangles.end())&&(res)){
    res=!((*titer)->dist(p).first);
    titer++;
  }

  // if no contact with triangle, check vs. Edges
  if(res){
    vector<Edge*>::const_iterator eiter=m_edges.begin();
    while((eiter!=m_edges.end())&&(res)){
      res=!((*eiter)->dist(p).first);
      eiter++;
    }
  }
  return res;
}

/*!
  get the unit direction vector between a point and the corner

  \param p the point
*/
Vec3 Corner::getDirectionFromPoint(const Vec3& p) const
{
  return (p-m_p).unit();
}

/*!
  move the corner

  \param d the displacement
*/
void Corner::move(const Vec3& d)
{
  m_p+=d;
}