Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 80 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
# dynamicAMR

## Descrition
forked from [HenningScheufler/multiDimAMR](https://github.com/HenningScheufler/multiDimAMR)
## Description

dynamic meshing with load balancing for hexahedral meshes in 3D and 2D

Library is based on:
The library is based on:

Rettenmaier, Daniel, et al. "Load balanced 2D and 3D adaptive mesh refinement in OpenFOAM." SoftwareX 10 (2019): 100317.

link:
https://www.sciencedirect.com/science/article/pii/S2352711018301699

port to the OpenFOAM+ version v1812 and v2006
port to the OpenFOAM+ version v1812 and v2006,v2012

refinement selection algoritm is based on foam extended 4.1
refinement selection algorithm is based on foam extended 4.1

## Getting Started

install OpenFOAM v1812

compile the library
install OpenFOAM v1812 and v2006

Compile the library
```
./Allwmake

```
in case of v2012 and later:
```
git checkout OF2306
./Allwmake
```
### Prerequisites

Requires OpenFOAM v1812:
Requires OpenFOAM v1812 or v2006,v2012:

```
https://www.openfoam.com/download/release-history.php
Expand All @@ -40,11 +45,16 @@ https://www.openfoam.com/download/release-history.php
```
### Usage

add to contolDict:
add the following lines to the contolDict:
```
libs
(
"libdynamicLoadBalanceFvMesh.so"
"libdynamicLoadBalanceFvMesh.so"
);
or depending on the openfoam version
libs
(
dynamicLoadBalanceFvMesh
);
```

Expand Down Expand Up @@ -115,6 +125,64 @@ constraints
}
// ************************************************************************* //
```
### refinement selection

the cells to refine are specified in the adaptCriteria dictionary
```
adaptCriteria
{
type fieldBounds; // options fieldBounds geometric
fieldName alpha.water;
lowerBound 0.001;
upperBound 0.999;
nLayer 2; // extends refinement zone by two layers
maxCellLevel 2; // default value very high number limits the maxium refinement level
minCellLevel 0; // default value 0 specify minimum refinement level
negate false; // default false // negates the selection
}
```
the composedAdaptCriteria enables us to combine the simple functions above by logial operator:
```
adaptCriteria
{

type composedAdaptCriteria;
operation or; // and or xor
criteria
(
interface // refine to the maxRefinement
{
type fieldBounds;
fieldName alpha.water;
lowerBound 0.01;
upperBound 0.99;
nLayer 2;
}
fluid // refLvl 2 in fluid
{
type fieldBounds;
fieldName alpha.water;
lowerBound 0.01;
upperBound 2;
maxCellLevel 2;
}
);
}
```
This way we can specify a higher refinement level at the interface than in the fluid or in combination with the geometric refinement option chose only to refine in a given region. Note that the composedAdaptCriteria can also consists of multiple composedAdaptCriteria


### Known Issues

* boundary condition that use function e.g. uniformFixedValue
crash if the table function is used see issue #2

Solution: the issue can be resolved by switching to v2012

* the load balancing crashes if a domain with no cells is created

Solution: use more cells or try a different method in balanceParDict kahip seems to work better than ptscotch
I

## License

Expand Down
2 changes: 1 addition & 1 deletion src/dynamicLoadBalanceFvMesh/adaptCriteria/adaptCriteria.C
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Foam::autoPtr<Foam::adaptCriteria> Foam::adaptCriteria::New
const word adaptCriteriaTypeName(dict.lookup("type"));
Info<< "Creating adaptCriteria " << adaptCriteriaTypeName << endl;

dictionaryConstructorTable::iterator cstrIter =
auto cstrIter =
dictionaryConstructorTablePtr_->find(adaptCriteriaTypeName);

if (cstrIter == dictionaryConstructorTablePtr_->end())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,8 @@ void Foam::fvMeshDistributeAddPatch::sendMesh
// Send
toDomain
<< mesh.points()
<< CompactListList<label, face>(mesh.faces())
// << CompactListList<label, face>(mesh.faces())//original
<< CompactListList<label>::pack<face>(mesh.faces()) // LX July 2 2024
<< mesh.faceOwner()
<< mesh.faceNeighbour()
<< mesh.boundaryMesh()
Expand Down Expand Up @@ -1521,7 +1522,8 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistributeAddPatch::receiveMesh
)
{
pointField domainPoints(fromNbr);
faceList domainFaces = CompactListList<label, face>(fromNbr)();
// faceList domainFaces = CompactListList<label, face>(fromNbr)(); // original
faceList domainFaces = CompactListList<label>(fromNbr).unpack<face>();// LX July 2 2024
labelList domainAllOwner(fromNbr);
labelList domainAllNeighbour(fromNbr);
PtrList<entry> patchEntries(fromNbr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ Foam::dynamicMultiDimRefineFvMesh::unrefine
forAllConstIters(faceToSplitPoint, iter)
{
const label oldFacei = iter.key();
const label oldPointi = iter.object();
const label oldPointi = iter.val();

if (reversePointMap[oldPointi] < 0)
{
Expand Down Expand Up @@ -929,7 +929,7 @@ Foam::dynamicMultiDimRefineFvMesh::dynamicMultiDimRefineFvMesh(const IOobject& i
protectedCell_(nCells()),
nRefinementIterations_(0),
dumpLevel_(false),
adaptCriteriaPtr_()
adaptCriteriaPtr_()
{
// Read static part of dictionary
readDict();
Expand Down Expand Up @@ -1210,7 +1210,7 @@ bool Foam::dynamicMultiDimRefineFvMesh::update()
newRefineCell.set(celli);
}
}
// move content in refineCell
// move content in refineCell
refineCell.transfer(newRefineCell);
}

Expand Down Expand Up @@ -1276,9 +1276,7 @@ bool Foam::dynamicMultiDimRefineFvMesh::update()

bool Foam::dynamicMultiDimRefineFvMesh::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
Expand All @@ -1287,7 +1285,7 @@ bool Foam::dynamicMultiDimRefineFvMesh::writeObject

bool writeOk =
(
dynamicFvMesh::writeObject(fmt, ver, cmp, valid)
dynamicFvMesh::writeObject(streamOpt, valid)
&& meshCutter_->write(valid)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ public:
//- Write using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void Foam::dynamicMultiDimRefineFvMesh::mapNewInternalFaces
// Convert to intensive and non oriented
// sqr(magSf) can throw float point exception
//NormalGeoField fFld(sFld*Sf/Foam::sqr(magSf));
surfaceVectorField n = Sf/magSf;
surfaceVectorField n(Sf/magSf);
NormalGeoField fFld(sFld*n/magSf);

// Interpolate
Expand Down
16 changes: 8 additions & 8 deletions src/dynamicLoadBalanceFvMesh/hexRef/hexRef.C
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Foam::label Foam::hexRef::getAnchorCell
{
if (cellAnchorPoints[celli].size())
{
label index = findIndex(cellAnchorPoints[celli], pointi);
label index = cellAnchorPoints[celli].find(pointi);

if (index != -1)
{
Expand All @@ -570,7 +570,7 @@ Foam::label Foam::hexRef::getAnchorCell

forAll(f, fp)
{
label index = findIndex(cellAnchorPoints[celli], f[fp]);
label index = cellAnchorPoints[celli].find(f[fp]);

if (index != -1)
{
Expand Down Expand Up @@ -1340,7 +1340,7 @@ bool Foam::hexRef::matchHexShape
if (iter != pointFaces.end())
{
labelList& pFaces = iter();
if (findIndex(pFaces, facei) == -1)
if (pFaces.find(facei) == -1)
{
pFaces.append(facei);
}
Expand Down Expand Up @@ -1904,7 +1904,7 @@ Foam::labelList Foam::hexRef::consistentSlowRefinement
<< "Argument facesToCheck seems to have duplicate entries!"
<< endl
<< "face:" << facei << " occurs at positions "
<< findIndices(facesToCheck, facei)
<< facesToCheck.find(facei)
<< abort(FatalError);
}

Expand Down Expand Up @@ -2390,7 +2390,7 @@ Foam::labelList Foam::hexRef::consistentSlowRefinement2
<< "Argument facesToCheck seems to have duplicate entries!"
<< endl
<< "face:" << facei << " occurs at positions "
<< findIndices(facesToCheck, facei)
<< facesToCheck.find(facei)
<< abort(FatalError);
}

Expand Down Expand Up @@ -2996,7 +2996,7 @@ void Foam::hexRef::subset

cellLevel_.transfer(newCellLevel);

if (findIndex(cellLevel_, -1) != -1)
if (cellLevel_.find(-1) != -1)
{
FatalErrorInFunction
<< "Problem : "
Expand All @@ -3017,7 +3017,7 @@ void Foam::hexRef::subset

pointLevel_.transfer(newPointLevel);

if (findIndex(pointLevel_, -1) != -1)
if (pointLevel_.find(-1) != -1)
{
FatalErrorInFunction
<< "Problem : "
Expand Down Expand Up @@ -3537,7 +3537,7 @@ void Foam::hexRef::checkRefinementLevels

const Foam::cellShapeList& Foam::hexRef::cellShapes() const
{
if (cellShapesPtr_.empty())
if (!cellShapesPtr_)
{
if (debug)
{
Expand Down
4 changes: 2 additions & 2 deletions src/dynamicLoadBalanceFvMesh/hexRef/hexRef3D/hexRef3D.C
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Foam::label Foam::hexRef3D::getAnchorCell
{
if (cellAnchorPoints[celli].size())
{
label index = findIndex(cellAnchorPoints[celli], pointi);
label index = cellAnchorPoints[celli].find(pointi);

if (index != -1)
{
Expand All @@ -88,7 +88,7 @@ Foam::label Foam::hexRef3D::getAnchorCell

forAll(f, fp)
{
label index = findIndex(cellAnchorPoints[celli], f[fp]);
label index = cellAnchorPoints[celli].find(f[fp]);

if (index != -1)
{
Expand Down
10 changes: 5 additions & 5 deletions src/dynamicLoadBalanceFvMesh/hexRef/hexRef4/hexRef4.C
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Foam::label Foam::hexRef4::getAnchorCell
{
if (cellAnchorPoints[celli].size())
{
label index = findIndex(cellAnchorPoints[celli], pointi);
label index = cellAnchorPoints[celli].find(pointi);

if (index != -1)
{
Expand All @@ -97,7 +97,7 @@ Foam::label Foam::hexRef4::getAnchorCell

forAll(f, fp)
{
label index = findIndex(cellAnchorPoints[celli], f[fp]);
label index = cellAnchorPoints[celli].find(f[fp]);

if (index != -1)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ Foam::label Foam::hexRef4::storeMidPointInfo
}

const edge& anchors = midPointToAnchors[edgeMidPointi];
label index = findIndex(cellAnchorPoints[celli], anchorPointi);
label index = cellAnchorPoints[celli].find(anchorPointi);

if (index == 0)
{
Expand All @@ -235,7 +235,7 @@ Foam::label Foam::hexRef4::storeMidPointInfo

if (faceOrder == (mesh_.faceOwner()[facei] == celli))
{
label anch = findIndex(f, point1);
label anch = f.find(point1);

if (pointLevel_[f[f.rcIndex(anch)]] <= cellLevel_[celli])
{
Expand Down Expand Up @@ -274,7 +274,7 @@ Foam::label Foam::hexRef4::storeMidPointInfo
}
else
{
label anch = findIndex(f, point1);
label anch = f.find(point1);

if (pointLevel_[f[f.fcIndex(anch)]] <= cellLevel_[celli])
{
Expand Down
Loading