CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   codedMixed boundary condition for switching between no-slip and slip (https://www.cfd-online.com/Forums/openfoam-programming-development/236378-codedmixed-boundary-condition-switching-between-no-slip-slip.html)

trailer May 27, 2021 05:28

codedMixed boundary condition for switching between no-slip and slip
 
Hello,


I would like to create a mixed boundary condition where based, on a switch, I change the boundary from no-slip to slip.


Let's assume that after 1s of simulation the walls go from no slip to slip.



For the time being I have:


Code:

myPatch
    {
        type            codedMixed;
        refValue        uniform (0 0 0);
        refGradient    uniform (0 0 0);
        valueFraction  uniform 0;

        name    myBC; 

        code
        #{

        // Access the current value of time
        const Time& time = mesh.time();

        const scalar t = time.value();

        // Loop over the patch
      forAll(patch(), faceI)
        { 

              if(t < 1)
              {
                // Imposes no-slip boundary condition
                  this->refValue()[faceI] = vector::zero;
                  this->valueFraction()[faceI] = scalar(1);
              }
              else
              {
                // Imposes slip boundary condition

                ?Help needed here?

              }
         
        }
      #};
    }


However, I am quite new at this and would appreciate the help.

gionni May 27, 2021 05:48

Hi, I have a few suggetsions for you, hoping to be of help:

1) I would put the for loop inside the if clause, since this way you have one evaluation of the if and one loop, otherwise you are evaluation the if clause multiple times, with lower performance;

2) From what I understand, the initial setup is not representing a no slip, since the fraction is 0 (you are starting with a zeroGradient basically, the flow can penetrate the wall!). You should start with a Dirichlet imposing zero velocity:

Code:

type            codedMixed;
        refValue        uniform (0 0 0);
        valueFraction  uniform 1;

        name    myBC;

(Actually you can implement a more correct no slip, which doesn't imply the stress tensor to be isotropic: you can find a detailed explanation of the theory in Moukalled's book about finite volume, at chapter 18; since that chapter is exactly about implementation of coded BCs in openfoam you could find it even more useful.

3) About your question, there are several ways you can follow to implement a slip condition, which is the equation you would like to use?

4) I don't know if you care, but you can express the switch threshold in the properties dict in the constant folder, this is an example where i get a variable called q from a dict called physicalProperties (which is defined in the solver, you could have transportProperties or something like that):
Code:

const dictionary& physicalProperties = db().lookupObject<IOdictionary>("physicalProperties");
scalar& q    = dimensionedScalar(physicalProperties.lookup("q")).value();

This way you don't need to recompile the BC to change the switch. I just put it here cause I know it takes a while to find info about codedBC, I hope it's useful.

gionni May 27, 2021 05:50

I forgot to mention the silly solution:
you can put no slip and solve till 1s, then change in the 1 folder the bc to slip and start again the simulation from 1.
This could avoid the use of a codedBC. :D

trailer May 27, 2021 05:59

Quote:

Originally Posted by gionni (Post 804775)
I forgot to mention the silly solution:
you can put no slip and solve till 1s, then change in the 1 folder the bc to slip and start again the simulation from 1.
This could avoid the use of a codedBC. :D


Thanks for the reply! But the purpose if to actually use the mixedCoded boundary.


Regarding the slip boundary. I would expect it to be the same as implemented in OF where the basicSymmetryFvPatchField is called. However, I do not know how to input this into the codedMixed :(

gionni May 27, 2021 07:00

I took a look to the code of the Bc you mention, the interesting part would be this

Code:

tmp<vectorField> nHat = this->patch().nf();

    const Field<Type> iF(this->patchInternalField());

    Field<Type>::operator=
    (
        (iF + transform(I - 2.0*sqr(nHat), iF))/2.0
    );

    transformFvPatchField<Type>::evaluate();

Honestly I can't understand what it does, since I don't know the transform function.

I guess imposing a symmetry you would need to put the orthogonal component of the velocity to zero; I don't think this would be a completely correct way, but you can try it to test the codedBC, waiting for someone else to explain the right interpretation of the BC.
At the end of the day it would be an approximation similar to no slip -> v=0, so you're basically imposing the no-penetrating condition rather than the whole symmetry.
If you decide to try this, the BC would be something like:

Code:


myPatch
    {
        type            codedMixed;
        refValue        uniform (0 0 0);
        valueFraction  uniform 1;

        name    myBC; 

        code
        #{

        // Access the current value of time
        const Time& time = mesh.time();

        const scalar t = time.value();
        vector currentVelocity;
        // Loop over the patch
      if(t < 1)
      {
                        forAll(patch(), faceI)
                        { 

                // Imposes no-slip boundary condition
                  this->refValue()[faceI] = vector::zero;
                        }
        }
        else
      {
                        forAll(patch(), faceI)
                        { 

                // no penetration only
                               
                                currentVelocity = this->refValue()[faceI];
                                this->refValue()[faceI] = currentVelocity - (currentVelocity&patch().nf()[f])&patch().nf()[f] ;
                        }
        }
      #};
    }

I can't test the code so there might be some mistakes. What I'd do is simply assign the velocity vector minus the component orthogonal to the wall (patch().nf()[f] is the face normal versor). I used the currentVelocity vector to make it more clear.
I hope it helps.


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