Commit 14b93d5f authored by mattijs's avatar mattijs
Browse files

ENH: subsetMesh: revert to original behaviour. Moved clever selection into cellSources

parent 9ffa7df9
cellSelection/cellSelection.C
cellSelection/badQualityCellSelection.C
cellSelection/outsideCellSelection.C
subsetMesh.C
EXE = $(FOAM_APPBIN)/subsetMesh
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "badQualityCellSelection.H"
#include "addToRunTimeSelectionTable.H"
#include "faceSet.H"
#include "polyMesh.H"
#include "motionSmoother.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace cellSelections
{
defineTypeNameAndDebug(badQualityCellSelection, 0);
addToRunTimeSelectionTable
(
cellSelection,
badQualityCellSelection,
dictionary
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cellSelections::badQualityCellSelection::badQualityCellSelection
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
cellSelection(name, mesh, dict)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cellSelections::badQualityCellSelection::~badQualityCellSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::cellSelections::badQualityCellSelection::select
(
boolList& selectedCell
) const
{
//- Delete cell of any face in error
faceSet faces(mesh_, "meshQualityFaces", mesh_.nFaces()/100+1);
motionSmoother::checkMesh(false, mesh_, dict_, faces);
label nFaces = returnReduce(faces.size(), sumOp<label>());
if (nFaces > 0)
{
faces.sync(mesh_);
forAllConstIter(faceSet, faces, iter)
{
label faceI = iter.key();
selectedCell[mesh_.faceOwner()[faceI]] = false;
if (mesh_.isInternalFace(faceI))
{
selectedCell[mesh_.faceNeighbour()[faceI]] = false;
}
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::cellSelections::badQualityCellSelection
Description
Deselect bad quality cells
SourceFiles
badQualityCellSelection.C
\*---------------------------------------------------------------------------*/
#ifndef badQualityCellSelection_H
#define badQualityCellSelection_H
#include "cellSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace cellSelections
{
/*---------------------------------------------------------------------------*\
Class badQualityCellSelection Declaration
\*---------------------------------------------------------------------------*/
class badQualityCellSelection
:
public cellSelection
{
public:
//- Runtime type information
TypeName("badQuality");
// Constructors
//- Construct from dictionary
badQualityCellSelection
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
);
//- Clone
autoPtr<cellSelection> clone() const
{
notImplemented("autoPtr<cellSelection> clone() const");
return autoPtr<cellSelection>(NULL);
}
//- Destructor
virtual ~badQualityCellSelection();
// Member Functions
virtual void select(boolList&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace cellSelections
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cellSelection.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(cellSelection, 0);
defineRunTimeSelectionTable(cellSelection, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cellSelection::cellSelection
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
name_(name),
mesh_(mesh),
dict_(dict)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cellSelection::~cellSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::cellSelection> Foam::cellSelection::New
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
{
const word sampleType(dict.lookup("type"));
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(sampleType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"cellSelection::New"
"(const word&, const polyMesh&, const dictionary&)"
) << "Unknown cellSelection type "
<< sampleType << nl << nl
<< "Valid cellSelection types : " << endl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<cellSelection>(cstrIter()(name, mesh, dict));
}
Foam::label Foam::cellSelection::count(const boolList& lst)
{
label n = 0;
forAll(lst, i)
{
if (lst[i])
{
n++;
}
}
return returnReduce(n, sumOp<label>());
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::cellSelection
Description
Cell selection methods in subsetMesh
SourceFiles
cellSelection.C
\*---------------------------------------------------------------------------*/
#ifndef cellSelection_H
#define cellSelection_H
#include "dictionary.H"
#include "typeInfo.H"
#include "runTimeSelectionTables.H"
#include "autoPtr.H"
#include "boolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyMesh;
/*---------------------------------------------------------------------------*\
Class cellSelection Declaration
\*---------------------------------------------------------------------------*/
class cellSelection
{
protected:
// Protected data
//- Name
const word name_;
//- Reference to mesh
const polyMesh& mesh_;
//- Input dictionary
const dictionary dict_;
public:
//- Runtime type information
TypeName("cellSelection");
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
cellSelection,
dictionary,
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
),
(name, mesh, dict)
);
// Constructors
//- Construct from dictionary
cellSelection
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
);
//- Clone
autoPtr<cellSelection> clone() const
{
notImplemented("autoPtr<cellSelection> clone() const");
return autoPtr<cellSelection>(NULL);
}
// Selectors
//- Return a reference to the selected cellSelection
static autoPtr<cellSelection> New
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~cellSelection();
// Member Functions
//- Count global number of selected elements
static label count(const boolList&);
const word& name() const
{
return name_;
}
virtual void select(boolList&) const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "outsideCellSelection.H"
#include "addToRunTimeSelectionTable.H"
#include "faceSet.H"
#include "polyMesh.H"
#include "motionSmoother.H"
#include "regionSplit.H"
#include "syncTools.H"
#include "zeroGradientFvPatchFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace cellSelections
{
defineTypeNameAndDebug(outsideCellSelection, 0);
addToRunTimeSelectionTable(cellSelection, outsideCellSelection, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField>
Foam::cellSelections::outsideCellSelection::generateField
(
const word& name,
const boolList& lst
) const
{
const fvMesh& mesh = dynamic_cast<const fvMesh&>(mesh_);
tmp<volScalarField> tfld
(
new volScalarField
(
IOobject
(
name,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar(name, dimless, 0),
zeroGradientFvPatchScalarField::typeName
)
);
scalarField& fld = tfld().internalField();
forAll(fld, celli)
{
fld[celli] = 1.0*lst[celli];
}
tfld().correctBoundaryConditions();
return tfld;
}
void Foam::cellSelections::outsideCellSelection::markRegionFaces
(
const boolList& selectedCell,
boolList& regionFace
) const
{
// Internal faces
const labelList& faceOwner = mesh_.faceOwner();
const labelList& faceNeighbour = mesh_.faceNeighbour();
forAll(faceNeighbour, faceI)
{
if
(
selectedCell[faceOwner[faceI]]
!= selectedCell[faceNeighbour[faceI]]
)
{
regionFace[faceI] = true;
}
}
// Swap neighbour selectedCell state
boolList nbrSelected;
syncTools::swapBoundaryCellList(mesh_, selectedCell, nbrSelected);
// Boundary faces
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
forAll(pbm, patchI)
{
const polyPatch& pp = pbm[patchI];
const labelUList& faceCells = pp.faceCells();
forAll(faceCells, i)
{
label faceI = pp.start()+i;
label bFaceI = faceI-mesh_.nInternalFaces();
if
(
selectedCell[faceCells[i]]
!= selectedCell[nbrSelected[bFaceI]]
)
{
regionFace[faceI] = true;
}
}
}