diff --git a/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/controlDict b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/controlDict index 58b7d5222e..a417bf71a5 100644 --- a/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/controlDict +++ b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/controlDict @@ -51,4 +51,9 @@ maxCo 1; maxDeltaT 1; +functions +{ + #include "relVelocity" +} + // ************************************************************************* // diff --git a/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity new file mode 100644 index 0000000000..5d0eb1e1e6 --- /dev/null +++ b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity @@ -0,0 +1,118 @@ +// --------------------------------*- C++ -*-------------------------------- // +// +// File +// OpenFOAM coded function object +// +// Description +// Write relative rotational speed +// +// ------------------------------------------------------------------------- // + +relVelocity +{ + type coded; + name relVelocity; + libs ( utilityFunctionObjects ); + + coeffs + { + // User input (duplicate of constant/dynamicMeshDict) + // origin (-3 2 2.6); + // axis (0 0 1); + // omega 10; + // zones ( rotatingZone ); + + #sinclude "/dynamicMeshDict" + } + + // Additional context for code execute/write + codeContext + { + verbose true; + } + + codeData + #{ + vector origin; + vector omega; + wordRes zoneNames; + #}; + + codeRead + #{ + const dictionary& coeffs = dict.optionalSubDict("coeffs"); + const dictionary& context = this->codeContext(); + + origin = coeffs.get("origin"); + + omega = + ( + // speed + ( + coeffs.found("rpm") + ? degToRad(coeffs.get("rpm") / 60.0) + : coeffs.get("omega") + ) + // axis + * normalised(coeffs.getOrDefault("axis", vector(0,0,1))) + ); + + if (!coeffs.readIfPresent("zones", zoneNames)) + { + if (coeffs.found("cellZone")) + { + zoneNames.resize(1); + coeffs.readEntry("cellZone", zoneNames[0]); + } + } + + if (context.getOrDefault("verbose", false)) + { + Log<< "Relative velocity at origin " << origin << "\n"; + } + #}; + + codeExecute // codeWrite + #{ + const dictionary& context = this->codeContext(); + + if (context.getOrDefault("verbose", false)) + { + Log<< "Calculate relative velocity\n"; + } + + const auto& cc = mesh().C(); + const auto& U = mesh().lookupObject("U"); + + auto trelVel = volVectorField::New + ( + "relVelocity", + mesh(), + dimensionedVector(dimVelocity, Zero), + "zeroGradient" + ); + auto& relVel = trelVel.ref(); + auto& relVelField = relVel.primitiveFieldRef(); + + if (zoneNames.empty()) + { + for (label celli = 0; celli < mesh().nCells(); ++celli) + { + relVelField[celli] = U[celli] - (omega ^ (cc[celli] - origin)); + } + } + else + { + for (const label celli : mesh().cellZones().selection(zoneNames)) + { + relVelField[celli] = U[celli] - (omega ^ (cc[celli] - origin)); + } + } + + relVel.correctBoundaryConditions(); + relVel.write(); + #}; +} + + +// ************************************************************************* // diff --git a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U index 3b184908a7..d6bb5b1805 100644 --- a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U +++ b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U @@ -1,14 +1,14 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2012 | +| \\ / O peration | Version: v2106 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; - format binary; + format ascii; class volVectorField; object U; } @@ -25,13 +25,82 @@ boundaryField type uniformFixedValue; value $internalField; - uniformValue table - ( - (0 (0 0 0.1)) - (1 (0 0 0.1)) - (4 (0 0 0.3)) - (14 (0 0 0.5)) - ); + uniformValue + { + type coded; + name examplePatchFunction1; + + // Example code to combine/adapt Function1 to PatchFunction1 + + // User inputs + + /// verbose true; + + timeFunction + { + type table; + + values + ( + (0 0.1) + (1 0.1) + (4 0.3) + (14 0.5) + ); + } + + // ... or a function of time + directionFunction (0 0 1); + + // Code implementation. + code + #{ + // Persistent (Member) Data + static autoPtr> baseVel; + static autoPtr> baseDir; + + // Base settings + const dictionary& dict = this->dictionaryContent::dict(); + + const polyPatch& pp = this->patch(); + + vector velDir(0, 0, 1); + + if (!baseVel) + { + baseVel = Function1::New("timeFunction", dict); + } + + const bool verbose = dict.getOrDefault("verbose", false); + + if (!baseDir && dict.found("directionFunction")) + { + // ie, NewIfPresent + baseDir = Function1::New("directionFunction", dict); + + InfoErr + << "Function1 for direction" << nl; + } + + if (baseDir) + { + velDir = normalised(baseDir->value(x)); + } + + if (verbose) + { + InfoErr + << "vel: " << baseVel->value(x) + << " dir:" << velDir << nl; + } + + return tmp::New + ( + pp.size(), + baseVel->value(x) * velDir + ); + #}; + } } outlet