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

initial commit

parents
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 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-boolList
Description
Test specialized boolList functionality
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "boolList.H"
#include "bitSet.H"
#include "BitOps.H"
#include "FlatOutput.H"
#include "bitSetOrBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
using namespace Foam;
labelList sortedToc(const UList<bool>& bools)
{
label count = 0;
for (const bool val : bools)
{
if (val) ++count;
}
labelList indices(count);
count = 0;
forAll(bools, i)
{
if (bools[i])
{
indices[count++] = i;
}
}
indices.resize(count);
return indices;
}
inline Ostream& info(const UList<bool>& bools)
{
Info<< "size=" << bools.size()
<< " count=" << BitOps::count(bools)
<< " !count=" << BitOps::count(bools, false)
<< " all:" << BitOps::all(bools)
<< " any:" << BitOps::any(bools)
<< " none:" << BitOps::none(bools) << nl;
return Info;
}
inline Ostream& report
(
const UList<bool>& bitset,
bool showBits = false,
bool debugOutput = false
)
{
info(bitset);
Info<< "values: " << flatOutput(sortedToc(bitset)) << nl;
return Info;
}
inline Ostream& report(const UList<bool>& bools)
{
info(bools);
return Info;
}
inline bool compare
(
const UList<bool>& bitset,
const std::string& expected
)
{
std::string has;
has.reserve(bitset.size());
forAll(bitset, i)
{
has += (bitset[i] ? '1' : '.');
}
if (has == expected)
{
Info<< "pass: " << has << nl;
return true;
}
Info<< "fail: " << has << nl;
Info<< "expect: " << expected << nl;
return false;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
boolList list1(22, false);
// Set every third one on
forAll(list1, i)
{
list1[i] = !(i % 3);
}
Info<< "\nalternating bit pattern\n";
compare(list1, "1..1..1..1..1..1..1..1");
BitOps::unset(list1, labelRange(13, 20)); // In range
Info<< "\nafter clear [13,..]\n";
compare(list1, "1..1..1..1..1.........");
BitOps::unset(list1, labelRange(40, 20)); // out of range
Info<< "\nafter clear [40,..]\n";
compare(list1, "1..1..1..1..1.........");
BitOps::set(list1, labelRange(13, 5)); // In range
Info<< "\nafter set [13,5]\n";
compare(list1, "1..1..1..1..111111....");
{
boolList list2(5, true);
list2.unset(2);
Info<< "Test wrapper idea" << nl;
bitSetOrBoolList wrapper(list2);
if (wrapper.test(1))
{
Info<< "1 is on" << nl;
}
if (!wrapper.test(2))
{
Info<< "2 is off" << nl;
}
}
Info<< "\nDone" << nl << endl;
return 0;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 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/>.
Class
Foam::bitSetOrBoolList
Description
Simple wrapper for handling test() on bitSet or boolList
without a templating layer or lambda expresssion.
\*---------------------------------------------------------------------------*/
#ifndef bitSetOrBoolList_H
#define bitSetOrBoolList_H
#include "bitSet.H"
#include "boolList.H"
/*---------------------------------------------------------------------------*\
Class bitSetOrBoolList Declaration
\*---------------------------------------------------------------------------*/
namespace Foam
{
class bitSetOrBoolList
{
const bitSet& bits_;
const boolList& bools_;
public:
// Constructors
//- Construct with a bitSet reference
explicit bitSetOrBoolList(const bitSet& select)
:
bits_(select),
bools_(boolList::null())
{}
//- Construct with a boolList reference
explicit bitSetOrBoolList(const boolList& select)
:
bits_(bitSet::null()),
bools_(select)
{}
// Member Functions
//- Is empty
bool empty() const
{
return bits_.empty() && bools_.empty();
}
//- Size
label size() const
{
return bits_.size() + bools_.size();
}
//- Test function
bool test(const label i) const
{
return bits_.test(i) || bools_.test(i);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 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/>.
Class
Foam::disabledBoolList
Description
A trivial structure to use as a boolList replacement when testing
compilation without using the [] accessors.
Example,
\code
const disableBoolList blockedFace;
...
if (blockedFace.test(facei)) ... // Good
if (blockedFace[facei]) ... // Compile error
\endcode
\*---------------------------------------------------------------------------*/
#ifndef disabledBoolList_H
#define disabledBoolList_H
/*---------------------------------------------------------------------------*\
Class disabledBoolList Declaration
\*---------------------------------------------------------------------------*/
namespace Foam
{
struct disabledBoolList
{
bool empty() const { return true; }
int size() const { return 0; }
bool test(int) const { return true; }
void set(bool) {}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
Test-boolVector.C
EXE = $(FOAM_USER_APPBIN)/Test-boolVector
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 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-boolVector
Description
Some simple tests for boolVector
\*---------------------------------------------------------------------------*/
#include "boolVector.H"
#include "IOstreams.H"
#include "Switch.H"
using namespace Foam;
void print(const boolVector& v)
{
Info<< v
<< " any:" << Switch::name(v.any())
<< " all:" << Switch::name(v.all())
<< " none:" << Switch::name(v.none())
<< " count:" << v.count() << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<< "boolVector" << nl
<< " size = " << boolVector::size() << nl
<< " contiguous = " << is_contiguous<boolVector>::value << nl
<< nl;
{
boolVector vec;
Info<< "null: " << vec << nl;
}
Info<< "false: " << boolVector(false) << nl;
Info<< "true: " << boolVector(true) << nl;
Info<< "zero: " << boolVector(Zero) << nl;
Info<< nl;
{
boolVector vec{1, 0, 1};
print(vec);
vec.flip();
print(vec);
vec = false;
print(vec);
vec = true;
print(vec);
}
Info<< "\nEnd\n" << nl;
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Test-boundBox.C
EXE = $(FOAM_USER_APPBIN)/Test-boundBox
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-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 bounding box behaviour
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "boundBox.H"
#include "treeBoundBox.H"
#include "cellModel.H"
#include "bitSet.H"
#include "HashSet.H"
#include "ListOps.H"
using namespace Foam;
//- simple helper to create a cube
boundBox cube(scalar start, scalar width)
{
return boundBox
(
point::uniform(start),
point::uniform(start + width)
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
#include "setRootCase.H"
Info<<"boundBox faces: " << boundBox::faces << nl
<<"hex faces: " << cellModel::ref(cellModel::HEX).modelFaces() << nl
<<"tree-bb faces: " << treeBoundBox::faces << nl
<<"tree-bb edges: " << treeBoundBox::edges << endl;
boundBox bb = boundBox::greatBox;
Info<<"great box: " << bb << endl;
// bb.clear();
// Info<<"zero box: " << bb << endl;
bb = boundBox::invertedBox;
Info<<"invalid box: " << bb << endl;
Info<< nl << endl;
if (Pstream::parRun())
{
bb = cube(Pstream::myProcNo(), 1.1);
Pout<<"box: " << bb << endl;
bb.reduce();
Pout<<"reduced: " << bb << endl;
}
else
{
bb = cube(0, 1);
Info<<"starting box: " << bb << endl;
point pt(Zero);
bb.add(pt);
Info<<"enclose point " << pt << " -> " << bb << endl;
pt = point(0,1.5,0.5);
bb.add(pt);
Info<<"enclose point " << pt << " -> " << bb << endl;
pt = point(5,2,-2);
bb.add(pt);
Info<<"enclose point " << pt << " -> " << bb << endl;
// restart with same points
bb = boundBox::invertedBox;
bb.add(point(1,1,1));
bb.add(point::zero);
bb.add(point(0,1.5,0.5));
bb.add(point(5,2,-2));
Info<<"repeated " << bb << endl;
boundBox box1 = cube(0, 1);
boundBox box2 = cube(0, 0.75);
boundBox box3 = cube(0.5, 1);
boundBox box4 = cube(-1, 0.5);
Info<<"union of " << box1 << " and " << box2 << " => ";
box1.add(box2);
Info<< box1 << endl;
box1.add(box3);
Info<<"union with " << box3 << " => " << box1 << endl;
box1.add(box4);
Info<<"union with " << box4 << " => " << box1 << endl;
labelRange range(10, 25);
auto variousPoints = ListOps::create<point>
(
range.begin(),
range.end(),
[](const label val) { return vector(val, val, val); }
);
Info<< nl << nl;
labelHashSet select1{4, 5, 55};
bitSet select2(15, {1, 5, 20, 24, 34});
Info<< "From points: size=" << variousPoints.size() << " from "
<< variousPoints.first() << " ... " << variousPoints.last() << nl;
Info<< "add points @ " << flatOutput(select1.sortedToc()) << nl;
box1.add(variousPoints, select1);
Info<< "box is now => " << box1 << endl;
box1.add(variousPoints, select2);
Info<< "box is now => " << box1 << endl;
}
return 0;
}
// ************************************************************************* //
Test-callback.C
EXE = $(FOAM_USER_APPBIN)/Test-callback
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
-------------------------------------------------------------------------------
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
callBackTest
Description
\*---------------------------------------------------------------------------*/
#include "Callback.H"
using namespace Foam;
class callback
:
public Callback<callback>
{
public:
callback(CallbackRegistry<callback>& cbr)
:
Callback<callback>(cbr)
{}
~callback()
{}
virtual const word& name() const
{
return word::null;
}
void testCallbackFunction() const
{
Info<< "calling testCallbackFunction for object " << name() << endl;
}
};
class callbackRegistry
:
public CallbackRegistry<callback>
{
public:
callbackRegistry()
{}
~callbackRegistry()
{}
void testCallbackFunction() const
{
forAllConstIters(*this, iter)
{
iter().testCallbackFunction();
}
}
};
class objectWithCallback
:
public callback
{
word name_;
public:
objectWithCallback(const word& n, callbackRegistry& cbr)
:
callback(cbr),
name_(n)
{}
virtual const word& name() const
{
return name_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
callbackRegistry cbr;
objectWithCallback ob1("ob1", cbr);
objectWithCallback ob2("ob2", cbr);
cbr.testCallbackFunction();
{
objectWithCallback ob1("ob1", cbr);
cbr.testCallbackFunction();
}
cbr.testCallbackFunction();
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
Test-cellModels.C
EXE = $(FOAM_USER_APPBIN)/Test-cellModels
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 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-cellModels
Description
Print information about known cellModels
\*---------------------------------------------------------------------------*/
#include "cellModel.H"
#include "cellModeller.H"
using namespace Foam;
void printInfo(const cellModel* mdl)
{
if (mdl)
{
Info<< *mdl << endl;
}
else
{
Info<< "nullptr" << endl;
}
}
void printInfo(const cellModel::modelType type)
{
Info<< cellModel::modelNames[type] << " = ";
printInfo(cellModel::ptr(type));
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<<"lookup by enum" << nl
<<"=========================" << endl;
printInfo(cellModel::UNKNOWN);
printInfo(cellModel::HEX);
printInfo(cellModel::WEDGE);
printInfo(cellModel::PRISM);
printInfo(cellModel::PYR);
printInfo(cellModel::TET);
printInfo(cellModel::SPLITHEX);
printInfo(cellModel::TETWEDGE);
Info<<"lookup by name" << nl
<<"=========================" << endl;
printInfo(cellModel::ptr("tet"));
Info<<"lookup by index" << nl
<<"=========================" << endl;
printInfo(cellModel::ptr(7));
// Compatibility mode
Info<<"cellModeller::lookup (compatibility)" << nl
<<"=========================" << endl;
printInfo(cellModeller::lookup("tet"));
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
Test-charList.C
EXE = $(FOAM_USER_APPBIN)/Test-charList
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 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-charList
Description
Some test of UList, List for characters
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "argList.H"
#include "IOstreams.H"
#include "messageStream.H"
#include "charList.H"
#include "labelList.H"
#include "StringStream.H"
#include "ListOps.H"
#include "SubList.H"
#include "FlatOutput.H"
#include <numeric>
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noBanner();
argList::noParallel();
argList::noFunctionObjects();
#include "setRootCase.H"
Info<< "Known compound tokens: "
<< token::compound::IstreamConstructorTablePtr_->sortedToc() << nl;
OStringStream ostr;
{
List<char> alphabet(64);
std::iota(alphabet.begin(), alphabet.end(), '@');
alphabet.writeEntry("alphabet", Info);
ostr << alphabet;
Info<< "wrote: " << ostr.str() << nl;
}
{
IStringStream istr(ostr.str());
List<char> alphabet(istr);
Info<< "re-read: " << alphabet << nl;
}
return 0;
}
// ************************************************************************* //
Test-checkDecomposePar.C
EXE = $(FOAM_USER_APPBIN)/Test-checkDecomposePar
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \
-I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-ldecompose \
-ldecompositionMethods
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