BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / test / spline / Test-spline.C
blob9254c2a3fa205579570b2ebf956cb30509c5398b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
25 #include "argList.H"
27 #include "vector.H"
28 #include "IFstream.H"
30 #include "BSpline.H"
31 #include "CatmullRomSpline.H"
33 using namespace Foam;
35 inline Ostream& printPoint(Ostream& os, const point& p)
37     os  << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
38     return os;
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // Main program:
45 int main(int argc, char *argv[])
47     argList::noParallel();
48     argList::validArgs.insert("file .. fileN");
49     argList::addBoolOption("B", "B-Spline implementation");
50     argList::addBoolOption("CMR", "catmull-rom spline (default)");
51     argList::addOption
52     (
53         "n",
54         "INT",
55         "number of segments for evaluation - default 20"
56     );
58     argList args(argc, argv, false, true);
60     if (args.size() <= 1)
61     {
62         args.printUsage();
63     }
65     bool useBSpline = args.optionFound("B");
66     bool useCatmullRom = args.optionFound("CMR");
67     label nSeg = args.optionLookupOrDefault<label>("n", 20);
69     if (!useCatmullRom && !useBSpline)
70     {
71         Info<<"defaulting to Catmull-Rom spline" << endl;
72         useCatmullRom = true;
73     }
75     for (label argI=1; argI < args.size(); ++argI)
76     {
77         const string& srcFile = args[argI];
78         Info<< nl << "reading " << srcFile << nl;
79         IFstream ifs(srcFile);
81         List<pointField> pointFields(ifs);
84         forAll(pointFields, splineI)
85         {
86             Info<<"\n# points:" << endl;
87             forAll(pointFields[splineI], ptI)
88             {
89                 printPoint(Info, pointFields[splineI][ptI]);
90             }
92             if (useBSpline)
93             {
94                 BSpline spl(pointFields[splineI]);
96                 Info<< nl << "# B-Spline" << endl;
98                 for (label segI = 0; segI <= nSeg; ++segI)
99                 {
100                     scalar lambda = scalar(segI)/scalar(nSeg);
101                     printPoint(Info, spl.position(lambda));
102                 }
103             }
105             if (useCatmullRom)
106             {
107                 CatmullRomSpline spl(pointFields[splineI]);
109                 Info<< nl <<"# Catmull-Rom" << endl;
111                 for (label segI = 0; segI <= nSeg; ++segI)
112                 {
113                     scalar lambda = scalar(segI)/scalar(nSeg);
114                     printPoint(Info, spl.position(lambda));
115                 }
116             }
118             {
119                 polyLine pl(pointFields[splineI]);
121                 Info<< nl <<"# polyList" << endl;
123                 for (label segI = 0; segI <= nSeg; ++segI)
124                 {
125                     scalar lambda = scalar(segI)/scalar(nSeg);
126                     printPoint(Info, pl.position(lambda));
127                 }
128             }
129         }
130     }
132     return 0;
136 // ************************************************************************* //