CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Pre-Processing (
-   -   dscmFoam : non-uniform rhoN (number density) boundary condition (

elfuertes June 11, 2013 04:36

dscmFoam : non-uniform rhoN (number density) boundary condition
Hi foamers !

I am new to openFoam, and I need to use dsmcFoam in order to simulate the expansion of a flow in a vacuum. In order to simulate my case, I need a non-uniform BC for RhoN.

I have read this validation review :
"An open source, parallel DSMC code for rarefied gas flows in arbitrary geometries. / Scanlon, T.J.; Roohi, E.; White, C.; Darbandi, M.; Reese, J.M."
In which I have found the following statement :
"dsmcFoam straightforwardly handles non-uniform distributions for the inlet conditions of velocity, temperature and number density"

However, by studying the source code (freeStream.C), it seems to me that the freestream inflow condition only handles a constant value (per specie) for rhoN. :confused:
But maybe I am wrong ?

Ideally I would like to have a boundaryRhoN file that would act as an input for my case such as boundaryU and boundaryT.
Can someone give me a hint on how to do that ?

Thanks for your help !

nimasam June 11, 2013 05:13

for creating a non-uniform BC, you have two options:
1-code stream

i recommend second, for ease of use

elfuertes June 12, 2013 09:02

Thanks nimasam, but I don't think this will suit my needs. Perhaps I was not clear enough so I will try to be more specific about my issue.

I want to use the dsmcFoam solver. The principle of the dsmc method is to inject, move, and collide dsmc particles in the domain, where each dsmc particle represent a high number of real particles. Then the macroscopic properties are evaluated by averaging the properties of these particles over the cells of the domain.

For this solver, the boundary conditions are not implemented in a classic way like in almost every other solver in OpenFoam. The boundary condition is "used" to inject particles in the domain by the freeStream inflow boundary model (src/lagrangian/dsmc/submodels/InflowBoundaryModel/FreeStream.C)

However, this boundary model seems to consider that a FreeStream patch can have a non-uniform Temperature and Velocity (defined in the boundaryT and boundaryU dictionaries in the time directory of a dsmc case), BUT all the Freestream patches must have the same number density of real particles, defined as a constant (for each specie) in the constant/dsmcProperties dictionnary (if my understanding of the code is correct).

src/lagrangian/dsmc/submodels/InflowBoundaryModel/FreeStream.C line 64-94
const dictionary& numberDensitiesDict
    List<word> molecules(numberDensitiesDict.toc());
    // Initialise the particleFluxAccumulators_
    forAll(patches_, p)
        const polyPatch& patch = cloud.mesh().boundaryMesh()[patches_[p]];
        particleFluxAccumulators_[p] = List<Field<scalar> >
            Field<scalar>(patch.size(), 0.0)
    forAll(molecules, i)
        numberDensities_[i] = readScalar


constant/dsmcProperties line 46-55
InflowBoundaryModel            FreeStream;
        N2      0.777e20;
        O2      0.223e20;

I would like to be able to enter a non uniform number density for one or several inflow patches, in the same way it is done with T and U.
It should be possible to modify the source code but my understanding of C++ is fairly low, that is why I am looking for some help.

Has anyone suceeded in implementing a non uniform BC for RhoN in a dsmc case ? Any help or advice would be welcome !

Thanks !

heksel8i August 16, 2013 04:51

Did you solve your problem? I have the same problem at the moment...

elfuertes August 19, 2013 04:51

I partially solved it. I had to modify the source code in order to define a non-uniform boundary condition for RhoN.

Unfortunately I am not allowed to share this work, but here are the key steps:
- Modify DsmcCloud to read an Input file : boundaryRhoN
- Create a new stream model, based on freeStream that will use this data
- Add this model in the inflow model list in the file "makeInflowBoundaryModels" (in dsmcParcels folder)

The best advice I can give you is to spend some time looking at the sources to understand how the solver works, and do this tutorial:

I hope it will help.

heksel8i August 20, 2013 02:57


Thanks for the hints! This far I had not time to consentrate to this, but from now on I'll start.

I quickly looked at the source code and started to think about that is it as complicated for U and T to give them as a non-uniform distribution? In Scanlon's article it "seems" to be so easy...

My goal is to give a CFD-based result as an initial condition for the dsmcFoam so all the variables will be non-unifom.

elfuertes August 20, 2013 03:41

The good news is that it is already implemented for U and T !
You just have to specify a non-uniform scalar list for your boundary in boundaryT and a non-uniform vector list for boundaryU (there are some examples in the tutorials for other solvers)

That's why it seems simple in Scanlon's article (but they forgot to mention that it is not possible for RhoN)


heksel8i August 20, 2013 13:21

Good tips! Today I have been reading the source code through the whole day and starting to get some insight into it. Before going into number density itself I have a question about the "normal" fields.

I have a complex boundary shape and I have a list of (x,y,z,value) where the coordinates refer to the cell centers in a mesh, thus there is a problem while using the basic nonuniform boundary condition because I don't know the right order of the values in a list (it should be in a same order as blockmesh generates the cells?). According to my knowlegde normal nonuniform boundaries are generated by expressions with swak4foam etc. So basically I think I have to implement this space-discretized boundary too?

Cheers Heikki

heksel8i August 21, 2013 07:41

Velocity and temperature worked out with timeVaryingMappedFixedValue - BC.

Still figuring out the number density.

elfuertes August 21, 2013 12:51

I deal with the same boundary condition type. I developped an external "interfacing" routine that extract the faces of the boundary, interpolate the values of the flow on this face, and write theses values in a non uniform list in the boundary files.

It looks like
timeVaryingMappedFixedValue - BC does pretty much the same, if it works for your case.

heksel8i August 22, 2013 04:32


I think I still have a problem with the boundaries because now dsmcInitialiseDict still have scalar temperature and one velocity vector so basically simulation will be initialised with one value but on the boundary it has a distribution.

There will be an error with determination of the molecules in cell level or something?

elfuertes August 22, 2013 04:58

This is a different issue:

dsmcInitialize can only initialise the flow field with a uniform flow.
However, you can launch a simulation without initialization. A 0-time your domain will be entirely free of molecules but it will fill up as the molecules enter from your boundaries.

The only thing to do is give an initial estimate of sigmaTcRMax in your domain, otherwise the collisions will not be computed.

All times are GMT -4. The time now is 23:50.