Accessing Patch Objects from Solver
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?
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:
Hope it helps.
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
@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.
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.
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.
|All times are GMT -4. The time now is 14:00.|