Commit 55e5a777 authored by shunbo's avatar shunbo
Browse files

initial commit

parents
Test-coordinateSystem.C
EXE = $(FOAM_USER_APPBIN)/Test-coordinateSystem
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
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
Test-coordinateSystem
Description
Expand coordinate system definitions
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "coordinateSystems.H"
#include "identityRotation.H"
#include "cartesianCS.H"
#include "indirectCS.H"
#include "Fstream.H"
#include "IOstreams.H"
#include "transform.H"
using namespace Foam;
template<class T>
void testTransform(const coordinateSystem& cs, const point& p, const T& val)
{
Info<< " " << pTraits<T>::typeName << ": " << val
<< " transform: " << cs.transform(p, val)
<< " invTransform: " << cs.invTransform(p, val) << nl;
// Info<< " both: " << cs.invTransform(p, cs.transform(p, val)) << nl;
}
void basicTests(const coordinateSystem& cs)
{
cs.writeEntry(cs.name(), Info);
if (const auto* cartptr = isA<coordSystem::cartesian>(cs))
{
if (!cartptr->active())
{
Info<< "inactive cartesian = " << (*cartptr)
<< " with: " << (*cartptr).R() << nl;
}
}
Info<< "rotation: " << cs.R() << nl;
List<point> testPoints
({
{1,0,0}, {0,1,0}, {0,0,1}, {1,1,1},
});
for (const point& p : testPoints)
{
Info<< nl
<< " test point: " << p
<< " = local point " << cs.transformPoint(p)
<< " = local coord " << cs.localPosition(p) << nl;
const vector v1(1, 1, 1);
const tensor t1(tensor::I);
const tensor t2(1, 2, 3, 4, 5, 6, 7, 8, 9);
testTransform(cs, p, v1);
testTransform(cs, p, t1);
testTransform(cs, p, t2);
}
Info<< nl;
}
void doTest(const dictionary& dict)
{
Info<< dict.dictName() << dict << nl;
// Could fail?
const bool oldThrowingError = FatalError.throwing(true);
const bool oldThrowingIOErr = FatalIOError.throwing(true);
try
{
auto cs1ptr = coordinateSystem::New(dict, "");
coordinateSystem& cs1 = *cs1ptr;
cs1.rename(dict.dictName());
basicTests(cs1);
}
catch (const Foam::IOerror& err)
{
Info<< "Caught FatalIOError " << err << nl << endl;
}
catch (const Foam::error& err)
{
Info<< "Caught FatalError " << err << nl << endl;
}
FatalError.throwing(oldThrowingError);
FatalIOError.throwing(oldThrowingIOErr);
}
void doTest(const objectRegistry& obr, const dictionary& dict)
{
Info<< dict.dictName() << dict << nl;
// Could fail?
const bool oldThrowingError = FatalError.throwing(true);
const bool oldThrowingIOErr = FatalIOError.throwing(true);
try
{
auto cs1ptr = coordinateSystem::New(obr, dict, word::null);
coordinateSystem& cs1 = *cs1ptr;
basicTests(cs1);
}
catch (const Foam::IOerror& err)
{
Info<< "Caught FatalIOError " << err << nl << endl;
}
catch (const Foam::error& err)
{
Info<< "Caught FatalError " << err << nl << endl;
}
FatalError.throwing(oldThrowingError);
FatalIOError.throwing(oldThrowingIOErr);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addArgument("dict .. dictN");
argList args(argc, argv, false, true);
if (args.found("case"))
{
Info<<"using case for tests" << nl;
#include "createTime.H"
const coordinateSystems& systems = coordinateSystems::New(runTime);
Info<< systems.size() << " global systems" << nl;
for (const coordinateSystem& cs : systems)
{
basicTests(cs);
}
// systems.write();
for (label argi=1; argi < args.size(); ++argi)
{
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary inputDict(is);
for (const entry& dEntry : inputDict)
{
if (dEntry.isDict())
{
doTest(runTime, dEntry.dict());
}
}
}
}
else if (args.size() <= 1)
{
Info<<"no coordinateSystem dictionaries to expand" << nl;
}
else
{
for (label argi=1; argi < args.size(); ++argi)
{
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary inputDict(is);
for (const entry& dEntry : inputDict)
{
if (dEntry.isDict())
{
doTest(dEntry.dict());
}
}
}
}
return 0;
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class IOPtrList<coordinateSystem>; //<-- Older name
object coordinateSystems;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
(
cs1
{
type cartesian;
origin (1 2 3);
coordinateRotation
{
type axes;
e1 (0 0 1);
e2 (0 1 0);
}
}
)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application simpleFoam;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 4;
deltaT 1;
writeControl timeStep;
writeInterval 100;
purgeWrite 0;
writeFormat binary;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
//OLD class IOPtrList<coordinateSystem>;
class coordinateSystems;
object coordinateSystems;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
(
cs1
{
type cartesian;
origin (1 2 3);
rotation
{
type axes;
e1 (0 0 1);
e2 (0 1 0);
}
}
cs2
{
type cartesian;
origin (0 3 5);
e1 (1 2 0);
e2 (2 0 2);
}
cs3
{
type cartesian;
origin (0 3 5);
coordinateRotation // older name
{
type euler;
angles (90 0 0);
}
}
cs4
{
type cylindrical;
origin (0 3 5);
rotation
{
type euler;
angles (90 0 0);
}
}
cyl
{
type cylindrical;
origin (0 0 0);
degrees false;
rotation
{
type axisAngle;
axis (0 0 1);
angle 90;
}
}
ident
{
origin (0 0 0);
rotation
{
type none;
}
}
)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application simpleFoam;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 4;
deltaT 1;
writeControl timeStep;
writeInterval 100;
purgeWrite 0;
writeFormat binary;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testCsys1;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Rotate 90 deg around x: y -> z, z -> -y
rot_x90
{
origin (0 0 0);
e1 (1 0 0);
e3 (0 -1 0);
}
rot_x90_axesRotation
{
origin (0 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 0 0);
e3 (0 -1 0);
}
}
rot_x90_axisAngle
{
origin (0 0 0);
coordinateRotation
{
type axisAngle;
axis (1 0 0); // non-unit also OK
angle 90;
}
}
rot_x90_euler
{
origin (0 0 0);
coordinateRotation
{
type euler;
angles (0 90 0); // z-x'-z''
}
}
// Rotate 45 deg around z: x -> (1 1 0), y = (-1 1 0)
rot_z45_axesRotation
{
origin (0 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 1 0);
e3 (0 0 1);
}
}
rot_z45_axisAngle
{
origin (0 0 0);
coordinateRotation
{
type axisAngle;
axis (0 0 10); // non-unit also OK
angle 45;
}
}
rot_z45_euler
{
origin (0 0 0);
coordinateRotation
{
type euler;
angles (45 0 0); // z-x'-z''
}
}
rot_z45_starcd
{
origin (0 0 0);
coordinateRotation
{
type starcd;
angles (45 0 0); // z-x'-y''
}
}
// Rotate -45 deg around z: x -> (1 -1 0), y = (1 1 0)
rot_zm45_axesRotation
{
origin (0 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 -1 0);
e3 (0 0 1);
}
}
rot_zm45_axisAngle
{
origin (0 0 0);
coordinateRotation
{
type axisAngle;
axis (0 0 10); // non-unit also OK
angle -45;
}
}
rot_zm45_euler
{
origin (0 0 0);
coordinateRotation
{
type euler;
angles (-45 0 0); // z-x'-z''
}
}
// Null transforms
null_axesRotation
{
origin (0 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 0 0);
e3 (0 0 1);
}
}
null_axisAngle0
{
origin (0 0 0);
coordinateRotation
{
type axisAngle;
axis (0 0 0); // non-unit also OK
angle 0;
}
}
null_axisAngle1
{
origin (0 0 0);
coordinateRotation
{
type axisAngle;
axis (1 1 1); // non-unit also OK
angle 0;
}
}
null_euler
{
origin (0 0 0);
coordinateRotation
{
type euler;
angles (0 0 0); // z-x'-z''
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testCsys1;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// This dictionary only works in combination with constant/coordinateSystems
mycs1
{
type indirect;
name cs1;
}
mycs2
{
type indirect;
name cs2;
}
mycs3
{
type indirect;
name cs3;
}
mycyl
{
type indirect;
name cyl;
}
mycy2
{
coordinateSystem
{
type indirect;
name cyl;
}
}
mycy3
{
coordinateSystem cyl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Test-copyFile.C
EXE = $(FOAM_USER_APPBIN)/Test-copyFile
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
/* EXE_LIBS = -lfiniteVolume */
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Test atomic copyFile as per timeActivatedFileUpdate
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "OSspecific.H"
#include "Switch.H"
using namespace Foam;
#ifdef _WIN32
#undef DebugInfo // Windows name clash with OpenFOAM messageStream
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
unsigned maxPath = MAX_PATH;
// Prefix "\\?\" for extended-length path and widen
// The prefix is only valid with absolute paths
//
// In the future, this code will be relocated in MSwindows.C
static inline std::wstring longName(const fileName& file)
{
const auto len = file.length();
std::wstring out;
out.reserve(4 + len);
if (len > maxPath)
{
if (file.isAbsolute())
{
out.append(L"\\\\?\\");
}
else
{
Warning
<< "Relative fileName exceeds " << maxPath
<< " characters" << nl
<< " " << file << nl << nl;
}
}
// Character-wise copy to get widening
for (const auto c : file)
{
out += c;
}
return out;
}
bool win_mv(const fileName& src, const fileName& dst)
{
constexpr const int flags
(
MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
| MOVEFILE_WRITE_THROUGH
);
if (src.length() > maxPath || dst.length() > maxPath)
{
const std::wstring srcName(longName(src));
const std::wstring dstName(longName(dst));
Info<< "Windows mv (wide)" << nl;
return ::MoveFileExW(srcName.c_str(), dstName.c_str(), flags);
}
Info<< "Windows mv (ansi)" << nl;
return ::MoveFileExA(src.c_str(), dst.c_str(), flags);
}
#else
bool win_mv(const fileName& src, const fileName& dst)
{
Info<< "No Windows mv, using Foam::mv" << nl;
return Foam::mv(src, dst);
}
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noBanner();
argList::noParallel();
argList::noFunctionObjects();
argList::addNote("Test atomic copyFile methods");
#ifdef _WIN32
argList::addBoolOption("win1", "Foam cp, Windows mv");
argList::addOption("maxPath", "length", "Test with shorter MAX_PATH");
#endif
argList::addArgument("srcFile");
argList::addArgument("dstFile");
#include "setRootCase.H"
#ifdef _WIN32
args.readIfPresent("maxPath", maxPath);
#endif
const auto srcFile = args.get<fileName>(1);
const auto dstFile = args.get<fileName>(2);
const fileName tmpFile(dstFile + Foam::name(pid()));
Info<< "src : " << srcFile << nl
<< "tmp : " << tmpFile << nl
<< "dst : " << dstFile << nl
#ifdef _WIN32
<< "test with max-path: " << maxPath << nl
#endif
<< nl;
bool cpOk = false, mvOk = false;
if (args.found("win1"))
{
const auto usage = argList::optionUsage.cfind("win1");
if (usage.good())
{
Info<< " " << (*usage).c_str() << nl;
}
cpOk = Foam::cp(srcFile, tmpFile);
mvOk = win_mv(tmpFile, dstFile);
}
else
{
Info<< " Foam cp, Foam mv" << nl;
cpOk = Foam::cp(srcFile, tmpFile);
mvOk = Foam::mv(tmpFile, dstFile);
}
Info<< nl
<< "cp: " << Switch(cpOk) << nl
<< "mv: " << Switch(mvOk) << nl;
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //
Test-cpluplus1.C
EXE = $(FOAM_USER_APPBIN)/Test-cpluplus1
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
/* EXE_LIBS = -lfiniteVolume */
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Test miscellaneous C++ templates/functionality.
\*---------------------------------------------------------------------------*/
#include "string.H"
#include "macros.H"
#include "IOstreams.H"
#include "UList.H"
#include "HashSet.H"
#include <typeinfo>
#include <type_traits>
#include <utility>
using namespace Foam;
#define PRINT_TYPEID(arg) \
Info<< typeid(arg).name() << " <= typeid of " << STRING_QUOTE(arg) << nl
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<< "various declaration types" << nl << nl;
PRINT_TYPEID(label);
PRINT_TYPEID(decltype(UList<label>::value_type()));
PRINT_TYPEID(decltype(std::declval<UList<label>>().cbegin()));
PRINT_TYPEID(decltype(*(std::declval<UList<label>>().cbegin())));
Info<< nl;
PRINT_TYPEID(decltype(HashTable<label>::key_type()));
PRINT_TYPEID(decltype(HashTable<label>::value_type()));
// Not yet: PRINT_TYPEID(decltype(HashTable<label>::mapped_type()));
PRINT_TYPEID(decltype(std::declval<HashTable<label>>().begin()));
PRINT_TYPEID(decltype(std::declval<const HashTable<label>>().begin()));
PRINT_TYPEID(decltype(*(std::declval<HashTable<label>>().begin())));
PRINT_TYPEID(decltype(*(std::declval<const HashTable<label>>().begin())));
PRINT_TYPEID(decltype(std::declval<const HashTable<label>>().keys()));
Info<< nl;
PRINT_TYPEID(decltype(HashSet<label>::key_type()));
PRINT_TYPEID(decltype(HashSet<label>::value_type()));
// Not yet: PRINT_TYPEID(decltype(HashSet<label>::mapped_type()));
PRINT_TYPEID(decltype(std::declval<HashSet<label>>().begin()));
PRINT_TYPEID(decltype(std::declval<const HashSet<label>>().begin()));
PRINT_TYPEID(decltype(*(std::declval<HashSet<label>>().begin())));
PRINT_TYPEID(decltype(*(std::declval<const HashSet<label>>().begin())));
Info<< nl;
Info << "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //
Test-cpuInfo.C
EXE = $(FOAM_USER_APPBIN)/Test-cpuInfo
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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
Description
\*---------------------------------------------------------------------------*/
#include "cpuInfo.H"
#include "IOstreams.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
cpuInfo().write(Info);
Info<< endl;
return 0;
}
// ************************************************************************* //
Test-cstring.C
EXE = $(FOAM_USER_APPBIN)/Test-cstring
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
/* EXE_LIBS = -lfiniteVolume */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment