Branch split: topo changes

This commit is contained in:
Hrvoje Jasak 2011-05-27 15:30:16 +01:00
parent 38b7115d69
commit aafe0363c3
24 changed files with 5092 additions and 1041 deletions

View file

@ -4,6 +4,7 @@ EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \
-I$(LIB_SRC)/dynamicMesh/dynamicFvMesh/lnInclude \
-I$(LIB_SRC)/edgeMesh/lnInclude \ -I$(LIB_SRC)/edgeMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
@ -12,4 +13,5 @@ EXE_LIBS = \
-ldecompositionMethods \ -ldecompositionMethods \
-lmeshTools \ -lmeshTools \
-ldynamicMesh \ -ldynamicMesh \
-ldynamicFvMesh \
-lautoMesh -lautoMesh

View file

@ -54,7 +54,8 @@ int main(int argc, char *argv[])
fadScalarField b = tf - ten; fadScalarField b = tf - ten;
fadScalarField c = ten - tf; fadScalarField c = ten - tf;
fadScalarField d = sqr(tf - ten); fadScalarField d = sqr(tf - ten);
fadScalarField e = (sqr(tf - bs + 10) + 22.3*sqr(cs - bs + 10)); fadScalarField e =
(sqr(tf - bs + fadScalar(10)) + 22.3*sqr(cs - bs + fadScalar(10)));
fadScalarField f = d/e; fadScalarField f = d/e;
// fadScalarField g = Foam::atan(f); // HJ, not prepared // fadScalarField g = Foam::atan(f); // HJ, not prepared
// fadScalarField h = Foam::log(f); // HJ, not prepared // fadScalarField h = Foam::log(f); // HJ, not prepared
@ -62,7 +63,11 @@ int main(int argc, char *argv[])
Info << "new tf: " << tf << endl; Info << "new tf: " << tf << endl;
Field<Vector<fadScalar> > tfVector(3, Vector<fadScalar>(1, 2, 3)); Field<Vector<fadScalar> > tfVector
(
3,
Vector<fadScalar>(fadScalar(1), fadScalar(2), fadScalar(3))
);
Info << "tfVector: " << tfVector << endl; Info << "tfVector: " << tfVector << endl;

View file

@ -1,6 +1,7 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/decompositionMethods/decompositionMethods/lnInclude \ -I$(LIB_SRC)/decompositionMethods/decompositionMethods/lnInclude \
-I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \
-I$(LIB_SRC)/dynamicMesh/dynamicFvMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
@ -10,6 +11,7 @@ EXE_INC = \
LIB_LIBS = \ LIB_LIBS = \
-ldecompositionMethods \ -ldecompositionMethods \
-ldynamicMesh \ -ldynamicMesh \
-ldynamicFvMesh \
-lfiniteVolume \ -lfiniteVolume \
-llagrangian \ -llagrangian \
-lmeshTools \ -lmeshTools \

View file

@ -3,6 +3,7 @@ EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/meshMotion/solidBodyMotion/lnInclude \
-I$(LIB_SRC)/dynamicMesh/meshMotion/tetDecompositionMotionSolver/lnInclude \ -I$(LIB_SRC)/dynamicMesh/meshMotion/tetDecompositionMotionSolver/lnInclude \
-I$(LIB_SRC)/tetDecompositionFiniteElement/lnInclude \ -I$(LIB_SRC)/tetDecompositionFiniteElement/lnInclude \
$(WM_DECOMP_INC) \ $(WM_DECOMP_INC) \
@ -15,6 +16,7 @@ LIB_LIBS = \
-lmeshTools \ -lmeshTools \
-ldynamicMesh \ -ldynamicMesh \
-lfiniteVolume \ -lfiniteVolume \
-lsolidBodyMotion \
$(WM_DECOMP_LIBS) \ $(WM_DECOMP_LIBS) \
-lfvMotionSolver \ -lfvMotionSolver \
-lRBFMotionSolver \ -lRBFMotionSolver \

View file

@ -0,0 +1,116 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fvMesh.H"
#include "fvMeshAdder.H"
#include "faceCoupleInfo.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//- Calculate map from new patch faces to old patch faces. -1 where
// could not map.
Foam::labelList Foam::fvMeshAdder::calcPatchMap
(
const label oldStart,
const label oldSize,
const labelList& oldToNew,
const polyPatch& newPatch,
const label unmappedValue
)
{
labelList newToOld(newPatch.size(), unmappedValue);
label newStart = newPatch.start();
label newSize = newPatch.size();
for (label i = 0; i < oldSize; i++)
{
label newFaceI = oldToNew[oldStart+i];
if (newFaceI >= newStart && newFaceI < newStart+newSize)
{
newToOld[newFaceI-newStart] = i;
}
}
return newToOld;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Inplace add mesh1 to mesh0
Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
(
fvMesh& mesh0,
const fvMesh& mesh1,
const faceCoupleInfo& coupleInfo,
const bool validBoundary
)
{
mesh0.clearOut();
// Resulting merged mesh (polyMesh only!)
autoPtr<mapAddedPolyMesh> mapPtr
(
polyMeshAdder::add
(
mesh0,
mesh1,
coupleInfo,
validBoundary
)
);
// Adjust the fvMesh part.
const polyBoundaryMesh& patches = mesh0.boundaryMesh();
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh0.boundary());
fvPatches.setSize(patches.size());
forAll(patches, patchI)
{
fvPatches.set(patchI, fvPatch::New(patches[patchI], fvPatches));
}
// Do the mapping of the stored fields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fvMeshAdder::MapVolFields<scalar>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<vector>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<sphericalTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<symmTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<tensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<scalar>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<vector>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<sphericalTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<symmTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<tensor>(mapPtr, mesh0, mesh1);
return mapPtr;
}
// ************************************************************************* //

View file

@ -0,0 +1,220 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fvMeshAdder
Description
Adds two fvMeshes without using any polyMesh morphing.
Uses fvMeshAdder.
SourceFiles
fvMeshAdder.C
fvMeshAdderTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvMeshAdder_H
#define fvMeshAdder_H
#include "polyMeshAdder.H"
#include "fvPatchFieldsFwd.H"
#include "fvsPatchFieldsFwd.H"
#include "fvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class IOobject;
class faceCoupleInfo;
class IOobjectList;
class fvMesh;
class volMesh;
class surfaceMesh;
class mapAddedPolyMesh;
/*---------------------------------------------------------------------------*\
Class fvMeshAdder Declaration
\*---------------------------------------------------------------------------*/
class fvMeshAdder
:
public polyMeshAdder
{
private:
// Private class
class directFvPatchFieldMapper
:
public fvPatchFieldMapper
{
// Private data
//- Size before mapping
label sizeBeforeMapping_;
//- Addressing
const labelList& directAddressing_;
public:
// Constructors
//- Construct from components
directFvPatchFieldMapper
(
const label sizeBeforeMapping,
const labelList& directAddressing
)
:
fvPatchFieldMapper(),
sizeBeforeMapping_(sizeBeforeMapping),
directAddressing_(directAddressing)
{}
// Destructor
virtual ~directFvPatchFieldMapper()
{}
// Member Functions
label size() const
{
return directAddressing_.size();
}
label sizeBeforeMapping() const
{
return sizeBeforeMapping_;
}
bool direct() const
{
return true;
}
const unallocLabelList& directAddressing() const
{
return directAddressing_;
}
};
// Private Member Functions
//- Calculate map from new patch faces to old patch faces. -1 where
// could not map.
static labelList calcPatchMap
(
const label oldStart,
const label oldSize,
const labelList& oldToNew,
const polyPatch& newPatch,
const label unmappedIndex
);
//- Map from old to new according to map. Handles map = -1.
template<class Type>
static void map
(
const Field<Type>&,
const labelList& map,
Field<Type>&
);
//- Update single volField.
template<class Type>
static void MapVolField
(
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvPatchField, volMesh>& fld,
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd
);
//- Update single surfaceField.
template<class Type>
static void MapSurfaceField
(
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd
);
public:
// Member Functions
//- Inplace add mesh to fvMesh. Maps all stored fields. Returns map.
static autoPtr<mapAddedPolyMesh> add
(
fvMesh& mesh0,
const fvMesh& mesh1,
const faceCoupleInfo& coupleInfo,
const bool validBoundary = true
);
//- Map all volFields of Type
template<class Type>
static void MapVolFields
(
const mapAddedPolyMesh&,
const fvMesh& mesh,
const fvMesh& meshToAdd
);
//- Map all surfaceFields of Type
template<class Type>
static void MapSurfaceFields
(
const mapAddedPolyMesh&,
const fvMesh& mesh,
const fvMesh& meshToAdd
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "fvMeshAdderTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,678 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "volFields.H"
#include "surfaceFields.H"
#include "emptyFvPatchField.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::fvMeshAdder::map
(
const Field<Type>& oldFld,
const labelList& oldToNew,
Field<Type>& fld
)
{
forAll(oldFld, cellI)
{
label newCellI = oldToNew[cellI];
if (newCellI >= 0 && newCellI < fld.size())
{
fld[newCellI] = oldFld[cellI];
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapVolField
(
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvPatchField, volMesh>& fld,
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd
)
{
const fvMesh& mesh = fld.mesh();
// Internal field
// ~~~~~~~~~~~~~~
{
// Store old internal field
Field<Type> oldInternalField(fld.internalField());
// Modify internal field
Field<Type>& intFld = fld.internalField();
intFld.setSize(mesh.nCells());
map(oldInternalField, meshMap.oldCellMap(), intFld);
map(fldToAdd.internalField(), meshMap.addedCellMap(), intFld);
}
// Patch fields from old mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& oldPatchMap = meshMap.oldPatchMap();
const labelList& oldPatchStarts = meshMap.oldPatchStarts();
const labelList& oldPatchSizes = meshMap.oldPatchSizes();
// Reorder old patches in order of new ones. Put removed patches at end.
label unusedPatchI = 0;
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
unusedPatchI++;
}
}
label nUsedPatches = unusedPatchI;
// Reorder list for patchFields
labelList oldToNew(oldPatchMap.size());
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
oldToNew[patchI] = newPatchI;
}
else
{
oldToNew[patchI] = unusedPatchI++;
}
}
// Sort deleted ones last so is now in newPatch ordering
fld.boundaryField().reorder(oldToNew);
// Extend to covers all patches
fld.boundaryField().setSize(mesh.boundaryMesh().size());
// Delete unused patches
for
(
label newPatchI = nUsedPatches;
newPatchI < fld.boundaryField().size();
newPatchI++
)
{
fld.boundaryField().set(newPatchI, NULL);
}
// Map old values
// ~~~~~~~~~~~~~~
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
labelList newToOld
(
calcPatchMap
(
oldPatchStarts[patchI],
oldPatchSizes[patchI],
meshMap.oldFaceMap(),
mesh.boundaryMesh()[newPatchI],
0 // unmapped value
)
);
directFvPatchFieldMapper patchMapper
(
oldPatchSizes[patchI],
newToOld
);
// Create new patchField with same type as existing one.
// Note:
// - boundaryField already in new order so access with newPatchI
// - fld.boundaryField()[newPatchI] both used for type and old
// value
// - hope that field mapping allows aliasing since old and new
// are same memory!
fld.boundaryField().set
(
newPatchI,
fvPatchField<Type>::New
(
fld.boundaryField()[newPatchI], // old field
mesh.boundary()[newPatchI], // new fvPatch
fld.dimensionedInternalField(), // new internal field
patchMapper // mapper (new to old)
)
);
}
}
}
// Patch fields from added mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& addedPatchMap = meshMap.addedPatchMap();
// Add addedMesh patches
forAll(addedPatchMap, patchI)
{
label newPatchI = addedPatchMap[patchI];
if (newPatchI != -1)
{
const polyPatch& newPatch = mesh.boundaryMesh()[newPatchI];
const polyPatch& oldPatch =
fldToAdd.mesh().boundaryMesh()[patchI];
if (!fld.boundaryField()(newPatchI))
{
// First occurrence of newPatchI. Map from existing
// patchField
// From new patch faces to patch faces on added mesh.
labelList newToAdded
(
calcPatchMap
(
oldPatch.start(),
oldPatch.size(),
meshMap.addedFaceMap(),
newPatch,
0 // unmapped values
)
);
directFvPatchFieldMapper patchMapper
(
oldPatch.size(),
newToAdded
);
fld.boundaryField().set
(
newPatchI,
fvPatchField<Type>::New
(
fldToAdd.boundaryField()[patchI], // added field
mesh.boundary()[newPatchI], // new fvPatch
fld.dimensionedInternalField(), // new int. field
patchMapper // mapper
)
);
}
else
{
// PatchField will have correct size already. Just slot in
// my elements.
// From new patch faces to patch faces on added mesh. This
// time keep unmapped elements -1.
labelList newToAdded
(
calcPatchMap
(
oldPatch.start(),
oldPatch.size(),
meshMap.addedFaceMap(),
newPatch,
-1 // unmapped values
)
);
const fvPatchField<Type>& addedFld =
fldToAdd.boundaryField()[patchI];
fvPatchField<Type>& newFld = fld.boundaryField()[newPatchI];
forAll(newFld, i)
{
label oldFaceI = newToAdded[i];
if (oldFaceI >= 0 && oldFaceI < addedFld.size())
{
newFld[i] = addedFld[oldFaceI];
}
}
}
}
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapVolFields
(
const mapAddedPolyMesh& meshMap,
const fvMesh& mesh,
const fvMesh& meshToAdd
)
{
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields
(
mesh.objectRegistry::lookupClass
<GeometricField<Type, fvPatchField, volMesh> >
()
);
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fieldsToAdd
(
meshToAdd.objectRegistry::lookupClass
<GeometricField<Type, fvPatchField, volMesh> >
()
);
// It is necessary to enforce that all old-time fields are stored
// before the mapping is performed. Otherwise, if the
// old-time-level field is mapped before the field itself, sizes
// will not match.
for
(
typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
const_cast<GeometricField<Type, fvPatchField, volMesh>*>(fieldIter())
->storeOldTimes();
}
for
(
typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
GeometricField<Type, fvPatchField, volMesh>& fld =
const_cast<GeometricField<Type, fvPatchField, volMesh>&>
(
*fieldIter()
);
if (fieldsToAdd.found(fld.name()))
{
Pout<< "Mapping field " << fld.name() << endl;
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd =
*fieldsToAdd[fld.name()];
MapVolField<Type>(meshMap, fld, fldToAdd);
}
else
{
WarningIn("fvMeshAdder::MapVolFields")
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapSurfaceField
(
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd
)
{
const fvMesh& mesh = fld.mesh();
const labelList& oldPatchStarts = meshMap.oldPatchStarts();
// Internal field
// ~~~~~~~~~~~~~~
// Store old internal field
{
Field<Type> oldField(fld);
// Modify internal field
Field<Type>& intFld = fld.internalField();
intFld.setSize(mesh.nInternalFaces());
map(oldField, meshMap.oldFaceMap(), intFld);
map(fldToAdd, meshMap.addedFaceMap(), intFld);
// Faces that were boundary faces but are not anymore.
// Use owner value (so lowest numbered cell, i.e. from 'old' not 'added'
// mesh)
forAll(fld.boundaryField(), patchI)
{
const fvsPatchField<Type>& pf = fld.boundaryField()[patchI];
label start = oldPatchStarts[patchI];
forAll(pf, i)
{
label newFaceI = meshMap.oldFaceMap()[start + i];
if (newFaceI >= 0 && newFaceI < mesh.nInternalFaces())
{
intFld[newFaceI] = pf[i];
}
}
}
}
// Patch fields from old mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& oldPatchMap = meshMap.oldPatchMap();
const labelList& oldPatchSizes = meshMap.oldPatchSizes();
// Reorder old patches in order of new ones. Put removed patches at end.
label unusedPatchI = 0;
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
unusedPatchI++;
}
}
label nUsedPatches = unusedPatchI;
// Reorder list for patchFields
labelList oldToNew(oldPatchMap.size());
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
oldToNew[patchI] = newPatchI;
}
else
{
oldToNew[patchI] = unusedPatchI++;
}
}
// Sort deleted ones last so is now in newPatch ordering
fld.boundaryField().reorder(oldToNew);
// Extend to covers all patches
fld.boundaryField().setSize(mesh.boundaryMesh().size());
// Delete unused patches
for
(
label newPatchI = nUsedPatches;
newPatchI < fld.boundaryField().size();
newPatchI++
)
{
fld.boundaryField().set(newPatchI, NULL);
}
// Map old values
// ~~~~~~~~~~~~~~
forAll(oldPatchMap, patchI)
{
label newPatchI = oldPatchMap[patchI];
if (newPatchI != -1)
{
labelList newToOld
(
calcPatchMap
(
oldPatchStarts[patchI],
oldPatchSizes[patchI],
meshMap.oldFaceMap(),
mesh.boundaryMesh()[newPatchI],
0 // unmapped value
)
);
directFvPatchFieldMapper patchMapper
(
oldPatchSizes[patchI],
newToOld
);
// Create new patchField with same type as existing one.
// Note:
// - boundaryField already in new order so access with newPatchI
// - fld.boundaryField()[newPatchI] both used for type and old
// value
// - hope that field mapping allows aliasing since old and new
// are same memory!
fld.boundaryField().set
(
newPatchI,
fvsPatchField<Type>::New
(
fld.boundaryField()[newPatchI], // old field
mesh.boundary()[newPatchI], // new fvPatch
fld.dimensionedInternalField(), // new internal field
patchMapper // mapper (new to old)
)
);
}
}
}
// Patch fields from added mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& addedPatchMap = meshMap.addedPatchMap();
// Add addedMesh patches
forAll(addedPatchMap, patchI)
{
label newPatchI = addedPatchMap[patchI];
if (newPatchI != -1)
{
const polyPatch& newPatch = mesh.boundaryMesh()[newPatchI];
const polyPatch& oldPatch =
fldToAdd.mesh().boundaryMesh()[patchI];
if (!fld.boundaryField()(newPatchI))
{
// First occurrence of newPatchI. Map from existing
// patchField
// From new patch faces to patch faces on added mesh.
labelList newToAdded
(
calcPatchMap
(
oldPatch.start(),
oldPatch.size(),
meshMap.addedFaceMap(),
newPatch,
0 // unmapped values
)
);
directFvPatchFieldMapper patchMapper
(
oldPatch.size(),
newToAdded
);
fld.boundaryField().set
(
newPatchI,
fvsPatchField<Type>::New
(
fldToAdd.boundaryField()[patchI],// added field
mesh.boundary()[newPatchI], // new fvPatch
fld.dimensionedInternalField(), // new int. field
patchMapper // mapper
)
);
}
else
{
// PatchField will have correct size already. Just slot in
// my elements.
// From new patch faces to patch faces on added mesh. This
// time keep unmapped elements -1.
labelList newToAdded
(
calcPatchMap
(
oldPatch.start(),
oldPatch.size(),
meshMap.addedFaceMap(),
newPatch,
-1 // unmapped values
)
);
const fvsPatchField<Type>& addedFld =
fldToAdd.boundaryField()[patchI];
fvsPatchField<Type>& newFld =
fld.boundaryField()[newPatchI];
forAll(newFld, i)
{
label oldFaceI = newToAdded[i];
if (oldFaceI >= 0 && oldFaceI < addedFld.size())
{
newFld[i] = addedFld[oldFaceI];
}
}
}
}
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapSurfaceFields
(
const mapAddedPolyMesh& meshMap,
const fvMesh& mesh,
const fvMesh& meshToAdd
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
HashTable<const fldType*> fields
(
mesh.objectRegistry::lookupClass<fldType>()
);
HashTable<const fldType*> fieldsToAdd
(
meshToAdd.objectRegistry::lookupClass<fldType>()
);
// It is necessary to enforce that all old-time fields are stored
// before the mapping is performed. Otherwise, if the
// old-time-level field is mapped before the field itself, sizes
// will not match.
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
const_cast<fldType*>(fieldIter())
->storeOldTimes();
}
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
if (fieldsToAdd.found(fld.name()))
{
Pout<< "Mapping field " << fld.name() << endl;
const fldType& fldToAdd = *fieldsToAdd[fld.name()];
MapSurfaceField<Type>(meshMap, fld, fldToAdd);
}
else
{
WarningIn("fvMeshAdder::MapSurfaceFields")
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
}
}
}
// ************************************************************************* //

View file

@ -0,0 +1,257 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "CompactListList_dev.H"
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev(const List<Container>& ll)
:
size_(ll.size()),
offsets_(ll.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(ll, i)
{
sumSize += ll[i].size();
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
label k = 0;
forAll(ll, i)
{
const Container& lli = ll[i];
forAll(lli, j)
{
m_[k++] = lli[j];
}
}
}
template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
const UList<label>& rowSizes
)
:
size_(rowSizes.size()),
offsets_(rowSizes.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
}
template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
const UList<label>& rowSizes,
const T& t
)
:
size_(rowSizes.size()),
offsets_(rowSizes.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize, t);
}
template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
const Xfer<CompactListList_dev<T, Container> >& lst
)
{
transfer(lst());
}
template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
CompactListList_dev<T, Container>& lst,
bool reUse
)
:
size_(lst.size()),
offsets_(lst.offsets_, reUse),
m_(lst.m_, reUse)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::setSize(const label nRows)
{
if (nRows == 0)
{
clear();
}
if (nRows < size())
{
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(offsets_[nRows]);
}
else if (nRows > size())
{
FatalErrorIn
(
"CompactListList_dev<T, Container>::setSize(const label nRows)"
) << "Cannot be used to extend the list from " << offsets_.size()
<< " to " << nRows << nl
<< " Please use one of the other setSize member functions"
<< abort(FatalError);
}
}
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::setSize
(
const label nRows,
const label nData
)
{
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(nData);
}
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::setSize
(
const label nRows,
const label nData,
const T& t
)
{
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(nData, t);
}
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::setSize(const UList<label>& rowSizes)
{
size_ = rowSizes.size();
offsets_.setSize(rowSizes.size()+1);
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
}
template<class T, class Container>
Foam::labelList Foam::CompactListList_dev<T, Container>::sizes() const
{
labelList rowSizes(size());
if (rowSizes.size() > 0)
{
forAll(rowSizes, i)
{
rowSizes[i] = offsets_[i+1] - offsets_[i];
}
}
return rowSizes;
}
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::clear()
{
size_ = 0;
offsets_.clear();
m_.clear();
}
template<class T, class Container>
void Foam::CompactListList_dev<T, Container>::transfer
(
CompactListList_dev<T, Container>& a
)
{
size_ = a.size_;
offsets_.transfer(a.offsets_);
m_.transfer(a.m_);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Container>
Foam::List<Container> Foam::CompactListList_dev<T, Container>::operator()()
const
{
List<Container> ll(size());
forAll(ll, i)
{
ll[i] = Container(operator[](i));
}
return ll;
}
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
#include "CompactListList_devIO.C"
// ************************************************************************* //

View file

@ -0,0 +1,270 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::CompactListList_dev
Description
A packed storage unstructured matrix of objects of type \<T\>
using an offset table for access.
The offset table is the size of the number of rows+1
whose elements are the
accumulated sizes of the rows, i.e.
- offset[i] gives the index of first element of row i
- offset[i+1] - offset[i] is the number of elements in row i
Storage is allocated on free-store during construction.
As a special case a null-contructed CompactListList_dev has an empty
offsets_ (instead of size 1).
SourceFiles
CompactListList_dev.C
CompactListList_devI.H
CompactListList_devIO.C
\*---------------------------------------------------------------------------*/
#ifndef CompactListListDev_H
#define CompactListListDev_H
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class T, class Container> class CompactListList_dev;
template<class T, class Container> Istream& operator>>
(
Istream&,
CompactListList_dev<T, Container>&
);
template<class T, class Container> Ostream& operator<<
(
Ostream&,
const CompactListList_dev<T, Container>&
);
/*---------------------------------------------------------------------------*\
Class CompactListList_dev Declaration
\*---------------------------------------------------------------------------*/
template<class T, class Container = List<T> >
class CompactListList_dev
{
// Private data
label size_;
//- Offset table
List<label> offsets_;
//- Packed matrix of data
List<T> m_;
public:
// Static Member Functions
//- Return a null CompactListList_dev
inline static const CompactListList_dev<T, Container>& null();
// Constructors
//- Null constructor.
inline CompactListList_dev();
//- Construct by converting given List<List<T> >
explicit CompactListList_dev(const List<Container>&);
//- Construct given size of offset table (number of rows)
// and number of data.
inline CompactListList_dev(const label nRows, const label nData);
//- Construct given size of offset table (number of rows),
// the number of data and a value for all elements.
inline CompactListList_dev(const label nRows, const label nData, const T&);
//- Construct given list of row-sizes.
explicit CompactListList_dev(const UList<label>& rowSizes);
//- Construct given list of row-sizes
CompactListList_dev(const UList<label>& rowSizes, const T&);
//- Construct by transferring the parameter contents
explicit CompactListList_dev(const Xfer<CompactListList_dev<T, Container> >&);
//- Construct as copy or re-use as specified.
CompactListList_dev(CompactListList_dev<T, Container>&, bool reUse);
//- Construct from Istream.
CompactListList_dev(Istream&);
//- Clone
inline autoPtr<CompactListList_dev<T, Container> > clone() const;
// Member Functions
// Access
//- Return the primary size, i.e. the number of rows
inline label size() const;
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table (= size()+1)
inline const List<label>& offsets() const;
//- Return non-const access to the offset table
inline List<label>& offsets();
//- Return the packed matrix of data
inline const List<T>& m() const;
//- Return non-const access to the packed matrix of data
inline List<T>& m();
// Edit
//- Reset size of CompactListList_dev.
// This form only allows contraction of the CompactListList_dev.
void setSize(const label nRows);
//- Reset size of CompactListList_dev.
void setSize(const label nRows, const label nData);
//- Reset sizes of CompactListList_dev and value for new elements.
void setSize(const label nRows, const label nData, const T&);
//- Reset size of CompactListList_dev.
void setSize(const UList<label>& rowSizes);
//- Reset size of CompactListList_dev.
// This form only allows contraction of the CompactListList_dev.
inline void resize(const label nRows);
//- Reset size of CompactListList_dev.
inline void resize(const label nRows, const label nData);
//- Reset sizes of CompactListList_dev and value for new elements.
inline void resize(const label nRows, const label nData, const T&);
//- Reset size of CompactListList_dev.
inline void resize(const UList<label>& rowSizes);
//- Clear the CompactListList_dev, i.e. set sizes to zero.
void clear();
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Transfer the contents of the argument CompactListList_dev
// into this CompactListList_dev and annul the argument list.
void transfer(CompactListList_dev<T, Container>&);
//- Transfer the contents to the Xfer container
inline Xfer<CompactListList_dev<T, Container> > xfer();
// Other
//- Return index into m
inline label index(const label row, const label col) const;
//- Get row for index into m.
inline label whichRow(const label index) const;
//- Get column index (j) given above row
inline label whichColumn(const label row, const label index) const;
// Member operators
//- Return subscript-checked row as UList.
inline UList<T> operator[](const label i);
//- Return const subscript-checked row as UList.
inline const UList<T> operator[](const label i) const;
//- Return subscript-checked element.
inline T& operator()(const label i, const label j);
//- Return const subscript-checked element.
inline const T& operator()(const label i, const label j) const;
//- Return as List<Container>
List<Container> operator()() const;
//- Assignment of all entries to the given value
inline void operator=(const T&);
// Istream operator
//- Read CompactListList_dev from Istream, discarding contents
// of existing CompactListList_dev.
friend Istream& operator>> <T, Container>
(
Istream&,
CompactListList_dev<T, Container>&
);
// Write CompactListList_dev to Ostream.
friend Ostream& operator<< <T, Container>
(
Ostream&,
const CompactListList_dev<T, Container>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "CompactListList_devI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "CompactListList_dev.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,276 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "ListOps.H"
#include "SubList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Container>
inline Foam::CompactListList_dev<T, Container>::CompactListList_dev()
:
size_(0)
{}
template<class T, class Container>
inline Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
const label nRows,
const label nData
)
:
size_(nRows),
offsets_(nRows+1, 0),
m_(nData)
{}
template<class T, class Container>
inline Foam::CompactListList_dev<T, Container>::CompactListList_dev
(
const label nRows,
const label nData,
const T& t
)
:
size_(nRows),
offsets_(nRows+1, 0),
m_(nData, t)
{}
template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList_dev<T, Container> >
Foam::CompactListList_dev<T, Container>::clone() const
{
return autoPtr<CompactListList_dev<T, Container> >
(
new CompactListList_dev<T, Container>(*this)
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Container>
inline const Foam::CompactListList_dev<T, Container>&
Foam::CompactListList_dev<T, Container>::null()
{
return *reinterpret_cast< CompactListList_dev<T, Container>* >(0);
}
template<class T, class Container>
inline Foam::label Foam::CompactListList_dev<T, Container>::size() const
{
return size_;
}
template<class T, class Container>
inline bool Foam::CompactListList_dev<T, Container>::empty() const
{
return !size_;
}
template<class T, class Container>
inline const Foam::List<Foam::label>&
Foam::CompactListList_dev<T, Container>::offsets() const
{
return offsets_;
}
template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList_dev<T, Container>::offsets()
{
return offsets_;
}
template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList_dev<T, Container>::m()
const
{
return m_;
}
template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList_dev<T, Container>::m()
{
return m_;
}
template<class T, class Container>
inline Foam::label Foam::CompactListList_dev<T, Container>::index
(
const label i,
const label j
) const
{
return offsets_[i] + j;
}
template<class T, class Container>
inline Foam::label Foam::CompactListList_dev<T, Container>::whichRow(const label i)
const
{
if (i < 0 || i >= m_.size())
{
FatalErrorIn
(
"CompactListList_dev<T, Container>::whichRow(const label) const"
) << "Index " << i << " outside 0.." << m_.size()
<< abort(FatalError);
}
return findLower(offsets_, i+1);
}
template<class T, class Container>
inline Foam::label Foam::CompactListList_dev<T, Container>::whichColumn
(
const label row,
const label i
) const
{
return i - index(row, 0);
}
template<class T, class Container>
inline Foam::Xfer<Foam::CompactListList_dev<T, Container> >
Foam::CompactListList_dev<T, Container>::xfer()
{
return xferMove(*this);
}
template<class T, class Container>
inline void Foam::CompactListList_dev<T, Container>::resize(const label nRows)
{
this->setSize(nRows);
}
template<class T, class Container>
inline void Foam::CompactListList_dev<T, Container>::resize
(
const label nRows,
const label nData
)
{
this->setSize(nRows, nData);
}
template<class T, class Container>
inline void Foam::CompactListList_dev<T, Container>::resize
(
const label nRows,
const label nData,
const T& t
)
{
this->setSize(nRows, nData, t);
}
template<class T, class Container>
inline void Foam::CompactListList_dev<T, Container>::resize
(
const UList<label>& rowSizes
)
{
this->setSize(rowSizes);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList_dev<T, Container>::operator[]
(
const label i
)
{
label start = offsets_[i];
return UList<T>((m_.size() ? &m_[start] : NULL), offsets_[i+1] - start);
}
template<class T, class Container>
inline const Foam::UList<T>
Foam::CompactListList_dev<T, Container>::operator[]
(
const label i
) const
{
label start = offsets_[i];
return UList<T>
(
(m_.size() ? const_cast<T*>(&m_[start]) : NULL),
offsets_[i+1] - start
);
}
template<class T, class Container>
inline T& Foam::CompactListList_dev<T, Container>::operator()
(
const label i,
const label j
)
{
return m_[index(i, j)];
}
template<class T, class Container>
inline const T& Foam::CompactListList_dev<T, Container>::operator()
(
const label i,
const label j
) const
{
return m_[index(i, j)];
}
template<class T, class Container>
inline void Foam::CompactListList_dev<T, Container>::operator=(const T& t)
{
m_ = t;
}
// ************************************************************************* //

View file

@ -24,46 +24,42 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "solidBodyMotionFunction.H" #include "CompactListList_dev.H"
#include "Istream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::solidBodyMotionFunction, 0); template<class T, class Container>
Foam::CompactListList_dev<T, Container>::CompactListList_dev(Istream& is)
defineRunTimeSelectionTable(Foam::solidBodyMotionFunction, dictionary);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunction::solidBodyMotionFunction
(
const dictionary& SBMFCoeffs,
const Time& runTime
)
:
SBMFCoeffs_
(
SBMFCoeffs.subDict
(
word(SBMFCoeffs.lookup("solidBodyMotionFunction")) + "Coeffs"
)
),
time_(runTime)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunction::~solidBodyMotionFunction()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::solidBodyMotionFunction::read(const dictionary& SBMFCoeffs)
{ {
SBMFCoeffs_ = SBMFCoeffs.subDict(type() + "Coeffs"); operator>>(is, *this);
}
return true;
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Container>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList_dev<T, Container>& lst)
{
is >> lst.offsets_ >> lst.m_;
// Note: empty list gets output as two empty lists
if (lst.offsets_.size() == 0)
{
lst.size_ = 0;
}
else
{
lst.size_ = lst.offsets_.size()-1;
}
return is;
}
template<class T, class Container>
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList_dev<T, Container>& lst)
{
os << lst.offsets_ << lst.m_;
return os;
} }

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,368 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fvMeshDistribute
Description
Sends/receives parts of mesh+fvfields to neighbouring processors.
Used in load balancing.
Input is per local cell the processor it should move to. Moves meshes
and volFields/surfaceFields and returns map which can be used to
distribute other.
Notes:
- does not handle cyclics. Will probably handle separated proc patches.
- if all cells move off processor also all its processor patches will
get deleted so comms might be screwed up (since e.g. globalMeshData
expects procPatches on all)
- initial mesh has to have procPatches last and all normal patches common
to all processors and in the same order. This is checked.
- faces are matched topologically but points on the faces are not. So
expect problems -on separated patches (cyclics?) -on zero sized processor
edges.
SourceFiles
fvMeshDistribute.C
fvMeshDistributeTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvMeshDistribute_H
#define fvMeshDistribute_H
#include "Field.H"
//#include "uLabel.H"
#include "fvMeshSubset.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class mapAddedPolyMesh;
class mapDistributePolyMesh;
/*---------------------------------------------------------------------------*\
Class fvMeshDistribute Declaration
\*---------------------------------------------------------------------------*/
class fvMeshDistribute
{
// Private data
//- Underlying fvMesh
fvMesh& mesh_;
//- Absolute merging tolerance (constructing meshes gets done using
// geometric matching)
const scalar mergeTol_;
// Private Member Functions
//- Find indices with value
static labelList select
(
const bool selectEqual,
const labelList& values,
const label value
);
//- Check all procs have same names and in exactly same order.
static void checkEqualWordList(const string&, const wordList&);
//- Merge wordlists over all processors
static wordList mergeWordList(const wordList&);
// Patch handling
//- Find patch to put exposed faces into.
label findNonEmptyPatch() const;
//- Appends processorPolyPatch. Returns patchID.
label addProcPatch(const word& patchName, const label nbrProc);
//- Add patch field
template<class GeoField>
void addPatchFields(const word& patchFieldType);
//- Deletes last patch.
void deleteTrailingPatch();
// Delete trailing patch fields
template<class GeoField>
void deleteTrailingPatchFields();
//- Save boundary fields
template <class T, class Mesh>
void saveBoundaryFields
(
PtrList<FieldField<fvsPatchField, T> >& bflds
) const;
//- Map boundary fields
template <class T, class Mesh>
void mapBoundaryFields
(
const mapPolyMesh& map,
const PtrList<FieldField<fvsPatchField, T> >& oldBflds
);
//- Init patch fields of certain type
template<class GeoField, class PatchFieldType>
void initPatchFields
(
const typename GeoField::value_type& initVal
);
//- Delete all processor patches. Move any processor faces into
// patchI.
autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
//- Repatch the mesh. This is only nessecary for the proc
// boundary faces. newPatchID is over all boundary faces: -1 or
// new patchID. constructFaceMap is being adapted for the
// possible new face position (since proc faces get automatically
// matched)
autoPtr<mapPolyMesh> repatch
(
const labelList& newPatchID,
labelListList& constructFaceMap
);
//- Merge any shared points that are geometrically shared. Needs
// parallel valid mesh - uses globalMeshData.
// constructPointMap is adapted for the new point labels.
autoPtr<mapPolyMesh> mergeSharedPoints
(
labelListList& constructPointMap
);
// Coupling information
//- Construct the local environment of all boundary faces.
void getNeighbourData
(
const labelList& distribution,
labelList& sourceFace,
labelList& sourceProc,
labelList& sourceNewProc
) const;
// Subset the neighbourCell/neighbourProc fields
static void subsetBoundaryData
(
const fvMesh& mesh,
const labelList& faceMap,
const labelList& cellMap,
const labelList& oldDistribution,
const labelList& oldFaceOwner,
const labelList& oldFaceNeighbour,
const label oldInternalFaces,
const labelList& sourceFace,
const labelList& sourceProc,
const labelList& sourceNewProc,
labelList& subFace,
labelList& subProc,
labelList& subNewProc
);
//- Find cells on mesh whose faceID/procID match the neighbour
// cell/proc of domainMesh. Store the matching face.
static void findCouples
(
const primitiveMesh&,
const labelList& sourceFace,
const labelList& sourceProc,
const label domain,
const primitiveMesh& domainMesh,
const labelList& domainFace,
const labelList& domainProc,
labelList& masterCoupledFaces,
labelList& slaveCoupledFaces
);
//- Map data on boundary faces to new mesh (resulting from adding
// two meshes)
static labelList mapBoundaryData
(
const primitiveMesh& mesh, // mesh after adding
const mapAddedPolyMesh& map,
const labelList& boundaryData0, // mesh before adding
const label nInternalFaces1,
const labelList& boundaryData1 // added mesh
);
// Other
//- Remove cells. Add all exposed faces to patch oldInternalPatchI
autoPtr<mapPolyMesh> doRemoveCells
(
const labelList& cellsToRemove,
const label oldInternalPatchI
);
//- Add processor patches. Changes mesh and returns per neighbour
// proc the processor patchID.
void addProcPatches
(
const labelList&, // processor that neighbour is on
labelList& procPatchID
);
//- Get boundary faces to be repatched. Is -1 or new patchID
static labelList getProcBoundaryPatch
(
const labelList& neighbourNewProc,// new processor per b. face
const labelList& procPatchID // patchID
);
//- Send mesh and coupling data.
static void sendMesh
(
const label domain,
const fvMesh& mesh,
const wordList& pointZoneNames,
const wordList& facesZoneNames,
const wordList& cellZoneNames,
const labelList& sourceFace,
const labelList& sourceProc,
const labelList& sourceNewProc,
OSstream& toDomain
);
//- Send subset of fields
template<class GeoField>
static void sendFields
(
const label domain,
const wordList& fieldNames,
const fvMeshSubset&,
OSstream& toNbr
);
//- Receive mesh. Opposite of sendMesh
static autoPtr<fvMesh> receiveMesh
(
const label domain,
const wordList& pointZoneNames,
const wordList& facesZoneNames,
const wordList& cellZoneNames,
const Time& runTime,
labelList& domainSourceFace,
labelList& domainSourceProc,
labelList& domainSourceNewProc,
ISstream& fromNbr
);
//- Receive fields. Opposite of sendFields
template<class GeoField>
static void receiveFields
(
const label domain,
const wordList& fieldNames,
fvMesh&,
PtrList<GeoField>&,
const dictionary& fieldDicts
);
//- Do parallel exchange
template <class Container, class T>
static void exchange
(
const List<Container >& sendBufs,
List<Container >& recvBufs,
labelListList& sizes
);
//- Disallow default bitwise copy construct
fvMeshDistribute(const fvMeshDistribute&);
//- Disallow default bitwise assignment
void operator=(const fvMeshDistribute&);
public:
ClassName("fvMeshDistribute");
// Constructors
//- Construct from mesh and absolute merge tolerance
fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
// Member Functions
//- Helper function: count cells per processor in wanted distribution
static labelList countCells(const labelList&);
//- Send cells to neighbours according to distribution
// (for every cell the new proc)
autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
// Debugging
//- Print some info on coupling data
static void printCoupleInfo
(
const primitiveMesh&,
const labelList&,
const labelList&,
const labelList&
);
//- Print some field info
template<class GeoField>
static void printFieldInfo(const fvMesh&);
//- Print some info on mesh.
static void printMeshInfo(const fvMesh&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "fvMeshDistributeTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,507 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "mapPolyMesh.H"
#include "PstreamCombineReduceOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//- combineReduce operator for lists. Used for counting.
class listEq
{
public:
template<class T>
void operator()(T& x, const T& y) const
{
forAll(y, i)
{
if (y[i].size())
{
x[i] = y[i];
}
}
}
};
template <class Container, class T>
void Foam::fvMeshDistribute::exchange
(
const List<Container >& sendBufs,
List<Container >& recvBufs,
labelListList& sizes
)
{
if (Pstream::parRun())
{
if (!contiguous<T>())
{
FatalErrorIn
(
"Pstream::exchange(..)"
) << "Continuous data only." << Foam::abort(FatalError);
}
if (sendBufs.size() != Pstream::nProcs())
{
FatalErrorIn
(
"Pstream::exchange(..)"
) << "Size of list:" << sendBufs.size()
<< " does not equal the number of processors:"
<< Pstream::nProcs()
<< Foam::abort(FatalError);
}
sizes.setSize(Pstream::nProcs());
labelList& nsTransPs = sizes[Pstream::myProcNo()];
nsTransPs.setSize(Pstream::nProcs());
forAll(sendBufs, procI)
{
nsTransPs[procI] = sendBufs[procI].size();
}
Foam::combineReduce(sizes, listEq());
// Set up receives
// ~~~~~~~~~~~~~~~
recvBufs.setSize(sendBufs.size());
forAll(sizes, procI)
{
label nRecv = sizes[procI][Pstream::myProcNo()];
if (procI != Pstream::myProcNo() && nRecv > 0)
{
recvBufs[procI].setSize(nRecv);
IPstream::read
(
Pstream::nonBlocking,
procI,
reinterpret_cast<char*>(recvBufs[procI].begin()),
nRecv*sizeof(T)
);
}
}
// Set up sends
// ~~~~~~~~~~~~
forAll(sendBufs, procI)
{
if (procI != Pstream::myProcNo() && sendBufs[procI].size() > 0)
{
if
(
!OPstream::write
(
Pstream::nonBlocking,
procI,
reinterpret_cast<const char*>(sendBufs[procI].begin()),
sendBufs[procI].size()*sizeof(T)
)
)
{
FatalErrorIn("Pstream::exchange(..)")
<< "Cannot send outgoing message. "
<< "to:" << procI << " nBytes:"
<< label(sendBufs[procI].size()*sizeof(T))
<< Foam::abort(FatalError);
}
}
}
// Wait for all to finish
// ~~~~~~~~~~~~~~~~~~~~~~
IPstream::waitRequests();
OPstream::waitRequests();
}
// Do myself
recvBufs[Pstream::myProcNo()] = sendBufs[Pstream::myProcNo()];
}
template<class GeoField>
void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
{
HashTable<const GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
for
(
typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
iter != flds.end();
++iter
)
{
const GeoField& fld = *iter();
Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
//<< " value:" << fld
<< endl;
forAll(fld.boundaryField(), patchI)
{
Pout<< " " << patchI
<< ' ' << fld.boundaryField()[patchI].patch().name()
<< ' ' << fld.boundaryField()[patchI].type()
<< ' ' << fld.boundaryField()[patchI].size()
<< endl;
}
}
}
template<class GeoField>
void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType)
{
HashTable<const GeoField*> flds
(
mesh_.objectRegistry::lookupClass<GeoField>()
);
for
(
typename HashTable<const GeoField*>::const_iterator iter =
flds.begin();
iter != flds.end();
++iter
)
{
const GeoField& fld = *iter();
typename GeoField::GeometricBoundaryField& bfld =
const_cast<typename GeoField::GeometricBoundaryField&>
(
fld.boundaryField()
);
label sz = bfld.size();
bfld.setSize(sz + 1);
bfld.set
(
sz,
GeoField::PatchFieldType::New
(
patchFieldType,
mesh_.boundary()[sz],
fld.dimensionedInternalField()
)
);
}
}
// Delete trailing patch fields
template<class GeoField>
void Foam::fvMeshDistribute::deleteTrailingPatchFields()
{
HashTable<const GeoField*> flds
(
mesh_.objectRegistry::lookupClass<GeoField>()
);
for
(
typename HashTable<const GeoField*>::const_iterator iter =
flds.begin();
iter != flds.end();
++iter
)
{
const GeoField& fld = *iter();
typename GeoField::GeometricBoundaryField& bfld =
const_cast<typename GeoField::GeometricBoundaryField&>
(
fld.boundaryField()
);
// Shrink patchFields
bfld.setSize(bfld.size() - 1);
}
}
// Save whole boundary field
template <class T, class Mesh>
void Foam::fvMeshDistribute::saveBoundaryFields
(
PtrList<FieldField<fvsPatchField, T> >& bflds
) const
{
typedef GeometricField<T, fvsPatchField, Mesh> fldType;
HashTable<const fldType*> flds
(
mesh_.objectRegistry::lookupClass<fldType>()
);
bflds.setSize(flds.size());
label i = 0;
for
(
typename HashTable<const fldType*>::const_iterator iter = flds.begin();
iter != flds.end();
++iter
)
{
const fldType& fld = *iter();
bflds.set(i, fld.boundaryField().clone().ptr());
i++;
}
}
// Map boundary field
template <class T, class Mesh>
void Foam::fvMeshDistribute::mapBoundaryFields
(
const mapPolyMesh& map,
const PtrList<FieldField<fvsPatchField, T> >& oldBflds
)
{
const labelList& oldPatchStarts = map.oldPatchStarts();
const labelList& faceMap = map.faceMap();
typedef GeometricField<T, fvsPatchField, Mesh> fldType;
HashTable<const fldType*> flds
(
mesh_.objectRegistry::lookupClass<fldType>()
);
if (flds.size() != oldBflds.size())
{
FatalErrorIn("fvMeshDistribute::mapBoundaryFields(..)") << "problem"
<< abort(FatalError);
}
label fieldI = 0;
for
(
typename HashTable<const fldType*>::const_iterator iter = flds.begin();
iter != flds.end();
++iter
)
{
const fldType& fld = *iter();
typename fldType::GeometricBoundaryField& bfld =
const_cast<typename fldType::GeometricBoundaryField&>
(
fld.boundaryField()
);
const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldI++];
// Pull from old boundary field into bfld.
forAll(bfld, patchI)
{
fvsPatchField<T>& patchFld = bfld[patchI];
label faceI = patchFld.patch().patch().start();
forAll(patchFld, i)
{
label oldFaceI = faceMap[faceI++];
// Find patch and local patch face oldFaceI was in.
forAll(oldPatchStarts, oldPatchI)
{
label oldLocalI = oldFaceI - oldPatchStarts[oldPatchI];
if
(
oldLocalI >= 0
&& oldLocalI < oldBfld[oldPatchI].size()
)
{
patchFld[i] = oldBfld[oldPatchI][oldLocalI];
}
}
}
}
}
}
// Init patch fields of certain type
template<class GeoField, class PatchFieldType>
void Foam::fvMeshDistribute::initPatchFields
(
const typename GeoField::value_type& initVal
)
{
HashTable<const GeoField*> flds
(
mesh_.objectRegistry::lookupClass<GeoField>()
);
for
(
typename HashTable<const GeoField*>::const_iterator iter =
flds.begin();
iter != flds.end();
++iter
)
{
const GeoField& fld = *iter();
typename GeoField::GeometricBoundaryField& bfld =
const_cast<typename GeoField::GeometricBoundaryField&>
(
fld.boundaryField()
);
forAll(bfld, patchI)
{
if (isA<PatchFieldType>(bfld[patchI]))
{
bfld[patchI] == initVal;
}
}
}
}
// Send fields. Note order supplied so we can receive in exactly the same order
// Note that field gets written as entry in dictionary so we
// can construct from subdictionary.
// (since otherwise the reading as-a-dictionary mixes up entries from
// consecutive fields)
// The dictionary constructed is:
// volScalarField
// {
// p {internalField ..; boundaryField ..;}
// k {internalField ..; boundaryField ..;}
// }
// volVectorField
// {
// U {internalField ... }
// }
// volVectorField {U {internalField ..; boundaryField ..;}}
template<class GeoField>
void Foam::fvMeshDistribute::sendFields
(
const label domain,
const wordList& fieldNames,
const fvMeshSubset& subsetter,
OSstream& toNbr
)
{
toNbr<< GeoField::typeName << token::NL << token::BEGIN_BLOCK
<< token::NL;
forAll(fieldNames, i)
{
if (debug)
{
Pout<< "Subsetting field " << fieldNames[i]
<< " for domain:" << domain << endl;
}
// Send all fieldNames. This has to be exactly the same set as is
// being received!
const GeoField& fld =
subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
tmp<GeoField> tsubfld = subsetter.interpolate(fld);
toNbr
<< fieldNames[i] << token::NL << token::BEGIN_BLOCK
<< tsubfld
<< token::NL << token::END_BLOCK << token::NL;
}
toNbr << token::END_BLOCK << token::NL;
}
// Opposite of sendFields
template<class GeoField>
void Foam::fvMeshDistribute::receiveFields
(
const label domain,
const wordList& fieldNames,
fvMesh& mesh,
PtrList<GeoField>& fields,
const dictionary& fieldDicts
)
{
if (debug)
{
Pout<< "Receiving fields " << fieldNames
<< " from domain:" << domain << endl;
}
fields.setSize(fieldNames.size());
forAll(fieldNames, i)
{
if (debug)
{
Pout<< "Constructing field " << fieldNames[i]
<< " from domain:" << domain << endl;
}
fields.set
(
i,
new GeoField
(
IOobject
(
fieldNames[i],
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
fieldDicts.subDict(fieldNames[i])
)
);
}
}
// ************************************************************************* //

View file

@ -1,135 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "SDA.H"
#include "addToRunTimeSelectionTable.H"
#include "mathematicalConstants.H"
using namespace Foam::mathematicalConstant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
defineTypeNameAndDebug(SDA, 0);
addToRunTimeSelectionTable(solidBodyMotionFunction, SDA, dictionary);
};
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::SDA::SDA
(
const dictionary& SBMFCoeffs,
const Time& runTime
)
:
solidBodyMotionFunction(SBMFCoeffs, runTime),
CofG_(SBMFCoeffs_.lookup("CofG"))
{
read(SBMFCoeffs);
}
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::SDA::~SDA()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::septernion Foam::solidBodyMotionFunctions::SDA::transformation() const
{
scalar time = time_.value();
scalar Tpi = Tp_ + dTp_*(time/dTi_); // Current roll period [sec]
scalar wr = 2*pi/Tpi; // Current Freq [/sec]
// Current Phase for roll [rad]
scalar r = dTp_/dTi_;
scalar u = Tp_ + r*time;
scalar phr = 2*pi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
// Current Phase for Sway [rad]
scalar phs = phr + pi;
// Current Phase for Heave [rad]
scalar phh = phr + pi/2;
scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
vector T
(
0,
swayA_*(sin(wr*time + phs) - sin(phs)),
heaveA_*(sin(wr*time + phh) - sin(phh))
);
quaternion R(rollA*sin(wr*time + phr), 0, 0);
septernion TR(septernion(CofG_ + T)*R*septernion(-CofG_));
Info<< "solidBodyMotionFunctions::SDA::transformation(): "
<< "Time = " << time << " transformation: " << TR << endl;
return TR;
}
bool Foam::solidBodyMotionFunctions::SDA::read(const dictionary& SBMFCoeffs)
{
solidBodyMotionFunction::read(SBMFCoeffs);
SBMFCoeffs_.lookup("CofG") >> CofG_;
SBMFCoeffs_.lookup("lamda") >> lamda_;
SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
SBMFCoeffs_.lookup("heaveA") >> heaveA_;
SBMFCoeffs_.lookup("swayA") >> swayA_;
SBMFCoeffs_.lookup("Q") >> Q_;
SBMFCoeffs_.lookup("Tp") >> Tp_;
SBMFCoeffs_.lookup("Tpn") >> Tpn_;
SBMFCoeffs_.lookup("dTi") >> dTi_;
SBMFCoeffs_.lookup("dTp") >> dTp_;
// Rescale parameters according to the given scale parameter
if (lamda_ > 1 + SMALL)
{
heaveA_ /= lamda_;
swayA_ /= lamda_;
Tp_ /= sqrt(lamda_);
Tpn_ /= sqrt(lamda_);
dTi_ /= sqrt(lamda_);
dTp_ /= sqrt(lamda_);
}
return true;
}
// ************************************************************************* //

View file

@ -1,147 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::solidBodyMotionFunctions::SDA
Description
Ship design analysis (SDA) 3DoF motion function.
Comprising sinusoidal roll (rotation about x), heave (z-translation)
and sway (y-translation) motions with changing amplitude and phase.
See Also
SKA (Sea Keeping Analysis) for 6DoF motion.
SourceFiles
SDA.C
\*---------------------------------------------------------------------------*/
#ifndef SDA_H
#define SDA_H
#include "solidBodyMotionFunction.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
/*---------------------------------------------------------------------------*\
Class SDA Declaration
\*---------------------------------------------------------------------------*/
class SDA
:
public solidBodyMotionFunction
{
// Private data
//- Center of gravity
vector CofG_;
//- Model scale ratio
scalar lamda_;
//- Max roll amplitude [rad]
scalar rollAmax_;
//- Min roll amplitude [rad]
scalar rollAmin_;
//- Heave amplitude [m]
scalar heaveA_;
//- Sway amplitude [m]
scalar swayA_;
//- Damping Coefficient [-]
scalar Q_;
//- Time Period for liquid [sec]
scalar Tp_;
//- Natural Period of Ship [sec]
scalar Tpn_;
//- Reference time step [sec]
scalar dTi_;
//- Incr. in Tp/unit 'dTi'[-]
scalar dTp_;
// Private Member Functions
//- Disallow copy construct
SDA(const SDA&);
//- Disallow default bitwise assignment
void operator=(const SDA&);
public:
//- Runtime type information
TypeName("SDA");
// Constructors
//- Construct from components
SDA
(
const dictionary& SBMFCoeffs,
const Time& runTime
);
// Destructor
virtual ~SDA();
// Member Functions
//- Return the solid-body motion transformation septernion
virtual septernion transformation() const;
//- Update properties from given dictionary
virtual bool read(const dictionary& SBMFCoeffs);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace solidBodyMotionFunctions
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,162 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "SKA.H"
#include "addToRunTimeSelectionTable.H"
#include "Tuple2.H"
#include "IFstream.H"
#include "interpolateXY.H"
#include "mathematicalConstants.H"
using namespace Foam::mathematicalConstant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
defineTypeNameAndDebug(SKA, 0);
addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
};
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::SKA::SKA
(
const dictionary& SBMFCoeffs,
const Time& runTime
)
:
solidBodyMotionFunction(SBMFCoeffs, runTime)
{
read(SBMFCoeffs);
}
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::SKA::~SKA()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
{
scalar t = time_.value();
if (t < times_[0])
{
FatalErrorIn
(
"solidBodyMotionFunctions::SKA::transformation()"
) << "current time (" << t
<< ") is less than the minimum in the data table ("
<< times_[0] << ')'
<< exit(FatalError);
}
if (t > times_[times_.size()-1])
{
FatalErrorIn
(
"solidBodyMotionFunctions::SKA::transformation()"
) << "current time (" << t
<< ") is greater than the maximum in the data table ("
<< times_[times_.size()-1] << ')'
<< exit(FatalError);
}
translationRotationVectors TRV = interpolateXY
(
t,
times_,
values_
);
// Convert the rotational motion from deg to rad
TRV[1] *= pi/180.0;
quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
Info<< "solidBodyMotionFunctions::SKA::transformation(): "
<< "Time = " << t << " transformation: " << TR << endl;
return TR;
}
bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
{
solidBodyMotionFunction::read(SBMFCoeffs);
// If the timeDataFileName has changed read the file
fileName newTimeDataFileName(SBMFCoeffs_.lookup("timeDataFileName"));
if (newTimeDataFileName != timeDataFileName_)
{
timeDataFileName_ = newTimeDataFileName;
IFstream dataStream(timeDataFileName_);
if (dataStream.good())
{
List<Tuple2<scalar, translationRotationVectors> > timeValues
(
dataStream
);
times_.setSize(timeValues.size());
values_.setSize(timeValues.size());
forAll(timeValues, i)
{
times_[i] = timeValues[i].first();
values_[i] = timeValues[i].second();
}
}
else
{
FatalErrorIn
(
"solidBodyMotionFunctions::SKA::read(const dictionary&)"
) << "Cannot open time data file " << timeDataFileName_
<< exit(FatalError);
}
}
SBMFCoeffs_.lookup("CofG") >> CofG_;
return true;
}
// ************************************************************************* //

View file

@ -1,132 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::solidBodyMotionFunctions::SKA
Description
Sea Keeping Analysis (SKA) 6DoF motion function.
Obtained by interpolating tabulated data for surge (x-translation),
sway (y-translation), heave (z-translation), roll (rotation about x),
pitch (rotation about y) and yaw (rotation about z).
See Also
SDA (Ship design analysis) for 3DoF motion.
SourceFiles
SKA.C
\*---------------------------------------------------------------------------*/
#ifndef SKA_H
#define SKA_H
#include "solidBodyMotionFunction.H"
#include "primitiveFields.H"
#include "Vector2D.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
/*---------------------------------------------------------------------------*\
Class SKA Declaration
\*---------------------------------------------------------------------------*/
class SKA
:
public solidBodyMotionFunction
{
// Private data
//- Time data file name read from dictionary
fileName timeDataFileName_;
//- Center of gravity read from dictionary
vector CofG_;
//- Type used to read in the translation and rotation "vectors"
typedef Vector2D<vector> translationRotationVectors;
//- Field of times
scalarField times_;
//- Field of translation and rotation "vectors"
Field<translationRotationVectors> values_;
// Private Member Functions
//- Disallow copy construct
SKA(const SKA&);
//- Disallow default bitwise assignment
void operator=(const SKA&);
public:
//- Runtime type information
TypeName("SKA");
// Constructors
//- Construct from components
SKA
(
const dictionary& SBMFCoeffs,
const Time& runTime
);
// Destructor
virtual ~SKA();
// Member Functions
//- Return the solid-body motion transformation septernion
virtual septernion transformation() const;
//- Update properties from given dictionary
virtual bool read(const dictionary& SBMFCoeffs);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace solidBodyMotionFunctions
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,66 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "solidBodyMotionFunction.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::solidBodyMotionFunction> Foam::solidBodyMotionFunction::New
(
const dictionary& SBMFCoeffs,
const Time& runTime
)
{
word solidBodyMotionFunctionTypeName =
SBMFCoeffs.lookup("solidBodyMotionFunction");
Info<< "Selecting solid-body motion function "
<< solidBodyMotionFunctionTypeName << endl;
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(solidBodyMotionFunctionTypeName);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"solidBodyMotionFunction::New"
"("
" const dictionary& SBMFCoeffs,"
" const Time& runTime"
")"
) << "Unknown solidBodyMotionFunction type "
<< solidBodyMotionFunctionTypeName << endl << endl
<< "Valid solidBodyMotionFunctions are : " << endl
<< dictionaryConstructorTablePtr_->toc()
<< exit(FatalError);
}
return autoPtr<solidBodyMotionFunction>(cstrIter()(SBMFCoeffs, runTime));
}
// ************************************************************************* //

View file

@ -1,144 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Namespace
Foam::solidBodyMotionFunctions
Description
Namespace for solid-body motions
Class
Foam::solidBodyMotionFunction
Description
Base class for defining solid-body motions
SourceFiles
solidBodyMotionFunction.C
newDynamicFvMesh.C
\*---------------------------------------------------------------------------*/
#ifndef solidBodyMotionFunction_H
#define solidBodyMotionFunction_H
#include "Time.H"
#include "dictionary.H"
#include "septernion.H"
#include "autoPtr.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class solidBodyMotionFunction Declaration
\*---------------------------------------------------------------------------*/
class solidBodyMotionFunction
{
protected:
// Protected data
dictionary SBMFCoeffs_;
const Time& time_;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
solidBodyMotionFunction(const solidBodyMotionFunction&);
//- Disallow default bitwise assignment
void operator=(const solidBodyMotionFunction&);
public:
//- Runtime type information
TypeName("solidBodyMotionFunction");
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
solidBodyMotionFunction,
dictionary,
(const dictionary& SBMFCoeffs, const Time& runTime),
(SBMFCoeffs, runTime)
);
// Constructors
//- Construct from the SBMFCoeffs dictionary and Time
solidBodyMotionFunction
(
const dictionary& SBMFCoeffs,
const Time& runTime
);
// Selectors
//- Select constructed from the SBMFCoeffs dictionary and Time
static autoPtr<solidBodyMotionFunction> New
(
const dictionary& SBMFCoeffs,
const Time& runTime
);
// Destructor
virtual ~solidBodyMotionFunction();
// Member Functions
//- Return the solid-body motion transformation septernion
virtual septernion transformation() const = 0;
//- Update properties from given dictionary
virtual bool read(const dictionary& SBMFCoeffs) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,98 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "translation.H"
#include "addToRunTimeSelectionTable.H"
#include "mathematicalConstants.H"
using namespace Foam::mathematicalConstant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
defineTypeNameAndDebug(translation, 0);
addToRunTimeSelectionTable
(
solidBodyMotionFunction,
translation,
dictionary
);
};
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::translation::translation
(
const dictionary& SBMFCoeffs,
const Time& runTime
)
:
solidBodyMotionFunction(SBMFCoeffs, runTime),
velocity_(SBMFCoeffs_.lookup("velocity"))
{}
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
Foam::solidBodyMotionFunctions::translation::~translation()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::septernion
Foam::solidBodyMotionFunctions::translation::transformation() const
{
scalar time = time_.value();
septernion TR(velocity_*time, quaternion::I);
Info<< "solidBodyMotionFunctions::translation::transformation(): "
<< "Time = " << time << " transformation: " << TR << endl;
return TR;
}
bool Foam::solidBodyMotionFunctions::translation::read
(
const dictionary& SBMFCoeffs
)
{
solidBodyMotionFunction::read(SBMFCoeffs);
SBMFCoeffs_.lookup("velocity") >> velocity_;
return true;
}
// ************************************************************************* //

View file

@ -1,111 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::solidBodyMotionFunctions::translation
Description
translation motion function
SourceFiles
translation.C
\*---------------------------------------------------------------------------*/
#ifndef translation_H
#define translation_H
#include "solidBodyMotionFunction.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace solidBodyMotionFunctions
{
/*---------------------------------------------------------------------------*\
Class translation Declaration
\*---------------------------------------------------------------------------*/
class translation
:
public solidBodyMotionFunction
{
// Private data
//- Velocity
vector velocity_;
// Private Member Functions
//- Disallow copy construct
translation(const translation&);
//- Disallow default bitwise assignment
void operator=(const translation&);
public:
//- Runtime type information
TypeName("translation");
// Constructors
//- Construct from components
translation
(
const dictionary& SBMFCoeffs,
const Time& runTime
);
// Destructor
virtual ~translation();
// Member Functions
//- Return the solid-body motion transformation septernion
virtual septernion transformation() const;
//- Update properties from given dictionary
virtual bool read(const dictionary& SBMFCoeffs);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace solidBodyMotionFunctions
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -53,20 +53,20 @@ Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io)
IOobject IOobject
( (
"dynamicMeshDict", "dynamicMeshDict",
io.time().constant(), time().constant(),
*this, *this,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
) )
).subDict(typeName + "Coeffs") ).subDict(typeName + "Coeffs")
), ),
SBMFPtr_(solidBodyMotionFunction::New(dynamicMeshCoeffs_, io.time())), SBMFPtr_(solidBodyMotionFunction::New(dynamicMeshCoeffs_, time())),
undisplacedPoints_ undisplacedPoints_
( (
IOobject IOobject
( (
"points", "points",
io.time().constant(), time().constant(),
meshSubDir, meshSubDir,
*this, *this,
IOobject::MUST_READ, IOobject::MUST_READ,
@ -88,8 +88,7 @@ bool Foam::solidBodyMotionFvMesh::update()
{ {
fvMesh::movePoints fvMesh::movePoints
( (
transform(SBMFPtr_().transformation(), transform(SBMFPtr_().transformation(), undisplacedPoints_)
undisplacedPoints_)
); );
return false; return false;

View file

@ -60,10 +60,10 @@ class solidBodyMotionFvMesh
//- Dictionary of motion control parameters //- Dictionary of motion control parameters
dictionary dynamicMeshCoeffs_; dictionary dynamicMeshCoeffs_;
//- The motion control function //- Motion control function
autoPtr<solidBodyMotionFunction> SBMFPtr_; autoPtr<solidBodyMotionFunction> SBMFPtr_;
//- The reference points which are transformed //- Reference points which are transformed
pointIOField undisplacedPoints_; pointIOField undisplacedPoints_;
@ -85,7 +85,7 @@ public:
// Constructors // Constructors
//- Construct from IOobject //- Construct from IOobject
solidBodyMotionFvMesh(const IOobject& io); explicit solidBodyMotionFvMesh(const IOobject& io);
// Destructor // Destructor