1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "ruleedgelengthsource.h"
23 #include "guimainwindow.h"
25 RuleEdgeLengthSource::RuleEdgeLengthSource(QString rule
, vtkUnstructuredGrid
*grid
)
29 QList
<QList
<int> > bc_combinations
;
30 rule
= rule
.trimmed();
31 QList
<QString
> all_symbolic_bcs
;
32 QMap
<QString
, int> name2bc
;
34 GuiMainWindow::pointer()->getAllBoundaryCodes(bcs
);
35 foreach (int bc
, bcs
) {
36 QString name
= GuiMainWindow::pointer()->getBC(bc
).getName();
37 all_symbolic_bcs
.append(name
);
40 QStringList parts
= rule
.split("=");
41 if (parts
.count() > 1) {
42 QString left
= parts
[0].trimmed();
43 m_EdgeLength
= parts
[1].trimmed().toDouble();
44 QStringList or_parts
= left
.split("<OR>");
45 foreach (QString or_part
, or_parts
) {
46 QList
<int> bc_combination
;
47 or_part
= or_part
.trimmed();
48 QStringList and_parts
= or_part
.split("<AND>");
49 foreach (QString and_part
, and_parts
) {
50 and_part
= and_part
.trimmed();
51 if (!all_symbolic_bcs
.contains(and_part
)) {
52 QString msg
= "unknown boundary name \"" + and_part
+ "\" in rule:\"" + rule
+ "\"";
55 int bc
= name2bc
[and_part
];
56 bc_combination
.append(bc
);
58 bc_combinations
.append(bc_combination
);
64 QString msg
= "invalid rule:\"" + rule
+ "\"";
67 MeshPartition
part(grid
, true);
68 for (vtkIdType id_node
= 0; id_node
< grid
->GetNumberOfPoints(); ++id_node
) {
70 for (int i
= 0; i
< part
.n2bcGSize(id_node
); ++i
) {
71 bcs
.append(part
.n2bcG(id_node
, i
));
73 bool use_node
= false;
74 foreach (QList
<int> bc_combination
, bc_combinations
) {
76 foreach (int bc
, bc_combination
) {
77 if (!bcs
.contains(bc
)) {
89 grid
->GetPoint(id_node
, x
.data());
93 m_PointFinder
.setPoints(m_Points
);
96 void RuleEdgeLengthSource::readGrowthFactor()
98 QString buffer
= GuiMainWindow::pointer()->getXmlSection("engrid/surface/settings");
99 if(!buffer
.isEmpty()) {
100 QTextStream
in(&buffer
, QIODevice::ReadOnly
);
105 m_GrowthFactor
= str
.toDouble();
107 m_GrowthFactor
= 2.0;
111 double RuleEdgeLengthSource::edgeLength(vec3_t x
)
113 QVector
<int> close_points
;
114 m_PointFinder
.getClosePoints(x
, close_points
);
115 if (close_points
.size() == 0) {
116 return EG_LARGE_REAL
;
118 double d
= EG_LARGE_REAL
;
119 foreach (int i
, close_points
) {
120 vec3_t xp
= m_Points
[i
];
121 d
= min(d
, (x
- xp
).abs());
123 double n
= logarithm(m_GrowthFactor
, 1.0 - (1.0 - m_GrowthFactor
)*d
/m_EdgeLength
) - 1.0;
124 return m_EdgeLength
*pow(m_GrowthFactor
, n
);