Anit Scratch App
Anit Scratch App
1. $> cd $WM_PROJECT_USER_DIR/run
• The utility foamNewApp, will create the directory structure and all the files needed to
create the new application from scratch. The name of the application is
scratchFoam.
• If you want to get more information on how to use foamNewApp, type in the terminal,
30
31 #include "fvCFD.H“
• Now open the file with your favorite editor, and start to add the following information,
1. $> wmake
• If everything went fine, you should have a working solver named scratchFoam.
• If you are feeling lazy or you can not fix the compilation errors, you will find the source
code in the directory,
• $PTOFC/101programming/applications/solvers/scratchFoam
$PTOFC/101programming/applications/solvers/scratchFoam/test_case
• At this point, we are all familiar with the convection-diffusion equation and
OpenFOAM®, so you know how to run the case. Do your magic.
Implementing an application from scratch
• Let us now add a little bit more complexity, a non-uniform initialization of the scalar
field T.
• Remember codeStream? Well, we just need to proceed in a similar way.
• As you will see, initializing directly in the source code of the solver is more intrusive
than using codeStream in the input dicitionaries.
• It also requires recompiling the application.
• Add the following statements to the createFields.H file, recompile and run again
the test case.
16
17 forAll(T, i) We add the initialization of T after the its declaration
18 {
19 const scalar x = mesh.C()[i][0];
20 const scalar y = mesh.C()[i][1]; Access cell center coordinates.
21 const scalar z = mesh.C()[i][2]; In this case y and z coordinates are not used.
22
23 if ( 0.3 < x && x < 0.7) Conditional structure
24 {
25 T[i] = 1.;
26 }
27 }
28 T.write(); Write field T. As the file createFields.H is outside the time loop
the value is saved in the time directory 0
Implementing an application from scratch
• Let us compute a few extra fields. We are going to compute the gradient, divergence,
and Laplacian of T.
• We are going to compute these fields in a explicit way, that is, after finding the
solution of T.
• Therefore we are going to use the operator fvc.
• Add the following statements to the source code of the solver (scratchFoam.C),
68 }
69
70 #include "continuityErrs.H"
71 #include "write.H" Add this header file
72 runTime.write();
73 The file is located in the directory
74 } $PTOFC/101programming/applications/solvers/scratchFoam
In this file we declare and define the new variables, take a look at it