CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   compiling a solver (https://www.cfd-online.com/Forums/openfoam-programming-development/96557-compiling-solver.html)

fferroni January 25, 2012 17:43

compiling a solver
 
Hello.

I need to compile a solver, and I've never done this before.

I have a .C file for a new solver. I suppose I need to create a "createFields.H" file. I tried creating one, and then doing wmake. However, these are errors I get.

DNSsolverMHD.C:27:27: error: 'B0' was not declared in this scope
DNSsolverMHD.C:31:54: error: 'PotE' was not declared in this scope
In file included from DNSsolverMHD.C:37:0:
/Users/MacbookPro/OpenFOAM/OpenFOAM-2.0.x/src/finiteVolume/lnInclude/CourantNo.H:39:29: error: 'phi' was not declared in this scope
DNSsolverMHD.C:39:29: error: 'PotElnCorr' was not declared in this scope
DNSsolverMHD.C:47:22: error: 'phi' was not declared in this scope
DNSsolverMHD.C:98:30: error: 'PotERefCell' was not declared in this scope
DNSsolverMHD.C:98:43: error: 'PotERefValue' was not declared in this scope


I need to declare these, but where?

Kind Regards,

Francesco

wyldckat January 25, 2012 18:39

Greetings Francesco,

I suggest that you first see the following tutorial and do the steps shown there: http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam
That way you can get a better grasp of what is needed and what you should look for ;) And when in doubt: see the code that already exists in OpenFOAM!

Best regards,
Bruno

fferroni January 26, 2012 17:02

Hello.

I read the tutorial and still have some questions (and errors)

1. I have a vector B0 and would like to find it's direction. So:

const vector nB = B0.value()/mag(B0.value())

However, I get that:

EpotFoam.C:27:30: error: 'struct Foam::volVectorField' has no member named 'value'.
I'm not sure why this is happening.


2. For the equation:
volVectorField lorentz = sigma * (-fvc::grad(PotE) ^ B0) + sigma * ((U ^ B0) ^ B0);

I add to the createFields.H, following the tutorial, the following:

Info<< "Reading field PotE\n" << endl;
volVectorField PotE
(
IOobject
(
"PotE",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

Similarly for B0, and phi etc. but I get errors like:

EpotFoam.C:31:90: error: conversion from 'Foam::tmp<Foam::GeometricField<Foam::Tensor<doubl e>, Foam::fvPatchField, Foam::volMesh> >' to non-scalar type 'Foam::volVectorField' requested

Does this mean I am not defining the class of the field correctly?

Basically, what I'm trying to achieve is reconstruct current density and potential field from a magnetic field...

Kind Regards,

Francesco

wyldckat January 28, 2012 02:52

Hi Francesco,

Quote:

Originally Posted by fferroni (Post 341389)
Hello.

I read the tutorial and still have some questions (and errors)

1. I have a vector B0 and would like to find it's direction. So:

const vector nB = B0.value()/mag(B0.value())

However, I get that:

EpotFoam.C:27:30: error: 'struct Foam::volVectorField' has no member named 'value'.
I'm not sure why this is happening.

Well, the compiler isn't wrong... there is no "value" method for "volVectorField". You can search for it on the code documentation, namely here: http://foam.sourceforge.net/docs/cpp/
I don't know the solution :(, but looking at more OpenFOAM code might help you :)

Quote:

Originally Posted by fferroni (Post 341389)
2. For the equation:
volVectorField lorentz = sigma * (-fvc::grad(PotE) ^ B0) + sigma * ((U ^ B0) ^ B0);

I add to the createFields.H, following the tutorial, the following:

Info<< "Reading field PotE\n" << endl;
volVectorField PotE
(
IOobject
(
"PotE",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
&nbsp;),
mesh
);

Similarly for B0, and phi etc. but I get errors like:

EpotFoam.C:31:90: error: conversion from 'Foam::tmp<Foam::GeometricField<Foam::Tensor<doubl e>, Foam::fvPatchField, Foam::volMesh> >' to non-scalar type 'Foam::volVectorField' requested

Does this mean I am not defining the class of the field correctly?

When in more doubt, check the code documentation. For example: http://foam.sourceforge.net/docs/cpp...ce.html#l00055
Basically, the problem is that "volVectorField" is of this type (Line 55 of volFieldsFwd.H):
Code:

typedef GeometricField<vector, fvPatchField, volMesh> volVectorField;
AFAIK, the conversion fails because "tensor" and "vector" are not compatible. So it looks like something on the equation is not working as you would expect. So you better check the types of each item and operation on the equation.

Quote:

Originally Posted by fferroni (Post 341389)
Basically, what I'm trying to achieve is reconstruct current density and potential field from a magnetic field...

I'm not 100% certain about this, but "applications/solvers/electromagnetics/magneticFoam" might have what you need or at least give you some more ideas.

If anyone else has more experience than me here on the forum, please do reply!

Best regards,
Bruno

fferroni January 28, 2012 08:20

Thanks that was very useful.
Managed to iron out most of the errors by understanding the required classes.

However, there is one that I don't understand.

EpotFoam.C:96:44: error: no matching function for call to 'laplacian(Foam::scalar&, Foam::volScalarField&)'

I have:
fvm::laplacian(consist,PotE) == consist * fvc::div(psiub)

where consist is defined as a scalar, and PotE as a volScalarField.

From the Programmers Guide,
laplacian(Gamma,phi)
it seems to say that Gamma can be a scalar, and phi can be a volScalarField... so I don't see why it gives me an error...

Any ideas?

Kind Regards,

Francesco

wyldckat January 28, 2012 09:05

Hi Francesco,

You gotta be cautious with what is written on the Programmers Guide, because it hasn't been properly reviewed for quite a while: http://www.openfoam.org/archive/1.6/docs/

But according to the source code documentation, on the "Foam::fvm Namespace Reference" (here), the closest I can find are these two:
Code:

template<class Type , class GType >  tmp< fvMatrix< Type > > laplacian (const dimensioned< GType > &gamma, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
template<class Type , class GType >  tmp< fvMatrix< Type > > laplacian (const dimensioned< GType > &gamma, const GeometricField< Type, fvPatchField, volMesh > &vf)

Basically, when Gamma is a "dimensioned< GType >".

Best regards,
Bruno

fferroni January 28, 2012 17:24

Yay. It compiles now... dimensionedScalar seems to have done the trick. Thank you!


I now have another n00b question..*sigh*

When I run the solver, it gives me an IO error because I haven't given it sufficient boundary conditions.
There are some variables however that I have had to define in define.H that I don't know the boundary conditions. It's just calculated from some other term which I know... I tried doing

inlet
{
type calculated;
}
but it doesn't seem to be working. Do you know how to write this correctly?

Cheers,

Francesco

wyldckat January 28, 2012 19:25

Hi Francesco,

As with any boundary conditions, you need to know what kind of simulation you are doing, so you can have a better understanding of the necessary boundary conditions. But failing that, you can always try the usual suspects: fixed value, zero gradient and calculated. And alternate around each patch, in an attempt to have a viable solver functionality. For example, inlet with fixed value and outlet with zero gradient and then vice-versa.

But when in doubt, the best thing to do is to reduce the problem to the smallest thing you can do math yourself, such as 2D case with an inlet and an outlet. Pretty much one of those unit tests of comparing the simulation results with the analytical/theoretical solutions.

Good luck!
Bruno


All times are GMT -4. The time now is 08:06.