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

surfaceScalarField definition on-the-fly

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 18, 2023, 05:56
Default surfaceScalarField definition on-the-fly
  #1
New Member
 
Sreehari Perumanath
Join Date: Jun 2022
Posts: 28
Rep Power: 3
sreehahaha is on a distinguished road
Dear Foamers,

I have to define a surfaceScalarField in my code on-the-fly at each time-step for my system. In createFields.H, I do:

Code:
surfaceScalarField stochHfx
(
    IOobject
    (
        "stochHfx",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("stochHfx", dimPower, scalar(0))
);
In the main solver.C file, I give values to stochHfx like

Code:
forAll(stochHfx,facei) // loop over all internal faces
{
	stochHfx[facei]=rnumq.scalarNormal(); //a random number
}
1. Now, I have to give random values to the boundary faces. How can I do it?

2. Mostly, I use a cubic domain with cyclicBC in all directinos. So, I have to make the values of stochHfx on the left patch the same as that on the right patch. How can I do that?

Any suggestion would be appreciated. I've been spending quite a long time on this, sadly.

Thanks,
S
sreehahaha is offline   Reply With Quote

Old   August 21, 2023, 06:33
Default
  #2
Member
 
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 62
Rep Power: 16
alundilong is on a distinguished road
Quote:
Originally Posted by sreehahaha View Post
Dear Foamers,

I have to define a surfaceScalarField in my code on-the-fly at each time-step for my system. In createFields.H, I do:

Code:
surfaceScalarField stochHfx
(
    IOobject
    (
        "stochHfx",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("stochHfx", dimPower, scalar(0))
);
In the main solver.C file, I give values to stochHfx like

Code:
forAll(stochHfx,facei) // loop over all internal faces
{
	stochHfx[facei]=rnumq.scalarNormal(); //a random number
}
1. Now, I have to give random values to the boundary faces. How can I do it?

2. Mostly, I use a cubic domain with cyclicBC in all directinos. So, I have to make the values of stochHfx on the left patch the same as that on the right patch. How can I do that?

Any suggestion would be appreciated. I've been spending quite a long time on this, sadly.

Thanks,
S
following is the general idea of how, hope it helps.

1. use Random object, such as Random rndGen(215444), then use this object to generate random numbers.
2. to access boundary faces of field alphaf(lets say)
Code:
//- loop all boundaryField of alphaf field
//- apply user-defined operation on each face
forAll(alphaf.boundaryField(), patchi)
{
fvsPatchScalarField& palphaf = alphaf.ref().boundaryFieldRef()[patchi];

forAll(palphaf, facei)
{
palphaf[facei] = rndGen.scalar01();
}
}
3. if you want to applied this a specific boundary, you can set it apart by its name.
Code:
palphaf.patch().name() should return the name of the boundary.
alundilong is offline   Reply With Quote

Old   August 21, 2023, 16:23
Default
  #3
New Member
 
Sreehari Perumanath
Join Date: Jun 2022
Posts: 28
Rep Power: 3
sreehahaha is on a distinguished road
Hi Alundilong,

Thanks a lot for the suggestion; very helpful. I think I got the idea.

Cheers,
S
sreehahaha is offline   Reply With Quote

Reply

Tags
boundary cells, cyclic bc, surfacescalarfield

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
Upwind Gradient Not Recognizing surfaceScalarField MajidHagh OpenFOAM 2 October 30, 2019 11:58
Change boundary conditions on fly by string definition Algis OpenFOAM Programming & Development 0 December 15, 2015 11:03
Function returning uniform surfaceScalarField lichmaster OpenFOAM 3 June 25, 2012 03:46
Very basic problem with surfaceScalarField definition feldy77 OpenFOAM 4 December 8, 2011 13:13
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21


All times are GMT -4. The time now is 00:01.