/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\/ 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 . Description Set values on a selected set of cells/patchfaces through a dictionary. \*---------------------------------------------------------------------------*/ #include "argList.H" #include "timeSelector.H" #include "Time.H" #include "fvMesh.H" #include "topoSetSource.H" #include "cellSet.H" #include "faceSet.H" #include "volFields.H" using namespace Foam; template bool setCellFieldType ( const word& fieldTypeDesc, const fvMesh& mesh, const labelList& selectedCells, Istream& fieldValueStream ) { typedef GeometricField 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 internal values of " << fieldHeader.headerClassName() << " " << fieldName << endl; fieldType field(fieldHeader, mesh); const Type& value = pTraits(fieldValueStream); if (selectedCells.size() == field.size()) { field.internalField() = value; } else { forAll(selectedCells, celli) { field[selectedCells[celli]] = value; } } forAll(field.boundaryField(), patchi) { field.boundaryField()[patchi] = field.boundaryField()[patchi].patchInternalField(); } field.write(); } else { WarningIn ( "void setCellFieldType" "(const fvMesh& mesh, const labelList& selectedCells," "Istream& fieldValueStream)" ) << "Field " << fieldName << " not found" << endl; } return true; } class setCellField { public: setCellField() {} autoPtr clone() const { return autoPtr(new setCellField()); } class iNew { const fvMesh& mesh_; const labelList& selectedCells_; public: iNew(const fvMesh& mesh, const labelList& selectedCells) : mesh_(mesh), selectedCells_(selectedCells) {} autoPtr operator()(Istream& fieldValues) const { word fieldType(fieldValues); if ( !( setCellFieldType (fieldType, mesh_, selectedCells_, fieldValues) || setCellFieldType (fieldType, mesh_, selectedCells_, fieldValues) || setCellFieldType (fieldType, mesh_, selectedCells_, fieldValues) || setCellFieldType (fieldType, mesh_, selectedCells_, fieldValues) || setCellFieldType (fieldType, mesh_, selectedCells_, fieldValues) ) ) { WarningIn("setCellField::iNew::operator()(Istream& is)") << "field type " << fieldType << " not currently supported" << endl; } return autoPtr(new setCellField()); } }; }; template bool setFaceFieldType ( const word& fieldTypeDesc, const fvMesh& mesh, const labelList& selectedFaces, Istream& fieldValueStream ) { typedef GeometricField 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(fieldValueStream); // Create flat list of selected faces and their value. Field allBoundaryValues(mesh.nFaces()-mesh.nInternalFaces()); forAll(field.boundaryField(), patchi) { SubField ( 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