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

Problem with setting initial field

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 28, 2013, 11:39
Default Problem with setting initial field
  #1
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 13
michel1988 is on a distinguished road
Hello,
I want to set the initial field (for example, scalar field s) in a centrosymmetric computational domain (for example, a cube [-1,1]*[-1,1]*[-1,1]) with:
(1) for the region z>=0, the field is a random field.
(2) for the region z<0, s(x,y,z)=-s(-x,-y,-z).
Anyone can teach me how to realize this initialization? I am new to OpenFOAM.
Thanks.
michel1988 is offline   Reply With Quote

Old   May 30, 2013, 19:12
Default
  #2
Member
 
Thomas Boucheres
Join Date: May 2013
Posts: 41
Rep Power: 13
thomasArk47 is on a distinguished road
The quickest/simplest way is to write "hard coded" functionality directly in the code source of the solver you want to use. But dirty job!

The cleaner/right way is to use a codedFunctionObject and writing your initialisation in the read section for example. Here is an example of possible implementation:

////////////////////////////////////////////////////////////////////////////
codedInitFields
{
// Load the library containing the 'coded' functionObject
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
// Name of on-the-fly generated functionObject
redirectType codedInit;
// Compilation rules
codeOptions
#{
-I$(LIB_SRC)/OpenFOAM/lnInclude
#};
codeLibs
#{
-lOpenFOAM
#};
codeInclude
#{
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
#};
codeData
#{
// Do nothing
#};
codeRead
#{
// Name of the field to initialise
word fieldName_ = "XXXXX";
//Search the field you want to initialise in the db
Info<< "coded : Looking up field " << fieldName_ << endl;
//I suppose your field is a vectorField. Adapt it.
if (mesh().foundObject<volVectorField>(fieldName_))
{
const volVectorField& field =
mesh().lookupObject<volVectorField>(fieldName_);
forAll (field,cellI)
{
const point& p = mesh().cellCentres()[cellI];
if (p.z()>=-VSMALL)
{
//do your job
field[cellI].x() = p.x();
field[cellI].y() = 2*p.y();
field[cellI].z() = 3*p.z();
}
else
{
//assume GREAT is not used in z>0 part!
field[cellI] = 2*GREAT;
}
}
// Costly procedure... If your mesh is cartesian, uses
// associated indexation to avoid findCell.
forAll (field,cellI)
{
const point& p = mesh().cellCentres()[cellI];
if (p.z()<=VSMALL && field[cellI]>GREAT)
{
point pSym(-p);
label cellSymI = mesh().findCell(pSym);
field[cellI] = field[cellSymI];
}
}
}
#};
codeExecute
#{
// Do nothing
#};
codeEnd
#{
// Do nothing
#};
code
#{
// Do nothing
#};
}
///////////////////////////////////////////////////////////////////////

Don't forget to activate the allowSystemOperations flag in the etc/controlDict file (set "allowSystemOperations 1");
thomasArk47 is offline   Reply With Quote

Old   June 8, 2018, 01:03
Default
  #3
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
Quote:
Originally Posted by thomasArk47 View Post
The quickest/simplest way is to write "hard coded" functionality directly in the code source of the solver you want to use. But dirty job!

The cleaner/right way is to use a codedFunctionObject and writing your initialisation in the read section for example. Here is an example of possible implementation:

////////////////////////////////////////////////////////////////////////////
codedInitFields
{
// Load the library containing the 'coded' functionObject
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
// Name of on-the-fly generated functionObject
redirectType codedInit;
// Compilation rules
codeOptions
#{
-I$(LIB_SRC)/OpenFOAM/lnInclude
#};
codeLibs
#{
-lOpenFOAM
#};
codeInclude
#{
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
#};
codeData
#{
// Do nothing
#};
codeRead
#{
// Name of the field to initialise
word fieldName_ = "XXXXX";
//Search the field you want to initialise in the db
Info<< "coded : Looking up field " << fieldName_ << endl;
//I suppose your field is a vectorField. Adapt it.
if (mesh().foundObject<volVectorField>(fieldName_))
{
const volVectorField& field =
mesh().lookupObject<volVectorField>(fieldName_);
forAll (field,cellI)
{
const point& p = mesh().cellCentres()[cellI];
if (p.z()>=-VSMALL)
{
//do your job
field[cellI].x() = p.x();
field[cellI].y() = 2*p.y();
field[cellI].z() = 3*p.z();
}
else
{
//assume GREAT is not used in z>0 part!
field[cellI] = 2*GREAT;
}
}
// Costly procedure... If your mesh is cartesian, uses
// associated indexation to avoid findCell.
forAll (field,cellI)
{
const point& p = mesh().cellCentres()[cellI];
if (p.z()<=VSMALL && field[cellI]>GREAT)
{
point pSym(-p);
label cellSymI = mesh().findCell(pSym);
field[cellI] = field[cellSymI];
}
}
}
#};
codeExecute
#{
// Do nothing
#};
codeEnd
#{
// Do nothing
#};
code
#{
// Do nothing
#};
}
///////////////////////////////////////////////////////////////////////

Don't forget to activate the allowSystemOperations flag in the etc/controlDict file (set "allowSystemOperations 1");

Hello,


Me I want to map a cylinder on a Cartesian grid, the cartesian grid is already made and has the center(0,0,0). May you help to know hoe it is done?


I would appreciate!
Ben UWIHANGANYE is offline   Reply With Quote

Reply


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
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 12:08
Velocity blows up suddenly after 30,000+ iterations lordvon OpenFOAM Running, Solving & CFD 15 October 19, 2015 14:52
Full pipe 3D using icoFoam cyberbrain OpenFOAM 4 March 16, 2011 10:20
ForcesCoeffs ronaldo OpenFOAM 4 September 14, 2009 08:11
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07


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