Computational Fluids and OpenFOAM

Source: Internet
Author: User
Tags file info scalar openfoam

From the master's computational mathematics to the current flow of applied mathematics, it is also five years to calculate. Always hope to find a semi-professional software can do computational fluid learning and research.

The so-called semi-professional, is that on the one hand we can be very silly as ansys,fluent, using their model directly to the numerical simulation, on the other hand we can easily modify the model. Build your own model. Write your own algorithm.

So the first time I touched OpenFOAM, she was completely attracted to her. Such a post and my request. More attractive is that she is an open source software that shows us not only CfD, but also a tutorial to write simulation software.

Even we can try to learn how to develop such large-scale numerical computing software.

The following example is from Dr. Su Junwei's Sina Blog, and the Prodigal son of our campus.

A code explanation

Example: Openfoam>>solver>>basic>>laplacianfoam

CreateFields.H

/************************************************/

-Screen tips. Info equivalent to C + + std::cout,info indirect call cout info<< "Reading field t\n" <<Endl This is the initialization of a class. The initialization of the Volscalarfield class T object. -Declares a scalar field, and the grid center stores variables. The field is set by a read-in file (Ioobject and Must_read) and is automatically write based on the settings in Controldict, by write. H Runtime.write () to execute write ();.Volscalarfield T (ioobject ("T",//corresponds to the case root directory T, is the way data is stored runTime.        Timename (),//t directory under the time name, the initial is 0 directory, mesh, Ioobject::must_read, ioobject::auto_write     ), mesh);    -Prompt read-in parameter control file info<< "Reading transportproperties\n" << Endl; -parameter control file declaration over file form read into iodictionary transportproperties (Ioobject ("Transportproperties" ,//File name Runtime.constant (),//File location, case folder in constant subfolder mesh, ioobject::must_read,//through READ a file, initialize IOOBJEC T::no_write//Do not write files according to the time) ); -Read into the diffusion law info<< "Reading diffusivity dt\n" << Endl;//-Initializes a scalar with units by using the query parameter control file, and the "DT" in lookup is the keyword  Dimensionedscalar DT (Transportproperties.lookup ("DT"));        

LAPLACIANFOAM.C (OpenFoam2.4.0)

1 #include "FvCFD.H"//-CFD header file, including most of the required header files for CFD calculations, in Src»finitevolume»cfdtools»general»include
2 #include "SimpleControl.H"
3
4//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
5
6 int main (int argc, char *Argv[])
7{
8 #include "SetRootCase.H"
9
Ten #include "CreateTime.H"
#include "CreateMesh.H"
#include "CreateFields.H"
13
14SimpleControl simple (mesh);
15
16/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
17
info<< "\ncalculating temperature distribution\n" <<Endl
19
While (Simple.loop ())
{
info<< "time =" << runtime.timename () << nl << Endl;
23
(Simple.correctnonorthogonal ())
{
solve
(
FVM::d DT (t)- Fvm::laplacian (DT, T)
);
(+ }
31
#include "write. H
33
info<< "ExecutionTime =" << runtime.elapsedcputime () << "s"
<< "Clocktime =" << runtime.elapsedclocktime () << "s"
<< nl << Endl;
PNS }
38
info<< "end\n" << Endl;
40
return 0;
*





1 #include "FvCFD.H"//-CFD header file, including most CFD calculation required header files, at Src»finitevolume»cfdtools»general»include 2 3 4//* * * * * *Argv[]) 7{8//Set rootcase, according to input parameters argc and argv to 9 # include "SetRootCase.H" 10 11//-creation time, following runtime control # include "CreateTime.H" 1 3 14//create mesh based on grid data in Polymesh folder in constant file, create mesh object in Src»openfoam»include15 # include "CreateMesh.H" 16 17//Create Farm Object, already stated in the previous # include "CreateFields.H" 19 20//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//21//Hint calculation temperature distribution info<< "\ncalculating temperature distribution\n" <<endl;23//Calculate master Control flow for (runtime++;!runtime.end (); runtime++) {26//Prompt for the current calculation time of info<< "times =" << runtime.timename () << nl << Endl; 28//Read into simple algorithm parameters, located in src»finitevolume»cfdtools»general»include31 # include "ReadSIMPLEControls.H" 33// For mesh non-orthogonal loop correction. nonorth<=nnonorthcorr; for (int nonorth=0; nonorth++) + {36//solve Laplace equation, where solve is the global function of foam space, The inner parameter is FVMATRIX,FVM for implicit discretization, returns the finite volume sparse matrix Class Fvmatrix object, the content of the specific object, and later describes the PNS solve38 (fvm::d DT (T)- Fvm::laplacian (dt , T) ; }42//write to solve variable # include "write. H "44//Prompt execution time and CPU time info<<" ExecutionTime = "<< runtime.elapsedcputime () <<" s "Clockti me = "<< runtime.elapsedclocktime () <<" s "endl;48 << nl << }49//Tip program ends in info< < "end\n" << endl;51 return (0);

Write. H

1 if(Runtime.outputtime ()) 2{3 Volvectorfield Gradt = Fvc::grad (T); Calculates the temperature gradient, the vector field 4 5//declares 3 variables, which are initialized in three directions of Gradt respectively. 6 7Volscalarfield GRADTX 8(9IOobject10 (One "GRADTX",//variable name Runtime.timename (),//location of the mesh,//mesh, mainly for object registration, according to the RunTime to write the Ioobject::no_read,//15 Ioobject::auto_write//Auto Write + ), gradt.component (VECTOR::X)//Useful initial session, VECTOR::X enumeration variable, can be directly written 0//gradt.component (0) )  Volscalarfield gradTy21  (on  IOobject23  ("Gradty" , +  runTime. Timename (), +  mesh,27  ioobject::no_read,28  ioobject::auto_write29 ), +  Gradt.component (vector::y) );  Volscalarfield gradTz34  ( IOobject36  (PNS) Gradtz ", $  runtime.timename (), mesh,40  ioobject::no_read,41  ioobject::auto_write42  ),  gradt.component (vector::z) ); 45 46//write to Field  runtime.write ();     
Two C file

We focus on the C file

LAPLACIANFOAM.C (OpenFoam2.4.0)

1 #include "FvCFD.H"//-CFD header file, including most of the required header files for CFD calculations, in Src»finitevolume»cfdtools»general»include
2 #include "SimpleControl.H"
3
4//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
5
6 int main (int argc, char *argv[])
7 {
8 #include "SetRootCase.H"
9
Ten #include "CreateTime.H"
#include "CreateMesh.H"
#include "CreateFields.H"
13
SimpleControl simple (mesh);
15
16/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
17
info<< "\ncalculating temperature distribution\n" << Endl;
19
while (Simple.loop ())
21 {
info<< "time =" << runtime.timename () << nl << Endl;
23
(Simple.correctnonorthogonal ())
25 {
Solve
27 (
FVM::d DT (t)-Fvm::laplacian (DT, T)
29);
30}
31
#include "write. H
33
info<< "ExecutionTime =" << runtime.elapsedcputime () << "s"
<< "Clocktime =" << runtime.elapsedclocktime () << "s"
<< nl << Endl;
37}
38
info<< "end\n" << Endl;
40
return 0;
42}

10-12 rows We set up a grid of fields, that is, we attach vectors to the geometric space and form a field. In other words, we currently have a mathematical description of the temperature field T. At this point, T is not yet anything, it is 0 scalar field.

Computational Fluids and OpenFOAM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.