CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to modify a patch from a functionObject (http://www.cfd-online.com/Forums/openfoam/60692-how-modify-patch-functionobject.html)

alesch February 17, 2009 14:03

Hello forum: I'm working wi
 
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, http://www.cfd-online.com/OpenFOAM_D...lipart/sad.gif

Thanks in advance for any hint!

gschaider February 18, 2009 13:50

Hi Alex! Just an idea: for
 
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

alesch February 18, 2009 15:22

Thanks for you answer, Bernhar
 
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.

gschaider February 19, 2009 08:11

Hi Alex! timeVaryingMappedF
 
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

alesch February 19, 2009 18:09

Bernhard: Without your help
 
Bernhard:

Without your help I wouldn't get anywhere, http://www.cfd-online.com/OpenFOAM_D...part/happy.gif

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 March 3, 2009 11:46

Bernhard: In a previous pos
 
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!

gschaider March 3, 2009 14:03

Hi Alex! @2: Don't tell any
 
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

alesch March 27, 2009 17:30

[Solved]
 
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.


All times are GMT -4. The time now is 02:09.