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

Accessing Patch Objects from Solver

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 24, 2011, 08:48
Default Accessing Patch Objects from Solver
  #1
New Member
 
Nils Lavesson
Join Date: Jan 2011
Posts: 4
Rep Power: 15
nilsl is on a distinguished road
Hi,

I am using OpenFOAM to solve an electrostatic problem involving several different potentials, represented by boundaries, that need to be optimized during the solution process. I am able to write optimization routines inside each boundary condition and change their values independently, but since the problem I am working on is quite strongly coupled this is not enough.

I need to optimize all the boundary conditions together. My plan is to find the pointers to all the relevant boundaries objects inside the main solver and write a routine there that handles the boundary value optimization. However, I have not been able to figure out how to do this.

Is there a way of accessing all the pointers to the boundaries (patchFields) inside the main solver? Maybe extracting them from the associated volField or from the fvMatrix? Do you know any other way to do something similar?

Cheers,
Nils
nilsl is offline   Reply With Quote

Old   January 25, 2011, 10:29
Default
  #2
New Member
 
Misha Marie Gregersen
Join Date: Nov 2009
Posts: 7
Rep Power: 16
Misha is on a distinguished road
Hi Niels

I am not sure exactly how you want to access the boundary values from the main script, so maybe my suggestion is a bit off, however I give it a try:

I know you can fetch the values of for instance the internal field next to a boundary patch (here number 1) as a patch field for the volScalarField T through the fvMesh using:

mesh.objectRegistry::lookupObject<volScalarField>( "T").boundaryField()[1].patchInternalField()

Hope it helps.
~ Misha
Misha is offline   Reply With Quote

Old   January 25, 2011, 11:15
Default
  #3
Senior Member
 
Stefan Herbert
Join Date: Dec 2009
Location: Darmstadt, Germany
Posts: 129
Rep Power: 17
herbert is on a distinguished road
Hi Nils,

it's hard to tell you what to do without knowing which kind of boundary conditions you are using. But if you want to set the gradient of a fixedGradient-BC of a volScalarField p at boundary no. 5 for example you can use
Code:
fixedGradientFvPatchScalarField& pPatch = refCast<fixedGradientFvPatchScalarField>(p.boundaryField()[5]);
scalarField& pGrad = pPatch.gradient();
and set for the gradient (pGrad) whatever you want. Note that you have to add
Code:
#include "fixedGradientFvPatchFields.H"
inside your header. Using other boundary conditions is working in a similar way.

Regards,
Stefan


@Misha: Your method is working if you need to know the internal field from within boundary conditions, but I think Nils is going to edit boundary condition from within top level solver.
herbert is offline   Reply With Quote

Old   January 26, 2011, 03:50
Default
  #4
New Member
 
Nils Lavesson
Join Date: Jan 2011
Posts: 4
Rep Power: 15
nilsl is on a distinguished road
Hi Misha and Stefan,

Stefan, the code you provided is exactly along the lines I was looking for. The exact implementation is not important, what I was looking for is how to get the patch objects. The real problem contains mostly fixed value boundary conditions, which I will probably modify using access functions.

Looking at the doxygen I realize how the whole thing works. p.boundaryField() gives me an object that has inherited a FieldField, which in turn has inherited a container with all the patch objects. Then I simply have to do a cast and I get what I was looking for.

Misha, your code also seems to get me the same objects. If I needed to get the same information and I didn't have access to the GeometricField object containing the electric potential, this would probably be the way to go.

Thanks a lot for your help.

Cheers,
Nils
nilsl is offline   Reply With Quote

Old   January 26, 2011, 06:33
Default
  #5
New Member
 
Misha Marie Gregersen
Join Date: Nov 2009
Posts: 7
Rep Power: 16
Misha is on a distinguished road
Hi Nils and Stefan

Nils, good that you figured out how to access the object you needed!

Stefan, I tested my code in the top level solver, and it actually accesses the internal patch field. But of course, you can also use it within a boundary condition.

Best regards,
Misha
Misha is offline   Reply With Quote

Reply

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
Cyclic Boundary Condition Luiz Eduardo Bittencourt Sampaio (Sampaio) OpenFOAM Running, Solving & CFD 36 July 2, 2012 13:23
Quarter Burner mesh with periosic condition SamCanuck FLUENT 2 August 31, 2011 12:34
Working directory via command line Luiz CFX 4 March 6, 2011 21:02
Accessing phi from a fvPatchField at same patch johndeas OpenFOAM 1 September 13, 2010 21:23
mapFields : internal edges Gearb0x OpenFOAM Running, Solving & CFD 3 April 19, 2010 10:02


All times are GMT -4. The time now is 07:45.