|
[Sponsors] |
June 13, 2017, 06:27 |
Adding layers to moving domain
|
#1 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 |
Dear Foamers,
I am trying to extrude a domain during run time by adding layers from the top boundary of the domain, as the whole liquid domain moves downwards at a constant velocity. I have modified movingConeTopoFvMesh and created a new class linearLayersFvMesh as follows: linearLayersFvMesh.H: Code:
#ifndef linearLayersFvMesh_H #define linearLayersFvMesh_H #include "topoChangerFvMesh.H" #include "motionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // Forward declaration of classes /*---------------------------------------------------------------------------*\ Class linearLayersFvMesh Declaration \*---------------------------------------------------------------------------*/ class linearLayersFvMesh : public topoChangerFvMesh { // Private data //- Motion dictionary dictionary motionDict_; //- Motion velocity amplitude vector motionVelAmplitude_; // Private Member Functions //- Disallow default bitwise copy construct linearLayersFvMesh(const linearLayersFvMesh&); //- Disallow default bitwise assignment void operator=(const linearLayersFvMesh&); //- Add mixer zones and modifiers void addZonesAndModifiers(); public: //- Runtime type information TypeName("linearLayersFvMesh"); // Constructors //- Construct from database explicit linearLayersFvMesh(const IOobject& io); //- Destructor virtual ~linearLayersFvMesh(); // Member Functions //- Update the mesh for both mesh motion and topology change virtual bool update(); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif Code:
#include "linearLayersFvMesh.H" #include "Time.T.H" #include "mapPolyMesh.H" #include "layerAdditionRemoval.H" #include "addToRunTimeSelectionTable.H" #include "meshTools.H" #include "OFstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(linearLayersFvMesh, 0); addToRunTimeSelectionTable ( topoChangerFvMesh, linearLayersFvMesh, IOobject ); } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::linearLayersFvMesh::addZonesAndModifiers() { // Add zones and modifiers for motion action if ( pointZones().size() || faceZones().size() || cellZones().size() || topoChanger_.size() ) { InfoInFunction << "Zones and modifiers already present. Skipping." << endl; return; } Info<< "Time = " << time().timeName() << endl << "Adding zones and modifiers to the mesh" << endl; // Add zones List<pointZone*> pz(1); List<faceZone*> fz(2); List<cellZone*> cz(0); // Add an empty zone for cut points pz[0] = new pointZone ( "cutPointZone", labelList(0), 0, pointZones() ); // Add empty zone for cut faces fz[0] = new faceZone ( "cutFaceZone", labelList(0), boolList(0, false), 2, faceZones() ); // Add face zone for layer addition const word layerPatchName ( motionDict_.subDict("layer").lookup("patch") ); const polyPatch& layerPatch = boundaryMesh()[layerPatchName]; labelList lpf(layerPatch.size()); forAll(lpf, i) { lpf[i] = layerPatch.start() + i; } fz[1] = new faceZone ( "linearLayerZone", lpf, boolList(layerPatch.size(), true), 0, faceZones() ); Info<< "Adding point and face zones" << endl; addZones(pz, fz, cz); // Add layer addition/removal interfaces List<polyMeshModifier*> tm(1); label nMods = 0; tm[nMods] = new layerAdditionRemoval ( "top", nMods, topoChanger_, "linearLayerZone", readScalar ( motionDict_.subDict("layer").lookup("minThickness") ), readScalar ( motionDict_.subDict("layer").lookup("maxThickness") ) ); nMods++; Info<< "Adding " << nMods << " mesh modifiers" << endl; topoChanger_.addTopologyModifiers(tm); write(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components Foam::linearLayersFvMesh::linearLayersFvMesh(const IOobject& io) : topoChangerFvMesh(io), motionDict_ ( IOdictionary ( IOobject ( "dynamicMeshDict", time().constant(), *this, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, false ) ).subDict(typeName + "Coeffs") ), motionVelAmplitude_(motionDict_.lookup("motionVelAmplitude")) { addZonesAndModifiers(); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::linearLayersFvMesh::~linearLayersFvMesh() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::linearLayersFvMesh::update() { // Do mesh changes (use inflation - put new points in topoChangeMap) autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true); // Calculate the new point positions depending on whether the // topological change has happened or not pointField newPoints; vector curMotionVel_ = motionVelAmplitude_; Pout<< "time:" << time().value() << " curMotionVel_:" << curMotionVel_ << endl; if (topoChangeMap.valid()) { Info<< "Topology change. Calculating motion points" << endl; newPoints = points() + pos(0.5) * curMotionVel_ * time().deltaT().value(); } else { Info<< "No topology change." << endl; newPoints = points() + pos(0.5) * curMotionVel_ * time().deltaT().value(); } // The mesh now contains the cells with zero volume Info << "Executing mesh motion" << endl; movePoints(newPoints); // The mesh now has got non-zero volume cells return true; } Code:
actions ( // Create faceZone for patch maxZ { name maxZFaceSet; type faceSet; action new; source patchToFace; sourceInfo { name maxZ; } } { // name maxZFaces; name linearLayerZone; type faceZoneSet; action new; source setToFaceZone; sourceInfo { faceSet maxZFaceSet; } } ); Thanks |
|
April 29, 2021, 02:47 |
|
#2 |
Member
Michael Sukham
Join Date: Mar 2020
Location: India
Posts: 79
Rep Power: 6 |
Well your case looks very similar to linearValveLayersFvMesh but without the sliding interface. I am working on foam ext 4.1 for a moving piston and changed the code to fit my motion.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Floating point exception: Zero divide | liladhar | CFX | 11 | December 16, 2013 04:07 |
CFX 11.0 "Vector Variable Normal” Does not Rotate with Domain? User Surface Moving | jrl4444 | CFX | 4 | November 14, 2013 17:46 |
[snappyHexMesh] Adding layers goes wrong with SnappyHexMesh | Elise | OpenFOAM Meshing & Mesh Conversion | 1 | April 22, 2013 02:32 |
[snappyHexMesh] SnappyHexMesh doesn't succeed in adding several layers | eti0123456789 | OpenFOAM Meshing & Mesh Conversion | 5 | April 9, 2013 02:36 |
Moving elemnt in the domain | kekko | CFX | 3 | February 21, 2007 16:17 |