CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   OpenFoam- Boundary condition from file (https://www.cfd-online.com/Forums/openfoam-programming-development/234582-openfoam-boundary-condition-file.html)

Rida_B March 11, 2021 08:09

OpenFoam- Boundary condition from file
 
Hello everyone,
I am working on a OpenFoam simulation with the energy equation.
My problem is very simple. When setting initial boundary conditions for temperature, I aim to give specific values of temperature to each point of the mesh (or face ) from an external csv file containting ( xpos, ypos, zpos, T(xpos,ypos,zpos) ).
I wrote this part of the code, but I get a warrning : " attempt to read beyond EOF " which I dont understand what It really means.

CODE :
boundaryField
{
".*"
{
type codedFixedValue;
code
#{
std::ifstream file(file_temperature);
if (file.is_open() )
{
for ( long row=1 ; row<=csv_total_rows ; row++ )
{
for(long column=1; column<=csv_total_columns; column++)
{
long index = (row-1)*csv_total_columns+column-1;
scalar xpos = csv_data[index].nodeposition[0];
scalar ypos = csv_data[index].nodeposition[1];
scalar zpos = csv_data[index].nodeposition[2];
pos(xpos, ypos, zpos);
scalar T = csv_data[index].nodeposition[3];

}


}
file.close();
}
#};
codeInclude
#{

#include <cmath>
#include <iostream>
#include <fstream>

#};
}
}

I hope I can get some answers,
thank you very much

gionni March 12, 2021 04:39

Hi, I'm not sure if I can help you, but I can share some thoughts.
First, the warning means that you are trying to read past the end of file (EOF). Maybe check the loop by printing the row every step and see exactly when the error arises.

Another thing, is this something you just want to do when you initialize the simulation? A coded BC is useful if you need it to run every timestep; there are better ways to impose a field in preprocessing.

Another thing, I think there is no point where you actually apply the values you read. To update the boundary you should use something like:
Code:

(*this)[faceID]=Temperature_scalar;
If you want to change a cell value:

Code:

const volScalarField& Temp = db().lookupObject<volScalarField>("Temp");
Temp[cellID]==Temperature_scalar;

where "Temp" has to be the name of your field.

I'm not sure if this is helpful, I hope so :)

PS: to improve readability, you can put code in a CODE tag, you find it in the toolbar at the # button.


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