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

write fields in openfoam database in boundary patch

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By medmast

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 2, 2016, 09:46
Default write fields in openfoam database in boundary patch
  #1
New Member
 
Join Date: Mar 2016
Location: Germany
Posts: 8
Rep Power: 10
medmast is on a distinguished road
Hi all,
I am trying to implement a new boundary condition that reads Internal fields U, P, and temperature from external solver and write these fields from OpenFOAM in a file for external solver.
to this end, i use the "externalCoupledMixedFvPatchField" boundary patch and i edit it.
i try the following code to write data in OpenFOAM fields:
Code:
 const volScalarField& Pressure= this->db().objectRegistry::lookupObject<volScalarField>("p");
   const volVectorField& Velocity= this->db().objectRegistry::lookupObject<volVectorField>("U");
   const volScalarField& Temperature= this->db().objectRegistry::lookupObject<volScalarField>("T");


    forAll(this->patch(), facei)
     {
             // define mesh on patch
             const fvMesh& mesh = this->patch().boundaryMesh().mesh();


                   // cell related to current face
                 label celli =this->patch().faceCells()[facei];

                  // define opposite face to patch face//
                 label oppfacei =mesh.cells()[celli].opposingFaceLabel
                                      (facei+this->patch().patch().start(),mesh.faces());
                 // define neighbour cell centre cellCentreN
                 vector cellCentreN = mesh.cellCentres()[mesh.owner()[oppfacei]];

                 // define patch cell centre cellCentre0
                 vector cellCentreO = mesh.cellCentres()[mesh.neighbour()[oppfacei]];


                 // cell lable of  cell
                 label CellP =mesh.findCell(cellCentreO);

 Pressure.internalField()[CellP] = "new value";


         }
Here I have error that Pressure field constant it, and when I try to define it as volScalarField, I can't define it with objectRegistry.
has anyone the idea, how i can change internal fields U,P and T within a boundary patch?
Thank you
iman
atulkjoy likes this.
medmast is offline   Reply With Quote

Old   February 14, 2017, 15:07
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

You have const_cast and ref.
alexeym is offline   Reply With Quote

Old   February 14, 2017, 15:21
Default
  #3
New Member
 
Join Date: Mar 2016
Location: Germany
Posts: 8
Rep Power: 10
medmast is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Hi,

You have const_cast and ref.
yes exactly, now my question is how can i define the internal variable not constant , or how can i change the internalfields at patch (not facevalues)
medmast is offline   Reply With Quote

Old   February 14, 2017, 15:25
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Well, now my question is what error happens if you add const_cast to your lookups and use ref instead of internalField to set value? And, please, this time post compiler output.
alexeym is offline   Reply With Quote

Old   February 14, 2017, 15:30
Default
  #5
New Member
 
Join Date: Mar 2016
Location: Germany
Posts: 8
Rep Power: 10
medmast is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Well, now my question is what error happens if you add const_cast to your lookups and use ref instead of internalField to set value? And, please, this time post compiler output.
actually no error but i can just read the internalfields, i want to change them too, because they are defined const_cast , they are not changeable
i'll post it at freiday, i don't have them right now.
thank you very much
medmast is offline   Reply With Quote

Old   February 14, 2017, 15:33
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Yes, internalField is read-only, ref is not (also you can use const_cast on internalField if you REALLY want).
alexeym is offline   Reply With Quote

Old   February 14, 2017, 15:38
Default
  #7
New Member
 
Join Date: Mar 2016
Location: Germany
Posts: 8
Rep Power: 10
medmast is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Yes, internalField is read-only, ref is not (also you can use const_cast on internalField if you REALLY want).
thank you for your solution.
how i understood, i must define internal fields as "const_cast " , then they are not read-only anymore?
and could you please a little explain about "ref"?
medmast is offline   Reply With Quote

Old   February 14, 2017, 15:53
Default
  #8
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
You CAN not that you MUST. Post #2 contains a link to ref documentation, not quite get what additional explanations do you need.

You use const_cast to remove const from field references you look up using objectRegistry, then you use ref method to access writable lists for modification of the fields.
alexeym 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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 07:38
Wind turbine simulation Saturn CFX 58 July 3, 2020 01:13
an odd(at least for me!) reconstructPar error on a field immortality OpenFOAM Running, Solving & CFD 3 June 3, 2013 22:36
[blockMesh] Cyclic BC's: Possible face ordering problem? (Channel flow) sega OpenFOAM Meshing & Mesh Conversion 3 September 28, 2010 12:46
RPM in Wind Turbine Pankaj CFX 9 November 23, 2009 04:05


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