|
[Sponsors] |
![]() |
![]() |
#1 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
Hi all,
I am getting an error here and I believe the relevant output is here: (START ERROR) codeStream : dictionary:"/home/user/OpenFOAM/user-9/mysimulation/0/region1/T" master-only-reading:0 --> FOAM FATAL IO ERROR: wrong token type - expected Scalar, found on line 2 the word 'ٌ@33333ٌ@�\�s�x�@33333ٌ@��:.�@33333ٌ@33333ٌ@�lh�@ 33333ٌ@33333ٌ@33333ٌ@33333ٌ@33333ٌ@33333ٌ@33333ٌ@3 3333ٌ@33333ٌ@33333ٌ@�' file: IStringStream.sourceFile at line 2. From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&) in file lnInclude/Scalar.C at line 101. FOAM exiting (END ERROR) I am just trying out codeStream for the first time and below is my code. I am concerned it might be the wrong writeEntry command, but if anyone knows for sure let me know please. Below is my codeStream. Thanks! Code:
dimensions [ 0 0 0 1 0 0 0 ]; internalField #codeStream { codeInclude #{ #include "fvCFD.H" #include <math.h> #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells()); const scalar maxt = 90; const scalar core_r = 0.762; const scalar avg_t = 40; const scalar a = (maxt - avg_t)/pow(core_r, 2); double r; forAll(T, i) { // Get Cell positions const scalar x = mesh.C()[i][0]; const scalar y = mesh.C()[i][1]; //const scalar z = mesh.C()[i][2]; r = sqrt(pow(x, 2) + pow(y,2)); if (r < core_r) { T[i] = maxt - a*pow(r, 2); } else { T[i] = avg_t; } } writeEntry(os, "", T); // Write to input dictionary #}; }; |
|
![]() |
![]() |
![]() |
![]() |
#2 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I found that I can only set T[i] with hardcode? I am so confused right now.
If I set T[i] = 75; for example, it works. If I set T[i] = Th; where Th is ANY variable type and even the same value (75), it will break and give me a new error --> FOAM FATAL IO ERROR: wrong token type - expected Scalar, found on line 2 the word '��E����@�\��\��@ ��З*�@�9L��@f��Gs��@�' Really this makes codeStream useless to me, why would it be doing this? |
|
![]() |
![]() |
![]() |
![]() |
#3 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I am thinking this may be a memory overflow error of some sort? I have around 2 million cells. If I even add a if statement it won't work, but if I set it to a stagnant value... it does.
This one is a real head scratcher. |
|
![]() |
![]() |
![]() |
![]() |
#4 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I have tried every iteration of the #codeStream and read all the relevant source code and combed the internet. I absolutely cannot initialize a temperature field and neither have I seen it done successfully with #codeStream.
It should be as easy as implementing these: https://www.cfd-china.com/assets/upl...1-solution.pdf The above examples work, but the temperature will not work in any circumstances I try. This is a very small blockmesh with 1000 cells, so it is not a memory error. Code:
internalField #codeStream { codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells(), 0.); double maxt = 90; double avg_t = 50; const scalar block = 0.05; forAll(T, i) { // Get Cell positions const scalar x = mesh.C()[i][0]; const scalar y = mesh.C()[i][1]; //const scalar z = mesh.C()[i][2]; ///const scalar r = pow(pow(x, 2.0) + pow(y, 2.0),0.5); if (x+y >= block) { T[i] = maxt; } else { T[i] = avg_t; } } writeEntry(os, "", T); // Write to input dictionary //Pout << "Initialization of internalField"; #}; }; This gives error: Code:
on processor 0 have masterSize:826176 and localSize:826176 on processor 0 after waiting: have masterSize:826176 and localSize:826176 Opening cached dictionary:"/home/user/OpenFOAM/user-9/2DTestGround/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_5bcb7371585e69419bfd74cf784f21d4784acc5e.so" codeStream : dictionary:"/home/user/OpenFOAM/user-9/2DTestGround/0/T" master-only-reading:0 --> FOAM FATAL IO ERROR: error in IOstream "IStringStream.sourceFile" for operation operator>>(Istream&, List<T>&) : reading entry file: IStringStream.sourceFile at line 2. From function void Foam::IOstream::fatalCheck(const char*) const in file db/IOstreams/IOstreams/IOstream.C at line 109. FOAM exiting |
|
![]() |
![]() |
![]() |
![]() |
#5 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,728
Rep Power: 66 ![]() ![]() ![]() |
well... for starters... anything with the const type qualifier is read only
|
|
![]() |
![]() |
![]() |
![]() |
#6 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I can see how this is relevant when I add x and y together, but I get the same problem when using x alone in the boolean operator.
These snippets of code: Code:
const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells(), 0.); as well as Code:
const scalar x = mesh.C()[i][0]; const scalar y = mesh.C()[i][1]; work in all the above tutorials but the code also only reads them so declaring them as const is appropriate as far as I can tell. The only thing I am writing to is scalarField T. For example, I could take my exact code and only change T to alpha, and it would run and I would see the results as intended. I must be referencing T incorrectly but I am not sure how. |
|
![]() |
![]() |
![]() |
![]() |
#7 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
With new code (using as few consts as possible)
Code:
internalField #codeStream { codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells(), 0.); scalar maxt = 90.0; scalar avg_t = 40.0; scalar block = 0.025; forAll(T, i) { // Get Cell positions scalar x = mesh.C()[i][0]; scalar y = mesh.C()[i][1]; if (x >= block) { T[i] = scalar(maxt); } else { T[i] = scalar(avg_t); } } T.writeEntry("", os); // Write to input dictionary #}; }; Code:
--> FOAM FATAL IO ERROR: (openfoam-2106) Bad token - could not get scalar value file: input at line 2. From Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&) in file lnInclude/Scalar.C at line 141. FOAM exiting OpenFOAM-2106:~/OpenFOAM/user-2106/run/2DTestGround/ |
|
![]() |
![]() |
![]() |
![]() |
#8 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,728
Rep Power: 66 ![]() ![]() ![]() |
you have a token error... Check all your { } ( ) pairs and ;'s
I would start with removing the semicolon at the end of your bracket for internalField |
|
![]() |
![]() |
![]() |
![]() |
#9 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I couldn't figure it out even with trying every permutation of semicolon and brackets. I instead just used the setExprFields utility on the v2106 of OpenFOAM, and then ran it on OF 9 (as v2106 isn't very friendly with solid only chtMultiRegionFoam). If anyone figures out how to get codeStream to work with temperature, let me know. I am just flabbergasted at this error and it might be something simple that I did wrong.
Thanks for the help thus far! |
|
![]() |
![]() |
![]() |
![]() |
#10 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,728
Rep Power: 66 ![]() ![]() ![]() |
A token error is really simple indeed
|
|
![]() |
![]() |
![]() |
![]() |
#11 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
I don't believe the error message is suggesting the token is actually in my dictionary and I have tried just in case. It compiles the dictionary code just fine and then makes a bad stream that gives a token error. The function it points to is not much help.
This also wouldn't necessarily make sense since this code snippet works verbatim with other scalar and vector fields as well. Thus, it might be that I am giving T the wrong datatype (I"ve tried everything here) or I am referencing T wrong. |
|
![]() |
![]() |
![]() |
![]() |
#12 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,728
Rep Power: 66 ![]() ![]() ![]() |
This
Code:
internalField { }; Code:
internalField { } It's also only one block of the dict so you may have made the same mistake elsewhere. The good news is that the parser tells you the token error is on this block (line 2). |
|
![]() |
![]() |
![]() |
![]() |
#13 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
Yes, but per my previous replies. It does not change the end result.
Code:
--> FOAM FATAL IO ERROR: wrong token type - expected Scalar, found on line 2 the word '�Sg��V@㛿�!V@w��c?V@lL1�Q�V@ŴJYV@���TV@��>�E' file: IStringStream.sourceFile at line 2. From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&) in file lnInclude/Scalar.C at line 101. FOAM exiting Here is my entire T dictionary Code:
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 8 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format binary; class volScalarField; location "0"; object T; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [ 0 0 0 1 0 0 0 ]; internalField #codeStream { codeInclude #{ #include "fvCFD.H" #include <math.h> #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells()); const scalar maxt = 90; const scalar core_r = 0.762; const scalar avg_t = 40; const scalar a = (maxt - avg_t)/pow(core_r, 2); double r; forAll(T, i) { // Get Cell positions const scalar x = mesh.C()[i][0]; const scalar y = mesh.C()[i][1]; //const scalar z = mesh.C()[i][2]; r = sqrt(pow(x, 2) + pow(y,2)); if (r < core_r) { T[i] = maxt - a*pow(r, 2); } else { T[i] = avg_t; } } writeEntry(os, "", T); // Write to input dictionary #}; } boundaryField { inlet { type fixedValue; value uniform 40; } outlet { type inletOutlet; inletValue uniform 40; value uniform 40; } walls { type zeroGradient; } } // ************************************************************************* // |
|
![]() |
![]() |
![]() |
![]() |
#14 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,728
Rep Power: 66 ![]() ![]() ![]() |
Your codeStream block works for me after I spent the time to manually retype it into a random case of mine in OF 2.4. You have a typo in your dict somewhere. It's that simple. Or maybe you have something extraordinary going on in your custom solver. Then I can't tell you where in the universe the token error might appear.
T.writeEntry("", os); is slightly safer to use if you continue to have trouble I'm done |
|
![]() |
![]() |
![]() |
![]() |
#15 |
New Member
George
Join Date: Oct 2020
Posts: 24
Rep Power: 5 ![]() |
Could you post the manually retyped dict? I've looked at mine for hours and don't think I am going to find it.
T.writeEntry("", os) is for the ESI version which I have posted a dict also attempting to get it to work with that. |
|
![]() |
![]() |
![]() |
![]() |
#16 |
New Member
mill
Join Date: Feb 2021
Posts: 9
Rep Power: 5 ![]() |
Hi Dicanic
I meet the similar problem when i use codeStream to set alpha of water. It shows a fatal error: Code:
--> FOAM FATAL IO ERROR expected keyword 'uniform' or 'nonuniform' , found codeInclude |
|
![]() |
![]() |
![]() |
![]() |
#17 |
New Member
Join Date: Jul 2021
Posts: 16
Rep Power: 5 ![]() |
I was having this issue and I changed the write format from binary to ascii and it fixed it.
|
|
![]() |
![]() |
![]() |
![]() |
#18 |
Member
|
Hi Foamers,
same here. I tried and tried and did not found my error. I was not able to set a temperature field with codeStream. I tried using http://www.wolfdynamics.com/wiki/pro...streamINIT.pdf But without success. I searched and foud differences in the writeEntry which 'only' gets my a different error, see note in the code: Any idea to solve this? Code:
code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField T(mesh.nCells(), 0); forAll(T, i) { const scalar z = mesh.C()[i][2]; // T[i] = 459.634 + 139.937*z + 71.306*z^2 - 50.764*z^3 + 10.339*z^4 - 0.722*z^5; T[i] = 20. * z; } writeEntry(os, "", T); // wrong token type - expected Scalar, found on line 2 the word '���' // T.writeEntry("", os); // error: ‘Foam::scalarField’ {aka ‘class Foam::Field<double>’} has no member named ‘writeEntry’ #}; Edit: This error was created by using Foundation Version 11 Best regards Michael |
|
![]() |
![]() |
![]() |
![]() |
#19 |
Member
|
I was not able to set a temperature field with common operations.
However I helped myself with a script appyling a lot of setFields runs. Preparing the table for the iterations is simple by using Excel, etc. Maybe this workaround helps somebody else. However - if one got a solution for the initial question please note it here. Code:
#!/bin/bash cd ${0%/*} || exit 1 # Run from this directory # Source tutorial run functions . $WM_PROJECT_DIR/bin/tools/RunFunctions z=(-0.2 0.1 0.2 0.3 0.4 ... ); Temp=(459.634 474.29102268 490.08383936 506.74400344 524.02614912 ... ); for i in 0 1 2 3 4 5 ... ; do echo "${z[i]} & ${Temp[i]}"; runApplication -a foamDictionary system/porous/setFieldsDict.T -entry regions -set "(boxToCell {box (-1 -1 ${z[i]})(1 1 60); fieldValues ( volScalarFieldValue T ${Temp[i]});});" runApplication -a foamDictionary system/air/setFieldsDict.T -entry regions -set "(boxToCell {box (-1 -1 ${z[i]})(1 1 60); fieldValues ( volScalarFieldValue T ${Temp[i]});});" runApplication -a setFields -region porous -dict setFieldsDict.T runApplication -a setFields -region air -dict setFieldsDict.T done Michael |
|
![]() |
![]() |
![]() |
Tags |
codestream, openfoam 9 |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] How to correctly show the result of #codeStream# internalField? | chengdi | ParaView | 24 | July 14, 2022 04:26 |
nonUniform internalField using codeStream | Saleh Abuhanieh | OpenFOAM Programming & Development | 9 | September 17, 2021 07:48 |
PROBLEMS DEFINING A LIST USING #CODESTREAM !! Help please !! | angatri_14 | OpenFOAM Programming & Development | 1 | August 21, 2020 17:16 |
twoPhaseEulerFoam confined plunging jet simulation failed | ves | OpenFOAM Running, Solving & CFD | 2 | June 17, 2020 05:08 |
How to create the internalField with #codeStream | chun | OpenFOAM Running, Solving & CFD | 3 | May 6, 2017 10:35 |