~ubuntu-branches/debian/squeeze/gmsh/squeeze

« back to all changes in this revision

Viewing changes to Plugin/Gradient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme
  • Date: 2009-09-02 18:12:15 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090902181215-yla8zvcas2ucvkm9
[Christophe Prud'homme]
* New upstream release
  + fixed surface mesh orientation bug introduced in 2.4.0;
  + mesh and graphics code refactoring;
  + small usability enhancements and bug fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
#include "Gradient.h"
7
7
#include "shapeFunctions.h"
 
8
#include "GmshDefines.h"
8
9
 
9
10
StringXNumber GradientOptions_Number[] = {
10
11
  {GMSH_FULLRC, "iView", NULL, -1.}
18
19
  }
19
20
}
20
21
 
21
 
void GMSH_GradientPlugin::getName(char *name) const
22
 
{
23
 
  strcpy(name, "Gradient");
24
 
}
25
 
 
26
 
void GMSH_GradientPlugin::getInfos(char *author, char *copyright,
27
 
                                   char *help_text) const
28
 
{
29
 
  strcpy(author, "C. Geuzaine, J.-F. Remacle");
30
 
  strcpy(copyright, "C. Geuzaine, J.-F. Remacle");
31
 
  strcpy(help_text,
32
 
         "Plugin(Gradient) computes the gradient of the\n"
 
22
std::string GMSH_GradientPlugin::getHelp() const
 
23
{
 
24
  return "Plugin(Gradient) computes the gradient of the\n"
33
25
         "field in the view `iView'. If `iView' < 0, the\n"
34
26
         "plugin is run on the current view.\n"
35
27
         "\n"
36
 
         "Plugin(Gradient) creates one new view.\n");
 
28
         "Plugin(Gradient) creates one new view.\n";
37
29
}
38
30
 
39
31
int GMSH_GradientPlugin::getNbOptions() const
46
38
  return &GradientOptions_Number[iopt];
47
39
}
48
40
 
49
 
void GMSH_GradientPlugin::catchErrorMessage(char *errorMessage) const
50
 
{
51
 
  strcpy(errorMessage, "Gradient failed...");
52
 
}
53
 
 
54
 
static List_T *incrementList(PViewDataList *data2, int numComp, int numEdges)
 
41
static std::vector<double> *incrementList(PViewDataList *data2, int numComp, int type)
55
42
{
56
43
  if(numComp == 1){
57
 
    switch(numEdges){
58
 
    case 0: data2->NbVP++; return data2->VP;
59
 
    case 1: data2->NbVL++; return data2->VL;
60
 
    case 3: data2->NbVT++; return data2->VT;
61
 
    case 4: data2->NbVQ++; return data2->VQ;
62
 
    case 6: data2->NbVS++; return data2->VS;
63
 
    case 12: data2->NbVH++; return data2->VH;
64
 
    case 9: data2->NbVI++; return data2->VI;
65
 
    case 8: data2->NbVY++; return data2->VY;
 
44
    switch(type){
 
45
    case TYPE_PNT: data2->NbVP++; return &data2->VP;
 
46
    case TYPE_LIN: data2->NbVL++; return &data2->VL;
 
47
    case TYPE_TRI: data2->NbVT++; return &data2->VT;
 
48
    case TYPE_QUA: data2->NbVQ++; return &data2->VQ;
 
49
    case TYPE_TET: data2->NbVS++; return &data2->VS;
 
50
    case TYPE_HEX: data2->NbVH++; return &data2->VH;
 
51
    case TYPE_PRI: data2->NbVI++; return &data2->VI;
 
52
    case TYPE_PYR: data2->NbVY++; return &data2->VY;
66
53
    default: return 0;
67
54
    }
68
55
  }
69
56
  else if(numComp == 3){
70
 
    switch(numEdges){
71
 
    case 0: data2->NbTP++; return data2->TP;
72
 
    case 1: data2->NbTL++; return data2->TL;
73
 
    case 3: data2->NbTT++; return data2->TT;
74
 
    case 4: data2->NbTQ++; return data2->TQ;
75
 
    case 6: data2->NbTS++; return data2->TS;
76
 
    case 12: data2->NbTH++; return data2->TH;
77
 
    case 9: data2->NbTI++; return data2->TI;
78
 
    case 8: data2->NbTY++; return data2->TY;
 
57
    switch(type){
 
58
    case TYPE_PNT: data2->NbTP++; return &data2->TP;
 
59
    case TYPE_LIN: data2->NbTL++; return &data2->TL;
 
60
    case TYPE_TRI: data2->NbTT++; return &data2->TT;
 
61
    case TYPE_QUA: data2->NbTQ++; return &data2->TQ;
 
62
    case TYPE_TET: data2->NbTS++; return &data2->TS;
 
63
    case TYPE_HEX: data2->NbTH++; return &data2->TH;
 
64
    case TYPE_PRI: data2->NbTI++; return &data2->TI;
 
65
    case TYPE_PYR: data2->NbTY++; return &data2->TY;
79
66
    default: return 0;
80
67
    }
81
68
  }
95
82
    return v;
96
83
  }
97
84
 
98
 
  PView *v2 = new PView(true, data1->getNumElements());
 
85
  PView *v2 = new PView();
99
86
  PViewDataList *data2 = getDataList(v2);
100
87
 
101
88
  for(int ent = 0; ent < data1->getNumEntities(0); ent++){
103
90
      if(data1->skipElement(0, ent, ele)) continue;
104
91
      int numComp = data1->getNumComponents(0, ent, ele);
105
92
      if(numComp != 1 && numComp != 3) continue;
106
 
      int numEdges = data1->getNumEdges(0, ent, ele);
107
 
      List_T *out = incrementList(data2, numComp, numEdges);
 
93
      int type = data1->getType(0, ent, ele);
 
94
      std::vector<double> *out = incrementList(data2, numComp, type);
108
95
      if(!out) continue;
109
96
      int numNodes = data1->getNumNodes(0, ent, ele);
110
97
      double x[8], y[8], z[8], val[8 * 3];
111
98
      for(int nod = 0; nod < numNodes; nod++)
112
 
        data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]);
 
99
        data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]);
113
100
      int dim = data1->getDimension(0, ent, ele);
114
101
      elementFactory factory;
115
102
      element *element = factory.create(numNodes, dim, x, y, z);
116
103
      if(!element) continue;
117
 
      for(int nod = 0; nod < numNodes; nod++) List_Add(out, &x[nod]);
118
 
      for(int nod = 0; nod < numNodes; nod++) List_Add(out, &y[nod]);
119
 
      for(int nod = 0; nod < numNodes; nod++) List_Add(out, &z[nod]);
 
104
      for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
 
105
      for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
 
106
      for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
120
107
      for(int step = 0; step < data1->getNumTimeSteps(); step++){
121
 
        for(int nod = 0; nod < numNodes; nod++)
122
 
          for(int comp = 0; comp < numComp; comp++)
123
 
            data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]);
124
 
        for(int nod = 0; nod < numNodes; nod++){
125
 
          double u, v, w, f[3];
126
 
          element->getNode(nod, u, v, w);
127
 
          for(int comp = 0; comp < numComp; comp++){
128
 
            element->interpolateGrad(val + comp, u, v, w, f, numComp);
129
 
            List_Add(out, &f[0]);
130
 
            List_Add(out, &f[1]);
131
 
            List_Add(out, &f[2]);
132
 
          }
133
 
        }
 
108
        for(int nod = 0; nod < numNodes; nod++)
 
109
          for(int comp = 0; comp < numComp; comp++)
 
110
            data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]);
 
111
        for(int nod = 0; nod < numNodes; nod++){
 
112
          double u, v, w, f[3];
 
113
          element->getNode(nod, u, v, w);
 
114
          for(int comp = 0; comp < numComp; comp++){
 
115
            element->interpolateGrad(val + comp, u, v, w, f, numComp);
 
116
            out->push_back(f[0]);
 
117
            out->push_back(f[1]);
 
118
            out->push_back(f[2]);
 
119
          }
 
120
        }
134
121
      }
135
122
      delete element;
136
123
    }
138
125
 
139
126
  for(int i = 0; i < data1->getNumTimeSteps(); i++){
140
127
    double time = data1->getTime(i);
141
 
    List_Add(data2->Time, &time);
 
128
    data2->Time.push_back(time);
142
129
  }
143
130
  data2->setName(data1->getName() + "_Gradient");
144
131
  data2->setFileName(data1->getName() + "_Gradient.pos");