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

How to generate the time-dependent random actuation in codeStream

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 15, 2019, 13:42
Default How to generate the time-dependent random actuation in codeStream
  #1
New Member
 
Hao Li
Join Date: May 2017
Posts: 7
Rep Power: 9
haolee0928 is on a distinguished road
Dear Openfoam ponieers

I am simulating a compressible mixing layer by means of Openfoam. My flow domain is very simple, just a rectangular. My inlet profile is tanh shape which defines a upper flow and lower flow with different velocity : 0.5*(U_1+U_2)+0.5*(U_1-U_2)*tanh(2*y/thick).

I used codeStream to do this. Now I have a trouble as following:


To promote the mixing layer instability, I add the white noise actuation in the v component of the velocity. But it won't changed every time step. the data is always the same in every time step. This has been confirmed after I extracted inlet profile of every time step.



Could you help me about this?


The next step, i will build a closed-loop in the Openfoam: the inlet v component velocity will be an actuation of the mixing layer and it is determined by an equation. The input of this equation is the velocities of a few points in the flow domain in the last time step.

Besides, there are 50 cases with 50 different equations. That means the equations should be read into the case from external files not be modified manually. Could you help me with a roadmap?



Here are my code for the inlet profile:

I tried two methods but both cannot work.

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

internalField uniform (0 0 0);

boundaryField
{
IN
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#include <random> /*generate the random number*/
#include <ctime> /* get the system number */
#include <iostream> /*Input and output*/
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-std=c++11
/* EXE_INC= "-std=c++11 -03"*/
/* -I...... \ */
/* $(CPP_DEP)\ */
/* EXE_INC='-std=gnu++11'*/
/* MAKE_CXX_FLAGS "-std=c++11 -03"*/
/* EXE_INC=\
'-std=c++11'*/
#};

//libs needed to visualize BC in paraview
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("IN");
const fvPatch& patch = mesh.boundary()[id];
//vectorField U(mesh.boundary()[id].size(), vector(0, 0, 0));
vectorField U(patch.size(), vector(0, 0, 0));


/* const scalar pi = constant::mathematical:i;*/
const scalar U_1 = 1151.6; //the upper velocity
const scalar U_2 = 669.1; // the lower velocity
const scalar thick = 0.198; //vorticity thickness unit mm
/* const Random randObj(time(NULL));*/
/* const scalar Uy = randobj.scalar01()*10*/
/* const scalar p_r = 8. */ //patch radius*/
cout << "add white noise";
std::default_random_engine e(time(0));
std::uniform_real_distribution<double> u(-10.0,10.0);
/* generate the white noise */
/* end the white noise */
forAll(U, i)
{
const scalar y = patch.Cf()[i][1];
//U[i] = vector(U_0*sin(pi*y/r), 0., 0.);
U[i] = vector(0.5*(U_1+U_2)+0.5*(U_1-U_2)*tanh(2*y/thick), u(e), 0.);
}
for(int i = 0; i < 1000;++i)
cout << u(e) <<endl;
/*return 0;*/
/*
for (int i; i<patch.size() ; i++)
{
const scalar y = patch.Cf()[i][1];
U[i] = vector(U_0*(1-(pow(y - p_ctr,2))/(p_r*p_r)), 0., 0.);
}
*/
U.writeEntry("", os);
#};
};
}







IN
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#include "Random.H"
#include "clock.H"
#include <iostream> /*Input and output*/
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
/* EXE_INC= "-std=c++11 -03"*/
/* -I...... \ */
/* $(CPP_DEP)\ */
/* EXE_INC='-std=gnu++11'*/
/* MAKE_CXX_FLAGS "-std=c++11 -03"*/
/* EXE_INC=\
'-std=c++11'*/
#};

//libs needed to visualize BC in paraview
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("IN");
const fvPatch& patch = mesh.boundary()[id];
//vectorField U(mesh.boundary()[id].size(), vector(0, 0, 0));
vectorField U(patch.size(), vector(0, 0, 0));


/* const scalar pi = constant::mathematical:i;*/
const scalar U_1 = 1151.6; //the upper velocity
const scalar U_2 = 669.1; // the lower velocity
const scalar thick = 0.198; //vorticity thickness unit mm
/* const Random randObj(time(NULL));*/
/* const scalar Uy = randobj.scalar01()*10*/
/* const scalar p_r = 8. */ //patch radius*/
cout << "add white noise";
/* generate the white noise */
/* end the white noise */
Random ranGen( clock::getTime() + pid());
scalar v = ranGen.integer(1,100);
forAll(U, i)
{
const scalar y = patch.Cf()[i][1];
//U[i] = vector(U_0*sin(pi*y/r), 0., 0.);
U[i] = vector(0.5*(U_1+U_2)+0.5*(U_1-U_2)*tanh(2*y/thick), v, 0.);
}
/* for(int i = 0; i < 1000;++i)
cout << ranGen.integer(1,100) <<endl;
return 0;*/
/*
for (int i; i<patch.size() ; i++)
{
const scalar y = patch.Cf()[i][1];
U[i] = vector(U_0*(1-(pow(y - p_ctr,2))/(p_r*p_r)), 0., 0.);
}
*/
U.writeEntry("", os);
#};
};
}
haolee0928 is offline   Reply With Quote

Old   May 16, 2019, 16:26
Default
  #2
New Member
 
Hao Li
Join Date: May 2017
Posts: 7
Rep Power: 9
haolee0928 is on a distinguished road
Thanks a lot everyone. I have finished it and coded the boundary by codedFixedValue.


It can work well.
haolee0928 is offline   Reply With Quote

Reply

Tags
codestream; mixing layer;


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
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 42 May 8, 2024 00:17
[General] Extracting ParaView Data into Python Arrays Jeffzda ParaView 30 November 6, 2023 22:00
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 05:13
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 14:58
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 08:56


All times are GMT -4. The time now is 14:44.