CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing Format & General Technical (http://www.cfd-online.com/Forums/openfoam-meshing-technical/)
-   -   Points (http://www.cfd-online.com/Forums/openfoam-meshing-technical/61658-points.html)

Satish Undapalli (Satish) January 28, 2004 17:00

Hi I want to read the points
 
Hi
I want to read the points file using a code. I have multi blocks in my FOAM grid. I would like to know how these points are written in the file. I want to read these points using a FORTRAN code. Is this possible?

Mattijs Janssens (Mattijs) January 28, 2004 18:27

Do you want to read the point
 
Do you want to read the points from the blockMeshDict only (i.e. the block points) or the points from the generated mesh?

If the latter you can write a simple application to read the mesh and dump the points into a file with one coordinate per line so Fortran can easily read it.

Something like (starting from an application which read a mesh)
..
OFstream pointStream("points.txt");
forAll(mesh.points(), pointI)
{
const point& pt = mesh.points()[pointI];
pointStream << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
}
..


(if you want to read the block points that will be a bit harder. You'll have to read the blockMeshDict dictionary and dump the points as above)

braennstroem May 5, 2008 12:57

Hi Mattijs, is there a chan
 
Hi Mattijs,

is there a chance to do it vice versa, i.e. read two different point text files and create a points file for the polymesh?

I would read a file like:


fileName fileC= runTime.path()/runTime.constant()/"points2.txt";
IFstream CFile(fileC);
double T1;
double T2;
double T3;

while(0==CFile.eof() )
{
if (0==CFile.eof())
{
CFile >> T1 >> T2>> T3;
Info << CFile.eof() << endl;

}
}
but I get this:

--> FOAM FATAL IO ERROR : Attempt to get back from bad stream

file: /Software/OpenFOAM-1.4.1/tutorials_1.4.1/tutorials/simpleFoam/pitzDaily/constant /points2.txt at line 25014.

From function void Istream::getBack(token& t)
in file db/IOstreams/IOstreams/Istream.C at line 44.


Once this would work, I would read a different points-file and assign newT1, newT2 and newT3. Afterwards the difference should be added to the existings points:

diff1=T1-newT1
diff2=T2-newT2
diff3=T3-newT3



The difference could be added to the existing points by:


pointField zeroPoints(mesh.points());

pointField newPoints = zeroPoints + scaleFactor*pInterp.interpolate(diff)().internalFi eld();

mesh.polyMesh::movePoints(newPoints);
mesh.write();


where 'diff' is a somehow created vector.

Would be nice, if you have (or anyone) some good hints :-)

Thanks!
Fabian

mattijs May 6, 2008 16:15

You are probably trying to rea
 
You are probably trying to read 3 scalars from a last empty line.

Fix file or loop instead mesh.nPoints() times is my advice.

braennstroem May 7, 2008 01:09

Oh, pretty simple with the loo
 
Oh, pretty simple with the loop over mesh.nPoints. Fixing the file my way did not help though. Thanks a lot!

Fabian

braennstroem May 7, 2008 02:42

me again... actually I use thi
 
me again... actually I use this for reading the points2.txt file and the orig mesh. It works fine, but now the trouble is to combine the vector to a vectorField, which can be passed to the morphing:


fileName fileC= runTime.path()/runTime.constant()/"points2.txt";
IFstream CFile(fileC);
scalar diff;
vector diffv;
vector T;
double scale=1.0;

forAll(mesh.points(), pointI)
{
CFile >> T; //read shape vectors
const point& pt = mesh.points()[pointI]; //orig mesh
pointStream << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; //read orig mesh
diff = pt.y()-T.component(1);
diffv = pt - scale* T; // create diff between orig mesh and shape
}

Info << "Vektor T: "<< T << endl;
Info << "Vektor T1: "<< T.component(1) << endl;
Info << "Diff: "<< diff << endl;
Info << "Diff-Vektor: "<< diffv << endl;


Do you have a hint, how to append the vectors to a vectorField?

Fabian

mattijs May 7, 2008 03:09

Read your new position into a
 
Read your new position into a pointField first, then do your manipulation.

pointField newPoints(mesh.nPoints());
forAll(newPoints, pointI)
{
point& pt = newPoints[pointI];
CFile >> pt.x() >> pt.y() >>> pt.z();
}

vectorField diffv = scale*(mesh.points()-newPoints);

braennstroem May 8, 2008 15:19

Thanks a lot! Works nice :-)
 
Thanks a lot! Works nice :-)
Fabian


All times are GMT -4. The time now is 05:53.