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

How to distribute particles randomly at initial time

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Jim Shi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 28, 2018, 10:40
Question How to distribute particles randomly at initial time
  #1
New Member
 
Shi Xiaolei
Join Date: Feb 2018
Posts: 1
Rep Power: 0
Jim Shi is on a distinguished road
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!
sourav90 likes this.
Jim Shi is offline   Reply With Quote

Old   May 25, 2020, 04:23
Default
  #2
Member
 
SimonStar's Avatar
 
Simon
Join Date: Sep 2019
Location: Germany
Posts: 51
Rep Power: 6
SimonStar is on a distinguished road
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 is offline   Reply With Quote

Old   May 25, 2020, 07:10
Default
  #3
Member
 
SimonStar's Avatar
 
Simon
Join Date: Sep 2019
Location: Germany
Posts: 51
Rep Power: 6
SimonStar is on a distinguished road
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

Last edited by SimonStar; May 25, 2020 at 08:42.
SimonStar is offline   Reply With Quote

Old   May 28, 2020, 06:08
Default
  #4
Member
 
SimonStar's Avatar
 
Simon
Join Date: Sep 2019
Location: Germany
Posts: 51
Rep Power: 6
SimonStar is on a distinguished road
Sorry to answer myself always


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
SimonStar is offline   Reply With Quote

Old   June 1, 2021, 15:30
Default Latin Hypercube design
  #5
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 6
sourav90 is on a distinguished road
Quote:
Originally Posted by Jim Shi View Post
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

Last edited by sourav90; June 8, 2021 at 08:48. Reason: More specific
sourav90 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
pimpleDyMFoam computation randomly stops babapeti OpenFOAM Running, Solving & CFD 5 January 24, 2018 06:28
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 06:49
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 12:08
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 03:20
Simulation seems to converge but crashes suddenly xxxx OpenFOAM 16 September 12, 2014 09:07


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