fixed edge display for volume cells
[engrid-github.git] / src / libengrid / ruleedgelengthsource.cpp
blob2ba8c7a7a1dbee8f186b04d6210c4f6f254440f7
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 //
22 #include "ruleedgelengthsource.h"
23 #include "guimainwindow.h"
25 RuleEdgeLengthSource::RuleEdgeLengthSource(QString rule, vtkUnstructuredGrid *grid)
27 readGrowthFactor();
28 bool is_valid = true;
29 QList<QList<int> > bc_combinations;
30 rule = rule.trimmed();
31 QList<QString> all_symbolic_bcs;
32 QMap<QString, int> name2bc;
33 QVector<int> bcs;
34 GuiMainWindow::pointer()->getAllBoundaryCodes(bcs);
35 foreach (int bc, bcs) {
36 QString name = GuiMainWindow::pointer()->getBC(bc).getName();
37 all_symbolic_bcs.append(name);
38 name2bc[name] = bc;
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 + "\"";
53 EG_ERR_RETURN(msg);
55 int bc = name2bc[and_part];
56 bc_combination.append(bc);
58 bc_combinations.append(bc_combination);
60 } else {
61 is_valid = true;
63 if (!is_valid) {
64 QString msg = "invalid rule:\"" + rule + "\"";
65 EG_ERR_RETURN(msg);
67 MeshPartition part(grid, true);
68 for (vtkIdType id_node = 0; id_node < grid->GetNumberOfPoints(); ++id_node) {
69 QList<int> bcs;
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) {
75 bool found = true;
76 foreach (int bc, bc_combination) {
77 if (!bcs.contains(bc)) {
78 found = false;
79 break;
82 if (found) {
83 use_node = true;
84 break;
87 if (use_node) {
88 vec3_t x;
89 grid->GetPoint(id_node, x.data());
90 m_Points.append(x);
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);
101 QString str;
102 in >> str;
103 in >> str;
104 in >> str;
105 m_GrowthFactor = str.toDouble();
106 } else {
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);