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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "openfoamcase.h"
23 #include "filetemplate.h"
24 #include "guimainwindow.h"
31 OpenFOAMcase::OpenFOAMcase()
35 ///\todo Finish this by adding decomposeParDict creation and calling writeMpiParameters from operate
36 void OpenFOAMcase::writeMpiParameters()
38 QString hostfile_text
= GuiMainWindow::pointer()->getXmlSection( "solver/general/host_weight_list" );
40 QVector
<QString
> host
;
41 QVector
<QString
> weight
;
43 QStringList host_weight_list
= hostfile_text
.split(",");
44 foreach(QString host_weight
, host_weight_list
) {
45 if(!host_weight
.isEmpty()){
46 QStringList values
= host_weight
.split(":");
47 qWarning()<<"values="<<values
;
48 host
.push_back(values
[0].trimmed());
49 weight
.push_back(values
[1].trimmed());
53 // create the hostfile
54 QFileInfo
fileinfo( getFileName() + "/" + "hostfile.txt" );
55 QFile
hostfile( fileinfo
.filePath() );
56 if (!hostfile
.open(QIODevice::WriteOnly
| QIODevice::Text
)) {
58 EG_ERR_RETURN( "ERROR: Failed to open file " + fileinfo
.filePath() );
59 } catch ( Error err
) {
63 QTextStream
out( &hostfile
);
64 for(int i
= 0; i
< host
.size(); i
++) {
65 out
<< host
[i
] << endl
;
71 void OpenFOAMcase::upateVarFile(QString file_name
, QString bc_txt
)
73 QFile
file(getFileName() + "/0/" + file_name
);
77 file
.open(QIODevice::ReadOnly
);
82 buffer
= buffer
.replace("$$$", bc_txt
);
84 file
.open(QIODevice::WriteOnly
);
92 void OpenFOAMcase::writeBoundaryConditions()
95 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
96 GuiMainWindow::pointer()->getAllBoundaryCodes(bcs
);
97 QString U_buffer
= "";
98 QString p_buffer
= "";
99 QString T_buffer
= "";
100 QString k_buffer
= "";
101 QString epsilon_buffer
= "";
102 QString omega_buffer
= "";
103 QString nut_buffer
= "";
104 foreach (int bc
, bcs
) {
105 BoundaryCondition BC
= GuiMainWindow::pointer()->getBC(bc
);
106 if (!GuiMainWindow::pointer()->physicalTypeDefined(BC
.getType())) {
109 msg
= "boundary code " + msg
+ " has not been properly defined";
113 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
114 if (isSurface(id_cell
, m_Grid
)) {
115 if (cell_code
->GetValue(id_cell
) == bc
) {
116 n
+= GeometryTools::cellNormal(m_Grid
, id_cell
);
122 PhysicalBoundaryCondition PBC
= GuiMainWindow::pointer()->getPhysicalBoundaryCondition(BC
.getType());
123 U_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamU(getSolverVersion(), n
) + " }\n";
124 p_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamP(getSolverVersion()) + " }\n";
125 T_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamT(getSolverVersion()) + " }\n";
126 k_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamK(getSolverVersion()) + " }\n";
127 epsilon_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamEpsilon(getSolverVersion()) + " }\n";
128 omega_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamOmega(getSolverVersion()) + " }\n";
129 nut_buffer
+= " " + BC
.getName() + "\n {\n" + PBC
.getFoamNut(getSolverVersion()) + " }\n";
131 upateVarFile("U", U_buffer
);
132 upateVarFile("p", p_buffer
);
133 upateVarFile("T", T_buffer
);
134 upateVarFile("k", k_buffer
);
135 upateVarFile("epsilon", epsilon_buffer
);
136 upateVarFile("omega", omega_buffer
);
137 upateVarFile("nut", nut_buffer
);
140 void OpenFOAMcase::operate()
143 if ( getFileName() == "" ) {
144 readOutputDirectory();
147 writeSolverParameters(getFileName());
148 bool has_volume
= false;
149 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
150 if (isVolume(id_cell
, m_Grid
)) {
154 setFixedFileName(getFileName());
155 FoamWriter::operate();
156 QFileInfo
file_info(getFileName());
157 QFile
file(getFileName() + "/" + file_info
.baseName() + ".foam");
158 file
.open(QIODevice::WriteOnly
);
159 writeBoundaryConditions();
162 catch ( Error err
) {