CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   programming a new solver (http://www.cfd-online.com/Forums/openfoam/98890-programming-new-solver.html)

samiam1000 March 21, 2012 09:48

programming a new solver
 
1 Attachment(s)
Dear all,

I am trying to embed the Field Source functionality (see here) in the buoyantSimpleFoam solver.

My new solver is attached.

When I compile it, I get the following error:
Code:

lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/buoyantSimpleFoam_Epta$ wmake
Making dependency list for source file buoyantSimpleFoam_Epta.C
could not open file singlePhaseTransportModel.H for source file buoyantSimpleFoam_Epta.C
could not open file cellSet.H for source file buoyantSimpleFoam_Epta.C
SOURCE=buoyantSimpleFoam_Epta.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/buoyantSimpleFoam_Epta.o
buoyantSimpleFoam_Epta.C:36:39: error: singlePhaseTransportModel.H: No such file or directory
In file included from /opt/openfoam210/src/finiteVolume/lnInclude/basicSourceList.H:41,
                from /opt/openfoam210/src/finiteVolume/lnInclude/IObasicSourceList.H:38,
                from buoyantSimpleFoam_Epta.C:38:
/opt/openfoam210/src/finiteVolume/lnInclude/basicSource.H:49:21: error: cellSet.H: No such file or directory
make: *** [Make/linux64GccDPOpt/buoyantSimpleFoam_Epta.o] Error 1

. Do you know how I can solve it?

Thanks a lot,

Samuele

kwardle March 21, 2012 10:18

Take a look at the .dep file in the original solver and see where it is looking for these files. Perhaps it is using a relative path and you have moved the new solver somewhere else so it can't find the files. You will need to update your Make/options file accordingly so it knows where to look.

samiam1000 March 21, 2012 10:55

Dear Kent,

thanks a lot for answering.

Well, I understand what you say, but I would like to let you know that I have doubled the simpleFoam solver (calling it my_simpleFoam) and I saved it in the same directory with buoyantSimpleFoam_Epta.

When I compile the my_simpleFoam, everything works properly. reading the 2 .dep files, in the my_simpleFoam.dep the cellSets.H appears
Code:

.
.
.
my_simpleFoam.dep: $(WM_PROJECT_DIR)/src/finiteVolume/lnInclude/basicSource.H
my_simpleFoam.dep: $(WM_PROJECT_DIR)/src/meshTools/lnInclude/cellSet.H
my_simpleFoam.dep: $(WM_PROJECT_DIR)/src/meshTools/lnInclude/topoSet.H
my_simpleFoam.dep: $(WM_PROJECT_DIR)/src/finiteVolume/lnInclude/basicSourceI.H
my_simpleFoam.dep: $(WM_PROJECT_DIR)/src/finiteVolume/lnInclude/basicSourceListTemplates.C
.
.
.

, while in the buoyantSimpleFoam, it doesn't.

Any idea??

samiam1000 March 22, 2012 07:04

The compilation is now ok
 
Dear all,

the compilation of the solver I am trying to set is ok.

The point is that I can use it. When I try it on a case that usually works I get this error message:
Code:

--> FOAM FATAL ERROR:
incompatible dimensions for operation
    [U[1 -2 -2 0 0 0 0] ] == [U[0 1 -2 0 0 0 0] ]

    From function checkMethod(const fvMatrix<Type>&, const fvMatrix<Type>&)
    in file /opt/openfoam210/src/finiteVolume/lnInclude/fvMatrix.C at line 1313.

The meaning is pretty clear, but the point is that I don't know where the problem is.

Can anyone help?

ata March 22, 2012 07:08

Hi
May be I do not understand you correctly but I think any solver need its .dep file independent of where the solver is copied. So, the .dep file of two solvers are different.
Good luck

samiam1000 March 22, 2012 07:16

1 Attachment(s)
Dear Ata,

thanks for your answer.

Actually, I have compiled my new solver (I forgot the attachement, here it is)..

Now I do have a problem when I try to use it. And the problem is the one posted above.

Could you help?

Thanks,

Samuele

kwardle March 22, 2012 10:41

It is complaining that the units for the equation UEqn don't match on the LHS and RHS somewhere. Looks like you've got kg/m2s2 on the left and m/s2 on the right somewhere U is being called. So what's missing? Looks like density on RHS (multiply by kg/m3 and ...).

Perhaps the problem is in the momentumPredictor section, do you have momentumPredictor on? Something may need to be changed in that if statement in UEqn.H to make it work with sources, but I am not sure offhand. Try turning off momentumPredictor in fvSolution to check if that indeed is the problem.

samiam1000 March 22, 2012 10:53

2 Attachment(s)
Dear Kent,

thanks again for answering.

Well, I solved this point and now - in my buoyantSimplFoam_Epta I can fix the velocity in a certain region.

What I can not still do is to fix the temperature. I think I have to edit (adding the source) the hEqn.H file.

Is that a good way to proceed, to you?

I am attaching the working solver (where you can impose the U) and the tmp version, where I am trying (without success, so far!) to be able to impose the temperature.

Any idea?

kwardle March 22, 2012 10:58

Yes, you need to add sources(h) in to HEqn as you did for UEqn. Of course, in this case you already have some other source term there on the RHS. Add it in along with that one as +sources(h) and see if it works.

samiam1000 March 22, 2012 11:02

I've edited my hEqn.H file like this
Code:

{
    fvScalarMatrix hEqn
    (
        fvm::div(phi, h)
      - fvm::Sp(fvc::div(phi), h)
      - fvm::laplacian(turbulence->alphaEff(), h)
    ==
      - fvc::div(phi, 0.5*magSqr(U), "div(phi,K)")
      + sources(h)
    );

    hEqn.relax();
    sources.constrain(hEqn());
    hEqn.solve();

    thermo.correct();
}

and when I try to compile it I get the following error:

Code:

lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/buoyantSimpleFoam_Epta_tmp$ wclean
lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/buoyantSimpleFoam_Epta_tmp$ wmake
Making dependency list for source file buoyantSimpleFoam_Epta_tmp.C
SOURCE=buoyantSimpleFoam_Epta_tmp.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/buoyantSimpleFoam_Epta_tmp.o
In file included from buoyantSimpleFoam_Epta_tmp.C:63:
hEqn.H: In function ‘int main(int, char**)’:
hEqn.H:13: error: no match for call to ‘(Foam::fvScalarMatrix) ()’
make: *** [Make/linux64GccDPOpt/buoyantSimpleFoam_Epta_tmp.o] Error 1

Could you figure out what's wrong and what I should do?

Thanks a lot!

kwardle March 22, 2012 11:14

should be

sources.constrain(hEqn);

I think. Does that work?

samiam1000 March 22, 2012 11:17

It doesnt. If I add such a line, like:

Code:

{
    fvScalarMatrix hEqn
    (
        fvm::div(phi, h)
      - fvm::Sp(fvc::div(phi), h)
      - fvm::laplacian(turbulence->alphaEff(), h)
    ==
      - fvc::div(phi, 0.5*magSqr(U), "div(phi,K)")
      //+ sources(h)
    );

    hEqn.relax();
    sources.constrain(hEqn());
    hEqn.solve();

    thermo.correct();
}

it says:

Code:

lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/buoyantSimpleFoam_Epta_tmp$ wclean
lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/buoyantSimpleFoam_Epta_tmp$ wmake
Making dependency list for source file buoyantSimpleFoam_Epta_tmp.C
SOURCE=buoyantSimpleFoam_Epta_tmp.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/buoyantSimpleFoam_Epta_tmp.o
In file included from buoyantSimpleFoam_Epta_tmp.C:63:
hEqn.H: In function ‘int main(int, char**)’:
hEqn.H:13: error: no match for call to ‘(Foam::fvScalarMatrix) ()’
make: *** [Make/linux64GccDPOpt/buoyantSimpleFoam_Epta_tmp.o] Error 1

I am trying to find an example with fixed temperature/entalphy, but I can't find it!

samiam1000 March 22, 2012 12:07

WoW: it works, now. Just a small bug that I would like to solve, i.e. I'd like to impose the temperature and not the enthalpy..
But to get my goal this is not very important: it's just to have a `more practical' solver..

If you have any suggestion, please let me know.

Also, do you know if I can share the developed sover? If so, to whom should I send it?

kwardle March 22, 2012 12:16

Glad to hear it. Well, you can always just post it here for people to grab. How to 'share' things with the main distribution is one of those things that is a little nebulous...

You may also be able to get the folks who run the openfoamwiki to include it as a contrib. Not sure how to go about that myself.

samiam1000 March 22, 2012 12:20

1 Attachment(s)
Thanks!

Attached the solver. It is possible to fix either the entahlpy or the velocity.

It needs being compiled.

Have fun,

Samuele

Toorop June 1, 2012 09:30

2 Attachment(s)
Hi,

I have a very similar problem. I would like to fix the velocity in some cells and the solver in use is buoyantBoussinesqPimpleFoam.

I made the modifications to incorporate the field source addition to the existing solver:

creatField.H
Code:

+ IObasicSourceList sources(mesh);
pEqn.H
Code:

U = rAU*(UEqn() == sources(U))().H();
...
        if (pimple.finalNonOrthogonalIter())
        {
            // Calculate the conservative fluxes
            phi -= p_rghEqn.flux();

            // Explicitly relax pressure for momentum corrector
            p_rgh.relax();

            // Correct the momentum source with the pressure gradient flux
            // calculated from the relaxed pressure
            U -= rAU*fvc::reconstruct((buoyancyPhi + p_rghEqn.flux())/rAUf);
            U.correctBoundaryConditions();
            sources.correct(U);
        }

UEqn.H
Code:

    // Solve the momentum equation

    tmp<fvVectorMatrix> UEqn
    (
        fvm::ddt(U)
      + fvm::div(phi, U)
      + turbulence->divDevReff(U)
    );

    UEqn().relax();
   
    sources.constrain(UEqn());

    if (pimple.momentumPredictor())
    {
        solve
        (
            UEqn()
        ==
            fvc::reconstruct
            (
                (
                  - ghf*fvc::snGrad(rhok)
                  - fvc::snGrad(p_rgh)
                )*mesh.magSf()
            )
            + sources(U)
        );
    }

The code compile without errors, but the little sample case I created blows up within a few iterations. I just made the modifications the were evident in the releases between pimpleFoam version 2.0 and 2.1, so I guess it's a bit more complicated and I think the problem may be with the pEqn.H but I have no clue about it. If you remove the sourcesProperties from constant folder the case runs without any problem.
Any help would be appreciated!

samiam1000 June 1, 2012 09:48

I'll study your case, since it's that same thing that I'd like to do :)..

dl6tud June 5, 2012 07:56

I am working on the same problem ...

@samiam1000: Do you have an example case to try your modified solver? Thank you!!

samiam1000 June 5, 2012 08:07

For sure..

But not here. Please, give me your email and I'll share it with you asap.

Have fun,

Samuele

dl6tud June 5, 2012 08:12

@Toorop: There may be an error in the line
Quote:

sources.correct(U);
. Without that line, I can compile it, with it, not:
Quote:

class Foam::IObasicSourceList hast no member named 'correct'


All times are GMT -4. The time now is 00:14.