fixed edge display for volume cells
[engrid-github.git] / src / libengrid / foamobject.cpp
blob3dc7e3997abbc816aef7a84f7f1c91c85caacd53
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "foamobject.h"
23 #include <iostream>
25 #include "guimainwindow.h"
27 FoamObject::FoamObject()
29 m_CaseDir = "";
30 m_BufferedFileName = "";
31 m_FoamVersion = "1.5";
34 int FoamObject::deleteBetween(int i, QString str1, QString str2)
36 int i1 = m_Buffer.indexOf(str1, i);
37 if (i1 != -1) {
38 int i2 = m_Buffer.indexOf(str2, i1);
39 if (i2 != -1) {
40 m_Buffer = m_Buffer.remove(i1, i2 - i1 + str2.size());
41 return i2-i1;
44 return 0;
47 void FoamObject::stripBuffer()
49 while (deleteBetween(0, "/*", "*/")) {};
50 while (deleteBetween(0, "//", "\n")) {};
51 int i = m_Buffer.indexOf("FoamFile", 0);
52 if (i != -1) {
53 deleteBetween(i, "{", "}");
55 m_Buffer.replace("FoamFile","");
56 m_Buffer.replace("{", " ");
57 m_Buffer.replace("}", " ");
58 m_Buffer.replace("(", " ");
59 m_Buffer.replace(")", " ");
60 m_Buffer.replace(";", " ");
61 m_Buffer = m_Buffer.simplified();
64 void FoamObject::readFile(QString file_name)
66 file_name = m_CaseDir + "/" + file_name;
67 if(m_BufferedFileName != m_CaseDir + "/" + file_name) {
68 m_BufferedFileName = file_name;
69 QFile file(file_name);
70 if (!file.open(QIODevice::ReadOnly)) {
71 EG_ERR_RETURN(QString("error loading file:\n") + file_name);
73 QTextStream f(&file);
74 m_Buffer = "";
75 m_Buffer.reserve(file.size());
76 while(!f.atEnd())
78 m_Buffer += f.readLine() + "\n";
80 stripBuffer();
84 void FoamObject::buildMaps()
86 int num_foam_nodes;
87 readFile("constant/polyMesh/points");
89 QTextStream f(getBuffer());
90 f >> num_foam_nodes;
93 readFile("constant/polyMesh/neighbour");
94 QTextStream f(getBuffer());
95 int num_neigh;
96 f >> num_neigh;
97 int neigh = 0;
98 m_FirstBoundaryFace = 0;
99 while (m_FirstBoundaryFace < num_neigh) {
100 f >> neigh;
101 if (neigh == -1) {
102 break;
104 ++m_FirstBoundaryFace;
108 m_VolToSurfMap.fill(-1, num_foam_nodes);
109 readFile("constant/polyMesh/faces");
110 int num_surf_nodes = 0;
111 int max_node = 0;
113 int num_foam_faces;
114 QTextStream f(getBuffer());
115 f >> num_foam_faces;
116 for (int i = 0; i < num_foam_faces; ++i) {
117 int num_nodes;
118 f >> num_nodes;
119 for (int j = 0; j < num_nodes; ++j) {
120 int node;
121 f >> node;
122 max_node = max(node, max_node);
123 if (i >= m_FirstBoundaryFace) {
124 if (m_VolToSurfMap[node] == -1) {
125 m_VolToSurfMap[node] = num_surf_nodes;
126 ++num_surf_nodes;
132 m_SurfToVolMap.fill(-1, num_surf_nodes);
133 for (int i = 0; i < m_VolToSurfMap.size(); ++i) {
134 if (m_VolToSurfMap[i] != -1) {
135 if (m_VolToSurfMap[i] > m_SurfToVolMap.size()) {
136 EG_BUG;
138 m_SurfToVolMap[m_VolToSurfMap[i]] = i;
141 for (int i = 0; i < m_SurfToVolMap.size(); ++i) {
142 if (m_SurfToVolMap[i] == -1) {
143 EG_BUG;
148 void FoamObject::setCaseDir(QString case_dir)
150 m_CaseDir = case_dir;
151 GuiMainWindow::pointer()->setXmlSection("openfoam/CaseDir",m_CaseDir);