This Blog will describe the process of creating a case that solves the rotation of a square with an incompressible solver. The project is already done and the information will be added to the blog in the near future.
The steps that are going to be explained are:
- Creating icoDyMFoam (incompressible dynamic mesh solver) from pimpleDyMFoam. IcoDyMFoam already exists in older versions of OpenFoam, however, it was created since version 1.7.1 does not include it.
- Solving movingCone tutorial with icoDyMFoam.
- Modifying cavity tutorial by: Adding a square obstacle in the middle.
- Solving the modified cavity case displacing the square.
- Solving the modified cavity case rotating the square.
- Run the application in parallel
If you are interested in some of the topics above, do not hesitate and contact me. As I said, it has already been developed and the information will be posted shortly.
The steps that are going to be explained are:
- Creating icoDyMFoam (incompressible dynamic mesh solver) from pimpleDyMFoam. IcoDyMFoam already exists in older versions of OpenFoam, however, it was created since version 1.7.1 does not include it.
- Solving movingCone tutorial with icoDyMFoam.
- Modifying cavity tutorial by: Adding a square obstacle in the middle.
- Solving the modified cavity case displacing the square.
- Solving the modified cavity case rotating the square.
- Run the application in parallel
If you are interested in some of the topics above, do not hesitate and contact me. As I said, it has already been developed and the information will be posted shortly.
openFoam 1.7.1 IcoDyMFoam CODE
Posted January 26, 2011 at 13:29 by McCarra
This entry is related to the changes needed to apply in icoDyMFoam code to turn it into a dynamic mesh solver. Further entries will determine the changes to the ancillary files ( correctPhi.H, readControls.H ...) which are needed to prepare it for compilation.
The objective is to identify in the code of pimpleDyMFoam what are the lines related to the mesh motion. This code is what should be added to original icoFoam to make it run with dynamic meshes. To do this pimpleDyMFoam is compared to pimpleFoam, since the only difference between them lies on the fact that pimpleDyMFoam deals with dynamic meshes.
Things that pimpleDyMFoam has and pimpleFoam does not (Ln indicates line in original pimpleDyMFoam code):
1.
Ln 38
Which includes the necessary library for dynamic mesh handling.
2.
Ln 47
Since we have another type of mesh we do not include "createMesh" as pimpleFoam does. Is the same as in Ln 45 in pimpleFoam but for our case (mesh motion).
3.
Ln 63
Since the mesh moves, the flow moves relatively to the mesh. This statement makes the flux absolute for the following part of the code. Is used because at the end of the loop the flux is made relative (discussed later).
4.
Ln 71.
If the mesh is moving we have a different geometry. The solver updates the geometry every time step before going to the pimple loop.
5.
Ln 73 to 76
In case the mesh is moving the mass flux is corrected according to it.
6.
Ln 79
Fluxes are made relative.
7.
Ln 81 to 84
Calculate Courant number taking into account the change in geometry. This calculation is already made in line 60, but has to be corrected in case there is mesh motion.
8.
Ln 106
And
Ln 108
The flux is made relative before adjusting the fluxes to obey continuity and made absolute just after that.
9.
Ln 148
Make the fluxes relative before correcting U.
This lines of code should be added to icoFoam, but where? Well, if we have a look at the structure of icoFoam is very similar to that of pimpleDyMFoam, but instead of using PIMPLE (PISO & SIMPLE) uses just PISO. Therefore, comparing the code of icoFoam and pimpleDyMFoam the location of the lines to add is easy to deduce.
The resulting icoDyMFoam is similar to icoFoam except for these new lines of code. IcoDyMFoam is included below and the code added is in bold.
It must be noted that the solver is not ready to compile yet. As it is mentioned at the beginning of this text, the secondary files that are included in the code have to be modified as well. Fortunately the changes are few and easy and will be detailed in the following entry.
The objective is to identify in the code of pimpleDyMFoam what are the lines related to the mesh motion. This code is what should be added to original icoFoam to make it run with dynamic meshes. To do this pimpleDyMFoam is compared to pimpleFoam, since the only difference between them lies on the fact that pimpleDyMFoam deals with dynamic meshes.
Things that pimpleDyMFoam has and pimpleFoam does not (Ln indicates line in original pimpleDyMFoam code):
1.
Code:
#include "dynamicFvMesh.H"
Which includes the necessary library for dynamic mesh handling.
2.
Code:
#include "createDynamicFvMesh.H"
Since we have another type of mesh we do not include "createMesh" as pimpleFoam does. Is the same as in Ln 45 in pimpleFoam but for our case (mesh motion).
3.
Code:
fvc::makeAbsolute(phi, U);
Since the mesh moves, the flow moves relatively to the mesh. This statement makes the flux absolute for the following part of the code. Is used because at the end of the loop the flux is made relative (discussed later).
4.
Code:
mesh.update();
If the mesh is moving we have a different geometry. The solver updates the geometry every time step before going to the pimple loop.
5.
Code:
if (mesh.changing() && correctPhi) { #include "correctPhi.H" }
Ln 73 to 76
In case the mesh is moving the mass flux is corrected according to it.
6.
Code:
fvc::makeRelative(phi, U);
Fluxes are made relative.
7.
Code:
if (mesh.changing() && checkMeshCourantNo) { #include "meshCourantNo.H" }
Calculate Courant number taking into account the change in geometry. This calculation is already made in line 60, but has to be corrected in case there is mesh motion.
8.
Code:
fvc::makeRelative(phi, U);
And
Code:
fvc::makeAbsolute(phi, U);
The flux is made relative before adjusting the fluxes to obey continuity and made absolute just after that.
9.
Code:
fvc::makeRelative(phi, U);
Make the fluxes relative before correcting U.
This lines of code should be added to icoFoam, but where? Well, if we have a look at the structure of icoFoam is very similar to that of pimpleDyMFoam, but instead of using PIMPLE (PISO & SIMPLE) uses just PISO. Therefore, comparing the code of icoFoam and pimpleDyMFoam the location of the lines to add is easy to deduce.
The resulting icoDyMFoam is similar to icoFoam except for these new lines of code. IcoDyMFoam is included below and the code added is in bold.
Code:
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Application icoDyMFoam Description Transient solver for incompressible, laminar flow of Newtonian fluids including mesh motion \*---------------------------------------------------------------------------*/ #include "fvCFD.H" #include "dynamicFvMesh.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" #include "createFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop with fascinating new icoDyMFoam\n" << endl; while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << nl << endl; #include "readControls.H" #include "CourantNo.H" fvc::makeAbsolute(phi, U); // Do any mesh changes mesh.update(); if (mesh.changing() && correctPhi) { #include "correctPhi.H" } // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); if (mesh.changing() && checkMeshCourantNo) { #include "meshCourantNo.H" } fvVectorMatrix UEqn ( fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U) ); solve(UEqn == -fvc::grad(p)); // --- PISO loop for (int corr=0; corr<nCorr; corr++) { rAU = 1.0/UEqn.A(); U = rAU*UEqn.H(); phi = (fvc::interpolate(U) & mesh.Sf()) + fvc::ddtPhiCorr(rAU, U, phi); fvc::makeRelative(phi, U); adjustPhi(phi, U, p); fvc::makeAbsolute(phi, U); for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { fvScalarMatrix pEqn ( fvm::laplacian(rAU, p) == fvc::div(phi) ); pEqn.setReference(pRefCell, pRefValue); pEqn.solve(); if (nonOrth == nNonOrthCorr) { phi -= pEqn.flux(); } } #include "continuityErrs.H" // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); U -= rAU*fvc::grad(p); U.correctBoundaryConditions(); } runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return 0; } // ************************************************************************* //
Total Comments 7
Comments
-
Greetings McCarra,
Uhm, icoDyMFoam was integrated into pimpleDyMFoam: OpenFOAM 1.6 missing some solvers
But nonetheless, this is a very good tutorial for learning the inner workings of OpenFOAM Very good work!
When you manage to complete it, it would be great if it was also posted at openfoamwiki.net!
Best regards,
BrunoPosted February 5, 2011 at 14:38 by wyldckat -
Hello Bruno!
I didn't know that icoDyMFoam was in pimpleDyMFoam since the restructuring of release 1.6. If I wanted to obtain the same results as in icoDyMFoam, what should I do? What I understood is that old icoDyMFoam is included in pimpleDyMFoam but there's no solver equivalent to icoDyMFoam then, am I right?
Thanks for your interest and your help!
Good idea to post it on openfoamwiki.net!
RegardsPosted February 6, 2011 at 08:34 by McCarra -
Hi José,
Mmm, I actually thought that the tutorials for pimpleDyMFoam would help making the adaptation between 1.5 and 1.6. I also think it should be as easy as simply stating to use the laminar flow model to achieve the same results, but I could be wrong
Nonetheless, you might want to check out OpenFOAM 1.6-ext, because the -Extend project kept the icoMyDFoam solver when evolving from 1.5-dev to 1.6-ext. You can see the code directly online here: icoMyDFoam git web-browsing
The tutorials for it are also worth seeing, but they very likely will only work with 1.6-ext and not 1.6.x/1.7.x, at least not without some adjustments to fvSolution, if I'm not mistaken.
Best regards,
BrunoPosted February 6, 2011 at 08:54 by wyldckat -
Hi McCarra, i hope that you are well
i added the lines mentioned above to the solver, but when i wanna compile it with wmake this error apears:
'correctPhi' was not declared in this scope
how to solve this problem?
tanx
____________
RasoulPosted August 2, 2011 at 05:57 by desert_1250 -
Rasoul,
if I'm not mistaken, you should include a file called correctPhi.H in the folder where you have the solver. Try copying it from the folder of the existing pimpleDyMFoam, pimpleFoam or icoFoam, I think one of them has it.
Good luck,
McPosted August 3, 2011 at 02:14 by McCarra -
Tanx Mc
i wanna to add dynamic mesh into viscoelasticFluidFoam solver. my solver didnt include correctPhi.H so i copy it from the existing icoDyMFoam solver. but the error mentioned in the last post, still apeared
would you send me your mail that i send my solver to you.
mail: rasoul_varedi@yahoo.com
tnx
__________
RasoulPosted August 3, 2011 at 04:29 by desert_1250 -
Dynamic Mesh for twoLiquidMixingFoam
Hi,
I am unable to compile twoLiquidMixingFoam with dynamic mesh.
I am using openFOAM V6. I would appreciate it if I get any assistance.
Please let me know if you want to hear about the details.Posted March 18, 2020 at 15:53 by Bodo1993