Node assignment problem

Hi,

I am trying to assign the random number to each lattice node. The random number looks like the marking of the node. But I am failed. The command I used is as below:


for (int iX=0; iX<nx; ++iX) {
        for (int iY=0; iY<ny; ++iY) {

	lattice.get(iX,iY) = (rand()%10)+1;    // set random number from 1 to 10 to the lattice node.
    }
}

I think I can not use the lattice.get(iX, iY) to store the random number, but I donot know what can do that. Do anyone know what I can do? Thank you in advance for any help.

Hello,

the get(iX,iY) method returns a cell. A cell is made of different things. Among them the f_i’s are stored there. I guess that what you want to do is to assign a random number to each f_i. TO access them you have to use the brackets :

lattice.get(iX,iY)[iPop]

returns f[iPop]. Then you can assign the random number to each f_i.

I hope it helps.

Orestis

Hi Orestis,

Thanks for your reply. I am confused of another problem. If I assign the randonm number to each f_i, do you think the random number will affect the result of CollideAndStream. Actually, what I want to do is to assign the obstacles on stochastic site in the domain. It is aimed to achieve the porous medium in the domain. Do you have any suggestions? Thank you!

I’m a bit confused because I’m not sure to understand what you are trying to do.

If you are trying to simulate a porous media. Then you should not change the values of the f_i (of the populations) but rather put “walls” in your domain. To do so you should define bounceBack nodes on random places (I think that’s what you want to do). This means that you will change the dynamics of your nodes and not the f_i (the behavior during the collision will be different). Look into the examples of OpenLB to see how to define bounceBack nodes.

I hope it helps.

Orestis

Thank you. Yes, you are right. I really want to define bounceBack nodes on random places. I have found the method to define the bouceBack nodes in the examples. However, I want to find an easy way to define the sites of obstacles (not to define the bounceback site one by one), becasue there are a number of obstacles (bounce back nodes) in the porous medium, I thought maybe the rendon() should make it come true (C++). Firstly, a random number is given to each node. Secondly, the bounceBack nodes are defined by limitation of the random number as below


for (int iX=0; iX<nx; ++iX) {
        for (int iY=0; iY<ny; ++iY) {

	lattice.get(iX,iY) = (rand()%10)+1;    // set random number from 1 to 10 to the lattice node.
    }
}
  if ( lattice.get(iX,iY)< 8 )
            {
               lattice.defineDynamics( iX,iX,iY,iY,
                        &instances::getBounceBack<T,DESCRIPTOR>() );
            }

But I am failed. Do you have any suggestions to define the bounceback nodes on random places? Thank you very much.

As I told you in a preceding post. lattice.get(iX,iY) return a Cell object. The cell object contains the f_i, a pointer to a dynamic, and different other methods.

You therefore cannot give a integer value to a cell :

lattice.get(iX,iY) = 1

will not compile since 1 is not of type cell but of type integer.

Four your purpose you should simply write some thing like :

for (int iX=0; iX<nx; ++iX) {
for (int iY=0; iY<ny; ++iY) {

if ( (rand()%10)+1 < 8)    // set random number from 1 to 10 to the lattice node.
   {
          lattice.defineDynamics( iX,iX,iY,iY,
                    &instances::getBounceBack<T,DESCRIPTOR>() );
    }
}

}

Good luck.

Orestis

Thank you very much! Your response is really useful. Thanks again.