CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Help with read in values from a file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 6, 2022, 10:42
Default Help with read in values from a file
  #1
Senior Member
 
TWB
Join Date: Mar 2009
Posts: 402
Rep Power: 19
quarkz is on a distinguished road
Hi,

I have a txt file with data:

Orientation (1 7.87011e-08 0 -7.87011e-08 1 0 0 0 1)
Orientation (1 9.07449e-08 0 -9.07449e-08 1 0 0 0 1)

I have a modified mesh deformation codee coming from oscillatingRotatingMotion.

In that code, I need to read in the 2 tensor values. Actually, I just need the values, whether read in as tensor or not is not important.

I tried:

orientationdict_
(
IOobject
(
"orientationdict",
runTime_.constant(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),

tensor orientation = orientationdict.lookup("orientation");

but it doesn't compile. I got the error:

Code:
prototype_retract_motionPointPatchVectorField.C:224:3: error: ‘runTime_’ was not declared in this scope
  224 |   runTime_.constant(),
      |   ^~~~~~~~
prototype_retract_motionPointPatchVectorField.C:225:3: error: ‘mesh_’ was not declared in this scope; did you mean ‘mesh’?
  225 |   mesh_,
      |   ^~~~~
      |   mesh
prototype_retract_motionPointPatchVectorField.C:219:3: error: ‘orientationdict_’ was not declared in this scope
  219 |   orientationdict_
      |   ^~~~~~~~~~~~~~~~
prototype_retract_motionPointPatchVectorField.C:231:10: error: expected primary-expression before ‘orientation’
  231 |   tensor orientation = orientationdict.lookup("orientation");
is this the way to do it? I'm a Fortran programmer so my understanding is limited. I got the code searching thru cfd-online forum.

Hope someoe can help to correct me. Thanks.
quarkz is offline   Reply With Quote

Old   February 7, 2022, 10:09
Default
  #2
Senior Member
 
TWB
Join Date: Mar 2009
Posts: 402
Rep Power: 19
quarkz is on a distinguished road
I was thinking in terms of how OF uses dictionary.

But then I realised that it's just a piece of C++ code and I can do it the c++ way too.

So to ans my own qn:

My file, consisting of actually 2 tensors

1 3.02823e-07 0 -3.02823e-07 1 0 0 0 1
1 3.26108e-07 0 -3.26108e-07 1 0 0 0 1

and I just need to extract the 2nd value of each tensor.

add

Code:
#include <iostream>
#include <fstream>
using namespace std;
to top of code to be modified

and this part to the file reading:

Code:
// Read from the text file
	ifstream file;
	
	file.open("orientation2.dat");
	
	string line;
	int i = 0;
	double tmp_orientation, orient[2];
	
	while(file.good() && (getline(file, line)))
	{
		istringstream iss(line);
		
		iss >> tmp_orientation >> orient[i] >> tmp_orientation >> tmp_orientation >> tmp_orientation >> tmp_orientation >> tmp_orientation >> tmp_orientation >> tmp_orientation;
		//cout << orient[i];
	}
	
	file.close();
	
	scalar orient_pitch_old = asin(orient[0]);
	scalar orient_pitch = asin(orient[1]);
So that's it!
quarkz is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] Tabulated thermophysicalProperties library chriss85 OpenFOAM Community Contributions 62 October 2, 2022 03:50
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 35 April 29, 2022 15:35
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 10:59
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit ParaView 60 September 18, 2013 03:23
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 10:57


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