CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

Variation of boundary condition using codedFixedValue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 15, 2023, 09:14
Default Variation of boundary condition using codedFixedValue
  #1
New Member
 
Clément Pélissier
Join Date: May 2023
Posts: 5
Rep Power: 3
clempel is on a distinguished road
Hello,

I am on a project on which one I want build a variation of the boundary condition of the slope. For this, I use codedFixedValue and want to retrieve the time of the simulation and the endtime of the simulation as a scalar as it runs. But I can't find the good function or syntaxe to retrieve these both values. I work on OpenFOAM 9.
Here is the code to let you understand what I want to explain.
I hope that someone can help me.
Thank you very much in advance,

Clément

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*-----------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       volScalarField;
    location    "0";
    object      T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [ 0 0 0 1 0 0 0 ];

internalField   uniform 296.15;

boundaryField
{
    ground
    {
        type            fixedValue;
        value           uniform 296.15;
    }   

    slope
    {
    type            codedFixedValue;
    value           uniform 0;  // initial value
    name            variationHeatFlux;
    code
    #{
        #include "createTime.H"
        #include "Time.H"


        const fvPatch& patch = this->patch();
        const vectorField& cf = patch.Cf();
        scalarField& field = *this;
        forAll(cf, i)
        {
            const scalar currentTime = runTime.time();  // current time of the simulation
            const scalar endTime = runTime.endtime();  // end of the simulation
            const scalar tStart = 0;         // initial time
            const scalar gradStart = 0;    // initial gradient
            const scalar gradMax = 758.99;     // maximal gradient
            const scalar tMax = endTime/2;         // maximal gradient time (half of the simulation)
            const scalar gradDecrease = gradMax/tMax;  // decrease step after reach maximum

            scalar grad;
            if (currentTime <= tMax)
            {
                grad = gradStart + (gradMax - gradStart) * (currentTime - tStart) / (tMax - tStart);
            }
            else
            {
                grad = gradMax - gradDecrease * (currentTime - tMax) / (endTime - tMax);
            }

            field[i] = grad;
        }
    #};
    }
    ceiling
    {
        type            fixedValue;
        value           uniform 296.15;
    }
    front
    {
        type            symmetryPlane;
    }
    back //maybe here we need to use frontandback with zerogradient
    {
        type            fixedValue;
        value           uniform 296.15;
    }
    right //maybe here we need to use sideWalls with zerogradient
    {
        type            cyclic;
    }
    left
    {
        type            cyclic;
    }
}
clempel is offline   Reply With Quote

Old   July 5, 2023, 03:45
Default
  #2
New Member
 
Join Date: Jun 2023
Location: Brest
Posts: 21
Rep Power: 3
CFDUser29 is on a distinguished road
I am new to openfoam, but if you set a good writing step in controlDict, shouldn't it be enough ?

I notice that you might forgot a "const" before "scalar grad".
CFDUser29 is offline   Reply With Quote

Old   July 7, 2023, 03:56
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
You mostly have the right idea except for the fatal mistake of using 'include "createTime.H"' within your code. This is definitely not what you want!
It goes off and tries to create TIme by reading the system/controlDict (every time that you call the boundary condition). It also means that that particular Time you have created corresponds to the time state at the start of the simulation.

What you do want is to go from the *this (the boundary condition) back upwards, for example:
Code:
// Starting from the fvPatchField (*this)
const Time& runTIme = this->db().time();
...
https://www.openfoam.com/documentati...atchField.html


Oh, and it would be cleaner to grab the current/end times outside of the loop! If you rework the code you'll see that it reduces down to a single value, which you can then assign to the entire field in one step.
olesen is offline   Reply With Quote

Reply

Tags
codedfixedvalue, openfoam9, runtime


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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 08:38
CFD analaysis of Pelton turbine amodpanthee CFX 31 April 19, 2018 19:02
Problem in setting Boundary Condition Madhatter92 CFX 12 January 12, 2016 05:39
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00


All times are GMT -4. The time now is 12:11.