CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How to modify fvScheme automatically inside the code? (https://www.cfd-online.com/Forums/openfoam-solving/90989-how-modify-fvscheme-automatically-inside-code.html)

matteoL July 27, 2011 09:44

How to modify fvScheme automatically inside the code?
 
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

marupio July 27, 2011 17:56

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!

matteoL July 27, 2011 18:31

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


All times are GMT -4. The time now is 18:55.