gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MeshVolume.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
#include "
MeshVolume.h
"
7
#include "
GModel.h
"
8
#include "
PViewOptions.h
"
9
10
StringXNumber
MeshVolumeOptions_Number
[] = {
11
{
GMSH_FULLRC
,
"PhysicalGroup"
,
nullptr
, -1},
12
{
GMSH_FULLRC
,
"Dimension"
,
nullptr
, 3}};
13
14
extern
"C"
{
15
GMSH_Plugin
*
GMSH_RegisterMeshVolumePlugin
()
16
{
17
return
new
GMSH_MeshVolumePlugin
();
18
}
19
}
20
21
std::string
GMSH_MeshVolumePlugin::getHelp
()
const
22
{
23
return
"Plugin(MeshVolume) computes the volume of the mesh.\n\n"
24
"Only the elements in the physical group `PhysicalGroup' "
25
"of dimension `Dimension' are taken into account, unless "
26
"'PhysicalGroup' is negative, in which case all the elements of "
27
"the given `Dimension' are considered. If `Dimension` is "
28
"negative, all the elements are considered.\n\n"
29
"Plugin(MeshVolume) creates one new list-based view."
;
30
}
31
32
int
GMSH_MeshVolumePlugin::getNbOptions
()
const
33
{
34
return
sizeof
(
MeshVolumeOptions_Number
) /
sizeof
(
StringXNumber
);
35
}
36
37
StringXNumber
*
GMSH_MeshVolumePlugin::getOption
(
int
iopt)
38
{
39
return
&
MeshVolumeOptions_Number
[iopt];
40
}
41
42
PView
*
GMSH_MeshVolumePlugin::execute
(
PView
*v)
43
{
44
int
physical = (int)
MeshVolumeOptions_Number
[0].def;
45
int
dim = (int)
MeshVolumeOptions_Number
[1].def;
46
47
GModel
*model =
GModel::current
();
48
if
(!model->
getNumMeshVertices
()) {
49
Msg::Error
(
"Plugin(MeshVolume) needs a mesh"
);
50
return
v;
51
}
52
53
std::vector<GEntity *> entities;
54
if
(physical == -1) { model->
getEntities
(entities, dim); }
55
else
{
56
std::map<int, std::vector<GEntity *> > groups;
57
model->
getPhysicalGroups
(dim, groups);
58
entities = groups[physical];
59
}
60
61
if
(entities.empty())
Msg::Warning
(
"The specified domain is empty"
);
62
63
double
vol = 0;
64
for
(std::size_t i = 0; i < entities.size(); i++)
65
for
(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++)
66
vol += entities[i]->getMeshElement(j)->getVolume();
67
68
Msg::Info
(
"Mesh volume (physical %d | dimension %d): %g"
, physical, dim, vol);
69
70
PView
*v2 =
new
PView
();
71
PViewDataList
*data2 =
getDataList
(v2);
72
SBoundingBox3d
bbox = model->
bounds
();
73
data2->
SP
.push_back(bbox.
center
().
x
());
74
data2->
SP
.push_back(bbox.
center
().
y
());
75
data2->
SP
.push_back(bbox.
center
().
z
());
76
data2->
SP
.push_back(vol);
77
data2->
NbSP
= 1;
78
v2->
getOptions
()->
intervalsType
=
PViewOptions::Numeric
;
79
data2->
setName
(
"MeshVolume"
);
80
data2->
setFileName
(
"MeshVolume.pos"
);
81
data2->
finalize
();
82
return
v2;
83
}
PView
Definition:
PView.h:27
GModel::getNumMeshVertices
std::size_t getNumMeshVertices(int dim=-1) const
Definition:
GModel.cpp:1529
GMSH_RegisterMeshVolumePlugin
GMSH_Plugin * GMSH_RegisterMeshVolumePlugin()
Definition:
MeshVolume.cpp:15
GMSH_Plugin
Definition:
Plugin.h:26
Msg::Info
static void Info(const char *fmt,...)
Definition:
GmshMessage.cpp:587
PViewDataList
Definition:
PViewDataList.h:17
Msg::Warning
static void Warning(const char *fmt,...)
Definition:
GmshMessage.cpp:543
Msg::Error
static void Error(const char *fmt,...)
Definition:
GmshMessage.cpp:482
PViewDataList::NbSP
int NbSP
Definition:
PViewDataList.h:26
GMSH_MeshVolumePlugin::getOption
StringXNumber * getOption(int iopt)
Definition:
MeshVolume.cpp:37
GMSH_MeshVolumePlugin
Definition:
MeshVolume.h:15
StringXNumber
Definition:
Options.h:918
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition:
PViewData.h:75
SBoundingBox3d::center
SPoint3 center() const
Definition:
SBoundingBox3d.h:92
PViewOptions::Numeric
@ Numeric
Definition:
PViewOptions.h:19
SPoint3::x
double x(void) const
Definition:
SPoint3.h:125
GModel::getPhysicalGroups
void getPhysicalGroups(std::map< int, std::vector< GEntity * > > groups[4]) const
Definition:
GModel.cpp:837
GModel::bounds
SBoundingBox3d bounds(bool aroundVisible=false)
Definition:
GModel.cpp:1043
PViewDataList::SP
std::vector< double > SP
Definition:
PViewDataList.h:27
GMSH_FULLRC
#define GMSH_FULLRC
Definition:
Options.h:20
GModel
Definition:
GModel.h:44
PViewOptions::intervalsType
int intervalsType
Definition:
PViewOptions.h:54
PViewOptions.h
GMSH_MeshVolumePlugin::getNbOptions
int getNbOptions() const
Definition:
MeshVolume.cpp:32
SPoint3::y
double y(void) const
Definition:
SPoint3.h:127
MeshVolumeOptions_Number
StringXNumber MeshVolumeOptions_Number[]
Definition:
MeshVolume.cpp:10
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition:
PViewDataList.cpp:81
PViewData::setName
virtual void setName(const std::string &val)
Definition:
PViewData.h:71
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition:
GModel.cpp:651
MeshVolume.h
PView::getOptions
PViewOptions * getOptions()
Definition:
PView.h:81
SPoint3::z
double z(void) const
Definition:
SPoint3.h:129
GModel.h
GMSH_MeshVolumePlugin::execute
PView * execute(PView *)
Definition:
MeshVolume.cpp:42
GMSH_MeshVolumePlugin::getHelp
std::string getHelp() const
Definition:
MeshVolume.cpp:21
SBoundingBox3d
Definition:
SBoundingBox3d.h:21
GModel::current
static GModel * current(int index=-1)
Definition:
GModel.cpp:136
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition:
Plugin.cpp:107
src
plugin
MeshVolume.cpp
Generated by
1.8.18