~ubuntu-branches/ubuntu/karmic/gmsh/karmic

« back to all changes in this revision

Viewing changes to Plugin/Divergence.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Daniel Leidert
  • Date: 2008-05-18 12:46:05 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080518124605-716xqbqeo07o497k
Tags: 2.2.0-2
[Christophe Prud'homme]
* Bug fix: "gmsh ships no .desktop", thanks to Vassilis Pandis (Closes:
  #375770). Applied the Ubuntu patch.

[Daniel Leidert]
* debian/control (Vcs-Svn): Fixed.
  (Build-Depends): Use texlive instead of tetex-bin.
* debian/gmsh.doc-base (Section): Fixed accordingly to doc-base (>= 0.8.10).
* debian/rules: Removed some variable declarations, that lead to double
  configuration and seem to be useless.
  (build/gmsh): Try to avoid multiple runs by using a stamp.
  (orig-tarball): Renamed to get-orig-source and changed to use uscan.
* debian/watch: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: Divergence.cpp,v 1.4 2007-05-04 10:45:08 geuzaine Exp $
 
1
// $Id: Divergence.cpp,v 1.9 2008-04-05 17:49:23 geuzaine Exp $
2
2
//
3
 
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 
3
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
19
19
// 
20
20
// Please report all bugs and problems to <gmsh@geuz.org>.
21
21
 
22
 
#include "Plugin.h"
23
22
#include "Divergence.h"
24
 
#include "List.h"
25
 
#include "Views.h"
26
 
#include "Context.h"
27
 
#include "Numeric.h"
28
23
#include "ShapeFunctions.h"
29
24
 
30
 
extern Context_T CTX;
31
 
 
32
25
StringXNumber DivergenceOptions_Number[] = {
33
26
  {GMSH_FULLRC, "iView", NULL, -1.}
34
27
};
41
34
  }
42
35
}
43
36
 
44
 
GMSH_DivergencePlugin::GMSH_DivergencePlugin()
45
 
{
46
 
  ;
47
 
}
48
 
 
49
37
void GMSH_DivergencePlugin::getName(char *name) const
50
38
{
51
39
  strcpy(name, "Divergence");
52
40
}
53
41
 
54
42
void GMSH_DivergencePlugin::getInfos(char *author, char *copyright,
55
 
                                    char *help_text) const
 
43
                                     char *help_text) const
56
44
{
57
45
  strcpy(author, "C. Geuzaine");
58
46
  strcpy(copyright, "DGR (www.multiphysics.com)");
59
47
  strcpy(help_text,
60
 
         "Plugin(Divergence) computes the divergence of the\n"
61
 
         "field in the view `iView'. If `iView' < 0, the plugin\n"
62
 
         "is run on the current view.\n"
63
 
         "\n"
64
 
         "Plugin(Divergence) creates one new view.\n");
 
48
         "Plugin(Divergence) computes the divergence of the\n"
 
49
         "field in the view `iView'. If `iView' < 0, the plugin\n"
 
50
         "is run on the current view.\n"
 
51
         "\n"
 
52
         "Plugin(Divergence) creates one new view.\n");
65
53
}
66
54
 
67
55
int GMSH_DivergencePlugin::getNbOptions() const
79
67
  strcpy(errorMessage, "Divergence failed...");
80
68
}
81
69
 
82
 
static void divergence(int inNb, List_T *inList, int *outNb, List_T *outList, 
83
 
                     int dim, int nbNod, int nbTime)
84
 
{
85
 
  if(!inNb) return;
 
70
static List_T *incrementList(PViewDataList *data2, int numEdges)
 
71
{
 
72
  switch(numEdges){
 
73
  case 0: data2->NbSP++; return data2->SP;
 
74
  case 1: data2->NbSL++; return data2->SL;
 
75
  case 3: data2->NbST++; return data2->ST;
 
76
  case 4: data2->NbSQ++; return data2->SQ;
 
77
  case 6: data2->NbSS++; return data2->SS;
 
78
  case 12: data2->NbSH++; return data2->SH;
 
79
  case 9: data2->NbSI++; return data2->SI;
 
80
  case 8: data2->NbSY++; return data2->SY;
 
81
  default: return 0;
 
82
  }
 
83
}
 
84
 
 
85
PView *GMSH_DivergencePlugin::execute(PView *v)
 
86
{
 
87
  int iView = (int)DivergenceOptions_Number[0].def;
86
88
  
87
 
  int nb = List_Nbr(inList) / inNb;
88
 
  for(int i = 0; i < List_Nbr(inList); i += nb) {
89
 
    double *x = (double *)List_Pointer_Fast(inList, i);
90
 
    double *y = (double *)List_Pointer_Fast(inList, i + nbNod);
91
 
    double *z = (double *)List_Pointer_Fast(inList, i + 2 * nbNod);
92
 
    elementFactory factory;
93
 
    element *element = factory.create(nbNod, dim, x, y, z);
94
 
    if(!element) return;
95
 
    for(int j = 0; j < 3 * nbNod; j++)
96
 
      List_Add(outList, &x[j]);
97
 
    for(int j = 0; j < nbTime; j++){
98
 
      double *val = (double *)List_Pointer(inList, i + 3 * nbNod + nbNod * 3 * j);
99
 
      for(int k = 0; k < nbNod; k++){
100
 
        double u, v, w;
101
 
        element->getNode(k, u, v, w);
102
 
        double f = element->interpolateDiv(val, u, v, w, 3);
103
 
        List_Add(outList, &f);
 
89
  PView *v1 = getView(iView, v);
 
90
  if(!v1) return v;
 
91
 
 
92
  PViewData *data1 = v1->getData();
 
93
  if(data1->hasMultipleMeshes()){
 
94
    Msg(GERROR, "Divergence plugin cannot be run on multi-mesh views");
 
95
    return v;
 
96
  }
 
97
 
 
98
  PView *v2 = new PView(true);
 
99
  PViewDataList *data2 = getDataList(v2);
 
100
 
 
101
  for(int ent = 0; ent < data1->getNumEntities(0); ent++){
 
102
    for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){
 
103
      if(data1->skipElement(0, ent, ele)) continue;
 
104
      int numComp = data1->getNumComponents(0, ent, ele);
 
105
      if(numComp != 3) continue;
 
106
      int numEdges = data1->getNumEdges(0, ent, ele);
 
107
      List_T *out = incrementList(data2, numEdges);
 
108
      if(!out) continue;
 
109
      int numNodes = data1->getNumNodes(0, ent, ele);
 
110
      double x[8], y[8], z[8], val[8 * 3];
 
111
      for(int nod = 0; nod < numNodes; nod++)
 
112
        data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]);
 
113
      int dim = data1->getDimension(0, ent, ele);
 
114
      elementFactory factory;
 
115
      element *element = factory.create(numNodes, dim, x, y, z);
 
116
      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]);
 
120
      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;
 
126
          element->getNode(nod, u, v, w);
 
127
          double f = element->interpolateDiv(val, u, v, w, 3);
 
128
          List_Add(out, &f);
 
129
        }
104
130
      }
 
131
      delete element;
105
132
    }
106
 
    delete element;
107
 
    (*outNb)++;
108
 
  }
109
 
}
110
 
 
111
 
Post_View *GMSH_DivergencePlugin::execute(Post_View * v)
112
 
{
113
 
  int iView = (int)DivergenceOptions_Number[0].def;
114
 
  
115
 
  if(iView < 0)
116
 
    iView = v ? v->Index : 0;
117
 
  
118
 
  if(!List_Pointer_Test(CTX.post.list, iView)) {
119
 
    Msg(GERROR, "View[%d] does not exist", iView);
120
 
    return v;
121
 
  }
122
 
  
123
 
  Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView);
124
 
  Post_View *v2 = BeginView(1);
125
 
 
126
 
  divergence(v1->NbVL, v1->VL, &v2->NbSL, v2->SL, 1, 2, v1->NbTimeStep);
127
 
  divergence(v1->NbVT, v1->VT, &v2->NbST, v2->ST, 2, 3, v1->NbTimeStep);
128
 
  divergence(v1->NbVQ, v1->VQ, &v2->NbSQ, v2->SQ, 2, 4, v1->NbTimeStep);
129
 
  divergence(v1->NbVS, v1->VS, &v2->NbSS, v2->SS, 3, 4, v1->NbTimeStep);
130
 
  divergence(v1->NbVH, v1->VH, &v2->NbSH, v2->SH, 3, 8, v1->NbTimeStep);
131
 
  divergence(v1->NbVI, v1->VI, &v2->NbSI, v2->SI, 3, 6, v1->NbTimeStep);
132
 
  divergence(v1->NbVY, v1->VY, &v2->NbSY, v2->SY, 3, 5, v1->NbTimeStep);
133
 
 
134
 
  // copy time data
135
 
  for(int i = 0; i < List_Nbr(v1->Time); i++)
136
 
    List_Add(v2->Time, List_Pointer(v1->Time, i));
137
 
  // finalize
138
 
  char name[1024], filename[1024];
139
 
  sprintf(name, "%s_Divergence", v1->Name);
140
 
  sprintf(filename, "%s_Divergence.pos", v1->Name);
141
 
  EndView(v2, 1, filename, name);
142
 
  
 
133
  }
 
134
 
 
135
  for(int i = 0; i < data1->getNumTimeSteps(); i++){
 
136
    double time = data1->getTime(i);
 
137
    List_Add(data2->Time, &time);
 
138
  }
 
139
  data2->setName(data1->getName() + "_Divergence");
 
140
  data2->setFileName(data1->getName() + "_Divergence.pos");
 
141
  data2->finalize();
 
142
 
143
143
  return v2;
144
144
}