File: Cell.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (132 lines) | stat: -rw-r--r-- 3,707 bytes parent folder | download | duplicates (2)
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
123
124
125
126
127
128
129
130
131
132
/*=========================================================================

Copyright (c) Kitware Inc.
All rights reserved.

=========================================================================*/
// This class was written by Daniel Aguilera and Philippe Pebay
// This work was supported by Commissariat a l'Energie Atomique (CEA/DIF)

#include "Mesh.h"
#include "Cell.h"
#include "Node.h"

#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

int Cell::_count = 0;
int Cell::_refinedCount = 0;
int Cell::_refineNumber = 0;
double Cell::_R = 10.0;

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
Cell::Cell (int id, vector<Node*> nodes)
{
  _refined = false;
  _id = id;
  _nodes = nodes;
  _nodeIds = 0;
  _count++;

  for (vector<Node*>::iterator it = _nodes.begin(); it != _nodes.end(); it++)
  {
    (*it)->registerCell (this);
  }

}

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
Cell::~Cell()
{
  for (vector<Node*>::iterator it = _nodes.begin(); it != _nodes.end(); it++)
  {
    (*it)->unregisterCell (this);
  }
  delete [] _nodeIds;
}

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
void Cell::refineIfNeeded()
{
  if (_refined) return;

  double v1 = computeValue (_nodes[0]);
  for (int i = 1; i < 8; i++)
  {
    double v2 = computeValue (_nodes[i]);
    if (v1*v2 < 0)
    {
      this->refine();
      return;
    }
  }
}

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
void Cell::refine ()
{
  _refinedCount++;
  // attention : petite inversion entre X et Z par rapport a la creation du maillage initial
  _cells = Mesh::instance()->createCells (_refineNumber + 1, _refineNumber + 1, _refineNumber + 1,
                                          _nodes[0], _nodes[3], _nodes[2], _nodes[1],
                                          _nodes[4], _nodes[7], _nodes[6], _nodes[5]);

  // desenregistrement de la maille aupres des noeuds
  for (vector<Node*>::iterator it = _nodes.begin(); it != _nodes.end(); it++)
  {
    (*it)->unregisterCell (this);
  }
  delete [] _nodeIds;

  _count--;
  _refined = true;
}

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
double Cell::computeValue (Node * n)
{
  // sphere de rayon _R
  double x = n->getX();
  double y = n->getY();
  double z = n->getZ();

  return (sqrt (x*x + y*y + z*z) - _R);
}


/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
vtkIdType * Cell::getNodeIds()
{
  delete [] _nodeIds;
  _nodeIds = new vtkIdType[_nodes.size()+1];
  int index = 0;
  for (vector<Node*>::iterator it = _nodes.begin(); it != _nodes.end(); it++)
  {
    _nodeIds[index++] = (*it)->getId();
  }
  _nodeIds[index++] = -1;
  return _nodeIds;
}

/*-------------------------------------------------------------------------
  -----------------------------------------------------------------------*/
void Cell::replaceNode (Node* oldNode, Node* newNode)
{
  vector<Node*>::iterator it = std::find (_nodes.begin(), _nodes.end(), oldNode);
  if (it != _nodes.end())
  {
    _nodes.insert (it, newNode);
    _nodes.erase (it);
    oldNode->unregisterCell (this);
    newNode->registerCell (this);
  }
}