Commit 673100d8 authored by mattijs's avatar mattijs
Browse files

have non-uniform offset vector

parent 6b439e63
......@@ -50,6 +50,34 @@ namespace Foam
const NamedEnum<directMappedPatchBase::sampleMode, 3>
directMappedPatchBase::sampleModeNames_;
//- Private class for finding nearest
// - point+local index
// - sqr(distance)
// - processor
typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo;
class nearestEqOp
{
public:
void operator()(nearInfo& x, const nearInfo& y) const
{
if (y.first().hit())
{
if (!x.first().hit())
{
x = y;
}
else if (y.second().first() < x.second().first())
{
x = y;
}
}
}
};
}
......@@ -70,7 +98,7 @@ void Foam::directMappedPatchBase::collectSamples
labelListList globalFaces(Pstream::nProcs());
globalFc[Pstream::myProcNo()] = patch_.faceCentres();
globalSamples[Pstream::myProcNo()] = globalFc[Pstream::myProcNo()]+offset_;
globalSamples[Pstream::myProcNo()] = globalFc[Pstream::myProcNo()]+offsets_;
globalFaces[Pstream::myProcNo()] = identity(patch_.size());
// Distribute to all processors
......@@ -365,17 +393,17 @@ void Foam::directMappedPatchBase::calcMapping() const
if
(
offset_ == vector::zero
gAverage(mag(offsets_)) <= ROOTVSMALL
&& mode_ == NEARESTPATCHFACE
&& sampleRegion_ == patch_.boundaryMesh().mesh().name()
&& samplePatch_ == patch_.name()
)
{
WarningIn("directMappedPatchBase::calcMapping() const")
<< "Invalid offset " << offset_ << endl
<< "Invalid offset " << offsets_ << endl
<< "Offset is the vector added to the patch face centres to"
<< " find the patch face supplying the data." << endl
<< "Setting it to " << offset_
<< "Setting it to " << offsets_
<< " on the same patch, on the same region"
<< " will find the faces themselves which does not make sense"
<< " for anything but testing." << endl
......@@ -383,7 +411,7 @@ void Foam::directMappedPatchBase::calcMapping() const
<< "sampleRegion_:" << sampleRegion_ << endl
<< "mode_:" << sampleModeNames_[mode_] << endl
<< "samplePatch_:" << samplePatch_ << endl
<< "offset_:" << offset_ << endl;
<< "offsets_:" << offsets_ << endl;
}
......@@ -447,34 +475,38 @@ void Foam::directMappedPatchBase::calcMapping() const
}
// Check that actual offset vector (sampleLocations - patchFc) is more or
// less constant.
if (Pstream::master())
{
const scalarField magOffset(mag(sampleLocations - patchFc));
const scalar avgOffset(average(magOffset));
forAll(magOffset, sampleI)
{
if (mag(magOffset[sampleI]-avgOffset) > max(SMALL, 0.001*avgOffset))
{
WarningIn("directMappedPatchBase::calcMapping() const")
<< "The actual cell/face centres picked up using offset "
<< offset_ << " are not" << endl
<< " on a single plane."
<< " This might give numerical problems." << endl
<< " At patchface " << patchFc[sampleI]
<< " the sampled cell/face " << sampleLocations[sampleI]
<< endl
<< " is not on a plane " << avgOffset
<< " offset from the patch." << endl
<< " You might want to shift your plane offset."
<< " Set the debug flag to get a dump of sampled cells."
<< endl;
break;
}
}
}
//// Check that actual offset vector (sampleLocations - patchFc) is more or
//// less constant.
//if (Pstream::master())
//{
// const scalarField magOffset(mag(sampleLocations - patchFc));
// const scalar avgOffset(average(magOffset));
//
// forAll(magOffset, sampleI)
// {
// if
// (
// mag(magOffset[sampleI]-avgOffset)
// > max(SMALL, 0.001*avgOffset)
// )
// {
// WarningIn("directMappedPatchBase::calcMapping() const")
// << "The actual cell/face centres picked up using offset "
// << offsets_ << " are not" << endl
// << " on a single plane."
// << " This might give numerical problems." << endl
// << " At patchface " << patchFc[sampleI]
// << " the sampled cell/face " << sampleLocations[sampleI]
// << endl
// << " is not on a plane " << avgOffset
// << " offset from the patch." << endl
// << " You might want to shift your plane offset."
// << " Set the debug flag to get a dump of sampled cells."
// << endl;
// break;
// }
// }
//}
// Determine schedule.
......@@ -556,14 +588,36 @@ void Foam::directMappedPatchBase::calcMapping() const
Foam::directMappedPatchBase::directMappedPatchBase
(
const polyPatch& pp
const polyPatch& pp
)
:
patch_(pp),
sampleRegion_(patch_.boundaryMesh().mesh().name()),
mode_(NEARESTPATCHFACE),
samplePatch_("none"),
uniformOffset_(true),
offset_(vector::zero),
offsets_(pp.size(), offset_),
sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
mapPtr_(NULL)
{}
Foam::directMappedPatchBase::directMappedPatchBase
(
const polyPatch& pp,
const word& sampleRegion,
const sampleMode mode,
const word& samplePatch,
const vectorField& offsets
)
:
patch_(pp),
sampleRegion_(sampleRegion),
mode_(mode),
samplePatch_(samplePatch),
uniformOffset_(false),
offsets_(offsets),
sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
mapPtr_(NULL)
{}
......@@ -586,7 +640,19 @@ Foam::directMappedPatchBase::directMappedPatchBase
),
mode_(sampleModeNames_.read(dict.lookup("sampleMode"))),
samplePatch_(dict.lookup("samplePatch")),
offset_(dict.lookup("offset")),
uniformOffset_(dict.found("offset")),
offset_
(
uniformOffset_
? point(dict.lookup("offset"))
: vector::zero
),
offsets_
(
uniformOffset_
? pointField(patch_.size(), offset_)
: dict.lookup("offsets")
),
sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
mapPtr_(NULL)
{}
......@@ -602,7 +668,9 @@ Foam::directMappedPatchBase::directMappedPatchBase
sampleRegion_(dmp.sampleRegion_),
mode_(dmp.mode_),
samplePatch_(dmp.samplePatch_),
uniformOffset_(dmp.uniformOffset_),
offset_(dmp.offset_),
offsets_(dmp.offsets_),
sameRegion_(dmp.sameRegion_),
mapPtr_(NULL)
{}
......@@ -660,7 +728,14 @@ void Foam::directMappedPatchBase::write(Ostream& os) const
<< token::END_STATEMENT << nl;
os.writeKeyword("samplePatch") << samplePatch_
<< token::END_STATEMENT << nl;
os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl;
if (uniformOffset_)
{
os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl;
}
else
{
os.writeKeyword("offsets") << offsets_ << token::END_STATEMENT << nl;
}
}
......
......@@ -87,12 +87,18 @@ private:
//- What to sample
const sampleMode mode_;
//- Patch (only if NEARESTBOUNDARY)
//- Patch (only if NEARESTPATCHFACE)
const word samplePatch_;
//- Offset vector
//- For backwards compatibility : reading/writing of uniform offset.
const bool uniformOffset_;
//- Offset vector (uniform)
const vector offset_;
//- Offset vector
const vectorField offsets_;
//- Same region
const bool sameRegion_;
......@@ -130,36 +136,6 @@ private:
void calcMapping() const;
// Private class
//- Private class for finding nearest
// - point+local index
// - sqr(distance)
// - processor
typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo;
class nearestEqOp
{
public:
void operator()(nearInfo& x, const nearInfo& y) const
{
if (y.first().hit())
{
if (!x.first().hit())
{
x = y;
}
else if (y.second().first() < x.second().first())
{
x = y;
}
}
}
};
public:
//- Runtime type information
......@@ -168,9 +144,19 @@ public:
// Constructors
//- Construct from components
//- Construct from patch
directMappedPatchBase(const polyPatch&);
//- Construct from components
directMappedPatchBase
(
const polyPatch& pp,
const word& sampleRegion,
const sampleMode sampleMode,
const word& samplePatch,
const vectorField& offset
);
//- Construct from dictionary
directMappedPatchBase(const polyPatch&, const dictionary&);
......@@ -210,6 +196,12 @@ public:
return offset_;
}
//- Offset vector (from patch faces to destination mesh objects)
const vectorField& offsets() const
{
return offsets_;
}
//- Return reference to the parallel distribution map
const mapDistribute& map() const
{
......
......@@ -57,6 +57,31 @@ Foam::directMappedPolyPatch::directMappedPolyPatch
{}
Foam::directMappedPolyPatch::directMappedPolyPatch
(
const word& name,
const label size,
const label start,
const label index,
const word& sampleRegion,
const directMappedPatchBase::sampleMode mode,
const word& samplePatch,
const vectorField& offset,
const polyBoundaryMesh& bm
)
:
polyPatch(name, size, start, index, bm),
directMappedPatchBase
(
static_cast<const polyPatch&>(*this),
sampleRegion,
mode,
samplePatch,
offset
)
{}
Foam::directMappedPolyPatch::directMappedPolyPatch
(
const word& name,
......
......@@ -101,6 +101,20 @@ public:
const polyBoundaryMesh& bm
);
//- Construct from components
directMappedPolyPatch
(
const word& name,
const label size,
const label start,
const label index,
const word& sampleRegion,
const directMappedPatchBase::sampleMode mode,
const word& samplePatch,
const vectorField& offset,
const polyBoundaryMesh& bm
);
//- Construct from dictionary
directMappedPolyPatch
(
......
......@@ -62,6 +62,31 @@ Foam::directMappedWallPolyPatch::directMappedWallPolyPatch
{}
Foam::directMappedWallPolyPatch::directMappedWallPolyPatch
(
const word& name,
const label size,
const label start,
const label index,
const word& sampleRegion,
const directMappedPatchBase::sampleMode mode,
const word& samplePatch,
const vectorField& offset,
const polyBoundaryMesh& bm
)
:
wallPolyPatch(name, size, start, index, bm),
directMappedPatchBase
(
static_cast<const polyPatch&>(*this),
sampleRegion,
mode,
samplePatch,
offset
)
{}
Foam::directMappedWallPolyPatch::directMappedWallPolyPatch
(
const word& name,
......
......@@ -101,6 +101,20 @@ public:
const polyBoundaryMesh& bm
);
//- Construct from components
directMappedWallPolyPatch
(
const word& name,
const label size,
const label start,
const label index,
const word& sampleRegion,
const directMappedPatchBase::sampleMode mode,
const word& samplePatch,
const vectorField& offset,
const polyBoundaryMesh& bm
);
//- Construct from dictionary
directMappedWallPolyPatch
(
......
Supports Markdown
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