|
[Sponsors] |
July 27, 2016, 21:33 |
How to update fvSchemes at run time
|
#1 |
Member
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14 |
Hi guys,
I would like to update the div(phi,U) scheme within one iteration at runtime. I want to calculate the div(phi,U) term using both 1st and 2nd order schemes. I did the following and I managed to change the div scheme from the default "bounded Gauss linear" to "bounded Gauss upwind". Code:
volVectorField div( fvc::div(phi,U) ); Info<<"Initial Div: "<< div[100] <<endl; const objectRegistry& db = mesh.thisDb(); IOdictionary& fvSchemeDict = const_cast<IOdictionary&>(db.lookupObject<IOdictionary>("fvSchemes") ); dictionary& tmp ( fvSchemeDict.subDict("divSchemes")) ; tmp.set("div(phi,U)","bounded Gauss upwind"); volVectorField div1( fvc::div(phi,U) ); Info<<"Modified Div: "<< div1[100] <<endl; Best regards, Jack |
|
July 27, 2016, 21:36 |
|
#2 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
why are you casting IOdictionary when you have it on both sides?
|
|
July 27, 2016, 21:45 |
|
#3 | |
Member
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14 |
Quote:
Thanks very much for your reply! Do u mean this line? Code:
IOdictionary& fvSchemeDict = const_cast<IOdictionary&>( db.lookupObject<IOdictionary>("fvSchemes") ); Code:
Info<<"Modified fvScheme "<<fvSchemeDict<<endl; And the div(phi,U) scheme is indeed changed to "bounded Gauss upwind". It will be great if you can help me to check if I change the fvScheme in a right way. Thanks very much in advance! Best regards, Jack |
||
July 27, 2016, 21:52 |
|
#4 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
Yeah I realized that you wanted the constness to be casted away after I took a closer look. Not sure how div works though. Gotta take a look at the source code.
|
|
July 28, 2016, 00:21 |
|
#5 | ||
Member
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12 |
Quote:
Hi ripperjack, I come up with another way to walk around. Instead of trying to reset the values of the fvSchemes dictionary, try to add another entry in the fvSchemes file. For example, add a new entry as div(phi,U1) bounded Gauss upwind grad(U1) in the divSchemes sub-dictionary. As for why it doesn't work just by resetting is because, in the evaluation of the div operation, it reads the scheme from the divSchemes_ rather than fvSchemes directly. I tracked the source code, it seems that it's pretty hard to reset this divSchemes_. If someone can think of a way to reset this divSchemes_ dictionary, please add. Quote:
|
|||
July 28, 2016, 00:52 |
|
#6 | ||
Member
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12 |
Quote:
dictionary& Foam::fvSchemes:: divSchemeDic () { return divSchemes_; } or dictionary& Foam::myfvSchemes:: divSchemeDic () //myfvScheme is derived from fvSchemes { return divSchemes_; } Then recompile fvSchemes class. And in the implementation, we then try to reset divSchemes_ dictionary. Quote:
|
|||
July 28, 2016, 09:23 |
|
#7 | |
Member
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14 |
Quote:
Thank you so much for your reply! Your last post is exactly what I need! I will try and let you know how it goes. Thanks, Jack |
||
July 28, 2016, 13:00 |
|
#8 | |
Member
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12 |
Hi jack,
I come up with a even simpler way to work around. We can rename the name of U variable to "U1". And read the scheme for U1 like what I suggested defining another variable before and adding an extra entry for U1 in the fvSchemes file. Therefore, in this case, it's the same variable, but without causing extra memory usage. The only thing that is changed is the name. Quote:
Best regards, Jerry |
||
July 28, 2016, 13:08 |
|
#9 | |
Member
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14 |
Quote:
Cheers, Jack |
||
July 28, 2016, 13:21 |
|
#10 |
Member
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12 |
Hi Jack,
I thought about it for quite long. That's the beauty of O.F. There are always ways to work around. But that's also the downside, sometimes. ^-^. Good luck to you. Best regards, jerry |
|
July 28, 2016, 13:34 |
|
#11 |
Member
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14 |
I totally agree with you. And this is the beauty of this forum as well! There are always nice people like u helping around. I have been stuck for a few days and now it finally works. Thanks again for your help!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Floating point exception error | lpz_michele | OpenFOAM Running, Solving & CFD | 53 | October 19, 2015 02:50 |
Star cd es-ice solver error | ernarasimman | STAR-CD | 2 | September 12, 2014 00:01 |
How to write k and epsilon before the abnormal end | xiuying | OpenFOAM Running, Solving & CFD | 8 | August 27, 2013 15:33 |
plot over time | fferroni | OpenFOAM Post-Processing | 7 | June 8, 2012 07:56 |
Upgraded from Karmic Koala 9.10 to Lucid Lynx10.04.3 | bookie56 | OpenFOAM Installation | 8 | August 13, 2011 04:03 |