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

How to update Boundary Condition in the loop with #codeStream?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2024, 03:56
Default How to update Boundary Condition in the loop with #codeStream?
  #1
New Member
 
Teddy Liu
Join Date: May 2024
Posts: 5
Rep Power: 2
TeddyL is on a distinguished road
Hi, everyone!

I'm trying to update the boundary condition as the mesh moves using #codeStream, here is a more detailed description for my problem:

I managed to make my own outlet poiseuille flow boundary condition, which gives a parabolic velocity distribution using #codeStream, the codes are like this in 0/U:

Code:
outlet
    {
        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());
                label id = mesh.boundary().findPatchID("outlet");
                if (id ==-1)
                {
                    FatalError << "patch not found!" << exit(FatalError);
                }

                const fvPatch& patch = refCast<const fvPatch>(mesh.boundary()[id]);

                vectorField NF(patch.nf());

                vectorField U(NF); 

                const scalar pi = constant::mathematical::pi;

                const vector patch_Center = vector(1,0.25,0);
                const scalar patch_R = 0.1;

                const scalar flow_Flux = 0.1; 
                const scalar U_max = 2 * flow_Flux / (pi * pow(patch_R,4));

                forAll(U, i)
                {
                    const scalar x = patch.Cf()[i][0];
                    const scalar y = patch.Cf()[i][1];
                    U[i] = (U_max*(pow(patch_R,2)-pow(x-patch_Center[0],2)-pow(y-patch_Center[1],2)))*NF[i];
                }

                const scalarField area = patch.magSf();
                vectorField pointed_area = patch.Sf();
                scalar areaTotal = gSum(area);
                scalar realize_Flux = mag(gSum((U & pointed_area)()));

                vectorField U_fix(U);
                forAll(U_fix, i)
                {
                    U_fix[i] = U_fix[i] - ((flow_Flux - realize_Flux)/areaTotal)*NF[i];
                }
                
                U_fix.writeEntry("", os);
            #};
        };
    }
I did a kind of fixing to the velocity to make sure the flow flux is consistent with the intended one, i.e. 0.1. It worked well in steady cases where the mesh does't move, and gives a parabolic velocity at the outlet patch that is normal to the patch surface.

The problem occurred when I tried to set the whole mesh to an oscillatingRotatingMotion centered at the outlet patch center. I monitored the outlet flow from the outlet patch, and it gave a sinusoidal curve in a period:

flux.png

which means that the velocity at the patch is no longer normal to the patch face. I checked it in paraView, and it obviously is not normal to the patch according to a closer look around the outlet patch:

detail.png

So the problem here is:

How can I set this boundary condition to get a parabolic velocity field at the patch that is always normal to the patch face? I firstly wanted to realize it with #codeStream, or do I have to use high-level programming? Because I noticed there is a function called "updateCoeffs()" I wondered if it has anything to do with my problem.

This is my first thread here, and sorry for this long story. And any suggestions will be appreciated!

Regards,
Teddy
TeddyL is offline   Reply With Quote

Reply

Tags
boundary condition, codestream, dynamic mesh


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
UDF for Automatic Solution Initialization for previous case data file gartz89 Fluent UDF and Scheme Programming 6 March 30, 2020 08:38
My radial inflow turbine Abo Anas CFX 27 May 11, 2018 02:44
Out File does not show Imbalance in % Mmaragann CFX 5 January 20, 2017 11:20
External Radiation Boundary Condition (Two sided wall), Grid Interface CFD XUE FLUENT 0 July 8, 2010 07:49
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 16:57


All times are GMT -4. The time now is 09:53.