|
[Sponsors] |
Write Cell Volumes and Velocities for each TimeStep |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 19, 2017, 04:35 |
Write Cell Volumes and Velocities for each TimeStep
|
#1 |
Member
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11 |
Hello everybody,
I am write a little post-processing tool which writes out the cell volumes and the velocities in the cells for a specific region in the domain. Since I am only interested in a small part of my domain, I define a distance from z_min to z_max in an so called CoordinatesDict in the constant directory. I want to write the data in a .dat file to proceed working with python. At the moment the code looks like this... Code:
// This file is based on OpenFOAM. // Description // Write mesh cell volumes in volumes.dat file and velocity in // velocity.dat file in current folder. #include "OFstream.H" #include "argList.H" #include "timeSelector.H" #include "Time.H" #include "fvMesh.H" #include "vectorIOField.H" #include "volFields.H" #include "surfaceFields.H" //#include "fvCFD.H" using namespace Foam; int main(int argc, char *argv[]) { timeSelector::addOptions(); # include "setRootCase.H" Info << "\n***EXTRACT CELL VOLUMES AND VELOCITIES***\n" << endl; Info << "This applications is extacting the volumes and the velocities from a region in the domain\n" << endl; # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" # include "createFields.H" Info << "1) Reading all volumes..." << endl; Info << "Extracting cells between z = " << z_min.value(); Info << " and z = " << z_max.value() << endl; OFstream volumes("volumes_" + runTime.timeName() + ".dat"); forAll(mesh.C(), idx) { if (mesh.C()[idx].component(2) >= z_min.value()) if (mesh.C()[idx].component(2) <= z_max.value()) { volumes << idx << ' ' << mesh.V()[idx] << ' ' << mesh.C()[idx] << endl; } } Info << "Volumes DONE...\n" << endl; Info << "2) Reading velocities...\n" << endl; forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; #include "createMesh.H" #include "createFields.H" OFstream velocity("velocity_" + runTime.timeName() + ".dat"); Info << "Extracting cells between z = " << z_min.value(); Info << " and z = " << z_max.value() << endl; //Extract the z component of the cell centers Info << "Writing data to the files velocity_" + runTime.timeName() + ".dat" << "\n" << endl; forAll(mesh.C(), idx) { if (mesh.C()[idx].component(2) >= z_min.value()) if (mesh.C()[idx].component(2) <= z_max.value()) { velocity << idx << ' ' << U[idx].component(0) << ' ' << U[idx].component(1) << ' ' << U[idx].component(2) << endl; } } } Info << "Writing done \n" << endl; return 0; } Code:
#include "createMesh.H" #include "createFields.H" I tried so come around with mesh.readUpdate() but I did not work out... Thank a lot for your input! Best regards |
|
|
|