gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
NewView.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 //
6 // Contributor(s):
7 // Ruth Sabariego & Francois Henrotte
8 //
9 
10 #include "NewView.h"
11 #include "GModel.h"
12 #include "MElement.h"
13 
15  {GMSH_FULLRC, "NumComp", nullptr, 1.},
16  {GMSH_FULLRC, "Value", nullptr, 0.},
17  {GMSH_FULLRC, "ViewTag", nullptr, -1.},
18  {GMSH_FULLRC, "PhysicalGroup", nullptr, -1.}};
19 
21  {GMSH_FULLRC, "Type", nullptr, "NodeData"}};
22 
23 extern "C" {
25 }
26 
27 std::string GMSH_NewViewPlugin::getHelp() const
28 {
29  return "Plugin(NewView) creates a new model-based view from the "
30  "current mesh, with `NumComp' field components, set to value "
31  "`Value'.\n\n"
32  "If `ViewTag' is positive, force that tag for the created view. "
33  "The view type is determined by `Type' (NodeData or ElementData). "
34  "In the case of an ElementData type, the view can be restricted "
35  "to a specific physical group with a positive `PhysicalGroup'.";
36 }
37 
39 {
40  return sizeof(NewViewOptions_Number) / sizeof(StringXNumber);
41 }
42 
44 {
45  return &NewViewOptions_Number[iopt];
46 }
47 
49 {
50  return sizeof(NewViewOptions_String) / sizeof(StringXString);
51 }
52 
54 {
55  return &NewViewOptions_String[iopt];
56 }
57 
59 {
60  int numComp = (int)NewViewOptions_Number[0].def;
61  double value = NewViewOptions_Number[1].def;
62  int tag = (int)NewViewOptions_Number[2].def;
63  int phys = (int)NewViewOptions_Number[3].def;
64  std::string type = NewViewOptions_String[0].def;
65 
66  if(GModel::current()->getMeshStatus() < 0) {
67  Msg::Error("No mesh available to create the view: please mesh your model!");
68  return v;
69  }
70  if(numComp < 1) {
71  Msg::Error("Bad number of components for Plugin(NewView)");
72  return v;
73  }
74  if(!(type == "NodeData" || type == "ElementData")) {
75  Msg::Error("Unknown data type for Plugin(NewView)");
76  return v;
77  }
78 
79  std::map<int, std::vector<double> > d;
80  if(type == "NodeData") nodeData(numComp, value, d);
81  if(type == "ElementData") elementData(numComp, value, d, phys);
82 
83  PView *vn = new PView("New view", type, GModel::current(), d, tag);
84  return vn;
85 }
86 
87 void GMSH_NewViewPlugin::nodeData(int numComp, double value,
88  std::map<int, std::vector<double> > &d)
89 {
90  std::vector<GEntity *> entities;
91  GModel::current()->getEntities(entities);
92  for(std::size_t i = 0; i < entities.size(); i++) {
93  for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++) {
94  MVertex *ve = entities[i]->mesh_vertices[j];
95  d[ve->getNum()].resize(numComp, value);
96  }
97  }
98 }
99 
100 void GMSH_NewViewPlugin::elementData(int numComp, double value,
101  std::map<int, std::vector<double> > &d,
102  int phys)
103 {
104  std::vector<GEntity *> entities;
105  if(phys == -1) { GModel::current()->getEntities(entities, -1); }
106  else {
107  std::map<int, std::vector<GEntity *> > groups;
108  GModel::current()->getPhysicalGroups(-1, groups);
109  entities = groups[phys];
110  }
111 
112  for(std::size_t i = 0; i < entities.size(); i++) {
113  for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
114  MElement *e = entities[i]->getMeshElement(j);
115  d[e->getNum()].resize(numComp, value);
116  }
117  }
118 }
MElement::getNum
virtual std::size_t getNum() const
Definition: MElement.h:68
GMSH_NewViewPlugin
Definition: NewView.h:15
StringXString
Definition: Options.h:910
GMSH_NewViewPlugin::getNbOptions
int getNbOptions() const
Definition: NewView.cpp:38
PView
Definition: PView.h:27
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
MVertex
Definition: MVertex.h:24
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
GMSH_NewViewPlugin::elementData
void elementData(int numComp, double value, std::map< int, std::vector< double > > &d, int phys)
Definition: NewView.cpp:100
GMSH_NewViewPlugin::getHelp
std::string getHelp() const
Definition: NewView.cpp:27
StringXNumber
Definition: Options.h:918
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
GMSH_NewViewPlugin::getNbOptionsStr
int getNbOptionsStr() const
Definition: NewView.cpp:48
GMSH_NewViewPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: NewView.cpp:43
GModel::getPhysicalGroups
void getPhysicalGroups(std::map< int, std::vector< GEntity * > > groups[4]) const
Definition: GModel.cpp:837
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GMSH_NewViewPlugin::getOptionStr
StringXString * getOptionStr(int iopt)
Definition: NewView.cpp:53
StringXString::def
std::string def
Definition: Options.h:914
MElement
Definition: MElement.h:30
GMSH_NewViewPlugin::nodeData
void nodeData(int numComp, double value, std::map< int, std::vector< double > > &d)
Definition: NewView.cpp:87
GMSH_RegisterNewViewPlugin
GMSH_Plugin * GMSH_RegisterNewViewPlugin()
Definition: NewView.cpp:24
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition: GModel.cpp:651
GMSH_NewViewPlugin::execute
PView * execute(PView *)
Definition: NewView.cpp:58
MElement.h
NewViewOptions_Number
StringXNumber NewViewOptions_Number[]
Definition: NewView.cpp:14
GModel.h
GModel::getMeshStatus
int getMeshStatus(bool countDiscrete=true)
Definition: GModel.cpp:1474
NewView.h
NewViewOptions_String
StringXString NewViewOptions_String[]
Definition: NewView.cpp:20
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136