CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How to overwrite a value in fvSolutions?

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By Tobi
  • 1 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 11, 2017, 19:25
Default How to overwrite a value in fvSolutions?
  #1
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
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
klausb is offline   Reply With Quote

Old   September 13, 2017, 05:32
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
Tobi is offline   Reply With Quote

Old   September 13, 2017, 10:53
Default
  #3
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 339
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
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.
GerhardHolzinger is offline   Reply With Quote

Old   September 13, 2017, 11:06
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Gerhard 's test application can be found in:

Code:
../OpenFOAM/OpenFOAM-dev/applications/test/fvSolutionCombine
and is actually what I wanted to say with my first statement.

Thanks Gerhard for mentioning that. I totally forgot this folder
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 13, 2017, 18:26
Default
  #5
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
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();
Klaus
klausb is offline   Reply With Quote

Old   September 15, 2017, 12:27
Default
  #6
New Member
 
Huipeng Xiao
Join Date: Sep 2017
Posts: 7
Rep Power: 8
Huipeng Xiao is on a distinguished road
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 .
Huipeng Xiao is offline   Reply With Quote

Old   September 15, 2017, 12:48
Default
  #7
New Member
 
Huipeng Xiao
Join Date: Sep 2017
Posts: 7
Rep Power: 8
Huipeng Xiao is on a distinguished road
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
Huipeng Xiao is offline   Reply With Quote

Old   September 15, 2017, 12:50
Default
  #8
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
Tobi is offline   Reply With Quote

Old   September 15, 2017, 17:07
Default
  #9
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
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();
klausb is offline   Reply With Quote

Old   September 15, 2017, 17:48
Default
  #10
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
You have to include the corresponding header files in order to give the class information to the compiler. Otherwise it will not work.
Huipeng Xiao likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 22, 2017, 16:13
Default
  #11
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
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?
klausb is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 20:59.