CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

How to modify a patch from a functionObject

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

Reply
 
LinkBack Thread Tools Display Modes
Old   February 17, 2009, 13:03
Default Hello forum: I'm working wi
  #1
New Member
 
Alex Schenkman
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 13
Rep Power: 7
alesch is on a distinguished road
Hello forum:

I'm working with functionObejcts to interface OpenFOAM with another application.
Each time step, I need to send and receive information from the other app.

Sending is solved by extending PatchAverageFunctionObject, found here: simpleFunctionObjects

But receiving?
For example, for icoFoam, how could I modify the pressure or the velocity field, for a given patch, between time steps?

I have debugged icoFoam but I get lost in the code,

Thanks in advance for any hint!
alesch is offline   Reply With Quote

Old   February 18, 2009, 12:50
Default Hi Alex! Just an idea: for
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,752
Rep Power: 36
gschaider will become famous soon enoughgschaider will become famous soon enough
Hi Alex!

Just an idea: for "pulling" another solution I'd write a boundary-condition (timeVaryingMappedFixedValueFvPatchField might be similar to what you're trying to achieve)

OR

the functionObject directly writes the values to the patch (I assume that after sending the external program calculates and then can send back a solution)

Bernhard
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 18, 2009, 14:22
Default Thanks for you answer, Bernhar
  #3
New Member
 
Alex Schenkman
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 13
Rep Power: 7
alesch is on a distinguished road
Thanks for you answer, Bernhard!

Do you have any links to any code using timeVaryingMappedFixedValueFvPatchField?
So I can try to understand what it is, and how it is used?
From the name I can see that it is some kind of mapping between a patch, that varies in time...

From my functionObject, how can I modify a patch? Or where can I find some code to look at that does it?

Thanks again!

PS: I find it very hard to navigate through ALL these C++ code.
alesch is offline   Reply With Quote

Old   February 19, 2009, 07:11
Default Hi Alex! timeVaryingMappedF
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,752
Rep Power: 36
gschaider will become famous soon enoughgschaider will become famous soon enough
Hi Alex!

timeVaryingMappedFixedValueFvPatchField is found in $FOAM_SRC/finiteVolue/fields/fvPatchFields/derived (quoting from memory). Or you can look it up in the Doxygen.

A quick and dirty-approach to writing the patch field in the function-object would be the reverse of what you're already doing: just put the "fld.boundaryField()[index]" (that is an example from the simpleFunctionObjects onto the left side of an = and voila you're writting to the patch.

Bernhard
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 19, 2009, 17:09
Default Bernhard: Without your help
  #5
New Member
 
Alex Schenkman
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 13
Rep Power: 7
alesch is on a distinguished road
Bernhard:

Without your help I wouldn't get anywhere,

I think that the following line, placed after the average is calculated in the for-loop, within patchAverageFunctionObject::average(), will achieve what I want:

fld.boundaryField()[index] *= anExternalScalar / vals[patchI].component(0);

where vals[patchI].component(0) should give me the x-component of the newly computed average.

But it doesn't work !?!

The compiler complains when [T = double], as patchAverageFunctionObject::average() is a templated function.

I don't get why, becasue even scalarField defines the component() method.

Any clues?
alesch is offline   Reply With Quote

Old   March 3, 2009, 10:46
Default Bernhard: In a previous pos
  #6
New Member
 
Alex Schenkman
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 13
Rep Power: 7
alesch is on a distinguished road
Bernhard:

In a previous post you suggest the following:

Quote:
A quick and dirty-approach to writing the patch field in the function-object would be the reverse of what you're already doing: just put the "fld.boundaryField()[index]" (that is an example from the simpleFunctionObjects onto the left side of an = and voila you're writting to the patch.
After two days trying with the compiler, I'm still stuck.

If I don't missunderstand it, fld is constant and thus cannot be modified.

1) Is it possible to write to fld anyway?
2) Or, how could I get a writtable reference to U?

All examples I've found on the forum modify U and p from within the solver (the main function), and we are trying to avoid modifying the solvers.

Thanks in advance!
alesch is offline   Reply With Quote

Old   March 3, 2009, 13:03
Default Hi Alex! @2: Don't tell any
  #7
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,752
Rep Power: 36
gschaider will become famous soon enoughgschaider will become famous soon enough
Hi Alex!

@2: Don't tell anyone, that I said this: google for const_cast. But beware: this operator allows you to violate the encapsulation mechanisms and therefor using it is similar to running with an open knife
@1: what I would suggest is writing a boundary-condition and provide it with an interface to change the boundary values. In the functionObject dynamicCast the general patch field to that type (maybe use a isA to guard that cast) to your type and use your methods to set the value (Look thorough the doxygen for isA and dynamicCast and grep the sources for example usages)

Bernhard
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   March 27, 2009, 17:30
Thumbs up [Solved]
  #8
New Member
 
Alex Schenkman
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 13
Rep Power: 7
alesch is on a distinguished road
I just wanted to post the solution to my question.
I extended pathAverageFunctionObject, and reused much of the code in the average() method.

Here follows the code I added within average() to write on the boundary defined in the controlDict.

Code:
fvPatchField<T> *aField = const_cast<fvPatchField<T>*>(&fld.boundaryField()[index]);

forAll(*aField, valueIndex)
{ 
     assignFieldValue( (*aField)[valueIndex], aDouble );
}
I didn't know how the templatize the function assingFieldValue() so I wrote 5 versions of it.

Thanks for your help, and I hope this helps someone else.
alesch is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP NEEDED HOW TO MAP VALUES FROM PATCH OF ONE MESH TO PATCH OF ANOTHER MESH mkraposhin OpenFOAM Running, Solving & CFD 3 September 4, 2011 09:42
Patch names amp forces functionObject david OpenFOAM Bugs 3 April 26, 2011 21:59
How To Modify the eqution yinyajun436 OpenFOAM Running, Solving & CFD 1 March 31, 2008 17:01
How to modify a value by a UDF? jwt FLUENT 3 May 23, 2003 12:01
Modify the htc using UDF on NT frederic FLUENT 0 February 7, 2000 07:51


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