CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Problem in codestream for applying time dependent boundary condition in OF V1906/2112 (https://www.cfd-online.com/Forums/openfoam-solving/243725-problem-codestream-applying-time-dependent-boundary-condition-v1906-2112-a.html)

chandra shekhar pant July 3, 2022 04:52

Problem in codestream for applying time dependent boundary condition in OF V1906/2112
 
Dear Foamers,
For a couple of weeks I am trying to write a time dependent boundary condition for pressure, after looking multiple post in the CFD Online, I found that codeStream boundary condition could do that (also swak4FOAM could do that, but unfortunately I am unable to compile that). This code runs and compiles well with OF v 1906/2112 but it's actually not been able to calculate the time variable, instead it is treating "t" as variable with value 0.
Code:

source
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};

codeLibs
#{
-lmeshTools \
-lfiniteVolume
#};

code
#{
const IOdictionary& d = static_cast<const IOdictionary&>
(
dict.parent().parent()
);
const fvMesh& mesh = refCast<const fvMesh>(d.db());
const label id = mesh.boundary().findPatchID("source");
const fvPatch& patch = mesh.boundary()[id];
scalarField p(patch.size(), scalar(0));

const scalar t = d.db().time().value();
scalar t2 = t-tp*(floor(t/tp)); //
const scalar tp = 0.035;
const scalar tf = 0.0116;
{
forAll(p, i)
{
{
if (t2<tf)
{
p[i] = 1000000.0*t;
}
if (t2>=tf && t2<=tp)
{
p[i] = 1.0*(t-0.01);
}
}
}
}

p.writeEntry("", os);


#};
};

 }


Any comment/suggestion would be a great help, thanks in advance.

chandra shekhar pant July 14, 2022 03:16

I am still struggling with this issue, could any one please help.

chandra shekhar pant July 14, 2022 08:28

Hello again,

After struggling for a very quite long time, finally I managed to get the things working using the instructions given in the link http://www.wolfdynamics.com/wiki/pro...streamINIT.pdf



Previously maybe I was messing up with the initial condition and boundary condition. I have done the following to make it work (could be useful to someone):



Code:

source
    {
      type            codedFixedValue;
      value            uniform 0;
      name            inletProfile2;
     
    code
    #{

      const fvPatch& boundaryPatch = patch();
        const vectorField& Cf = boundaryPatch.Cf();
        scalarField& p = *this;
        p = patchInternalField();
        scalar t = this->db().time().value();
      const scalar tf = 0.5;
    const scalar tp = 1.0;

  forAll(p, i)
        {
       
        {
            if (t<=tf)
            {
                    p[i] = 1000000.0*t;
                   
                   
            }
            if (t>=tf && t<=tp)
            {
                p[i] = 1.0*(t-0.01);   
               
            }
           
            } 
       
        }
    #};
  }



All times are GMT -4. The time now is 06:54.