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

How to modify discrete scheme

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 2, 2010, 05:21
Default How to modify discrete scheme
  #1
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear all,

If I developed a new scheme of Laplacian, may I know how to add the c++ code into openFoam so that I can call it like "fvm::Laplacian()"?

Many thanks!

Crammer008
crammer008 is offline   Reply With Quote

Old   September 2, 2010, 22:33
Default Supplement of the above problem
  #2
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear all,

I'd like to give a simple example to demonstrate my problem.
Assume the new scheme is quite simple.
Based on two nodes (i and j), the scheme is
dF/dx = ( F(i) - F(j) ) / ( x(i) - x(j) )

May I know how to append such a simple sheme to openFoam so that I can call this scheme by "fvm::Laplacian()"?

Many thanks and looking forward to your guidance

Crammer008
crammer008 is offline   Reply With Quote

Old   September 3, 2010, 03:50
Default
  #3
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
I suggest finding the fvm::lapl operator, copying the files, and making the modifications according to your new scheme and changing the name to Laplacian. Not sure if that's all there's to it but that would be a way to start.
akidess is offline   Reply With Quote

Old   September 7, 2010, 23:02
Default How to fine the source file?
  #4
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear Akidess,

Thanks a lot for your guidance Would you please tell me how to find the file related to the detailed description of fvm::lapl? It seems that there are a lot of files including fvm::lapl but all of them are not related to the algorithm level. May I know what kind of file is related to the bottom code?

Many thanks!
Crammer008
crammer008 is offline   Reply With Quote

Old   September 8, 2010, 03:03
Default
  #5
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
I'm guessing it's this: http://foam.sourceforge.net/docs/cpp...cianScheme.php
akidess is offline   Reply With Quote

Old   September 8, 2010, 22:14
Default
  #6
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear Akidess,

Thanks a lot for your guidance
It seems that there are tons of materials. I will read them carefully. Hope to get your further guidance.

Best regards,
Crammer008
crammer008 is offline   Reply With Quote

Old   October 22, 2010, 03:52
Default Is is possible to see code of algorithm?
  #7
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear OpenFoam expert,

As aforesaid, I am trying to find the bottom code related to algorithm. I read almost all the *.H and *.c files related to Laplacian or divScheme from OpenFoam source. However, I found the original point of the Laplacian or divergence operator is limited to member function. For example, disScheme is realized by two functions mesh_ and tinterpScheme_ (look at the code below). If you dig further, you'll never find how these two functions are realized.

May I know whether OpenFoam does not provide the bottom code related to the algorithm realization? For example, OpenFoam just tells you how to use a member function add(a,b) but it never tells you that the add is realized by a+b. Is it the current status of OpenFoam? If so, think OpenFoam is just a blackbox for me.

Looking forward to your guidance

Thanks a lot
Luo Chao

--------------------------------------
00108 //- Construct from mesh
00109 divScheme(const fvMesh& mesh)
00110 :
00111 mesh_(mesh),
00112 tinterpScheme_(new linear<Type>(mesh))
00113 {}
-----------------------------------------------------
crammer008 is offline   Reply With Quote

Old   October 24, 2010, 23:24
Default
  #8
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear OpenFoam expert,

Is there anybody who can help answer the above problem?

Many thanks
crammer008
crammer008 is offline   Reply With Quote

Old   October 25, 2010, 11:44
Default
  #9
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
Quote:
Originally Posted by crammer008 View Post
Dear OpenFoam expert,

As aforesaid, I am trying to find the bottom code related to algorithm. I read almost all the *.H and *.c files related to Laplacian or divScheme from OpenFoam source. However, I found the original point of the Laplacian or divergence operator is limited to member function. For example, disScheme is realized by two functions mesh_ and tinterpScheme_ (look at the code below). If you dig further, you'll never find how these two functions are realized.

May I know whether OpenFoam does not provide the bottom code related to the algorithm realization? For example, OpenFoam just tells you how to use a member function add(a,b) but it never tells you that the add is realized by a+b. Is it the current status of OpenFoam? If so, think OpenFoam is just a blackbox for me.

Looking forward to your guidance

Thanks a lot
Luo Chao

--------------------------------------
00108 //- Construct from mesh
00109 divScheme(const fvMesh& mesh)
00110 :
00111 mesh_(mesh),
00112 tinterpScheme_(new linear<Type>(mesh))
00113 {}
-----------------------------------------------------
Hi &quot;crammer&quot;, the code you are quoting is from the generic &quot;divScheme&quot;, which only provides the interface for the actual divScheme. I think what may be causing you trouble is OpenFOAM's runTimeSelection.

See an article on it here: http://openfoamwiki.net/index.php/Op...tion_mechanism

When it comes to things like schemes, boundary conditions, solvers - anything that varies depending on what the user puts into the case dictionary files - you can't tell by looking at the code what is actually going to be constructed.

Luckily for you, there is only one divScheme and one LaplacianScheme... at least in my version. Look for the subdirectories under src/finiteVolume/finiteVolume/laplacianSchemes and divSchemes. laplacianSchemes has &quot;gaussLaplacianScheme&quot; and divSchemes has &quot;gaussDivScheme&quot;. The source for the algorithms you want are in there.

As for tinterpScheme_, this is also runTimeSelectable, but it seems to be hard-coded to &quot;linear&quot;. mesh_ is a reference to the mesh, which comes from the parameter mesh.
Sometimes you will find other functions that do not appear to be defined in the source code. For instance try to find the definition of exp(scalar)... exp is a standard C++ function, but there is no scalar in standard C++. Many of the primitive functions are defined in macros... so reading the full definition of something like this requires some macro reconstruction. For exp(scalar), it is defined in Scalar.H:

transFunc(exp)

And the definition of this macro is in doubleScalar.H (or floatScalar.H):
Code:
 #define transFunc(func)            \ inline Scalar func(const Scalar s) \ {                                    \     return ::func(s);              \ }
The deeper you go into the source code, the foggier it gets. But really, you shouldn't ever need to go that deep.

To write your own custom laplacianScheme, here's a rough list of what you need to do:

1- Copy the gaussLaplacianScheme folder to a new name customLaplacianScheme
2- Rename all the files in the folder to &quot;customLaplacianScheme&quot;... one file needs to end in 's'. Delete the .dep file.
3- Open each file and do a text search and replace for &quot;gaussLaplacianScheme&quot; with &quot;customLaplacianScheme&quot;
4- In gaussLaplacianScheme.H you'll find a line that says
Code:
     TypeName(&quot;Gauss&quot;)
This is the dictionary name it looks for in fvSchemes. Change it to whatever you want - say &quot;custom&quot;.
5- Edit the custom scheme to whatever you want.
6- Edit the file src/finiteVolume/Make/files
7- Search for &quot;gaussLaplacianScheme&quot;
8- Add a new line for your custom scheme. Remember the &quot;s&quot; on the end.
9- Compile the finiteVolume library (go to src/finiteVolume, and type wmake libso)


Good luck!
marupio is offline   Reply With Quote

Old   October 28, 2010, 01:47
Default Is OpenFoam a completely open source?
  #10
New Member
 
crammer008
Join Date: Apr 2009
Posts: 9
Rep Power: 17
crammer008 is on a distinguished road
Dear Marupio,

Thanks a lot for your great guidance Under your statement, I begin to realize that OpenFoam may not be a completely open source. I have the following statement about your reply. Hope to get your further guidance

Many thanks
Crammer008

Quote:
Originally Posted by marupio View Post
Hi &quot;crammer&quot;, the code you are quoting is from the generic &quot;divScheme&quot;, which only provides the interface for the actual divScheme. I think what may be causing you trouble is OpenFOAM's runTimeSelection.

See an article on it here: http://openfoamwiki.net/index.php/Op...tion_mechanism

When it comes to things like schemes, boundary conditions, solvers - anything that varies depending on what the user puts into the case dictionary files - you can't tell by looking at the code what is actually going to be constructed.
a). I guess it means that OpenFoam just publish the high-level code but hide the actual code of data operation.

The deeper you go into the source code, the foggier it gets. But really, you shouldn't ever need to go that deep.
b). As a common user who just wants to use OpenFoam as a tool, yes, there is no need to explore the source code so deep. However, as a researcher who wants to improve algorithm and compare it with the existing code, he hopes the data and relevant numerical operations are transparent to him. I think this is the original aim of open source.

To write your own custom laplacianScheme, here's a rough list of what you need to do:

1- Copy the gaussLaplacianScheme folder to a new name customLaplacianScheme
2- Rename all the files in the folder to &quot;customLaplacianScheme&quot;... one file needs to end in 's'. Delete the .dep file.
3- Open each file and do a text search and replace for &quot;gaussLaplacianScheme&quot; with &quot;customLaplacianScheme&quot;
4- In gaussLaplacianScheme.H you'll find a line that says
Code:
     TypeName(&quot;Gauss&quot;)
This is the dictionary name it looks for in fvSchemes. Change it to whatever you want - say &quot;custom&quot;.
5- Edit the custom scheme to whatever you want.
6- Edit the file src/finiteVolume/Make/files
7- Search for &quot;gaussLaplacianScheme&quot;
8- Add a new line for your custom scheme. Remember the &quot;s&quot; on the end.
9- Compile the finiteVolume library (go to src/finiteVolume, and type wmake libso)

c). Dear Marupio:
Thanks a lot for your guidance on how to modify the existed Scheme. This modification is just related to high-level code. In the file gaussLaplacianScheme.H, I can not find the source data to be manufactured. I can not even find any variable which is to be returned in the function. Since the input data, manufactured data and returned data are concealed, is there anything we can do to develop and improve the existing code?



Good luck!
crammer008 is offline   Reply With Quote

Old   October 28, 2010, 12:25
Default
  #11
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
Quote:
Originally Posted by crammer008 View Post
a). I guess it means that OpenFoam just publish the high-level code but hide the actual code of data operation.
No, all of the source code is available. When I said you can't tell what will be loaded, that is because the specific derived class to be constructed depends on what you put in the files in your case directory. For instance, you can't tell what specific function fvm::ddt() will be calling until you look at your fvSchemes in system. If you specified:
Code:
ddtSchemes
{
    default     Euler;
}
Then fvm::ddt() will call EulerDdtScheme<Type>::fvmDdt(). specified:
Code:
ddtSchemes
{
    default     backward;
}
Then fvm::ddt() will call backwardDdtScheme<Type>::fvmDdt().

Quote:
Originally Posted by crammer008 View Post
b). As a common user who just wants to use OpenFoam as a tool, yes, there is no need to explore the source code so deep. However, as a researcher who wants to improve algorithm and compare it with the existing code, he hopes the data and relevant numerical operations are transparent to him. I think this is the original aim of open source.
The macros are a useful short hand. Without them the code would get quite bloated. If you must understand what they do, you can reassemble them. It's often unnecessary. It is fairly obvious that scalar += scalar exists, and what it does... no need to look for it.

Quote:
Originally Posted by crammer008 View Post
c). Dear Marupio:
Thanks a lot for your guidance on how to modify the existed Scheme. This modification is just related to high-level code. In the file gaussLaplacianScheme.H, I can not find the source data to be manufactured. I can not even find any variable which is to be returned in the function. Since the input data, manufactured data and returned data are concealed, is there anything we can do to develop and improve the existing code?
gaussLaplacian? Let's see... the code is located in gaussLaplacianScheme.C. fvmLaplacianUncorrected performs the Laplacian itself, the guts of which is:
Code:
    fvm.upper() = deltaCoeffs.internalField()*gammaMagSf.internalField();
    fvm.negSumDiag();
Remember, the fvm.lower() is not mentioned because it is symmetric, and therefore equal to fvm.upper(). The function gammaSnGradCorr is (I'm guessing) the non-orthogonality correction... and I'm guessing the remaining functions are various dispatches for these first two.

When dealing with implicit calculations, the schemes are all about filling in the coefficients of the discretization matrix. See this article here:

http://openfoamwiki.net/index.php/Op...es_in_OpenFOAM

Good luck!
marupio 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
Implementation of QUICK scheme Romuald Skoda Main CFD Forum 11 November 6, 2017 21:20
AUSM scheme ? Central Scheme boling Main CFD Forum 7 January 7, 2016 02:41
Discrete scheme for VOF method in Large Density Ratio waynezw0618 OpenFOAM Running, Solving & CFD 0 August 11, 2008 09:46
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 11:55
extrapolation in MUSCL scheme Chandra Main CFD Forum 6 February 14, 2007 11:21


All times are GMT -4. The time now is 08:07.