Hello, I want to edit some parameters from a file.
Actually, I am not a programmer, so finding some difficulties in the basic.
Here is the file that I want to edit:
*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.0.1 |
| \\ / A nd | Web:
www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.1;
vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 0.1)
(1 0 0.1)
(1 1 0.1)
(0 1 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
movingWall
{
type wall;
faces
(
(3 7 6 2)
);
}
fixedWalls
{
type wall;
faces
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
For eg,
I want to change the parameters after the vertices which is bold.
Till now, I have written the code to open and read the file but couldnt do replacing or editing the required parameters.
Here is my code:
// reading a text file
#include <fstream>
#include <iostream>
#include <string>
#include<stdio.h>
using namespace std;
int main()
{
string line;
int count=0;
ifstream myfile ("blockMeshDict");
while(! myfile.eof()) {
getline(myfile, line);
count++;
if(count>=19 && count<=29) {
cout << line << endl;
}
}
// now to open an output file
//ofstream out ("blockMeshDict1");
if (count == 21){
line = line.replace("(2 2 2)","(0 0 0)");
cout << line << endl;
}
return 0;
}
.................................................................................................... ....
If anyone can help, I will really appreciate.
Thanks.