CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to impose fixed value at a point (or region) during calculation ? (https://www.cfd-online.com/Forums/openfoam-programming-development/77809-how-impose-fixed-value-point-region-during-calculation.html)

 Cyp July 5, 2010 05:34

how to impose averaged field equal to 0 at a point during calculation ?

Hi!

In my subject, I need to solve equations with a condition of average-field-equal-to-zero.

I defined the average of the T field as :

Code:

`T_moy=fvc::domainIntegrate(T) / V`
where V is the volume of the domain.

how can I impose T_moy=0 during the calculation ?

Thank you for your precious help.

 kathrin_kissling July 5, 2010 07:23

Hi Cyp,

Do you went to impose a value on certain points or do you search for a condition which will make sure that after solving the transport equation your field T is in accordance with your implied condition.

Kathrin

 Cyp July 5, 2010 08:57

I want to be sure that after my calculation, the implied condition is satisfied.

In Comsol I imposed a constraint ( moy(T)=0) on one point (it is sufficient). what is the equivalent on OpenFOAM ?

 olesen July 6, 2010 02:40

Quote:
 Originally Posted by Cyp (Post 265751) I want to be sure that after my calculation, the implied condition is satisfied. In Comsol I imposed a constraint ( moy(T)=0) on one point (it is sufficient). what is the equivalent on OpenFOAM ?
To impose values at specified cells, you'd want the fvMatrix::setValues() method.
http://foam.sourceforge.net/doc/Doxy...bc49953b884184

 Cyp July 6, 2010 03:59

The setValues definition precises that the imposed values are field value. In my case, I need to imposed a value for the average of a field over the domain.

Do you think setValue is a good hint for my problem ?

 herbert July 6, 2010 06:40

Hi Cyp,

I think it would be easier for us to help you, if you would show us your equation and boundary conditions in detail.

Regards,
Stefan

 Cyp July 6, 2010 08:52

Here is the problem I want to solve with OpenFOAM :

http://img5.imageshack.us/i/problemaaj.jpg/

It is the last condition ( <s_{gamma}>^{gamma}=0) I was talking about..

 Cyp July 8, 2010 09:31

I am a bit lost...

Such a condition (to impose averaged field on a region equal to 0) is fundamental in my calculation.

Can anyone give me a hint ??

 herbert July 8, 2010 11:47

Hi Cyp,

Regards,
Stefan

 Cyp July 8, 2010 11:49

can't you see the picture in my previous message ??

http://img5.imageshack.us/i/problemaaj.jpg/

 herbert July 8, 2010 11:54

No I can't. Sorry. But now I can take a look.

Thanks.

 Cyp July 15, 2010 12:21

Hi Herbert (and all of you of course!)

I still looking for a solution to my problem (it is a very fundamental point in my developpment).

Do you think I can use the setValue (or setReference) utility in my case ?

Thank you,
Cyprien

 herbert July 16, 2010 03:01

Hi Cyprien,

I did not come up to a solution as well. But I think you aren't able to use setValues or setReference.

Can you solve the equation without boundaries fixing values (only gradient bc's)? In that case you could solve the field using setReference and subtract the average field value afterwards.

I don't think there is a solution for your problem already existing in OpenFOAM.

Regards,
Stefan

 Cyp July 16, 2010 05:44

Hi!

In fact it is exactly what I do for the moment (subtract the average field value afterwards). But it only works with simple source terms. When I try this a more complicated source term, this method doesn't converge to a solution..

 Cyp July 19, 2010 08:30

Someone told me that I should directly insert my problem into the matrix I want to solve. If I understand what it is suggested, I declare my problem as

Code:

```fvScalarMatrix TEqn   (         fvm::ddt(rho,T)       +fvm::div(phi,T)       -fvm::laplacian(rho*DT,T)   )```
Then I calculate the average value of my T field over the gamma phase by

Code:

`T_moy=domainIntegrate(phase_gamma*T)/V_gamma`
where V_gamma is the volume of the gamma phase

The next step is to enlarge my TEqn matrix by adding T_moy in the last position of the diagonal and zeros elsewhere.

Finally I should get the result solving

Code:

`solve(TEqn == f)`
where f is the original source term of my problem with an additionnal 0 at the last position.

What do you think of this method ??

How can I enlarge my matrix ??

 Cyp July 20, 2010 10:06

In fact, I found a very easiest way to proceed!!

I just have to fix a value at a point (with setReference) which assure the convergence of my problem. Then I find out my real fields by subtracting the average value of the calculated field! I post the code if someone is interested by such a problem :

Code:

```while(runtime.loop()) { #  include "readSIMPLEControls.H"     for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)     {     fvScalarMatrix TEqn         (           fvm::ddt(rho,T)           +fvm::div(phi,T)           -fvm::laplacian(rho*DT,T)           == f         )     TEqn.setReference(TRefCell,TRefValue)     TEqn.solve()     } } T= phase_gamma*(T-fvc:domainIntegrate(phase_gamma*T)/V_gamma)   +phase_beta *(T-fvc:domainIntegrate(phase_gamma*T)/V_gamma)```
In the next step of my project, I need to do similar calculation with a vector field B. I want to use a similar strategy but the setReference seems to work only with scalar...

How can I fix the value of my vector B at a point ?

 herbert July 20, 2010 11:15

Hi Cyp,

the you can use setValues. Even if you want to fix only one point, setValues needs a list of points to be fixed. The following should work:
Code:

```label refCell = 12345; labelList refCells (1,refCell); vectorField refValues (1, vector(0,0,0)); TEqn.setValues(refCells, refValues);```
Regards,
Stefan

 Cyp July 21, 2010 03:18

Hi Stefan!

It perfectly works !! Thank you very much!

 jorkolino August 3, 2010 09:19

accessing cells from a patch

Does anyone know how can I access the cells from a patch with name patchname ? I want to run a procedure (particle injection) for each of the cells. I have the code, but I need the cell index.

 samiam1000 February 24, 2012 06:41

Hi everyone.

First of all, I would like to answer to this:

Quote:
 Does anyone know how can I access the cells from a patch with name patchname ? I want to run a procedure (particle injection) for each of the cells. I have the code, but I need the cell index.
I think you can find whay you want in the case_path/constant/polyMesh folder where there are different files.

Also, I have a question: I want to impose a fixed value of a temperature in a certain volume of my domain.
How can I do this? Should I use the fvMatrix::setValues() method?

Thanks a lot,

Samuele

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