CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Problems using Eqn.solve() on custom solver

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ErikNij

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2024, 11:11
Default Problems using Eqn.solve() on custom solver
  #1
New Member
 
Erik Nijkamp
Join Date: Dec 2023
Posts: 5
Rep Power: 2
ErikNij is on a distinguished road
Hi all,


Long time lurker, but first time poster, but I hope that I do this right, and that someone can help me and that I can help someone in the future.

In any case, I am trying to develop my own solver in OpenFOAM. This is a solver that should calculate the magnitude of induction heating due to a coiled wire with AC current.


There are of course many equations to be solved, however the first one I need to solve is simply:

curl(H) = J_Coil. J Coil is defined by the user, so this is a simple 1 unknown, 1 equation deal.


I tried to solve it in OpenFOAM in the following way. First, define the needed varibles



Code:
volVectorField HCoil
        (
            IOobject
            (
           "HCoil",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );


 volVectorField JCoil
    (
        IOobject
        (
           "JCoil",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
And then the solver itself


Code:
#include "fvCFD.H"
int main(int argc, char *argv[])
{

#   include "setRootCase.H"
#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initConvergenceCheck.H"

    Info<< "\nStarting time loop\n" << endl;
    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        tmp<fvVectorMatrix> HCoilEqn
        (
            fvc::curl(HCoil) - JCoil
        );
        solve(HCoilEqn);
        #include "convergenceCheck.H"

        runTime.write();
    }

    Info<< "End\n" << endl;

    return 0;
Sadly, this does not compile, and gives the following compile time error


Code:
MyEmFoam.C: In function ‘int main(int, char**)’:
MyEmFoam.C:88:9: error: no matching function for call to ‘Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > >::tmp(Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >)’
   88 |         );
      |         ^
In file included from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmp.H:140,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/PtrListI.H:29,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/PtrList.H:310,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/List.C:30,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/List.H:291,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/labelList.H:36,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/Pstream.H:43,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/OPstream.H:35,
                 from /home/erik/foam/foam-extend-5.0/src/foam/lnInclude/parRun.H:35,
                 from /home/erik/foam/foam-extend-5.0/src/finiteVolume/lnInclude/fvCFD.H:4,
                 from MyEmFoam.C:61:
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:74:8: note: candidate: ‘Foam::tmp<T>::tmp(const Foam::tmp<T>&, bool) [with T = Foam::fvMatrix<Foam::Vector<double> >]’
   74 | inline Foam::tmp<T>::tmp(const tmp<T>& t, bool allowTransfer)
      |        ^~~~
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:74:8: note:   candidate expects 2 arguments, 1 provided
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:50:8: note: candidate: ‘Foam::tmp<T>::tmp(const Foam::tmp<T>&) [with T = Foam::fvMatrix<Foam::Vector<double> >]’
   50 | inline Foam::tmp<T>::tmp(const tmp<T>& t)
      |        ^~~~
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:50:40: note:   no known conversion for argument 1 from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to ‘const Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > >&’
   50 | inline Foam::tmp<T>::tmp(const tmp<T>& t)
      |                          ~~~~~~~~~~~~~~^
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:41:8: note: candidate: ‘Foam::tmp<T>::tmp(const T&) [with T = Foam::fvMatrix<Foam::Vector<double> >]’
   41 | inline Foam::tmp<T>::tmp(const T& tRef)
      |        ^~~~
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:41:35: note:   no known conversion for argument 1 from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to ‘const Foam::fvMatrix<Foam::Vector<double> >&’
   41 | inline Foam::tmp<T>::tmp(const T& tRef)
      |                          ~~~~~~~~~^~~~
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:32:8: note: candidate: ‘Foam::tmp<T>::tmp(T*) [with T = Foam::fvMatrix<Foam::Vector<double> >]’
   32 | inline Foam::tmp<T>::tmp(T* tPtr)
      |        ^~~~
/home/erik/foam/foam-extend-5.0/src/foam/lnInclude/tmpI.H:32:29: note:   no known conversion for argument 1 from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to ‘Foam::fvMatrix<Foam::Vector<double> >*’
   32 | inline Foam::tmp<T>::tmp(T* tPtr)
      |                          ~~~^~~~
make: *** [MyEmFoam.dep:736: Make/linux64GccDPInt32Opt/MyEmFoam.o] Error 1
From what I can understand, there are 6 versions of the fvVectorMatrix, 3 of which take 2 inputs, which I'm not doing, and 3 more that take 1 argument, which should be of the type Foam::fvMatrix<Foam::Vector> >, and I see that my one input is of the type Foam::tmp<Foam::GeometricField<Foam::Vector<double >, Foam::fvPatchField, Foam::volMesh> >


However, from other times that I have seen solve be used (in simpleFoam for example) it seems like they are doing something similar to me, so I am confused as to what is going wrong.



At the risk of sounding stupid, I thought that fvVectorMatrix would make the matrix, so to me, I dont understand why it needs a matrix as an input, as I thought that it makes the matrix.



Anyways, I hope that someone can help for. For the record, I am using foam-extend 5.0, as the old electromagnetic solver used fe. However, I can switch off of it if needed, but I think it should still work.
ErikNij is offline   Reply With Quote

Old   February 12, 2024, 04:59
Default
  #2
New Member
 
Join Date: May 2019
Posts: 16
Rep Power: 7
NiklasW is on a distinguished road
Hi
I think the problem isn't the fvVectorMatrix itself, but that you're trying to construct it as a temporary object with that tmp<> wrapper.
So if there is no specific reason for you to make that matrix temporary, I'd suggest to leave that tmp<> wrapper away. I hope that helps.


Edit: I rethought this and no longer think that is the problem. Sorry about that
NiklasW is offline   Reply With Quote

Old   February 12, 2024, 09:06
Default
  #3
New Member
 
Erik Nijkamp
Join Date: Dec 2023
Posts: 5
Rep Power: 2
ErikNij is on a distinguished road
Ah thanks anyways.

I did try something, I changed fvc::curl to fvm::lapcian, and then it did compile, however the mathematics are of course wrong. So perhaps this indicates that fvc::curl is not expecting as I expect it to. What do you think about this?


Edit:

I think I might have figured it out after looking at the fourm: problem with fvc:div

TL;DR fvc::curl (and other fvc:: operators) are explicit, that is to say they don't output a matrix, only fvm:: operators do that. So I want to solve my problem, I will need to find out how to express my problem only using fvm:: operators. Back to the books I guess
NiklasW likes this.
ErikNij is offline   Reply With Quote

Reply

Tags
matrix, solve, solver compilation error, types


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPUs vs GPUs for CFD? hami11 Hardware 22 July 23, 2024 15:59
Duplicate library entries when running a solver with custom library francescomarra OpenFOAM Programming & Development 3 May 17, 2022 08:37
Custom surface reaction solver with reactingParcelFoam doesn'd execute MetEng OpenFOAM Programming & Development 0 December 17, 2020 18:42
[ICEM] Problems with coedge curves and surfaces tommymoose ANSYS Meshing & Geometry 6 December 1, 2020 11:12
[OpenFOAM.org] Custom solver not running in parallel syavash OpenFOAM Installation 12 June 6, 2019 15:02


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