|
[Sponsors] |
Read properties per component from an input file dictionary |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 2, 2013, 10:31 |
|
#21 |
Member
P.A.
Join Date: Mar 2009
Location: Germany
Posts: 83
Rep Power: 17 |
Hi Matvej,
I must apologize, this is all rubbish!!! Please forget this, I have to think over it again! Sorry for wasting your time with this! I will come back to you when I cleared things up. I wish I could somehow delete a posting... Thank you, Cheers, Pascal. |
|
September 3, 2013, 04:07 |
|
#22 |
Member
P.A.
Join Date: Mar 2009
Location: Germany
Posts: 83
Rep Power: 17 |
Hi Matvej,
I thought over my whole approach again and again, and I came to the conclusion, that my posting with the attached flake.tar.gz wasn't as much rubbish as I thought. I thought I mixed up two different ways to handle the data, but in fact the application I attached in my reply is almost what I want. To make things clearer: When we look at the dictionary file: Code:
setFormat raw; lambda 2.0; flakeVelocity (1.9 0 0); sym false; flakeProps ( flakeOne { flakeD 4.5; radii ( 0.1 0.2 0.3 0.4 0.5 ); } flakeTwo { flakeD 4.5; radii ( 0.1 0.2 0.3 0.4 0.5 ); } ); and the list "flakeProps" shall go into a list of dictionaries variable. In my code I declare this list of dictionaries, but I don't do anything with it as I do not know how to get the data into this list using the >>operator. For the main application the code should be something like this: Code:
// All the include stuff remains as it is. IOdictionary flakeProperties ( IOobject ( "flakeDict", runTime.system(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); flake flakes(); flakeProperties.lookupEntryPtr(".*", false, true)->stream() >> flakes; Info << "Flakes: " << flakes << nl; return 0; approach anyway? Of course I could simply pass the IOdictionary to a constructor and handle the loading of the variables in this constructor. But I think it would be more elegant to have the >>operator do all this work. I hope you can help me on this once more! Thanks and best regards, Pascal. |
|
May 27, 2015, 09:48 |
|
#23 |
New Member
Milad MU
Join Date: Feb 2013
Posts: 9
Rep Power: 13 |
Hi,
I am having similar case where I want to change from constant lewis number to using different values for different species. Therefore, I have introduced Lewis number (Le) by using a speciesDict in constant folder for all the species of my case as follow: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 1.6 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "constant"; object speciesDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // species ( H H2 O O2 OH H2O N2 HO2 H2O2 AR ); H { Le Le [0 0 0 0 0 0 0] 0.18; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } H2 { Le Le [0 0 0 0 0 0 0] 0.29; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } O { Le Le [0 0 0 0 0 0 0] 0.70; //assumed D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } O2 { Le Le [0 0 0 0 0 0 0] 1.10; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } OH { Le Le [0 0 0 0 0 0 0] 0.71; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } H2O { Le Le [0 0 0 0 0 0 0] 0.89; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } N2 { Le Le [0 0 0 0 0 0 0] 1.04; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } HO2 { Le Le [0 0 0 0 0 0 0] 1.08; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } H2O2 { Le Le [0 0 0 0 0 0 0] 1.09; D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } AR { Le Le [0 0 0 0 0 0 0] 0.18; //assumed D D [0 2 -1 0 0 0 0] 1e-5; DD DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5); } Code:
IOdictionary speciesDict ( IOobject ( "speciesDict", // dictionary name runTime.constant(), // dict is found in "constant" mesh, // registry for the dict IOobject::MUST_READ, // must exist, otherwise failure IOobject::NO_WRITE // dict is only read by the solver ) ); wordList speciesNames ( speciesDict.lookup("species") ); forAll(speciesNames, i) { word currentSpecie = speciesNames[i]; Info<< "Doing stuff for specie: " << currentSpecie << endl; const dictionary& subDict = speciesDict.subDict(currentSpecie); dimensionedScalar Le_("Le", dimensionSet(0,0,0,0,0,0,0), scalar(0.0)); Info<< "uliuli1: " << endl; dimensionedScalar D_("D", dimensionSet(0,2,-1,0,0,0,0), scalar(0.0)); dimensionedTensor DD_("DD", dimensionSet(0,2,-1,0,0,0,0), tensor(0.0)); Le_ = subDict.lookup("Le"); D_ = subDict.lookup("D"); DD_ = subDict.lookup("DD"); Info<< "Le = " << Le_ << endl; Info<< "D = " << D_ << endl; Info<< "DD = " << DD_ << endl; } Info<< "uliuli2: " << endl; PtrList<dimensionedScalar> Leval(speciesNames.size()); forAll(speciesNames, i) { word specieName = speciesNames[i]; Info<< "uliuli3: " << specieName << endl; const dictionary& subDict2 = speciesDict.subDict(specieName); Info<< "uliuli4: " << endl; Leval.set ( i, new dimensionedScalar(subDict2.lookup("Le")) ); } //end Info<< "list " << Leval << endl; Code:
10 ( Le [0 0 0 0 0 0 0] 0.18 Le [0 0 0 0 0 0 0] 0.29 Le [0 0 0 0 0 0 0] 0.7 Le [0 0 0 0 0 0 0] 1.1 Le [0 0 0 0 0 0 0] 0.71 Le [0 0 0 0 0 0 0] 0.89 Le [0 0 0 0 0 0 0] 1.04 Le [0 0 0 0 0 0 0] 1.08 Le [0 0 0 0 0 0 0] 1.09 Le [0 0 0 0 0 0 0] 0.18 ) 2. How can I use these 10 species Le numbers in the following equation as I want to divide my alphaEff by Le[i] of each specie in the loop. Code:
forAll(Y, i) { if (Y[i].name() != inertSpecie) { volScalarField& Yi = Y[i]; fvScalarMatrix YiEqn ( fvm::ddt(rho, Yi) + mvConvection->fvmDiv(phi, Yi) - fvm::laplacian(turbulence->alphaEff()/Leval[i] ,Yi) == reaction->R(Yi) + fvOptions(rho, Yi) ); Milad |
|
November 1, 2015, 07:34 |
|
#24 | |
Member
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 11 |
Quote:
i wonder how to read the following istream and use the parameters: Code:
// the following code is part of myDict listName 3 // name of this list and its size ( name0 1.0; // a word and a scalar (value) name1 2.0; // NOTE there is a ; name2 3.0; ); // could i use PtrList<...> ... and how:confused: thank you in advance. |
||
November 1, 2015, 08:02 |
|
#25 |
Senior Member
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21 |
Hi,
List and PtrList are used to store objects of the same type, but in your list there are two types - word and scalar So, may be you need to combine List and Tuple2 classes. Then your dictionary will look like: Code:
listName 3 // name of this list and its size ( (name0 1.0) // a word and a scalar (value) (name1 2.0) // NOTE there is a ; (name2 3.0) );
__________________
MDPI Fluids (Q2) special issue for OSS software: https://www.mdpi.com/journal/fluids/..._modelling_OSS GitHub: https://github.com/unicfdlab Linkedin: https://linkedin.com/in/matvey-kraposhin-413869163 RG: https://www.researchgate.net/profile/Matvey_Kraposhin |
|
November 1, 2015, 08:47 |
|
#26 | |
Member
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 11 |
Quote:
but, if the problem is more complicated: Code:
//the following code is part of myIODict variableName [0 -1 1 0 0 0 0] 1.0; // this is the default value 1.0 // below is the zoned value for cellSet or cellZone computing variableNameZoned 3 // name of this list and its size ( cellSetName0 1.5; // for cellSetName0 the value is 1.5 cellSetName1 2.0; // the dimension here is the same as that of the default value cellSetName2 3.0; // for cellSetName2 the value is 3.0 ); the reason why i omit the default dimension in the list is that the list size maybe large and i think this may help reduce error. and also easy to modify the dimension. So in mySolver.C, how could i read and access to the above maybe something like Code:
dimensionedScalar variableName(myIODict.lookup("variableName")); PtrList<dimensionedScalar> pvn(myIODict.lookup("variableNameZoned ")); ....(how to read??) |
||
November 1, 2015, 09:22 |
|
#27 |
Senior Member
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21 |
Hi again, you can't read variables of different types in List, because List can store objects of only similar type.
Also, according to OF format definition List is stored as a set of values, separated by space (' '). And i think that ';' is not allowed inside the List dictionary Why PtrList<Tuple2<word, label> > is not suitable for you?
__________________
MDPI Fluids (Q2) special issue for OSS software: https://www.mdpi.com/journal/fluids/..._modelling_OSS GitHub: https://github.com/unicfdlab Linkedin: https://linkedin.com/in/matvey-kraposhin-413869163 RG: https://www.researchgate.net/profile/Matvey_Kraposhin |
|
November 1, 2015, 10:43 |
|
#28 | |
Member
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 11 |
Quote:
Code:
variableName = unknownType.lookup("cellSetName0"); thanks again for your hints. |
||
November 1, 2015, 13:48 |
|
#29 |
Senior Member
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21 |
If you want to load data, separated by ';', you can use subdictionaries
For example, if you have data like this: Code:
variableNameZoned { name0 value0; name1 value1; name2 value2; //and so on } Code:
List<word> names = dict.subDict("variableNameZoned").toc(); List<scalar> values(names.size()); forAll(names, iName) { values[iName] = readScalar(dict.subDict("variableNameZoned").lookup(names[iName])); }
__________________
MDPI Fluids (Q2) special issue for OSS software: https://www.mdpi.com/journal/fluids/..._modelling_OSS GitHub: https://github.com/unicfdlab Linkedin: https://linkedin.com/in/matvey-kraposhin-413869163 RG: https://www.researchgate.net/profile/Matvey_Kraposhin |
|
November 1, 2015, 22:41 |
|
#30 |
Member
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 11 |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
1.7.x Environment Variables on Linux 10.04 | rasma | OpenFOAM Installation | 9 | July 30, 2010 05:43 |
Installation of OpenFOAM-1.6 on Ubuntu 9.10 | marval | OpenFOAM Installation | 2 | March 17, 2010 09:33 |
[OpenFOAM] ParaView 33 canbt open OpenFoam file | hariya03 | ParaView | 7 | September 25, 2008 18:33 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 02:24 |
Results saving in CFD | hawk | Main CFD Forum | 16 | July 21, 2005 21:51 |