CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

codedFIxedValue, writing only to Z-Component of an Inletpatch

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By fanta
  • 1 Post By fanta

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2018, 10:20
Arrow codedFIxedValue, writing only to Z-Component of an Inletpatch
  #1
Member
 
Join Date: Oct 2011
Posts: 49
Rep Power: 14
fanta is on a distinguished road
Hi,

i am working on a codedFixedValue Boundarycondition and i am stuck.
At the inlet i want to read the calculated rho from the field and correct the mass flow rate with the continuity equation. It starts with a rho read from the file rho.
Here ist my U file:


Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.1.x                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {    
        type            codedFixedValue;
    value        uniform (0 0 0.011449586); //5kg/h in +Z-Direction respectiv to the inlet;
    redirectType    rho_corrected;
    code
    #{
        const fvPatch& boundaryPatch = this->patch(); 
        vectorField& U = *this;
             const vectorField& Cf = boundaryPatch.Cf();
        scalar patchArea = gSum(boundaryPatch.magSf());
         const volScalarField& rhop = this->db().lookupObject<volScalarField>("rho");
        const scalar m_dot = 5.0/3600.0; // 5 kg/h Massflowrate
        volScalarField v = (m_dot/(rhop*patchArea)); //Continuity Equation
//        tmp<vectorField> n = this->patch().nf();
        fixedValueFvPatchVectorField myPatch(*this);
        forAll(this->patch().Cf(),i)
        {
            myPatch[i]=vector(0,0,v);
//            myPatch[i]=vector(0,0,0.011449586);
        }
        operator==(myPatch);
    #};
    }
    outlet
    {
        type            zeroGradient;
    }

    wall
    {
        type            noSlip;
    }
    defaultFaces
    {
    type         fixedValue;
    value        uniform (0 0 0);
    }
}
Can someone help me? It doesn't run because of this line:
myPatch[i]=vector(0,0,v);


in the For loop. Seems i cannot apply v as a component to a vector. How do i do this? v is from the type volScalarField, vector is a vector (of which type of components?).
Kummi likes this.
fanta is offline   Reply With Quote

Old   May 12, 2018, 11:28
Default
  #2
Senior Member
 
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12
Taataa is on a distinguished road
Because you've defined v as a field then you've used it as a scalar!


Either directly calculate v in the loop using rhop[i] or use v[i].
Taataa is offline   Reply With Quote

Old   May 12, 2018, 12:55
Default
  #3
Member
 
Join Date: Oct 2011
Posts: 49
Rep Power: 14
fanta is on a distinguished road
Thanks for the hint, this is the code:


Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.1.x                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {    
        type            codedFixedValue;
    value        uniform (0 0 0.011449586); //5kg/h in +Z-Direction respectiv to the inlet;
    redirectType    rho_corrected;
    code
    #{
        const fvPatch& boundaryPatch = this->patch(); 
        vectorField& U = *this;
             const vectorField& Cf = boundaryPatch.Cf();
        scalar patchArea = gSum(boundaryPatch.magSf());
         const volScalarField& rhop = this->db().lookupObject<volScalarField>("rho");
        const scalar m_dot = 5.0/3600.0; // 5 kg/h Massflowrate
//        scalar v = (m_dot/(rhop[2]*patchArea));
        fixedValueFvPatchVectorField myPatch(*this);
        forAll(this->patch().Cf(),i)
        {
            myPatch[i]=vector(0,0, (m_dot/(rhop[2]*patchArea)));
        }
        operator==(myPatch);
    #};
    }
    outlet
    {
        type            zeroGradient;
    }

    wall
    {
        type            noSlip;
    }
    defaultFaces
    {
    type         fixedValue;
    value        uniform (0 0 0);
    }
}

// ************************************************************************* //
Zhiheng Wang likes this.
fanta is offline   Reply With Quote

Old   May 24, 2018, 10:28
Default
  #4
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Quote:
Originally Posted by fanta View Post
Thanks for the hint, this is the code:


Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.1.x                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {    
        type            codedFixedValue;
    value        uniform (0 0 0.011449586); //5kg/h in +Z-Direction respectiv to the inlet;
    redirectType    rho_corrected;
    code
    #{
        const fvPatch& boundaryPatch = this->patch(); 
        vectorField& U = *this;
             const vectorField& Cf = boundaryPatch.Cf();
        scalar patchArea = gSum(boundaryPatch.magSf());
         const volScalarField& rhop = this->db().lookupObject<volScalarField>("rho");
        const scalar m_dot = 5.0/3600.0; // 5 kg/h Massflowrate
//        scalar v = (m_dot/(rhop[2]*patchArea));
        fixedValueFvPatchVectorField myPatch(*this);
        forAll(this->patch().Cf(),i)
        {
            myPatch[i]=vector(0,0, (m_dot/(rhop[2]*patchArea)));
        }
        operator==(myPatch);
    #};
    }
    outlet
    {
        type            zeroGradient;
    }

    wall
    {
        type            noSlip;
    }
    defaultFaces
    {
    type         fixedValue;
    value        uniform (0 0 0);
    }
}

// ************************************************************************* //
Excellent work thanks
Zhiheng Wang is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 58 December 23, 2021 02:36
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 05:38
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
[snappyHexMesh] crash sHM H25E OpenFOAM Meshing & Mesh Conversion 11 November 10, 2014 11:27


All times are GMT -4. The time now is 05:55.