/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . Application setExprFields Group grpPreProcessingUtilities Description Set values on a selected set of cells/patch-faces via a dictionary. Note Based on funkySetFields from Bernhard Gschaider \*---------------------------------------------------------------------------*/ #include "argList.H" #include "Time.H" #include "fvMesh.H" #include "pointMesh.H" #include "volFields.H" #include "surfaceFields.H" #include "pointFields.H" #include "exprOps.H" #include "volumeExprDriver.H" #include "timeSelector.H" #include "readFields.H" using namespace Foam; using FieldAssociation = expressions::volumeExpr::FieldAssociation; word fieldGeoType(const FieldAssociation geoType) { switch (geoType) { case FieldAssociation::VOLUME_DATA : return "cells"; break; case FieldAssociation::SURFACE_DATA : return "faces"; break; case FieldAssociation::POINT_DATA : return "points"; break; default: break; } return "unknown"; } //- Simple control structure to with collected switches to simplify passing struct setExprFieldsControl { bool dryRun; bool debugParsing; bool cacheVariables; bool useDimensions; bool createNew; bool keepPatches; bool correctPatches; bool correctBCs; IOstreamOption streamOpt; }; template void doCorrectBoundaryConditions ( bool correctBCs, GeometricField& field ) { if (correctBCs) { Info<< "Correcting boundary conditions: " << field.name() << nl; field.correctBoundaryConditions(); } } template void doCorrectBoundaryConditions ( bool correctBCs, GeometricField& field ) { if (correctBCs) { Info<< "Correcting boundary conditions: " << field.name() << nl; field.correctBoundaryConditions(); } } template void doCorrectBoundaryConditions ( bool correctBCs, GeometricField& field ) {} template void setField ( const word& fieldName, const Mesh& mesh, const GeoField& result, const scalarField& cond, const dimensionSet& dims, const wordList& valuePatches, const setExprFieldsControl& ctrl ) { Info<< "setField(" << fieldName << "): " << pTraits::typeName << endl; tmp toutput; if (ctrl.createNew) { // Create with zero toutput = GeoField::New ( fieldName, mesh, dimensioned(dims) ); } else { // Read toutput = tmp::New ( IOobject ( fieldName, mesh.thisDb().time().timeName(), mesh.thisDb(), IOobject::MUST_READ, IOobject::NO_WRITE, false // No register ), mesh ); } auto& output = toutput.ref(); label setCells = 0; if (cond.empty()) { // No condition - set all output = result; setCells = output.size(); } else { forAll(output, celli) { if (expressions::boolOp()(cond[celli])) { output[celli] = result[celli]; ++setCells; } } } const label totalCells = returnReduce(output.size(), plusOp