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

manipulating boundaryField of a volScalarField in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By thanasis
  • 4 Post By kmooney

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 30, 2013, 11:28
Default manipulating boundaryField of a volScalarField in OpenFOAM
  #1
New Member
 
Join Date: May 2013
Posts: 6
Rep Power: 13
thanasis is on a distinguished road
Dear all,

I need to manipulate a volScalarField using some complex expressions that include other volScalarFields and scalars. I have already a library (C++ class library) that operates on scalars and in order to take advantage of this I (note that I need to perform element by element multiplications), I employed a for loop for the internal field:

Code:
for (label i=0; i<D.internalField()[i]; ++i)
    {
         D.internalField()[i]*= libraryObject.libraryFunction
                                     (
                                         T.internalField()[i],
                                         P.internalField()[i],
                                         someScalar
                                     );
    }
I can not however perform the same type of calculations for the boundary field:

Code:
scalar scalarT;
scalar scalarP;
for (label i=0; i<D.boundaryField()[i]; ++i)
    {
         scalarT=T.boundaryField()[i];
         scalarP=P.boundaryField()[i];
         D.boundaryField()[i]*= libraryObject.libraryFunction
                                     (
                                         scalarT,
                                         scalarP,
                                         someScalar
                                     );
    }
The above code does not compile since T.boundaryField()[i] and P.boundaryField()[i] are of fvPatchField type and it seems that I can not assign them to scalars in order to call the library function.

Is there a way to "cast" boundaryField()[i] to a scalar? Is there any other way to manipulate the boundary field using the libraryFunction? I know that boundary condition models employ the == operator to reset them, but I can not figure out how this could work in the boundaryField of a volScalarField variable.

I would be grateful for any recommendations/suggestions.
mm.abdollahzadeh likes this.
thanasis is offline   Reply With Quote

Old   January 15, 2014, 16:47
Default
  #2
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: San Francisco, CA USA
Posts: 323
Rep Power: 18
kmooney is on a distinguished road
Howdy!

When referencing the index of an D.internalField[i] <-like that, the i is refering to a cell index. A boundaryField() is different in that it returns not a patch but a list of patches. For example, to access face j on patch i you would have to write D.boundaryField()[i][j]

You're most likey meaning to do something like this:
Code:
forAll(D.boundaryField(), patchI)
{
         scalarField& tPatch=T.boundaryField()[patchI];
         scalarField& pPatch=P.boundaryField()[patchI];
         scalarField& DPatch=D.boundaryField()[patchI];

         forAll(DPatch,faceI)
         {
       DPatch[faceI]*= libraryObject.libraryFunction
                                     (
                                         tPatch[faceI],
                                         pPatch[faceI],
                                         someScalar
                                     );
         }
}
Note that there is a pretty good chance I messed something up here but I think it will help explain things!
Good luck!

Kyle
kmooney is offline   Reply With Quote

Old   January 19, 2014, 03:23
Default
  #3
New Member
 
Join Date: May 2013
Posts: 6
Rep Power: 13
thanasis is on a distinguished road
Thank you Kyle! that was the problem.
thanasis is offline   Reply With Quote

Old   September 21, 2018, 05:00
Default
  #4
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 308
Rep Power: 12
alimea is on a distinguished road
Hi foamers

I defined a volSymmTensorField and now want to change the values of that in a special boundary:

Code:
volSymmTensorField TauT_RT = tauT;

// changing the values of internal field

forAll (TauT_RT , i)  
{
	TauT_RT[i].xy() =40.5;
}


// changing the values of boundary field

forAll (TauT_RT.boundaryField()[patchI] , i)
{
   TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;
}
But it gives me this error:

Quote:
error: assignment of read-only location ‘(&(&(& TauT_RT.Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>())->Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>::Boundary::<anonymous>.Foam::FieldF ield<Foam::fvPatchField, Foam::SymmTensor<double> >::<anonymous>.Foam::PtrList<Foam::fvPatchField<Fo am::SymmTensor<double> > >::<anonymous>.Foam::UPtrList<T>:perator[]<Foam::fvPatchField<Foam::SymmTensor<double> > >(patchI))->Foam::fvPatchField<Foam::SymmTensor<double> >::<anonymous>.Foam::Field<Foam::SymmTensor<double > >::<anonymous>.Foam::List<Foam::SymmTensor<doubl e> >::<anonymous>.Foam::UList<T>:perator[]<Foam::SymmTensor<double> >(i))->Foam::SymmTensor<double>::<anonymous>.Foam::Vecto rSpace<Form, Cmpt, Ncmpts>::component<Foam::SymmTensor<double>, double, 6u>(1)’
TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;
I'm really appreciated if you answers me.
alimea is offline   Reply With Quote

Old   February 5, 2020, 23:26
Default
  #5
Senior Member
 
ztdep's Avatar
 
p ding
Join Date: Mar 2009
Posts: 427
Rep Power: 19
ztdep is on a distinguished road
Send a message via Yahoo to ztdep Send a message via Skype™ to ztdep
Quote:
Originally Posted by alimea View Post
Hi foamers

I defined a volSymmTensorField and now want to change the values of that in a special boundary:

Code:
volSymmTensorField TauT_RT = tauT;

// changing the values of internal field

forAll (TauT_RT , i)  
{
	TauT_RT[i].xy() =40.5;
}


// changing the values of boundary field

forAll (TauT_RT.boundaryField()[patchI] , i)
{
   TauT_RT.boundaryField()[patchI][i].component(symmTensor::XY) = 40 * i;
}
But it gives me this error:



I'm really appreciated if you answers me.
just modify it to TauT_RT.boundaryFieldRef()
ztdep is offline   Reply With Quote

Reply

Tags
boundaryfield, fvpatchfield


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
ESI-OpenCFD Releases OpenFOAM v2.2.0 opencfd OpenFOAM Announcements from ESI-OpenCFD 13 March 30, 2013 17:52
[Gmsh] gmsh 2.6.0 conversion to OpenFoam 160 rosswin OpenFOAM Meshing & Mesh Conversion 0 March 5, 2013 08:34
Summer School on Numerical Modelling and OpenFOAM hjasak OpenFOAM 5 October 12, 2008 14:14
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 19:07
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 08:14


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