|
[Sponsors] |
[OpenFOAM] How to correctly show the result of #codeStream# internalField? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 7, 2017, 07:38 |
How to correctly show the result of #codeStream# internalField?
|
#1 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
Hi, everyone
I just used codeStream to generate some initial condtion and codedFixedValue to generate some boundary condtion. The codedFixedValue BC can be correctly executed and loaded using paraFoam (I am using OF1612+ in docker), however, the codeStream initial condition can be correctly interpreted and executed but cannot be loaded in paraFoam. I was running the forwardStep with following "0/U" file Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: plus | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volVectorField; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; //internalField uniform (3 0 0); internalField #codeStream { code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); vectorField T(mesh.nCells()); const vectorField& CC = mesh.C(); //cell center forAll(CC,cellI) { //spatial coordinates, type: scalar scalar x = CC[cellI].x(); scalar y = CC[cellI].y(); scalar z = CC[cellI].z(); T[cellI] = vector(3+0.2*sin(10*x),0,0); } //void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const T.writeEntry("", os); #}; //! Optional: codeInclude #{ #include "fvCFD.H" #}; //! Optional: codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; //! libs: codeLibs #{ -lmeshTools #}; }; boundaryField { inlet { type codedMixed; refValue uniform (3 0 0); //default value refGradient uniform (0 0 0); //default value valueFraction uniform 1; redirectType linearOscillatingBC; //name of new BC type code #{ const vectorField& Cf = patch().Cf(); // get face center coordinate; scalar ymax = max(Cf&vector(0,1,0)); // `&` is dot product scalar ymin = min(Cf&vector(0,1,0)); // Info<<"ymax="<<ymax<<",ymin="<<ymin<<nl; vectorField& rvf = this->refValue(); vectorField& rgf = this->refGrad(); scalarField& vf = this->valueFraction(); //temporal coordinate, type: scalar scalar t =this->db().time().value(); // get time //Oscillating parameters scalar omega = 5; scalar A = 0.2; scalar tt = (1+A*sin(omega*t)); // temporal term, separated forAll(Cf,faceI) { //spatial coordinates, type: scalar //scalar x = Cf[faceI].x(); scalar y = Cf[faceI].y(); //scalar z = Cf[faceI].z(); rvf[faceI] = vector(((y-ymin)/(ymax-ymin)+2.5)*tt,0.0,0.0); rgf[faceI] = Zero; vf[faceI] = 1.0; } #}; //I do not know why I need to add those things //codeInclude //#{ // #include "fvCFD.H" //#}; //codeOptions //#{ // -I$(LIB_SRC)/finiteVolume/lnInclude //#}; } outlet { type inletOutlet; inletValue uniform (3 0 0); value uniform (3 0 0); } bottom { type symmetryPlane; } top { type symmetryPlane; } obstacle { type slip; } defaultFaces { type empty; } } // ************************************************************************* // Code:
Created temporary 'forwardStepMod3.OpenFOAM' Using #codeStream at line 21 in file "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U" Using #codeStream with "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so" Invoking wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f --> FOAM FATAL IO ERROR: Failed loading library "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so" Did you add all libraries to the 'libs' entry in system/controlDict? file: /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U from line 17 to line 17. From function static void (* Foam::functionEntries::codeStream::getFunction(const Foam::dictionary&, const Foam::dictionary&))(Foam::Ostream&, const Foam::dictionary&) in file db/dictionary/functionEntries/codeStream/codeStream.C at line 309. FOAM exiting Code:
Created temporary 'forwardStepMod3.OpenFOAM' --> FOAM Warning : From function void* Foam::dlOpen(const Foam::fileName&, bool) in file POSIX.C at line 1244 dlopen error : /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so: undefined symbol: _ZTIN4Foam6fvMeshE --> FOAM Warning : From function bool Foam::dlLibraryTable::open(const Foam::fileName&, bool) in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 101 could not load "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so" Using #codeStream at line 21 in file "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U" Using #codeStream with "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so" Invoking wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f --> FOAM FATAL IO ERROR: Failed loading library "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so" Did you add all libraries to the 'libs' entry in system/controlDict? file: /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U from line 17 to line 17. From function static void (* Foam::functionEntries::codeStream::getFunction(const Foam::dictionary&, const Foam::dictionary&))(Foam::Ostream&, const Foam::dictionary&) in file db/dictionary/functionEntries/codeStream/codeStream.C at line 309. FOAM exiting |
|
May 7, 2017, 09:34 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Quick answer: You have this:
Code:
codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; //! libs: codeLibs #{ -lmeshTools #}; Code:
//! libs: codeLibs #{ -lmeshTools \ -lfiniteVolume #};
__________________
|
|
May 8, 2017, 03:08 |
|
#3 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
Dear Bruno
Thank you so much for you reply! |
|
May 8, 2017, 03:18 |
|
#4 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
Hi Bruno,
I just tried to use "paraview" rather than "paraFoam" to post-process the result after time "0". However, the "U" field cannot be read and here is the errors: Code:
ERROR: In /home/buzz2/pawan/OpenFOAM/ThirdParty-1606_plus/ParaView-5.0.1/VTK/IO/Geometry/vtkOpenFOAMReader.cxx, line 6497 vtkOpenFOAMReaderPrivate (0x40ace10): Error reading line 16332 of /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/8/U: Unsupported directive { Code:
internalField nonuniform List<vector> 16128 ( (2.877288422651 -3.144469067245e-05 0) ... ) ; name linearOscillatingBC; code #{ const vectorField& Cf = patch().Cf(); // get face center coordinate; scalar ymax = max(Cf&vector(0,1,0)); // `&` is dot product scalar ymin = min(Cf&vector(0,1,0)); // Info<<"ymax="<<ymax<<",ymin="<<ymin<<nl; vectorField& rvf = this->refValue(); vectorField& rgf = this->refGrad(); scalarField& vf = this->valueFraction(); //temporal coordinate, type: scalar scalar t =this->db().time().value(); // get time //Oscillating parameters scalar omega = 5; scalar A = 0.2; scalar tt = (1+A*sin(omega*t)); // temporal term, separated forAll(Cf,faceI) { //spatial coordinates, type: scalar //scalar x = Cf[faceI].x(); scalar y = Cf[faceI].y(); //scalar z = Cf[faceI].z(); rvf[faceI] = vector(((y-ymin)/(ymax-ymin)+2.5)*tt,0.0,0.0); rgf[faceI] = Zero; vf[faceI] = 1.0; } #}; } outlet { ... Last edited by wyldckat; May 8, 2017 at 20:17. Reason: Added [CODE][/CODE] markers |
|
May 8, 2017, 05:44 |
|
#5 |
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 16 |
Hi,
AFAIK, there isn't a very straightforward way to do this. What I do is to open up the result file and modify the type from 'coded...' to 'fixedValue'. OF seems to write the values in any case (usually in the line/lines right below type) and so making this change allows Paraview to understand and display the velocity. Hope this helps. Cheers, Antimony |
|
May 8, 2017, 20:19 |
|
#6 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Quick answer: If the file extension ".OpenFOAM" is not used and instead the built-in reader with ".foam" is used instead, then it will not work. You could try with ParaView 5.3, but I haven't tested it yet.
The only other solution is to use foamToVTK and then open the VTK files in ParaView. |
|
May 9, 2017, 03:51 |
|
#7 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
Dear Bruno
Thanks for your suggestion. I will try foamToVTK. |
|
May 18, 2017, 16:58 |
Implementing a new IOobject
|
#8 |
Member
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 47
Rep Power: 15 |
Hi,
I am using OpenFOAM 4.1 for melting and solidification problem. I am following this thread Marangoni bc for writing marangoni BC. The boundary condition uses an IOobject of volVectorField gradT. The thread suggest putting IOobject in solver. I want to know the possibility of calculating gradT from controlDict using functionObjects or codeStream. I have written the controlDict in this way Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object controlDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // application buoyantPimpleFoam; startFrom startTime; startTime 0; stopAt endTime; endTime 30.0; deltaT 1.0; writeControl adjustableRunTime; writeInterval 10; purgeWrite 0; writeFormat ascii; writePrecision 8; writeCompression off; timeFormat general; timePrecision 10; runTimeModifiable yes; adjustTimeStep yes; libs ( "libmyBoundaryConditions.so" "libOpenFOAM.so" ); /* maxCo 0.25; maxDeltaT 1; maxAlphaCo 1; */ #codeStream { code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); volVectorField gradT ( IOobject ( "gradT", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), fvc::grad(T) ); #}; /*codeInclude #{ #include "fvCFD.H" #};*/ codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ #}; codeLibs #{ -lmeshTools #}; } // ************************************************************************* // -- Tarang |
|
May 20, 2017, 00:47 |
|
#9 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
I think you can use post-processor to calculate grad(T)
|
|
May 20, 2017, 01:54 |
|
#10 |
Member
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 47
Rep Power: 15 |
Will I be able to use "post process"ed grad(T) as volVectorField in boundaryConditionFvPatchField?
|
|
May 20, 2017, 23:38 |
|
#11 |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
sorry, I misunderstood your purpose.
As far as I know. #codeStream is just used to generate some "TEXT" in the controlDict or other text-based configuration file for OpenFOAM. If you want to use some volVectorField grad(T) in your BC. you must modify your solver. |
|
May 21, 2017, 07:33 |
|
#12 |
Member
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 47
Rep Power: 15 |
Thanks chengdi. I have modified my solver to calculate gradT. One thing about the #codestream in controlDict I want to ask is that where in the execution flow process the code is executed?
|
|
June 12, 2017, 11:34 |
|
#13 | |
Member
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 47
Rep Power: 16 |
Quote:
You may understand it like this: When the foam app read the controlDict, what your app actually read is the text generated by your #codeStream at the start of the dict-entry-reading. |
||
September 7, 2017, 11:08 |
|
#14 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16 |
Hi
I use codeStream BC for U I tried to access time as you posted in How to correctly show the result of #codeStream# internalField? However I got error "error: invalid use of ‘this’ in non-member function" in the line scalar t = this->db().time().value(); My U file is Code:
dimensions [0 1 -1 0 0 0 0]; internalField uniform (16 0 0); boundaryField { WALL { type fixedValue; value #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.parent().parent() ); const fvMesh& mesh = refCast<const fvMesh>(d.db()); const label id = mesh.boundary().findPatchID("WALL"); const fvPatch& patch = mesh.boundary()[id]; vectorField U(patch.size(), vector(0, 0, 0)); scalar t = this->db().time().value(); forAll(U,i) { U[i] = vector(1, 0., 0.); } U.writeEntry("", os); #}; }; }
__________________
best regards pblasiak |
|
July 4, 2018, 10:14 |
|
#15 | |
Member
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9 |
Hi Foamers,
I got the same error as you: Quote:
Thanks! |
||
July 5, 2018, 09:34 |
|
#16 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16 |
Hi
I did not solve this. I used codedFixedValue instead of fixedValue.
__________________
best regards pblasiak |
|
July 5, 2018, 11:18 |
|
#17 |
Member
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9 |
||
July 5, 2018, 14:04 |
|
#18 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16 |
you can find basic info here
https://www.openfoam.com/documentati...xed-value.html or search on the forum
__________________
best regards pblasiak |
|
September 21, 2018, 09:41 |
|
#19 | |
New Member
Ali Amarloo
Join Date: Aug 2018
Posts: 9
Rep Power: 8 |
Quote:
It seems that by "scalar t = this->db().time().value(); " we can access time just for codedFixedvalue Does anybody know how can I access time (of simulation) in "codeStream"? |
||
September 21, 2018, 15:25 |
|
#20 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16 |
change
Code:
fixedValue Code:
codedFixedValue
__________________
best regards pblasiak |
|
Tags |
codestream, openfoam, parafoam |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Difference of the max function result with full field, internalField and boundaryFiel | cyss38 | OpenFOAM Programming & Development | 1 | October 2, 2018 06:39 |
CFD post cannot load results-Error appeared? | mariam.sara | ANSYS | 9 | September 17, 2018 16:23 |
[Workbench] Current result file may not contain requested result data | zhizhuo | ANSYS Meshing & Geometry | 0 | December 13, 2017 05:18 |
Simulation won't show turbulence | pete_87 | OpenFOAM Running, Solving & CFD | 4 | June 25, 2014 12:35 |
Geometry show in Result Display | ShFlow | FLOW-3D | 3 | January 11, 2009 21:51 |