|
[Sponsors] |
codeStream how to read a dictionary keyword in another file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 13, 2024, 13:53 |
codeStream how to read a dictionary keyword in another file
|
#1 |
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 44
Rep Power: 6 |
Hello foamers,
EDIT: replace "keyword" with "entry" in the title I want to read a scalar from let's say constant/transportProperties.nu and store it into a keyword nu in 0/U. One can achieve that by defining a third dictionary file that contains the keyword nu and its value, and this file is then #included in both transportProperties and 0/U, which is perfectly doable and valid. However, I have problem doing that using codeStream: Code:
/* file: 0/U */ NU #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()); dimensionedScalar nu ( "nu", dimViscosity, d.db().lookupObject<IOdictionary>("transportProperties") ); nu.writeEntry("", os); // or // os << nu.value(); #}; }; // ... Re 44000; L 0.06; // cm U_inlet_x #calc"$Re * $NU / $L"; Code:
/*---------------------------------------------------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2206 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ Build : f1da147925-20220907 OPENFOAM=2206 patch=220907 version=v2206 Arch : "LSB;label=64;scalar=64" Exec : simpleFoam Date : Mar 13 2024 Time : 21:16:27 Host : temple.local PID : 54182 I/O : uncollated Case : /Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase nProcs : 1 trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE). fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20) allowSystemOperations : Allowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Create time Create mesh for time = 0 SIMPLE: no convergence criteria found. Calculations will run for 2000 steps. Reading field p Reading field U Using #codeStream at line 27 in file "0/U" Using #codeStream with "/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib" Could not load "/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib" dlopen(/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib, 0x0009): tried: '/Users/ali/OpenFOAM/ali-v2206/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/OpenFOAM-v2206/site/2206/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/sys-openmpi/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ThirdParty-v2206/platforms/darwin64ClangDPInt64/lib/sys-openmpi/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ThirdParty-v2206/platforms/darwin64ClangDPInt64/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ThirdParty-v2206/platforms/darwin64Clang/fftw-3.3.10/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ThirdParty-v2206/platforms/darwin64Clang/CGAL-4.14.3/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ThirdParty-v2206/platforms/darwin64Clang/boost_1_74_0/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/opt/homebrew/Cellar/open-mpi/5.0.2/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/dummy/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file), '/Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib' (no such file) Creating new library in "dynamicCode/_2204d144ecda5b30bfa6a9010863d5ebdf133b0c/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib" Invoking wmake libso /Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/_2204d144ecda5b30bfa6a9010863d5ebdf133b0c wmake libso /Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/_2204d144ecda5b30bfa6a9010863d5ebdf133b0c ln: ./lnInclude dep: codeStreamTemplate.C Ctoo: codeStreamTemplate.C /Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/0/U.#codeStream:52:27: warning: 'dimensioned' is deprecated: Since 2018-11 [-Wdeprecated-declarations] 52 | dimensionedScalar nu | ^ /Volumes/OpenFOAM/OpenFOAM-v2206/src/OpenFOAM/lnInclude/dimensionedType.H:399:9: note: 'dimensioned' has been explicitly marked deprecated here 399 | FOAM_DEPRECATED(2018-11) | ^ /Volumes/OpenFOAM/OpenFOAM-v2206/src/OpenFOAM/lnInclude/stdFoam.H:45:35: note: expanded from macro 'FOAM_DEPRECATED' 45 | # define FOAM_DEPRECATED(since) [[deprecated("Since " #since)]] | ^ 1 warning generated. link: /Volumes/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/_2204d144ecda5b30bfa6a9010863d5ebdf133b0c/../platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib #0 Foam::error::printStack(Foam::Ostream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #1 Foam::sigSegv::sigHandler(int) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #2 _sigtramp in /usr/lib/system/libsystem_platform.dylib #3 Foam::IOdictionary const& Foam::objectRegistry::lookupObject<Foam::IOdictionary>(Foam::word const&, bool) const in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libfiniteVolume.dylib #4 Foam::IOdictionary const& Foam::objectRegistry::lookupObject<Foam::IOdictionary>(Foam::word const&, bool) const in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libfiniteVolume.dylib #5 codeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c in dynamicCode/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_2204d144ecda5b30bfa6a9010863d5ebdf133b0c.dylib #6 Foam::functionEntries::codeStream::evaluate(Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #7 Foam::functionEntries::codeStream::execute(Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #8 Foam::functionEntry::execute(Foam::word const&, Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #9 Foam::primitiveEntry::expandFunction(Foam::word const&, Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #10 Foam::primitiveEntry::acceptToken(Foam::token const&, Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #11 Foam::primitiveEntry::read(Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #12 Foam::primitiveEntry::readEntry(Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #13 Foam::primitiveEntry::primitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #14 Foam::primitiveEntry::primitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #15 Foam::entry::New(Foam::dictionary&, Foam::Istream&, Foam::entry::inputMode, int) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #16 Foam::dictionary::read(Foam::Istream&, bool) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #17 Foam::dictionary::read(Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #18 Foam::operator>>(Foam::Istream&, Foam::dictionary&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #19 Foam::baseIOdictionary::readData(Foam::Istream&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #20 Foam::fileOperations::uncollatedFileOperation::read(Foam::regIOobject&, bool, Foam::IOstreamOption::streamFormat, Foam::word const&) const in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #21 Foam::regIOobject::readHeaderOk(Foam::IOstreamOption::streamFormat, Foam::word const&) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #22 Foam::localIOdictionary::localIOdictionary(Foam::IOobject const&, Foam::word const&, Foam::dictionary const*) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #23 Foam::localIOdictionary::localIOdictionary(Foam::IOobject const&, Foam::word const&, Foam::dictionary const*) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/lib/libOpenFOAM.dylib #24 Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::readFields() in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/bin/simpleFoam #25 Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::fvMesh const&, bool) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/bin/simpleFoam #26 Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::fvMesh const&, bool) in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/bin/simpleFoam #27 main in /Volumes/OpenFOAM/OpenFOAM-v2206/platforms/darwin64ClangDPInt64Debug/bin/simpleFoam #28 start in /usr/lib/dyld [1] 54182 segmentation fault simpleFoam This seems to be a useful feature to use (i.e. getting access to another dictionary from other files and storing it in the dictionary entry of the same type), but I couldn't find much information online about it. Last edited by reverseila; March 14, 2024 at 13:03. |
|
March 14, 2024, 16:20 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
You are grabbing the IOdictionary from the objectRegistry lookup. I suspect that nobody has yet loaded though. For your particular case, it would probably make more sense to use a regular dictionary #include and have it expand out (automatically) before the codeStream gets thrown at the compiler.
Can't remember offhand if codeStream also supports the dictionary context (codeContext keyword?) for handling this type of thing, but take a look for something like that. |
|
March 15, 2024, 19:52 |
|
#3 | |||
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 44
Rep Power: 6 |
Thank you Mark for your reply.
Quote:
Quote:
Quote:
Code:
NU #codeStream { code #{ const dictionary& d = dict.codeContext(); os << d.getOrDefault<scalar>("myNu", 1e-5); #}; codeContext #{ myNu 1e-5; #} codeInclude #{ #}; codeOptions #{ #}; codeLibs #{ #}; }; Code:
wmake libso /Users/ali/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/dynamicCode/_c720e454df5e4847c8cd4763a2af1e41ff1a4df0 ln: ./lnInclude dep: codeStreamTemplate.C Ctoo: codeStreamTemplate.C /Users/ali/OpenFOAM/ali-v2206/run/incompressible/simpleFoam/backwardFacingStep_baseCase/0/U.#codeStream:45:36: error: no member named 'codeContext' in 'Foam::dictionary' 45 | const dictionary& d = dict.codeContext(); | ~~~~ ^ 1 error generated. make: *** [/Volumes/OpenFOAM/OpenFOAM-v2206/wmake/rules/General/transform:35: Make/darwin64ClangDPInt64Debug/codeStreamTemplate.o] Error 1 --> FOAM FATAL IO ERROR: (openfoam-2206 patch=220907) Failed wmake "dynamicCode/_c720e454df5e4847c8cd4763a2af1e41ff1a4df0/platforms/darwin64ClangDPInt64Debug/lib/libcodeStream_c720e454df5e4847c8cd4763a2af1e41ff1a4df0.dylib" file: 0/U at line 17. From static Foam::functionEntries::codeStream::streamingFunctionType Foam::functionEntries::codeStream::getFunction(const Foam::dictionary &, const Foam::dictionary &) in file db/dictionary/functionEntries/codeStream/codeStream.C at line 192. FOAM exiting |
||||
March 16, 2024, 07:45 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
The "codeContext" belongs to the dynamic code interface and possibly holds reference to a dictionary. A dictionary does not have a codeContext method (not even sure what that would supposed to mean).
You'll have to work at it a bit more... Another idea that looks a bit messier but is actually probably more elegant: in your code section, declare the dimensionedScalar nu as 'static', default initialized. You can then subsequently test it, if it has an empty name it is not properly populated with a value. In this case, use the db().getObjectPtr to lookup the transportProperties IOdictionary. If that returns a non-nullptr, you can use it directly, otherwise you will need to manually load and read the IOdictionary yourself. The IOdictionary::readContents method (not sure when that was added) makes this convenient. From either of these dictionary sources you then finalise the value of nu. Since your nu is marked as static, the content will persist and this entire lookup and/or load will only occur once. |
|
Tags |
codestream |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
SparceImage v1.7.x Issue on MAC OS X | rcarmi | OpenFOAM Installation | 4 | August 14, 2014 07:42 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 | keepfit | ParaView | 60 | September 18, 2013 04:23 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
friction forces icoFoam | ofslcm | OpenFOAM | 3 | April 7, 2012 11:57 |