File: SphericalRaise.cpp

package info (click to toggle)
gmsh 4.8.4%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,812 kB
  • sloc: cpp: 378,014; ansic: 99,669; yacc: 7,216; python: 6,680; java: 3,486; lisp: 659; lex: 621; perl: 571; makefile: 470; sh: 440; xml: 415; javascript: 113; pascal: 35; modula3: 32
file content (115 lines) | stat: -rw-r--r-- 4,008 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
// Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.

#include "SphericalRaise.h"
#include "Numeric.h"

StringXNumber SphericalRaiseOptions_Number[] = {
  {GMSH_FULLRC, "Xc", nullptr, 0.},     {GMSH_FULLRC, "Yc", nullptr, 0.},
  {GMSH_FULLRC, "Zc", nullptr, 0.},     {GMSH_FULLRC, "Raise", nullptr, 1.},
  {GMSH_FULLRC, "Offset", nullptr, 0.}, {GMSH_FULLRC, "TimeStep", nullptr, 0.},
  {GMSH_FULLRC, "View", nullptr, -1.}};

extern "C" {
GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin()
{
  return new GMSH_SphericalRaisePlugin();
}
}

std::string GMSH_SphericalRaisePlugin::getHelp() const
{
  return "Plugin(SphericalRaise) transforms the "
         "coordinates of the elements in the view "
         "`View' using the values associated with the "
         "`TimeStep'-th time step.\n\n"
         "Instead of elevating the nodes along the X, Y "
         "and Z axes as with the View[`View'].RaiseX, "
         "View[`View'].RaiseY and View[`View'].RaiseZ "
         "options, the raise is applied along the radius "
         "of a sphere centered at (`Xc', `Yc', `Zc').\n\n"
         "To produce a standard radiation pattern, set "
         "`Offset' to minus the radius of the sphere the "
         "original data lives on.\n\n"
         "If `View' < 0, the plugin is run on the current view.\n\n"
         "Plugin(SphericalRaise) is executed in-place.";
}

int GMSH_SphericalRaisePlugin::getNbOptions() const
{
  return sizeof(SphericalRaiseOptions_Number) / sizeof(StringXNumber);
}

StringXNumber *GMSH_SphericalRaisePlugin::getOption(int iopt)
{
  return &SphericalRaiseOptions_Number[iopt];
}

PView *GMSH_SphericalRaisePlugin::execute(PView *v)
{
  double center[3];
  center[0] = SphericalRaiseOptions_Number[0].def;
  center[1] = SphericalRaiseOptions_Number[1].def;
  center[2] = SphericalRaiseOptions_Number[2].def;
  double raise = SphericalRaiseOptions_Number[3].def;
  double offset = SphericalRaiseOptions_Number[4].def;
  int timeStep = (int)SphericalRaiseOptions_Number[5].def;
  int iView = (int)SphericalRaiseOptions_Number[6].def;

  PView *v1 = getView(iView, v);
  if(!v1) return v;

  PViewData *data1 = v1->getData();

  // sanity checks
  if(timeStep < 0 || timeStep > data1->getNumTimeSteps() - 1) {
    Msg::Error("Invalid TimeStep (%d) in view", timeStep);
    return v;
  }

  if(data1->isNodeData()) {
    // tag all the nodes with "0" (the default tag)
    for(int step = 0; step < data1->getNumTimeSteps(); step++) {
      for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
        for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
          if(data1->skipElement(step, ent, ele)) continue;
          for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
            data1->tagNode(step, ent, ele, nod, 0);
        }
      }
    }
  }

  // transform all "0" nodes
  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
    for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
      for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
        if(data1->skipElement(step, ent, ele)) continue;
        for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) {
          double x, y, z;
          int tag = data1->getNode(step, ent, ele, nod, x, y, z);
          if(data1->isNodeData() && tag) continue;
          double r[3], val;
          r[0] = x - center[0];
          r[1] = y - center[1];
          r[2] = z - center[2];
          norme(r);
          data1->getScalarValue(step, ent, ele, nod, val);
          double coef = offset + raise * val;
          x += coef * r[0];
          y += coef * r[1];
          z += coef * r[2];
          data1->setNode(step, ent, ele, nod, x, y, z);
          if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
        }
      }
    }
  }

  data1->finalize();
  v1->setChanged(true);

  return v1;
}