Skip to content

Commit 1c79fdd

Browse files
authored
Merge pull request UnnamedMoose#8 from UnnamedMoose/OF5
OpenFOAM 5.x compatibility resolved
2 parents 1156ad2 + 295f203 commit 1c79fdd

File tree

177 files changed

+638
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+638
-282
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ doc/Doxygen/DTAGS
7979
/.cproject
8080
/.project
8181
/.dir-locals.el
82+
/.dropbox
8283

8384
# Ignore the test directory
8485
/tutorialsTest

OFtutorial1_inputOutput/OFtutorial1.C renamed to OFtutorial01_inputOutput/OFtutorial1.C

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
4949
);
5050

5151
// Check the if the dictionary is present and follows the OF format
52-
if (!dictIO.headerOk())
52+
if (!dictIO.typeHeaderOk<dictionary>(true))
5353
FatalErrorIn(args.executable()) << "Cannot open specified refinement dictionary "
5454
<< dictName << exit(FatalError);
5555

@@ -106,6 +106,9 @@ int main(int argc, char *argv[])
106106
outputFilePtr() << "# This is a header" << endl;
107107
outputFilePtr() << "0 1 2 3 4 5" << endl;
108108

109+
// Append to the imported hash table and wirte it too
110+
someHashTable.insert("newKey", vector(1., 0., 0.));
111+
outputFilePtr() << someHashTable << endl;
109112

110113
Info<< "End\n" << endl;
111114
return 0;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*---------------------------------------------------------------------------*\
2+
========= |
3+
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4+
\\ / O peration |
5+
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6+
\\/ M anipulation |
7+
-------------------------------------------------------------------------------
8+
License
9+
This file is part of OpenFOAM.
10+
11+
OpenFOAM is free software: you can redistribute it and/or modify it
12+
under the terms of the GNU General Public License as published by
13+
the Free Software Foundation, either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19+
for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23+
24+
\*---------------------------------------------------------------------------*/
25+
26+
#include "fvCFD.H"
27+
28+
int main(int argc, char *argv[])
29+
{
30+
// ===
31+
// Define the help message for this application
32+
argList::addNote
33+
(
34+
"Demonstrates how to handle command line options.\n"
35+
"\n"
36+
"Input arguments:\n"
37+
"----------------\n"
38+
" someWord - does stuff\n"
39+
" someScalar - does more things\n"
40+
);
41+
42+
// prepare argument list
43+
argList::noParallel();
44+
argList::validArgs.append("someWord");
45+
argList::validArgs.append("someScalar");
46+
47+
// prepare options
48+
argList::addOption // string variable
49+
(
50+
"dict",
51+
"word",
52+
"Path to an additional dictionary (not really used now)"
53+
);
54+
55+
argList::addBoolOption // on/off depending on whether option is given or not
56+
(
57+
"someSwitch",
58+
"Switches from A to B"
59+
);
60+
61+
argList::addOption // integer variable
62+
(
63+
"someInt",
64+
"label",
65+
"Optional integer"
66+
);
67+
68+
// ===
69+
// create argument list
70+
// This is normally defined inside setRootCase.H
71+
// #include "setRootCase.H"
72+
Foam::argList args(argc, argv);
73+
if (!args.checkRootCase())
74+
{
75+
Foam::FatalError.exit();
76+
}
77+
78+
// ===
79+
// read arguments
80+
const word someWord = args[1];
81+
// NOTE: the built-in method for converting strings to other data types
82+
const scalar someScalar = args.argRead<scalar>(2);
83+
84+
Info << "Got argument word " << someWord << " and scalar " << someScalar << endl;
85+
86+
// ===
87+
// read options
88+
// default path to some dictionary
89+
fileName dictPath("./system/defaultDict");
90+
91+
// conditional execution based on an option being passed
92+
if (args.optionFound("dict"))
93+
{
94+
args.optionReadIfPresent("dict", dictPath);
95+
Info << "Got an override flag for dictionary path" << endl;
96+
}
97+
Info << "Would read dict from " << dictPath << endl;
98+
99+
// switch option
100+
const bool someConstBool = args.optionFound("someSwitch");
101+
Info << "Boolean switch set to " << someConstBool << endl;
102+
103+
// numeric value option - same as string variables really
104+
label someInt(0);
105+
args.optionReadIfPresent("someInt", someInt);
106+
Info << "Integer option value " << someInt << endl;
107+
108+
Info<< "End\n" << endl;
109+
110+
return 0;
111+
}
112+
113+
114+
// ************************************************************************* //
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
ofTutorial2
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*--------------------------------*- C++ -*----------------------------------*\
2+
| ========= | |
3+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4+
| \\ / O peration | Version: 3.0.1 |
5+
| \\ / A nd | Web: www.OpenFOAM.org |
6+
| \\/ M anipulation | |
7+
\*---------------------------------------------------------------------------*/
8+
FoamFile
9+
{
10+
version 2.0;
11+
format ascii;
12+
class dictionary;
13+
location "system";
14+
object controlDict;
15+
}
16+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
17+
18+
application icoFoam;
19+
20+
startFrom startTime;
21+
22+
startTime 0;
23+
24+
stopAt endTime;
25+
26+
endTime 0.5;
27+
28+
deltaT 0.005;
29+
30+
writeControl timeStep;
31+
32+
writeInterval 20;
33+
34+
purgeWrite 0;
35+
36+
writeFormat ascii;
37+
38+
writePrecision 6;
39+
40+
writeCompression off;
41+
42+
timeFormat general;
43+
44+
timePrecision 6;
45+
46+
runTimeModifiable true;
47+
48+
49+
// ************************************************************************* //
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33
blockMesh > log.blockMesh
4-
ofTutorial2
4+
ofTutorial4
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
customClass.C
2-
derivedClass.C
31
OFtutorial5.C
42

53
EXE = $(FOAM_USER_APPBIN)/ofTutorial5

OFtutorial4_basicParallelComputing/OFtutorial4.C renamed to OFtutorial05_basicParallelComputing/OFtutorial5.C

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ int main(int argc, char *argv[])
6666
// object-oriented programming in OpenFOAM, so we'll skip this for now.
6767

6868
// Spreading a value across all processors is done using a scatter operation.
69-
// The Pstream::blocking makes sure all processors are synchronised at this
70-
// line of the code and thus should use the same value.
71-
Pstream::scatter(meshVolume, Pstream::blocking);
69+
Pstream::scatter(meshVolume);
7270
Pout << "Mesh volume on this processor is now " << meshVolume << endl;
7371

7472
// It is often useful to check the distribution of something across all
75-
// processors. This may be done using a list, with each element of which
73+
// processors. This may be done using a list, with each element of it
7674
// being written to by only one processor.
7775
List<label> nInternalFaces (Pstream::nProcs()), nBoundaries (Pstream::nProcs());
7876
nInternalFaces[Pstream::myProcNo()] = mesh.Cf().size();
@@ -129,10 +127,10 @@ int main(int argc, char *argv[])
129127

130128
// pre-calculate geometric information using field expressions rather than
131129
// cell-by-cell assignment.
132-
const dimensionedVector originVector("x0",dimLength,vector(0.05,0.05,0.005));
133-
scalarField r (mag(mesh.C()-originVector));
134-
// NOTE: we need to get a global value
135-
const scalar rFarCell = returnReduce(max(r), maxOp<scalar>());
130+
const dimensionedVector originVector("x0", dimLength, vector(0.05,0.05,0.005));
131+
volScalarField r (mag(mesh.C()-originVector));
132+
// NOTE: we need to get a global value; convert from dimensionedScalar to scalar
133+
const scalar rFarCell = returnReduce(max(r).value(), maxOp<scalar>());
136134
scalar f (1.);
137135

138136
Info<< "\nStarting time loop\n" << endl;
@@ -141,16 +139,24 @@ int main(int argc, char *argv[])
141139
{
142140
Info<< "Time = " << runTime.timeName() << nl << endl;
143141

144-
// We use .internalField() to assign to the internal values only, thus
145-
// leaving boundary values unchanged. Thus, we assign a scalarField
146-
// object to the internal scalrField inside the volScalarField p.
147-
p.internalField() = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value())
148-
/ (r/rFarCell+1e-12);
142+
// assign values to the field;
143+
// sin function expects a dimensionless argument, hence need to convert
144+
// current time using .value().
145+
// r has dimensions of length, hence the small value being added to it
146+
// needs to match that.
147+
// Finally, the result has to match dimensions of pressure, which are
148+
// m^2 / s^-2/
149+
p = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value())
150+
/ (r/rFarCell + dimensionedScalar("small", dimLength, 1e-12))
151+
* dimensionedScalar("tmp", dimensionSet(0, 3, -2, 0, 0), 1.);
152+
149153
// NOTE: this is needed to update the values on the processor boundaries.
150154
// If this is not done, the gradient operator will get confused around the
151155
// processor patches.
152156
p.correctBoundaryConditions();
153-
U = fvc::grad(p)*dimensionedScalar("tmp",dimTime,1.);
157+
158+
// calculate velocity from gradient of pressure
159+
U = fvc::grad(p)*dimensionedScalar("tmp", dimTime, 1.);
154160
runTime.write();
155161
}
156162

OFtutorial4_basicParallelComputing/testCase/Allrun renamed to OFtutorial05_basicParallelComputing/testCase/Allrun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
blockMesh > log.blockMesh
44
decomposePar > log.decomposePar
5-
mpirun -np 4 ofTutorial4 -parallel
5+
mpirun -np 4 ofTutorial5 -parallel
66
rm -r processor* 2>/dev/null
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
customClass.C
2+
derivedClass.C
13
OFtutorial6.C
24

35
EXE = $(FOAM_USER_APPBIN)/ofTutorial6
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OFtutorial7.C
2+
3+
EXE = $(FOAM_USER_APPBIN)/ofTutorial7

OFtutorial6_customLibraries/OFtutorial6.C renamed to OFtutorial07_customLibraries/OFtutorial7.C

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,38 @@ int main(int argc, char *argv[])
4040
#include "createMesh.H"
4141
#include "createFields.H"
4242

43-
const dimensionedVector originVector("x0",dimLength,vector(0.05,0.05,0.005));
44-
scalarField r;
45-
// NOTE: use the method implemented in the library to calculate r and rFarCell
46-
const scalar rFarCell = computeR(mesh,r,originVector);
43+
const dimensionedVector originVector("x0", dimLength, vector(0.05, 0.05, 0.005));
4744
scalar f (1.);
45+
// NOTE: initialise the radius field with zero values and dimensions
46+
volScalarField r
47+
(
48+
IOobject
49+
(
50+
"r",
51+
runTime.timeName(),
52+
mesh,
53+
IOobject::NO_READ,
54+
IOobject::NO_WRITE
55+
),
56+
mesh,
57+
dimensionedScalar("r0", dimLength, 0.)
58+
);
59+
// NOTE: use the method implemented in the library to calculate r and rFarCell
60+
const scalar rFarCell = computeR(mesh, r, originVector);
4861

4962
Info<< "\nStarting time loop\n" << endl;
5063

5164
while (runTime.loop())
5265
{
5366
Info<< "Time = " << runTime.timeName() << nl << endl;
5467

55-
p.internalField() = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value())
56-
/ (r/rFarCell+1e-12);
68+
p = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value())
69+
/ (r/rFarCell + dimensionedScalar("small", dimLength, 1e-12))
70+
* dimensionedScalar("tmp", dimensionSet(0, 3, -2, 0, 0), 1.);
5771
p.correctBoundaryConditions();
5872

5973
// NOTE: call the library method to calculate U
60-
computeU(mesh,U);
74+
computeU(mesh, U);
6175

6276
runTime.write();
6377
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EXE_INC = \
2+
-I$(LIB_SRC)/finiteVolume/lnInclude \
3+
-I$(LIB_SRC)/meshTools/lnInclude
4+
5+
EXE_LIBS = \
6+
-lfiniteVolume \
7+
-lmeshTools
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "customLibrary.H"
22

3-
scalar computeR(const fvMesh& mesh, scalarField& r, dimensionedVector x0)
3+
scalar computeR(const fvMesh& mesh, volScalarField& r, dimensionedVector x0)
44
{
55
r = mag(mesh.C()-x0);
6-
return returnReduce(max(r), maxOp<scalar>());
6+
return returnReduce(max(r).value(), maxOp<scalar>());
77
}
88

99
void computeU(const fvMesh& mesh, volVectorField& U, word pName)
@@ -13,5 +13,5 @@ void computeU(const fvMesh& mesh, volVectorField& U, word pName)
1313
const volScalarField& pField = mesh.lookupObject<volScalarField>(pName);
1414

1515
// Do the usual
16-
U = fvc::grad(pField)*dimensionedScalar("tmp",dimTime,1.);
16+
U = fvc::grad(pField)*dimensionedScalar("tmp", dimTime, 1.);
1717
}

OFtutorial6_customLibraries/customLibrary/customLibrary.H renamed to OFtutorial07_customLibraries/customLibrary/customLibrary.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "fvCFD.H"
22

33
// This method simply implements the calculation of the distance of each
4-
// cell centre from x0; it accepts the scalarField r as a reference to avoid
4+
// cell centre from x0; it accepts the volScalarField r as a reference to avoid
55
// passing large amounts of information by value, as this is expensive.
66
// It returns the maximum value found.
7-
scalar computeR(const fvMesh& mesh, scalarField& r, dimensionedVector x0);
7+
scalar computeR(const fvMesh& mesh, volScalarField& r, dimensionedVector x0);
88

99
// This computes the velocity field. The reference to the pressure is obtained
1010
// through the mesh object, using the name of the p field only. This assmes a

0 commit comments

Comments
 (0)