Commit f53f614c authored by mattijs's avatar mattijs
Browse files

Initial autoMesh merge

parent c731cfdc
......@@ -87,7 +87,7 @@ void hexBlock::setHandedness()
if (blockHandedness_ == noPoints)
{
WarningIn("hexBlock::readPoints(const bool, Istream&)")
WarningIn("hexBlock::hexBlock::setHandedness()")
<< "Cannot determine orientation of block."
<< " Continuing as if right handed." << endl;
blockHandedness_ = right;
......@@ -105,35 +105,67 @@ hexBlock::hexBlock(const label nx, const label ny, const label nz)
zDim_(nz - 1),
blockHandedness_(noPoints),
points_((xDim_ + 1)*(yDim_ + 1)*(zDim_ + 1))
{
Pout<< "xDim:" << nx << " yDim:" << ny << " zDim:" << nz << endl;
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void hexBlock::readPoints(const bool readBlank, Istream& is)
void hexBlock::readPoints
(
const bool readBlank,
const scalar twoDThicknes,
Istream& is
)
{
scalar iBlank;
forAll (points_, i)
label nPoints = points_.size();
if (twoDThicknes > 0)
{
nPoints /= 2;
}
Info<< "Reading " << nPoints << " x coordinates..." << endl;
for (label i=0; i < nPoints; i++)
{
is >> points_[i].x();
}
forAll (points_, i)
Info<< "Reading " << nPoints << " y coordinates..." << endl;
for (label i=0; i < nPoints; i++)
{
is >> points_[i].y();
}
forAll (points_, i)
if (twoDThicknes > 0)
{
Info<< "Extruding " << nPoints << " points in z direction..." << endl;
// Duplicate points
for (label i=0; i < nPoints; i++)
{
points_[i+nPoints] = points_[i];
}
for (label i=0; i < nPoints; i++)
{
points_[i].z() = 0;
points_[i+nPoints].z() = twoDThicknes;
}
}
else
{
is >> points_[i].z();
Info<< "Reading " << nPoints << " z coordinates..." << endl;
for (label i=0; i < nPoints; i++)
{
is >> points_[i].z();
}
}
if (readBlank)
{
forAll (points_, i)
Info<< "Reading " << nPoints << " blanks..." << endl;
for (label i=0; i < nPoints; i++)
{
is >> iBlank;
}
......
......@@ -145,7 +145,14 @@ public:
//- Read block points either with or without blanking after every block.
void readPoints(const bool readBlank, Istream&);
// If twoDThickness > 0 reads (half) the points and extrudes the
// points in z direction.
void readPoints
(
const bool readBlank,
const scalar twoDThicknes,
Istream&
);
};
......
......@@ -23,11 +23,12 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Plot3d mesh (ascii format) converter.
Plot3d mesh (ascii/formatted format) converter.
Work in progress! Handles ascii multiblock (and optionally singleBlock)
format.
By default expects blanking. Use -noBlank if none.
Use -2D <thickness> if 2D.
Niklas Nordin has experienced a problem with lefthandedness of the blocks.
The code should detect this automatically - see hexBlock::readPoints but
if this goes wrong just set the blockHandedness_ variable to 'right'
......@@ -59,6 +60,7 @@ int main(int argc, char *argv[])
argList::validOptions.insert("scale", "scale factor");
argList::validOptions.insert("noBlank", "");
argList::validOptions.insert("singleBlock", "");
argList::validOptions.insert("2D", "thickness");
argList args(argc, argv);
......@@ -75,6 +77,13 @@ int main(int argc, char *argv[])
bool readBlank = !args.options().found("noBlank");
bool singleBlock = args.options().found("singleBlock");
scalar twoDThicknes = -1;
if (args.options().found("2D"))
{
twoDThicknes = readScalar(IStringStream(args.options()["2D"])());
Info<< "Reading 2D case by extruding points by " << twoDThicknes
<< " in z direction." << nl << endl;
}
# include "createTime.H"
......@@ -95,7 +104,7 @@ int main(int argc, char *argv[])
plot3dFile >> nblock;
}
Info << "Reading " << nblock << " blocks" << endl;
Info<< "Reading " << nblock << " blocks" << endl;
PtrList<hexBlock> blocks(nblock);
......@@ -104,20 +113,32 @@ int main(int argc, char *argv[])
forAll (blocks, blockI)
{
plot3dFile >> nx >> ny >> nz;
if (twoDThicknes > 0)
{
// Fake second set of points (done in readPoints below)
plot3dFile >> nx >> ny;
nz = 2;
}
else
{
plot3dFile >> nx >> ny >> nz;
}
Info<< "block " << blockI << " nx:" << nx
<< " ny:" << ny << " nz:" << nz << endl;
blocks.set(blockI, new hexBlock(nx, ny, nz));
}
}
Info << "Reading block points" << endl;
Info<< "Reading block points" << endl;
label sumPoints(0);
label nMeshCells(0);
forAll (blocks, blockI)
{
Info << "block " << blockI << ":" << nl;
blocks[blockI].readPoints(readBlank, plot3dFile);
Info<< "block " << blockI << ":" << nl;
blocks[blockI].readPoints(readBlank, twoDThicknes, plot3dFile);
sumPoints += blocks[blockI].nBlockPoints();
nMeshCells += blocks[blockI].nBlockCells();
Info<< nl;
......@@ -136,7 +157,6 @@ int main(int argc, char *argv[])
}
}
// From old to new master point
labelList oldToNew;
pointField newPoints;
......@@ -151,13 +171,17 @@ int main(int argc, char *argv[])
newPoints
);
Info<< "Merged points within " << SMALL << " distance. Merged from "
<< oldToNew.size() << " down to " << newPoints.size()
<< " points." << endl;
// Scale the points
if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
{
newPoints *= scaleFactor;
}
Info << "Creating cells" << endl;
Info<< "Creating cells" << endl;
cellShapeList cellShapes(nMeshCells);
......@@ -190,7 +214,7 @@ int main(int argc, char *argv[])
}
}
Info << "Creating boundary patches" << endl;
Info<< "Creating boundary patches" << endl;
faceListList boundary(0);
wordList patchNames(0);
......@@ -220,10 +244,10 @@ int main(int argc, char *argv[])
// Set the precision of the points data to 10
IOstream::defaultPrecision(10);
Info << "Writing polyMesh" << endl;
Info<< "Writing polyMesh" << endl;
pShapeMesh.write();
Info << "End\n" << endl;
Info<< "End\n" << endl;
return 0;
}
......
......@@ -42,6 +42,7 @@ Description
#include "demandDrivenData.H"
#include "writePatch.H"
#include "writePointSet.H"
#include "IOobjectList.H"
#include <stdio.h>
......@@ -233,8 +234,10 @@ void writeVTK
void printHelp(Ostream& os)
{
os << "Please type 'help', 'quit', 'time ddd'"
os << "Please type 'help', 'list', 'quit', 'time ddd'"
<< " or a set command after prompt." << endl
<< "'list' will show all current cell/face/point sets." << endl
<< "'time ddd' will change the current time." << endl
<< endl
<< "A set command should be of the following form" << endl
<< endl
......@@ -272,6 +275,47 @@ void printHelp(Ostream& os)
}
void printAllSets(const polyMesh& mesh, Ostream& os)
{
IOobjectList objects
(
mesh,
mesh.pointsInstance(),
polyMesh::meshSubDir/"sets"
);
IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
if (cellSets.size() > 0)
{
os << "cellSets:" << endl;
forAllConstIter(IOobjectList, cellSets, iter)
{
cellSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
}
}
IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
if (faceSets.size() > 0)
{
os << "faceSets:" << endl;
forAllConstIter(IOobjectList, faceSets, iter)
{
faceSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
}
}
IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
if (pointSets.size() > 0)
{
os << "pointSets:" << endl;
forAllConstIter(IOobjectList, pointSets, iter)
{
pointSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
}
}
os << endl;
}
// Read command and execute. Return true if ok, false otherwise.
bool doCommand
......@@ -531,6 +575,12 @@ commandStatus parseType
return INVALID;
}
else if (setType == "list")
{
printAllSets(mesh, Pout);
return INVALID;
}
else if (setType == "time")
{
scalar time = readScalar(is);
......@@ -612,8 +662,9 @@ commandStatus parseType
(
"commandStatus parseType(Time&, polyMesh&, const word&"
", IStringStream&)"
) << "Illegal set type " << setType << endl
<< "Should be one of 'cellSet' 'faceSet' 'pointSet'"
) << "Illegal command " << setType << endl
<< "Should be one of 'help', 'list', 'time' or a set type :"
<< " 'cellSet', 'faceSet', 'pointSet'"
<< endl;
return INVALID;
......
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.0 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
// couplePatches tool definition
description "Utility to reorder face numbering for cyclic and processor patches";
couplePatchesDict
{
type dictionary;
description "couplePatches control dictionary";
dictionaryPath "system";
entries
{
arguments
{
type rootCaseArguments;
}
}
}
// ************************************************************************* //
couplePatches.C
EXE = $(FOAM_APPBIN)/couplePatches
EXE_INC = \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-ldynamicMesh \
-lmeshTools
......@@ -41,6 +41,8 @@ wmake libso randomProcesses
( cd postProcessing && ./Allwmake )
wmake libso autoMesh
wmake libso errorEstimation
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
......@@ -26,7 +27,7 @@ InNamspace
Foam
Description
ListOps. Various functions to operate on Lists.
Various functions to operate on Lists.
SourceFiles
ListOps.C
......@@ -66,6 +67,17 @@ template<class List>
void inplaceReorder(const labelList& oldToNew, List&);
// Variants to work with iterators and sparse tables. Need to have iterators
// and insert()
//- Map values. Do not map negative values.
template<class Container>
void inplaceMapValue(const labelList& oldToNew, Container&);
//- Recreate with mapped keys. Remove elements with negative key.
template<class Container>
void inplaceMapKey(const labelList& oldToNew, Container&);
//- Extract elements of List whose region is certain value. Use e.g.
// to extract all selected elements:
// subset<boolList, labelList>(selectedElems, true, lst);
......@@ -103,11 +115,21 @@ labelList identity(const label len);
//- Find first occurence of given element and return index,
// return -1 if not found. Linear search.
template<class List>
label findIndex(const List&, typename List::const_reference);
label findIndex
(
const List&,
typename List::const_reference,
const label start=0
);
//- Find all occurences of given element. Linear search.
template<class List>
labelList findIndices(const List&, typename List::const_reference);
labelList findIndices
(
const List&,
typename List::const_reference,
const label start=0
);
//- Opposite of findIndices: set values at indices to given value
template<class List>
......@@ -123,7 +145,7 @@ template<class List>
List createWithValues
(
const label sz,
typename List::const_reference initValue,
const typename List::const_reference initValue,
const labelList& indices,
typename List::const_reference setValue
);
......@@ -131,25 +153,35 @@ List createWithValues
//- Find index of max element (and larger than given element).
// return -1 if not found. Linear search.
template<class List>
label findMax(const List&);
label findMax(const List&, const label start=0);
//- Find index of min element (and less than given element).
// return -1 if not found. Linear search.
template<class List>
label findMin(const List&);
label findMin(const List&, const label start=0);
//- Find first occurence of given element in sorted list and return index,
// return -1 if not found. Binary search.
template<class List>
label findSortedIndex(const List&, typename List::const_reference);
label findSortedIndex
(
const List&,
typename List::const_reference,
const label start=0
);
//- Find last element < given value in sorted list and return index,
// return -1 if not found. Binary search.
template<class List>
label findLower(const List&, typename List::const_reference);
label findLower
(
const List&,
typename List::const_reference,
const label start=0
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -118,6 +118,54 @@ void Foam::inplaceReorder
}
template<class Container>
void Foam::inplaceMapValue
(
const labelList& oldToNew,
Container& lst
)
{
for
(
typename Container::iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
if (iter() >= 0)
{
iter() = oldToNew[iter()];
}
}
}
template<class Container>
void Foam::inplaceMapKey
(
const labelList& oldToNew,
Container& lst
)
{
Container newLst(lst);
for
(
typename Container::iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
if (iter.key() >= 0)
{
newLst.insert(oldToNew[iter.key()], iter());
}
}
lst.transfer(newLst);
}
template<class T, class List>
List Foam::subset(const UList<T>& regions, const T& region, const List& lst)
{
......@@ -221,11 +269,16 @@ void Foam::invertManyToMany
template<class List>
Foam::label Foam::findIndex(const List& l, typename List::const_reference t)
Foam::label Foam::findIndex
(
const List& l,
typename List::const_reference t,
const label start
)
{
label index = -1;
forAll(l, i)
for (label i = start; i < l.size(); i++)
{
if (l[i] == t)
{
......@@ -242,13 +295,14 @@ template<class List>
Foam::labelList Foam::findIndices
(
const List& l,
typename List::const_reference t
typename List::const_reference t,
const label start
)
{
// Count occurrences
label n = 0;
forAll(l, i)
for (label i = start; i < l.size(); i++)
{
if (l[i] == t)
{
......@@ -260,7 +314,7 @@ Foam::labelList Foam::findIndices
labelList indices(n);
n = 0;
forAll(l, i)
for (label i = start; i < l.size(); i++)
{
if (l[i] == t)
{
......@@ -291,7 +345,7 @@ template<class List>
List Foam::createWithValues
(
const label sz,
typename List::const_reference initValue,
const typename List::const_reference initValue,
const labelList& indices,
typename List::const_reference setValue
)
......@@ -303,16 +357,16 @@ List Foam::createWithValues
template<class List>
Foam::label Foam::findMax(const List& l)
Foam::label Foam::findMax(const List& l, const label start)
{
if (l.size() == 0)
if (start >= l.size())
{
return -1;
}
label index = 0;
label index = start;
for (label i = 1; i < l.size(); i++)
for (label i = start+1; i < l.size(); i++)
{
if (l[i] > l[index])