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

How to modify fvScheme automatically inside the code?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 27, 2011, 10:44
Default How to modify fvScheme automatically inside the code?
  #1
Member
 
matteo lombardi
Join Date: Apr 2009
Posts: 67
Rep Power: 17
matteoL is on a distinguished road
Hello,
I would like to be able to modify my code so that after N iterations it switches automatically from a certain fvScheme (for example a first order schemes for the div term) to another ( for example to a second order scheme).

So Inside my code I would like to able to do something like this:

if (runTime.time().value()> 10)
{
mesh.fvScheme().divSchemes_="Gauss linear"
}

or something similar.. (this obviously doesn't work..divSchemes_ is private and is a dictionary...)

Any Idea on how to do it?

Thanks,
Matteo
matteoL is offline   Reply With Quote

Old   July 27, 2011, 18:56
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
Quick and dirty:
Code:
dictionary divSchemeDict;
if (runTime.time().value() > 10)
{
    divSchemeDict.set("myDivScheme", "Gauss linear");
}
else
{
    divSchemeDict.set("myDivScheme", mesh.fvScheme().divScheme("lookupName"));
    // lookupName is what you lookup in your fvSchemes dictionary file for the
    // default before runTime > 10 scheme
}
tmp<fv::divScheme<scalar /*or vector? */ > myDivScheme
(
    fv::divScheme<scalar /* or vector */ >::New
    (
        mesh,
        divSchemeDict.lookup("myDivScheme")
    )
);

// Then in your fvScalarMatrix:
fvScalarMatrix myEqn
(
    //all kinds of fancy equation terms, plus:
  + myDivScheme->fvmDiv( /*desired parameters */ )
    // etc...
);
It may have errors... but you get the right idea. If you are using 1.6 official, dictionary.set doesn't work, I don't think. Good luck!
marupio is offline   Reply With Quote

Old   July 27, 2011, 19:31
Default
  #3
Member
 
matteo lombardi
Join Date: Apr 2009
Posts: 67
Rep Power: 17
matteoL is on a distinguished road
Hello David,
thank you very much for you answer, I see what you mean.

At the moment I have actually managed to solve it with en even dirtier trick:
I have written a small code that modify directly the "system/fvSchemes" file and replace the words directly there (the file system/fvSchemes is re-read a the beginning of every time step) and I call it after a certain number of time steps...

Not very elegant but it works...

Your way is actually much cleaner, I will give it a try tomorrow.

Thanks again,
ciao,
Matteo
matteoL 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
own Code vs. commercial code Bernhard Mueck Main CFD Forum 10 February 16, 2000 11:07
State of the art in CFD technology Juan Carlos GARCIA SALAS Main CFD Forum 39 November 1, 1999 15:34
Use of an hydrodynamic model integrated in the vertical by the PHOENICS code Hafsia Zouhaier Main CFD Forum 2 March 15, 1999 09:23
public CFD Code development Heinz Wilkening Main CFD Forum 38 March 5, 1999 12:44
What kind of Cmmercial CFD code you feel well? Lans Main CFD Forum 13 October 27, 1998 11:20


All times are GMT -4. The time now is 17:10.