|
[Sponsors] |
September 11, 2017, 19:25 |
How to overwrite a value in fvSolutions?
|
#1 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22 |
Hello,
I want to dynamically adjust values in fvSolutions e.g. change minIters based on certain criteria from 1 to 3; I know how to access (read) values but I can't figure out how to overwrite values in fvSolutions. How can that be done? Klaus |
|
September 13, 2017, 05:32 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Do you mean inside the FOAM code? E.g. in the source of a solver? If so, why you do not access directly to the value and manipulate it? The way you like to go can be done by calling a script that is changing the value (but this is a really bad workaround - but possible )
__________________
Keep foaming, Tobias Holzmann |
|
September 13, 2017, 10:53 |
|
#3 |
Senior Member
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 339
Rep Power: 28 |
The test-application Test-fvSolutionCombine demonstrates the manipulation of the contents of fvSolution. This code would make a good starting point for whatever you want to manipulate in fvSolution.
|
|
September 13, 2017, 11:06 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Gerhard 's test application can be found in:
Code:
../OpenFOAM/OpenFOAM-dev/applications/test/fvSolutionCombine Thanks Gerhard for mentioning that. I totally forgot this folder
__________________
Keep foaming, Tobias Holzmann |
|
September 13, 2017, 18:26 |
|
#5 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22 |
Well, that's a separate application, I want to change values at p, U, k level from within a new solver, doing it manually is not very effective, the required adjustments are too frequent at times.
By the way, are p U, k subsubdictionaries? fvSsolution > solvers > p { value_to_be_adjusted_dynamically 10; } I tried this but the declarations are not valid for some reason: Code:
//IO test changing p-minIter value in fvSolutions file // Declare dictionary IOdictionary fvSolution(IOobject("fvSolution",runTime.system(),mesh,IOobject::NO_READ,IOobject::AUTO_WRITE)); // Declare subdictionary dictionary mySubDictUpdate(fvSolution.subDict("p")); // Update some values mySubDictUpdate.set("minIter", 33 ); mySubDictUpdate.set("maxIter", 500 ); // Write updates to dictionary/subdictionary fvSolution.Foam::IOobject::write(); |
|
September 15, 2017, 12:27 |
|
#6 |
New Member
Huipeng Xiao
Join Date: Sep 2017
Posts: 7
Rep Power: 8 |
HI:
I have write a test code for you as blew: IOdictionary solutionDict ( IOobject ( dictName, runTime.system(), runTime, IOobject::MUST_READ_IF_MODIFIED, IOobject::AUTO_WRITE, ) ); dictionary& PisoDict = solutionDict.subDict("PISO"); entry* PisoEntry = PisoDict.lookupEntryPtr("nCorrectors", 0, 1); primitiveEntry* PisoEntryPrim = dynamic_cast<primitiveEntry*>(PisoEntry); label val(9); (*PisoEntryPrim)[0] = val; solutionDict.regIOobject::write(); The code have given a right result . |
|
September 15, 2017, 12:48 |
|
#7 |
New Member
Huipeng Xiao
Join Date: Sep 2017
Posts: 7
Rep Power: 8 |
the best way to know what debug in your code is using a debuger trace your code.
Sent from my Le X620 using CFD Online Forum mobile app |
|
September 15, 2017, 12:50 |
|
#8 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
My suggestion is to manipulate the object directly and not by building a new one. However, both work and it is up to you.
Code:
word sol = "none"; if (for any reason you want to change something for U ) { sol = "U"; } Dictionary& directAccesss = mesh.solverDict(sol); //- And then get access to maxIter or minIter and change it . . .
__________________
Keep foaming, Tobias Holzmann |
|
September 15, 2017, 17:07 |
|
#9 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22 |
Problem is, I keep getting compile errors telling me that many things are not declared in this scope.
Code:
exGMRES.C:124:1: error: ‘IOdictionary’ was not declared in this scope IOdictionary fvSolution(IOobject("fvSolution",runTime.system(),runTime,IOobject::MUST_READ_IF_MODIFIED,IOobject::AUTO_W ^ exGMRES.C:127:31: error: ‘fvSolution’ was not declared in this scope dictionary& mySubDictUpdate = fvSolution.subDict("p"); ^ exGMRES.C:137:1: error: ‘solutionDict’ was not declared in this scope solutionDict.regIOobject::write(); ^ exGMRES.C:137:14: error: ‘regIOobject’ has not been declared solutionDict.regIOobject::write(); |
|
September 15, 2017, 17:48 |
|
#10 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
You have to include the corresponding header files in order to give the class information to the compiler. Otherwise it will not work.
__________________
Keep foaming, Tobias Holzmann |
|
September 22, 2017, 16:13 |
|
#11 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22 |
Hi, I am getting nowhere with this.
I went through pages like this: http://openfoamwiki.net/index.php/In...IOobject_class, looked at applications using the functionality, ... but I can't get any Input/Output functionality to work I still get stuck with missing declarations and incorrect file references in header files all the time so nothing compiles. Is there any complete example in the best case related to a solver? |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Does local boundary condition overwrite the global/domain ones? | powpawell | CFX | 2 | September 5, 2014 04:40 |
fvschemes and fvsolutions in MRFSimpleFoam | renyun0511 | OpenFOAM Running, Solving & CFD | 23 | August 3, 2011 04:07 |
overwrite iteration | bilalmerei | FLUENT | 1 | March 23, 2010 06:32 |
[snappyHexMesh] snappyHexMesh -overwrite flag in 1.5-dev | norman1981 | OpenFOAM Meshing & Mesh Conversion | 3 | January 31, 2010 13:31 |
overwrite temperature field using usrsrc | jess | CFX | 0 | November 13, 2002 02:50 |