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

OpenFoam- Boundary condition from file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 11, 2021, 08:09
Default OpenFoam- Boundary condition from file
  #1
New Member
 
Rida
Join Date: Mar 2021
Posts: 1
Rep Power: 0
Rida_B is on a distinguished road
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
Rida_B is offline   Reply With Quote

Old   March 12, 2021, 04:39
Default
  #2
New Member
 
Giovanni Luddeni
Join Date: Jan 2021
Posts: 14
Rep Power: 5
gionni is on a distinguished road
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.
gionni is offline   Reply With Quote

Reply

Tags
boundary conditions, csv files


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
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 03:30
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


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