CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   How to distribute particles randomly at initial time (https://www.cfd-online.com/Forums/openfoam-pre-processing/199205-how-distribute-particles-randomly-initial-time.html)

Jim Shi February 28, 2018 09:40

How to distribute particles randomly at initial time
 
Dear All,

I would like to simulate a channel turbulent flow with particles by using DPMFoam, there should be constant 20000 particles in the field for each time step.

My question is how to inject those 20000 particles into the field randomly at initial time, if I specify manualInjection in "kinematicCloudProperties" and use a "kinematicCloudPositions" file to specify the location of each particle, it would be troublesome.

Is there any better solution? Please let me know is you are aware of this..

Thank you!

SimonStar May 25, 2020 03:23

Hi,

I know that the answer is a little bit late and maybe you already found other help.

What I would try to do is to programm a small code that can create you the random positions in a X/Y/Z-Space. You can write them out of your programm as a .txt-File. That means you can use any programming language that you want (not necessarily C++).

Have you already exeriances with programming?

Simon

SimonStar May 25, 2020 06:10

Hello again,


i was writing a python-program for generating the random numbers and saving them in a file.

I put it in this post. If you want you can just copy it, paste it in your python-editor and edit the parameters.
Maybe there are better way to have the same result. So let me know if you found one.

Code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 10:52:19 2020

@author: simon
"""
# =============================================================================
# Program to generate random positions in a 3D box.
# Replace the positions in your kinematicCloudPositions-file with the points
# out of the file produced by this python script.
# =============================================================================

#import scipy.interpolate as si
import numpy as np

#Number of positions and size of cubic space where they can be
noOfPositions = 2000

xMin = -0.0025
xMax =  0.0025
yMin = -0.0025
yMax =  0.0025
zMin = -0.0025
zMax =  0.0025

# round the float numbers to a number of digits
xRound = 6
yRound = 6
zRound = 6

# create a new file and open it.
# Write also the Path from program-folder to saving-folder
file = open('Files/positions.txt', 'w')

file.write('( \n')

# create random numbers for X/Y/Z
for i in range(noOfPositions):
    xRand = np.round( np.random.uniform(xMin, xMax) ,xRound)
    yRand = np.round( np.random.uniform(yMin, yMax) ,yRound)
    zRand = np.round( np.random.uniform(zMin, zMax) ,zRound)
   
    # Write the random numbers in the file
    file.write('('+ str(xRand) +' '+ str(yRand) +' '+ str(zRand) +') \n')
   
file.write(') \n')

file.close()

As far as I am, the program is not checking if particles are created very close to each other. So they could possibly crash into each other afer calculating in openfoam.


Thank you
Simon

SimonStar May 28, 2020 05:08

Sorry to answer myself always :D


can someone help me how to inject particles instead at a single timepoint in a specified timeframe?


Maybe just upload the kinematicCloudProperties or what else I have to know for this.
This would be very nice from you.



Thank you
Simon

sourav90 June 1, 2021 14:30

Latin Hypercube design
 
Quote:

Originally Posted by Jim Shi (Post 683204)
Dear All,

I would like to simulate a channel turbulent flow with particles by using DPMFoam, there should be constant 20000 particles in the field for each time step.

My question is how to inject those 20000 particles into the field randomly at initial time, if I specify manualInjection in "kinematicCloudProperties" and use a "kinematicCloudPositions" file to specify the location of each particle, it would be troublesome.

Is there any better solution? Please let me know is you are aware of this..

Thank you!

This is one suitable approach (at least for 2D & 3D cuboids, rectangles) that do not fall directly under CFD or coding, rather than a statistical approach. It suits well for this particular purpose though (generating random positions of particles). The idea is not very complicated : Latin Hypercube Sampling, and is implemented in many packages of statistical languages (R or python for example) like https://github.com/bertcarnell/lhs


All times are GMT -4. The time now is 08:45.