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

"IF" statement in coded Boundary condition

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2018, 05:51
Default "IF" statement in coded Boundary condition
  #1
New Member
 
Tomas Turner
Join Date: May 2018
Posts: 1
Rep Power: 0
Tom_T is on a distinguished road
Dear all,


I am new to OpenFOAM and trying to simulate temperature inside a tube.
I need to have 3 different temperature 3 zones of the tube These zones are defined by the x coordinate.
Unfortunately this does not work. Under you can find my code and the error message.
I tried debugging by not including the if statement and just "field[faceI] = 473.15;" and it worked. The problem seems to lie in the if statement


has anyone used IF statements in coded BC before?
If yes could you link a example of code?


If not do you have a viable alternative of obtaining the same result?



"

defaultName
{
type codedFixedValue; //Befehl für die programmierbare Randbedingung
value uniform 473.15; //Standardwert der Temperatur, wenn die Bedingung des Codes nicht zutrifft (default value)
redirectType temperatureProfileInlet; //Name der programmierbaren Randbedingung (frei wählbar)

code //ab hier folgt die programmierbare Randbedingung
#{

const fvPatch& boundaryPatch = patch();
const vectorField& Cf = boundaryPatch.Cf();
//Definition der verwendeten Klasse; anders ausgedrückt: es wird definiert, dass sich der Code auf ein boundaryPatch - nämlich das inlet Patch aus dem Blender Mesh - bezieht
//die Klasse besitzt die Funktion Cf (center of face), mit der der Mittelpunkt einer Fläche (in diesem Fall eines Elementes) wiedergegeben werden kann

scalarField& field = *this; //Definition des Temperaturfeldes als skalares Feld

forAll(Cf, faceI) //die folgenden Definitionen beziehen sich auf den Flächenmittelpunkt jedes Elementes
{


scalar x = Cf[faceI].x();
//jedem Flächenmittelpunkt eines Elementes wird ein Radius r zugewiesen - r=Wurzel(y²+z²)


//die Temperatur des Elementes wird nach der Funktion in Abhängigkeit des Radius berechnet



if (x< -0.0668397095133788 && x>-0.02338856745933){
field[faceI] = 473.15;
}
if (x< -0.02338856745933 && x>0.0195893161446997){
field[faceI] = 473.15;
}
if (x< 0.0195893161446997 && x>0.0628503014378741){
field[faceI] = 473.15;
}
else field[faceI] = 473.15;
"


error message


"Reading field T

Using dynamicCode for patch defaultName on field T at line 41 in "/media/sf_sharedwithvm/02_Ergebnisse_Statikmischer/Cooling_neue_Uebergaenge/PEHD/200_level/full_data_Stege_minus_2_K3/0/T.boundaryField.defaultName"
Creating new library in "dynamicCode/temperatureProfileInlet/platforms/linux64GccDPInt32Opt/lib/libtemperatureProfileInlet_a41a253919dfc6320afc8cc 705b1e735598fe626.so"
Invoking "wmake -s libso /media/sf_sharedwithvm/02_Ergebnisse_Statikmischer/Cooling_neue_Uebergaenge/PEHD/200_level/full_data_Stege_minus_2_K3/dynamicCode/temperatureProfileInlet"
wmakeLnInclude: linking include files to ./lnInclude
ln: failed to create symbolic link './fixedValueFvPatchFieldTemplate.C': Read-only file system
ln: failed to create symbolic link './fixedValueFvPatchFieldTemplate.H': Read-only file system
Making dependency list for source file fixedValueFvPatchFieldTemplate.C
/media/sf_sharedwithvm/02_Ergebnisse_Statikmischer/Cooling_neue_Uebergaenge/PEHD/200_level/full_data_Stege_minus_2_K3/0/T.boundaryField.defaultName: In member function ‘virtual void Foam::temperatureProfileInletFixedValueFvPatchScal arField::updateCoeffs()’:
/media/sf_sharedwithvm/02_Ergebnisse_Statikmischer/Cooling_neue_Uebergaenge/PEHD/200_level/full_data_Stege_minus_2_K3/0/T.boundaryField.defaultName:65:7: error: expected primary-expression before ‘/’ token
/opt/openfoam4/wmake/rules/General/transform:8: recipe for target 'Make/linux64GccDPInt32Opt/fixedValueFvPatchFieldTemplate.o' failed
make: *** [Make/linux64GccDPInt32Opt/fixedValueFvPatchFieldTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/temperatureProfileInlet/platforms/linux64GccDPInt32Opt/lib/libtemperatureProfileInlet_a41a253919dfc6320afc8cc 705b1e735598fe626.so"


file: /media/sf_sharedwithvm/02_Ergebnisse_Statikmischer/Cooling_neue_Uebergaenge/PEHD/200_level/full_data_Stege_minus_2_K3/0/T.boundaryField.defaultName from line 41 to line 46.

From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

FOAM exiting
"
Tom_T is offline   Reply With Quote

Old   May 28, 2018, 17:10
Default
  #2
New Member
 
Dr. Peyman Davvalo Khongar
Join Date: Mar 2018
Location: Helsinki (Finland)
Posts: 16
Rep Power: 8
peyman.davvalo.khongar is on a distinguished road
Moi,

There is something strange in your else syntax. Do you use this format?

Code:
 if (CONDITION)
        {
     CODE;
        }
 else if (CONDITION)
        {
     CODE;
        }
 else
        {
     CODE;
        }
The line number in your code is not specified. I can not see line 65 that give you the following error.

Code:
65:7: error: expected primary-expression before ‘/’ token
You can of course always go to this website:

https://github.com/OpenFOAM/OpenFOAM-dev

and search your key word to see how it is used in OpenFOAM codes. Your key word is else.


Moikka,

Peyman
peyman.davvalo.khongar 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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 08:38
Radiation in semi-transparent media with surface-to-surface model? mpeppels CFX 11 August 22, 2019 08:30
Accessing multiple boundary patches from a custom boundary condition file ripudaman OpenFOAM Programming & Development 0 October 22, 2014 19:34
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00
RPM in Wind Turbine Pankaj CFX 9 November 23, 2009 05:05


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