ENH: setFields : all face sets to set patch values

This commit is contained in:
mattijs
2010-10-15 15:41:32 +01:00
parent 1526db114b
commit b31f8894aa
46 changed files with 446 additions and 44 deletions

View File

@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description Description
Selects a cell set through a dictionary. Set values on a selected set of cells/patchfaces through a dictionary.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -32,12 +32,13 @@ Description
#include "fvMesh.H" #include "fvMesh.H"
#include "topoSetSource.H" #include "topoSetSource.H"
#include "cellSet.H" #include "cellSet.H"
#include "faceSet.H"
#include "volFields.H" #include "volFields.H"
using namespace Foam; using namespace Foam;
template<class Type> template<class Type>
bool setFieldType bool setCellFieldType
( (
const word& fieldTypeDesc, const word& fieldTypeDesc,
const fvMesh& mesh, const fvMesh& mesh,
@ -65,7 +66,8 @@ bool setFieldType
// Check field exists // Check field exists
if (fieldHeader.headerOk()) if (fieldHeader.headerOk())
{ {
Info<< " Setting " << fieldHeader.headerClassName() Info<< " Setting internal values of "
<< fieldHeader.headerClassName()
<< " " << fieldName << endl; << " " << fieldName << endl;
fieldType field(fieldHeader, mesh); fieldType field(fieldHeader, mesh);
@ -96,7 +98,7 @@ bool setFieldType
{ {
WarningIn WarningIn
( (
"void setFieldType" "void setCellFieldType"
"(const fvMesh& mesh, const labelList& selectedCells," "(const fvMesh& mesh, const labelList& selectedCells,"
"Istream& fieldValueStream)" "Istream& fieldValueStream)"
) << "Field " << fieldName << " not found" << endl; ) << "Field " << fieldName << " not found" << endl;
@ -106,17 +108,17 @@ bool setFieldType
} }
class setField class setCellField
{ {
public: public:
setField() setCellField()
{} {}
autoPtr<setField> clone() const autoPtr<setCellField> clone() const
{ {
return autoPtr<setField>(new setField()); return autoPtr<setCellField>(new setCellField());
} }
class iNew class iNew
@ -132,37 +134,200 @@ public:
selectedCells_(selectedCells) selectedCells_(selectedCells)
{} {}
autoPtr<setField> operator()(Istream& fieldValues) const autoPtr<setCellField> operator()(Istream& fieldValues) const
{ {
word fieldType(fieldValues); word fieldType(fieldValues);
if if
( (
!( !(
setFieldType<scalar> setCellFieldType<scalar>
(fieldType, mesh_, selectedCells_, fieldValues) (fieldType, mesh_, selectedCells_, fieldValues)
|| setFieldType<vector> || setCellFieldType<vector>
(fieldType, mesh_, selectedCells_, fieldValues) (fieldType, mesh_, selectedCells_, fieldValues)
|| setFieldType<sphericalTensor> || setCellFieldType<sphericalTensor>
(fieldType, mesh_, selectedCells_, fieldValues) (fieldType, mesh_, selectedCells_, fieldValues)
|| setFieldType<symmTensor> || setCellFieldType<symmTensor>
(fieldType, mesh_, selectedCells_, fieldValues) (fieldType, mesh_, selectedCells_, fieldValues)
|| setFieldType<tensor> || setCellFieldType<tensor>
(fieldType, mesh_, selectedCells_, fieldValues) (fieldType, mesh_, selectedCells_, fieldValues)
) )
) )
{ {
WarningIn("setField::iNew::operator()(Istream& is)") WarningIn("setCellField::iNew::operator()(Istream& is)")
<< "field type " << fieldType << " not currently supported" << "field type " << fieldType << " not currently supported"
<< endl; << endl;
} }
return autoPtr<setField>(new setField()); return autoPtr<setCellField>(new setCellField());
} }
}; };
}; };
template<class Type>
bool setFaceFieldType
(
const word& fieldTypeDesc,
const fvMesh& mesh,
const labelList& selectedFaces,
Istream& fieldValueStream
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (fieldTypeDesc != fieldType::typeName + "Value")
{
return false;
}
word fieldName(fieldValueStream);
IOobject fieldHeader
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
);
// Check field exists
if (fieldHeader.headerOk())
{
Info<< " Setting patchField values of "
<< fieldHeader.headerClassName()
<< " " << fieldName << endl;
fieldType field(fieldHeader, mesh);
const Type& value = pTraits<Type>(fieldValueStream);
// Create flat list of selected faces and their value.
Field<Type> allBoundaryValues(mesh.nFaces()-mesh.nInternalFaces());
forAll(field.boundaryField(), patchi)
{
SubField<Type>
(
allBoundaryValues,
field.boundaryField()[patchi].size(),
field.boundaryField()[patchi].patch().start()
- mesh.nInternalFaces()
).assign(field.boundaryField()[patchi]);
}
// Override
labelList nChanged(field.boundaryField().size(), 0);
forAll(selectedFaces, i)
{
label facei = selectedFaces[i];
if (mesh.isInternalFace(facei))
{
WarningIn("setFaceFieldType(..)")
<< "Ignoring internal face " << facei << endl;
}
else
{
label bFaceI = facei-mesh.nInternalFaces();
allBoundaryValues[bFaceI] = value;
nChanged[mesh.boundaryMesh().patchID()[bFaceI]]++;
}
}
Pstream::listCombineGather(nChanged, plusEqOp<label>());
Pstream::listCombineScatter(nChanged);
// Reassign.
forAll(field.boundaryField(), patchi)
{
if (nChanged[patchi] > 0)
{
Info<< " On patch "
<< field.boundaryField()[patchi].patch().name()
<< " set " << nChanged[patchi] << " values" << endl;
field.boundaryField()[patchi] == SubField<Type>
(
allBoundaryValues,
field.boundaryField()[patchi].size(),
field.boundaryField()[patchi].patch().start()
- mesh.nInternalFaces()
);
}
}
field.write();
}
else
{
WarningIn
(
"void setFaceFieldType"
"(const fvMesh& mesh, const labelList& selectedFaces,"
"Istream& fieldValueStream)"
) << "Field " << fieldName << " not found" << endl;
}
return true;
}
class setFaceField
{
public:
setFaceField()
{}
autoPtr<setFaceField> clone() const
{
return autoPtr<setFaceField>(new setFaceField());
}
class iNew
{
const fvMesh& mesh_;
const labelList& selectedFaces_;
public:
iNew(const fvMesh& mesh, const labelList& selectedFaces)
:
mesh_(mesh),
selectedFaces_(selectedFaces)
{}
autoPtr<setFaceField> operator()(Istream& fieldValues) const
{
word fieldType(fieldValues);
if
(
!(
setFaceFieldType<scalar>
(fieldType, mesh_, selectedFaces_, fieldValues)
|| setFaceFieldType<vector>
(fieldType, mesh_, selectedFaces_, fieldValues)
|| setFaceFieldType<sphericalTensor>
(fieldType, mesh_, selectedFaces_, fieldValues)
|| setFaceFieldType<symmTensor>
(fieldType, mesh_, selectedFaces_, fieldValues)
|| setFaceFieldType<tensor>
(fieldType, mesh_, selectedFaces_, fieldValues)
)
)
{
WarningIn("setFaceField::iNew::operator()(Istream& is)")
<< "field type " << fieldType << " not currently supported"
<< endl;
}
return autoPtr<setFaceField>(new setFaceField());
}
};
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -194,10 +359,10 @@ int main(int argc, char *argv[])
if (setFieldsDict.found("defaultFieldValues")) if (setFieldsDict.found("defaultFieldValues"))
{ {
Info<< "Setting field default values" << endl; Info<< "Setting field default values" << endl;
PtrList<setField> defaultFieldValues PtrList<setCellField> defaultFieldValues
( (
setFieldsDict.lookup("defaultFieldValues"), setFieldsDict.lookup("defaultFieldValues"),
setField::iNew(mesh, labelList(mesh.nCells())) setCellField::iNew(mesh, labelList(mesh.nCells()))
); );
Info<< endl; Info<< endl;
} }
@ -211,9 +376,11 @@ int main(int argc, char *argv[])
{ {
const entry& region = regions[regionI]; const entry& region = regions[regionI];
autoPtr<topoSetSource> cellSelector = autoPtr<topoSetSource> source =
topoSetSource::New(region.keyword(), mesh, region.dict()); topoSetSource::New(region.keyword(), mesh, region.dict());
if (source().setType() == topoSetSource::CELLSETSOURCE)
{
cellSet selectedCellSet cellSet selectedCellSet
( (
mesh, mesh,
@ -221,18 +388,41 @@ int main(int argc, char *argv[])
mesh.nCells()/10+1 // Reasonable size estimate. mesh.nCells()/10+1 // Reasonable size estimate.
); );
cellSelector->applyToSet source->applyToSet
( (
topoSetSource::NEW, topoSetSource::NEW,
selectedCellSet selectedCellSet
); );
PtrList<setField> fieldValues PtrList<setCellField> fieldValues
( (
region.dict().lookup("fieldValues"), region.dict().lookup("fieldValues"),
setField::iNew(mesh, selectedCellSet.toc()) setCellField::iNew(mesh, selectedCellSet.toc())
); );
} }
else if (source().setType() == topoSetSource::FACESETSOURCE)
{
faceSet selectedFaceSet
(
mesh,
"faceSet",
(mesh.nFaces()-mesh.nInternalFaces())/10+1
);
source->applyToSet
(
topoSetSource::NEW,
selectedFaceSet
);
PtrList<setFaceField> fieldValues
(
region.dict().lookup("fieldValues"),
setFaceField::iNew(mesh, selectedFaceSet.toc())
);
}
}
Info<< "\nEnd\n" << endl; Info<< "\nEnd\n" << endl;

View File

@ -23,6 +23,8 @@ defaultFieldValues
regions regions
( (
// Set cell values
// (does zerogradient on boundaries)
boxToCell boxToCell
{ {
box (0 0 -1) (0.1461 0.292 1); box (0 0 -1) (0.1461 0.292 1);
@ -32,6 +34,17 @@ regions
volScalarFieldValue gamma 1 volScalarFieldValue gamma 1
); );
} }
// Set patch values (using ==)
boxToFace
{
box (0 0 -1) (0.1461 0.292 1);
fieldValues
(
volScalarFieldValue gamma 1
);
}
); );
// ************************************************************************* // // ************************************************************************* //

View File

@ -102,6 +102,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -109,6 +109,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -119,6 +119,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -116,6 +116,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -115,6 +115,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -100,6 +100,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -100,6 +100,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -115,6 +115,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -105,6 +105,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet(const topoSetSource::setAction action, topoSet&) virtual void applyToSet(const topoSetSource::setAction action, topoSet&)
const; const;

View File

@ -111,6 +111,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -109,6 +109,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -105,6 +105,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -195,6 +195,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return CELLZONESOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -92,6 +92,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -120,6 +120,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -100,6 +100,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -98,6 +98,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -118,6 +118,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACESETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACEZONESOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -94,6 +94,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACEZONESOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -97,6 +97,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return FACEZONESOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -115,6 +115,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -115,6 +115,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -100,6 +100,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -100,6 +100,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -123,6 +123,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -101,6 +101,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTSETSOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -93,6 +93,11 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const
{
return POINTZONESOURCE;
}
virtual void applyToSet virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

View File

@ -67,6 +67,18 @@ public:
// Public data types // Public data types
//- Enumeration defining the types of sources
enum sourceType
{
CELLSETSOURCE,
FACESETSOURCE,
POINTSETSOURCE,
CELLZONESOURCE,
FACEZONESOURCE,
POINTZONESOURCE
};
//- Enumeration defining the valid actions //- Enumeration defining the valid actions
enum setAction enum setAction
{ {
@ -268,6 +280,8 @@ public:
// Member Functions // Member Functions
virtual sourceType setType() const = 0;
virtual void applyToSet(const setAction action, topoSet&) const = 0; virtual void applyToSet(const setAction action, topoSet&) const = 0;
}; };

View File

@ -6,10 +6,9 @@ cd ${0%/*} || exit 1 # run from this directory
application=`getApplication` application=`getApplication`
compileApplication ../../buoyantPimpleFoam/hotRoom/setHotRoom
runApplication blockMesh runApplication blockMesh
cp 0/T.org 0/T cp 0/T.org 0/T
runApplication setHotRoom runApplication setFields
runApplication $application runApplication $application
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file

View File

@ -6,10 +6,9 @@ cd ${0%/*} || exit 1 # run from this directory
application=`getApplication` application=`getApplication`
compileApplication ../../buoyantPimpleFoam/hotRoom/setHotRoom
runApplication blockMesh runApplication blockMesh
cp 0/T.org 0/T cp 0/T.org 0/T
runApplication setHotRoom runApplication setFields
runApplication $application runApplication $application
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file

View File

@ -6,6 +6,5 @@ cd ${0%/*} || exit 1 # run from this directory
cleanCase cleanCase
cp 0/T.org 0/T cp 0/T.org 0/T
wclean setHotRoom
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file

View File

@ -7,9 +7,8 @@ cd ${0%/*} || exit 1 # run from this directory
# Get application name # Get application name
application=`getApplication` application=`getApplication`
compileApplication setHotRoom
runApplication blockMesh runApplication blockMesh
runApplication setHotRoom runApplication setFields
runApplication $application runApplication $application
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file

View File

@ -6,9 +6,8 @@ cd ${0%/*} || exit 1 # run from this directory
application=`getApplication` application=`getApplication`
compileApplication ../../buoyantPimpleFoam/hotRoom/setHotRoom
runApplication blockMesh runApplication blockMesh
runApplication setHotRoom runApplication setFields
runApplication $application runApplication $application
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file