Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Element.cpp
Go to the documentation of this file.
1 /* Generated by Together */
2 
3 #include "Element.hpp"
4 #include "HexElement.hpp"
5 #include "TetElement.hpp"
6 #include "TCoElement.hpp"
7 #include "QCoElement.hpp"
8 #include "Node.hpp"
9 #include "Face.hpp"
10 #include "Mesh.hpp"
11 #include <assert.h>
12 #include <math.h>
13 
15 
16 
18 d_eType( type ),
19 d_ID(-1),
20 d_nodes(0),
21 d_faces(0),
22 d_materialType( e_unset_material )
23 {}
24 
26 
27  if( d_nodes ){
28  delete [] d_nodes;
29  }
30  if( d_faces ){
31  delete [] d_faces;
32  }
33 }
34 
36 
37  Element *elem;
38 
39  switch( type ){
40  case e_hex:
41  elem = new HexElement();
42  break;
43  case e_tet:
44  elem = new TetElement();
45  break;
46  case e_tri_cohesive:
47  elem = new TCoElement();
48  break;
49  case e_quad_cohesive:
50  elem = new QCoElement();
51  break;
52  default:
53  cerr << "BUG: Illegal element type in construction " << type << endl;
54  }
55  elem->setID( id );
56  return elem;
57 }
58 
59 void Element::setFromNodes(Node ** thenodes){
60 
61  int numn = getNumNodes();
62  int i;
63  for( i = 0; i < numn; i++ ){
64  d_nodes[i] = thenodes[i];
65  d_nodes[i]->addElement( this );
66  }
68 }
69 
70 istream& operator>>(istream& stream, Element& elem){
71 
72  // read material
73  stream >> elem.d_materialType;
74 
75  // read nodes & set
76 
77  int numn = elem.getNumNodes();
78  int i;
79  for( i = 0; i < numn; i++ ){
80  int node_id;
81  stream >> node_id;
82  Node *node = elem.s_mesh->getNode(node_id);
83  elem.d_nodes[i] = node;
84  node->addElement( &elem );
85  }
86  elem.setFromMyNodes();
87  return stream;
88 
89 }
90 
91 ostream& operator<<(ostream& stream, Element& elem){
92 
93  stream << elem.d_ID << '\t' << elem.d_eType << '\t' << elem.d_materialType;
94 
95  // write nodes out to file.
96 
97  //OK, we have to special-case the cohesive elements due to
98  //the strange way that they are supposed to be output. So,
99  //the tet-cohesive element needs to have 1-2-3 as usual, but then "4" should be
100  //the node that matches up with node 3, instead of node 1. Thus, since
101  //the elements are stored 1-2-3 4-5-6, with 4 matched with 1, 5 matched
102  //with 2, etc., we have to output 1-2-3-6-4-5. Similarly, for the
103  //quad cohesive, we output 1-2-3-4-8-5-6-7.
104  switch(elem.d_eType) {
105  case 2: //e_tri_cohesive
106  stream << '\t' << elem.d_nodes[0]->getID();
107  stream << '\t' << elem.d_nodes[1]->getID();
108  stream << '\t' << elem.d_nodes[2]->getID();
109  stream << '\t' << elem.d_nodes[5]->getID();
110  stream << '\t' << elem.d_nodes[3]->getID();
111  stream << '\t' << elem.d_nodes[4]->getID();
112  stream << endl;
113  break;
114  case 3: //e_quad_cohesive
115  stream << '\t' << elem.d_nodes[0]->getID();
116  stream << '\t' << elem.d_nodes[1]->getID();
117  stream << '\t' << elem.d_nodes[2]->getID();
118  stream << '\t' << elem.d_nodes[3]->getID();
119  stream << '\t' << elem.d_nodes[7]->getID();
120  stream << '\t' << elem.d_nodes[4]->getID();
121  stream << '\t' << elem.d_nodes[5]->getID();
122  stream << '\t' << elem.d_nodes[6]->getID();
123  stream << endl;
124  break;
125  default:
126  //put out in the order it's stored in the d_nodes array.
127  //default for normal tet and brick elements.
128  int numn = elem.getNumNodes();
129  int i;
130  for( i = 0; i < numn; i++ ){
131  stream << '\t' << elem.d_nodes[i]->getID();
132  }
133  stream << endl;
134  }
135  return stream;
136 }
137 
138 void Element::replaceNode (Node *node, Node *new_node ) {
139 
140  int i;
141  int numn = getNumNodes();
142  for( i = 0; i< numn; i++ ){
143  if( d_nodes[i] == node ){
144  d_nodes[i] = new_node;
145  node->removeElement( this );
146  new_node->addElement( this );
147  }
148  }
149  int numf = getNumFaces();
150  for( i = 0; i < numf; i++ ){
151  d_faces[i]->replaceNode( node, new_node );
152  }
153 }
154 
155 void Element::replaceFace (Face *face, Face *new_face){
156 
157  int i;
158  int numf = getNumFaces();
159  for( i = 0; i< numf; i++ ){
160  if( d_faces[i] == face ){
161  d_faces[i] = new_face;
162  }
163  }
164 }
165 
166 //The following two methods should be overridden in derived classes.
167 
169  assert( 0 );
170 }
171 
172 
174  assert( 0 );
175 }
176 
Face ** d_faces
Definition: Element.hpp:87
virtual void replaceFaceNode(Node *node, Node *new_node, Face *face)
Definition: Element.cpp:168
virtual int getNumNodes() const =0
static Element * create(int id, Type type)
Definition: Element.cpp:35
void replaceNode(Node *node, Node *new_node)
Definition: Face.cpp:93
int d_ID
Definition: Element.hpp:84
This class encapsulate a node over a window manifold.
Definition: Manifold_2.h:370
Definition: face.h:90
Type d_eType
Definition: Element.hpp:82
void replaceNode(Node *node, Node *new_node)
Definition: Element.cpp:138
Class Mesh is the main class that holds all information to describe the current state of the mesh...
Definition: Mesh.hpp:19
int getID()
Definition: Node.hpp:119
Node ** d_nodes
Definition: Element.hpp:86
Definition: adj.h:150
virtual int getNumFaces() const =0
virtual void setFromMyNodes()=0
virtual void setFromNodes(Node **thenodes)
Definition: Element.cpp:59
blockLoc i
Definition: read.cpp:79
Element(Type type)
Definition: Element.cpp:17
Node * getNode(int ID)
The following get methods return a node, face or element.
Definition: Mesh.hpp:137
void setID(int theID)
Definition: Element.hpp:100
static Mesh * s_mesh
Definition: Element.hpp:91
virtual double getMinEdgeLength()
Definition: Element.cpp:173
~Element()
Definition: Element.cpp:25
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
void replaceFace(Face *face, Face *new_face)
Definition: Element.cpp:155
The Face class is an abstract base class that supplies implemented general methods, as well as a vew virtual interface methods to child classes.
Definition: Face.hpp:19
void addElement(Element *elem)
Definition: Node.cpp:86
void removeElement(Element *elem)
Definition: Node.cpp:102
int d_materialType
Definition: Element.hpp:89