CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (http://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Fixed Temperature Cell in Solution (http://www.cfd-online.com/Forums/openfoam-pre-processing/87317-fixed-temperature-cell-solution.html)

ozzythewise April 17, 2011 10:55

Fixed Temperature Cell in Solution
 
Hey all,

I have a simple transient channel flow problem with heat transfer from the walls but what I want to do is set one cell in my solution domain to have a fixed temperature. This is just to test something out with a code, not for any real application. Is there any way that I can set one arbitrarily located cell in my solution domain to have a fixed temperature?

Thanks
Jeff

ngj April 17, 2011 11:38

Hi Jeff

You could e.g. consider the setValue functionality for fvMatrix<Type>. You can find an example here:

~/OpenFOAM/OpenFOAM-1.5-dev/src/turbulenceModels/RAS/incompressible/kOmegaSST/wallOmegaI.H

The function simply put a fixed value in the given cell label(s). I do not know whether (i) the equation is removed from the matrix system or (ii) the off-diagonals are set to 0, the diagonal to 1 and the right hand side to the provided value? I do, however, suspect that the latter is the case, as the other approach seems to produce a lot of extra work in terms of necessary changes in the data structure.

Good luck

Niels

ozzythewise April 23, 2011 11:08

Hi Niels,

Thanks your reply, I'm still pretty confused about how I would go about this.

I checked out the kOmegaSST.H file but it makes no mention of a setValue function. Do you have any other suggestions for how I can go about doing this? I'm still relatively new to OF so am unfamiliar with a fair amount of the source code.

Thanks
Jeff

ngj April 23, 2011 11:13

Hi Jeff

I can see that the structure has changed from version 1.5-dev, which I am currently using. Do

Code:

find ./ | xargs grep setValues
in ~/OpenFOAM/OpenFOAM-<VERSION>/src/turbulenceModels and you will find some files, which uses setValues.

Best regards

Niels

ozzythewise April 23, 2011 11:29

Hi,

Okay, I found a mention of setValues in : ~/OpenFOAM/src/turbulenceModels//incompressible/RAS/lnInclude/wallDissipationI.H

the entry is as follows:


{
const fvPatchList& patches = mesh_.boundary();

forAll(patches, patchi)
{
const fvPatch& p = patches[patchi];

if (isA<wallFvPatch>(p))
{
epsEqn().setValues
(
p.faceCells(),
epsilon_.boundaryField()[patchi].patchInternalField()
);
}
}
}

This is all there is. I am still extremely lost, what would I need to do to be able to fix a value at a cell in my domain?

Thanks again,
Jeff

ngj April 23, 2011 11:44

Hi Jeff

The important part is

Code:

epsEqn().setValues
            (
                p.faceCells(),
                epsilon_.boundaryField()[patchi].patchInternalField()
            );

This part states that a fv<Type>Matrix with the name epsEqn has predefined values in the cells defined in the labelList p.faceCells(), and the corresponding values are given in the Field<Type> epsilon_.boundaryField()[patchi].patchInternalField().

Recapitulating in your case: (i) Give a labelList with the labels of the cells (tCells), where you would like to predefine the temperature. (ii) Define a scalarField of the same size of the the labelList, where the values are the required temperatures (tVals). (iii) Having a fvScalarMatrix probably called TEqn, then do

Code:

TEqn.setValues(tCells, tVal);
before

Code:

TEqn.solve();
If this is insufficient to solve the problem, I would recommend that you search the forum or look into the Doxygen documentation, which you find via www.opencfd.co.uk.

Good luck

Niels

ozzythewise April 23, 2011 12:01

Hi Neils,

You're going to have to be really patient with me here, I am really new with OF and have never done anything outside of changing case files around.

i) What is a labelList and how do I create one?

ii) How do I define a scalarField?

iii) What is a fvScalarMatrix and how do I create it?

If you have any examples of where this is done that would be awesome. Am I going to be changing around the source code or is this done in the case directory?

Thanks a lot for your help and I apologize for not really understanding what's going on haha.

Jeff

ngj April 23, 2011 12:18

Hi Jeff

I can unfortunately not help any further, as I am very shortly turning in my PhD-thesis, so I would not be able to focus on helping you out. I hope other people read this thread, and otherwise search the forum and use the "find" and "grep" in combination. The latter can get you far.

Good luck

Niels

mvoss April 26, 2011 05:01

hi,
Quote:

Originally Posted by ozzythewise (Post 304803)

i) What is a labelList and how do I create one?

A labelList is... a list of labels...labels are the "numbers" of the cells/faces/volumes. This is why you need to have to define a scalarField of the same size of the the labelList, where the values are the required temperatures (tVals).
You can create it from the patch where you want to have the temperatur fixed.

Code:

ii) How do I define a scalarField?
Just like any other field. Check out the createFields.H files from any solver.


Code:

iii) What is a fvScalarMatrix and how do I create it?
Just like above... the fvScalarMatrix for the Temperature will probably been named Teqn and is part of the solver.
With the .setValues you change the entries in this matrix.... that is why you need to tell the memberfunction what you want to change (entries in Teqn) and where (p.faceCells) to what (in your case a fixed integer e.g. 293 K).

Quote:

If you have any examples of where this is done that would be awesome. Am I going to be changing around the source code or is this done in the case directory?
There is a wise saying: "The documentation is the source code." which in case of OF is absolutely true. So read the source code of the solver you are working with and spot the fields you want to change (Teqn ??)
And YES.... you will have to mess around with the source code... so get yourself a local copy, change the resulting executable to
Code:

EXE = $(FOAM_USER_APPBIN)/WhateverFoam
and compile it once before changing anything for testing.

neewbie

mvoss April 26, 2011 05:11

ah... read the first post again... since you want to force one entire cell to have a fix temperature try
Code:

double P1, P2, P3;
int cellcenter=mesh.findNearestCell(Foam::point(P1,P2,P3));

with p1-p3 beeing coordinates in your mesh-coord.system.
to find the label next to your favored point.

ozzythewise April 28, 2011 15:46

Thanks neewbie, I'm beginning to understand some things. Of course I'm still having some difficulties so if you could help me a little bit more that'd be fantastic. I really appreciate it, I've had no training with OF and am just trying to keep up really.

My concern now is that I can't seem to find any mention of
Code:

TEqn.solve
anywhere in the solver. I've attached the solver if anyone wants to take a look and provide some hints. I did not create this solver, it was made by the person whose work I'm building upon. The TEqn file reads
Code:

solve
(
        fvm::ddt(T)
      + fvm::div(phi, T)
      - fvm::laplacian(DT, T)
);

What I'm guessing is I'm suppose to put
Code:

TEqn().setValues
            (
                T.faceCells(),
                T_.boundaryField()[patchi].patchInternalField()
            );

somewhere before TEqn is solved. And I would also need
Code:

TEqn.setValues(tCells, tVal);
somewhere, no idea where though. Haha, I guess I'm still more confused than I thought.

Thanks for sticking through with me though!
Jeff

MartinB April 28, 2011 16:58

Hi Jeff,

without knowing your solver (it's not attached so far, is it?), here is my proposal:

In "createFields.H" there should be the creation of T. A value for DT is read from transportProperties there, too. Your scalar field T must be defined in your 0 time folder, i.e. 0/T must exist. You can define boundary conditions in that file, for example zeroGradient to all walls.

Now with these lines similar to simpleFoam's createFields.H you can set your reference temperature:
Code:

    label TRefCell = 0;
    scalar TRefValue = 0.0;
    setRefCell(T, mesh.solutionDict().subDict("SIMPLE"), TRefCell, TRefValue);

Add these lines to your createFields.H. This approach assumes that in the SIMPLE dictionary in system/fvSolution appropriate values are defined for TRefCell and TRefValue.

Hope this information is helpful

Martin

mvoss April 28, 2011 16:59

hi,

nop.
You cannot find it since it is implemented a little bit different. TEqn.solve is simply using the solve function on a fvScalarMAtrix object,namely Teqn.
Code:

fvScalarMatrix TEqn
        (
            fvm::ddt(T)
            + fvm::div(phi, T)
            - fvm::laplacian(DT, T)
        );

is the same as
Code:

solve
(
    fvm::ddt(T)
      + fvm::div(phi, T)
      - fvm::laplacian(DT, T)
);

But the latter is doing it in one "step". Because you want to do a setValues, you need to create the fvScalarMatrix object and then apply the setValues with the correct attributes (the place/cells and the value).
You wrote
Code:

TEqn().setValues
            (
                T.faceCells(),
                T_.boundaryField()[patchi].patchInternalField()
            );

and
Code:

TEqn.setValues(tCells, tVal);
That´s basically the same but in the latter case, you storred the T.faceCells in a variable called tCells; same for tVal and patchInternalField.
So that´s a matter of taste.
Read post from .ngj April 23, 2011 15:44 again.
But i suppose you don´t want to use the internal field (which makes sence for the turbulent dissipation epsilon); instead you want to give a fixed number like 293K e.g. if i got you right so far.

neewbie

mvoss April 28, 2011 17:02

Quote:

Originally Posted by MartinB (Post 305485)
...

Now with these lines similar to simpleFoam's createFields.H you can set your reference temperature:
Code:

    label TRefCell = 0;
    scalar TRefValue = 0.0;
    setRefCell(T, mesh.solutionDict().subDict("SIMPLE"), TRefCell, TRefValue);

Add these lines to your createFields.H. This approach assumes that in the SIMPLE dictionary in system/fvSolution appropriate values are defined for TRefCell and TRefValue.
...

hi,
How is this approach making it possible to set specific cell values? Did i miss smth.?

MartinB April 28, 2011 17:11

Hi Matthias,

since this is a way to set a fixed value for the pressure to a specific cell, I would give it a try to use it for a temperature, too. It will not work, if there are more cells to be specified, but with a single cell, it should work...

May be Jeff could post his solver and a test case completely?

Martin

ozzythewise April 28, 2011 17:21

Oops, my bad. Sorry guys. The file was too large for this forum so I've uploaded it here:

http://www.2shared.com/file/i2tqQurk...sportFoam.html

I'll check out what you just wrote and let you know anything else I find out.

Thanks again, you guys rock for all the help!
Jeff

ozzythewise April 28, 2011 17:33

I tried Martin's suggestion, it didn't work. Here was the final few lines of my createFields.H file
Code:

    label pRefCell = 0;
    scalar pRefValue = 0.0;
    setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);

    label TRefCell = 0;
    scalar TRefValue = 0.0;
    setRefCell(T, mesh.solutionDict().subDict("PISO"), TRefCell, TRefValue);

and my fvSolution read
Code:

PISO
{
    nCorrectors    2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue      0;
    TRefCell            0;
    TRefValue      1000;
}

Nothing in the solution changed. I'll take a look at what Matthias said and get back to you.

Cheers
Jeff

ozzythewise April 28, 2011 17:35

1 Attachment(s)
Also, attached is a test case that I'm using. This isn't what I'm actually working on but it's what I'm playing around with right now. Simple channel flow with heat transfer case.

MartinB April 28, 2011 18:55

Hi Jeff,

I found something useful in this thread:
http://www.cfd-online.com/Forums/ope...ne-cell-2.html

Change your TEqn.H like this:
Code:

/*
solve
(
        fvm::ddt(T)
      + fvm::div(phi, T)
      - fvm::laplacian(DT, T)
);
*/
{
    fvScalarMatrix tEqn
    (
            fvm::ddt(T)
            + fvm::div(phi, T)
            - fvm::laplacian(DT,T)
    );
    tEqn.setReference(TRefCell, TRefValue);
    tEqn.solve();
}

And as a reference point:
Code:

        TRefPoint      (0 0 0);
    TRefValue      1000;

This should do the trick...

In the thread above you can find hints how to set multiple cell values, too... post #25 ff...

Martin

ozzythewise April 30, 2011 10:24

Hi Martin,

Okay, I think I've fudged a solution. I made my TEqn.H file like this:
Code:

{
    fvScalarMatrix TEqn
    (
            fvm::ddt(T)
            + fvm::div(phi, T)
            - fvm::laplacian(DT,T)
    );
    TEqn.setReference(0, 1000);
    TEqn.solve();

}

And it definitely changed the solution. But as you can see I'm just sort of telling it for all cases that cell 0 is 1000K, whereas it would be nice if in fvSolution I could say the point that I want the value to be at whatever Temperature I want. If I make the TEqn.H file like this:
Code:

{
    fvScalarMatrix TEqn
    (
            fvm::ddt(T)
            + fvm::div(phi, T)
            - fvm::laplacian(DT,T)
    );
    TEqn.setReference(TRefCell, TRefValue);
    TEqn.solve();

}

I get an error that reads:
Code:

In file included from icoPeriodicScalarTransportFixedFoam.C:126:
TEqn.H: In function ‘int main(int, char**)’:
TEqn.H:16: error: ‘TRefCell’ was not declared in this scope
TEqn.H:16: error: ‘TRefValue’ was not declared in this scope

How do I get around this?

Thanks again
Jeff


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