File: NewView.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 (118 lines) | stat: -rw-r--r-- 3,719 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
116
117
118
// 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.
//
// Contributor(s):
//   Ruth Sabariego  & Francois Henrotte
//

#include "NewView.h"
#include "GModel.h"
#include "MElement.h"

StringXNumber NewViewOptions_Number[] = {
  {GMSH_FULLRC, "NumComp", nullptr, 1.},
  {GMSH_FULLRC, "Value", nullptr, 0.},
  {GMSH_FULLRC, "ViewTag", nullptr, -1.},
  {GMSH_FULLRC, "PhysicalGroup", nullptr, -1.}};

StringXString NewViewOptions_String[] = {
  {GMSH_FULLRC, "Type", nullptr, "NodeData"}};

extern "C" {
GMSH_Plugin *GMSH_RegisterNewViewPlugin() { return new GMSH_NewViewPlugin(); }
}

std::string GMSH_NewViewPlugin::getHelp() const
{
  return "Plugin(NewView) creates a new model-based view from the "
         "current mesh, with `NumComp' field components, set to value "
         "`Value'.\n\n"
         "If `ViewTag' is positive, force that tag for the created view. "
         "The view type is determined by `Type' (NodeData or ElementData). "
         "In the case of an ElementData type, the view can be restricted "
         "to a specific physical group with a positive `PhysicalGroup'.";
}

int GMSH_NewViewPlugin::getNbOptions() const
{
  return sizeof(NewViewOptions_Number) / sizeof(StringXNumber);
}

StringXNumber *GMSH_NewViewPlugin::getOption(int iopt)
{
  return &NewViewOptions_Number[iopt];
}

int GMSH_NewViewPlugin::getNbOptionsStr() const
{
  return sizeof(NewViewOptions_String) / sizeof(StringXString);
}

StringXString *GMSH_NewViewPlugin::getOptionStr(int iopt)
{
  return &NewViewOptions_String[iopt];
}

PView *GMSH_NewViewPlugin::execute(PView *v)
{
  int numComp = (int)NewViewOptions_Number[0].def;
  double value = NewViewOptions_Number[1].def;
  int tag = (int)NewViewOptions_Number[2].def;
  int phys = (int)NewViewOptions_Number[3].def;
  std::string type = NewViewOptions_String[0].def;

  if(GModel::current()->getMeshStatus() < 0) {
    Msg::Error("No mesh available to create the view: please mesh your model!");
    return v;
  }
  if(numComp < 1) {
    Msg::Error("Bad number of components for Plugin(NewView)");
    return v;
  }
  if(!(type == "NodeData" || type == "ElementData")) {
    Msg::Error("Unknown data type for Plugin(NewView)");
    return v;
  }

  std::map<int, std::vector<double> > d;
  if(type == "NodeData") nodeData(numComp, value, d);
  if(type == "ElementData") elementData(numComp, value, d, phys);

  PView *vn = new PView("New view", type, GModel::current(), d, tag);
  return vn;
}

void GMSH_NewViewPlugin::nodeData(int numComp, double value,
                                  std::map<int, std::vector<double> > &d)
{
  std::vector<GEntity *> entities;
  GModel::current()->getEntities(entities);
  for(std::size_t i = 0; i < entities.size(); i++) {
    for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++) {
      MVertex *ve = entities[i]->mesh_vertices[j];
      d[ve->getNum()].resize(numComp, value);
    }
  }
}

void GMSH_NewViewPlugin::elementData(int numComp, double value,
                                     std::map<int, std::vector<double> > &d,
                                     int phys)
{
  std::vector<GEntity *> entities;
  if(phys == -1) { GModel::current()->getEntities(entities, -1); }
  else {
    std::map<int, std::vector<GEntity *> > groups;
    GModel::current()->getPhysicalGroups(-1, groups);
    entities = groups[phys];
  }

  for(std::size_t i = 0; i < entities.size(); i++) {
    for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
      MElement *e = entities[i]->getMeshElement(j);
      d[e->getNum()].resize(numComp, value);
    }
  }
}