CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Add time dependent Source term (http://www.cfd-online.com/Forums/openfoam-solving/80298-add-time-dependent-source-term.html)

libe September 22, 2010 03:54

Add time dependent Source term
 
Hello guys,
I am new in OpenFoam and I face several difficulties. I have followed the advice of Henrik for new openfoamers _ http://www.cfd-online.com/Forums/ope...gramming.html_ but still i cant find how to add in my model a new source term! I want to add the term
Source = A * cos(f * t)
I tried the following

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

Source = A* Foam::cos(f * runTime.time().value());

but nothing

and after the

At creatFields.H

volScalarField Source
(
"Source",
A* Foam::cos(f * runTime.time().value())
);

but nothing again...
I know its something very simple but I cant understand what I am missing!
Please help!
Thanks

akidess September 22, 2010 05:30

It sounds like you managed to create a source field, but you didn't include it in any equation.

libe September 22, 2010 06:32

Hello akidess for ur interest,
the system of equations that i try to solve is the following

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

// #include "readPISOControls.H"
// #include "CourantNo.H"

Source = A* Foam::cos(f * runTime.time().value());

tmp<fvVectorMatrix> EEqn
(
epsilon0*fvm::ddt(E)==fvc::curl(H)

);
// EEqn().relax();
EEqn().solve();


tmp<fvVectorMatrix> HEqn
(
mu*fvm::ddt(H)== -fvc::curl(E)+Source


);
// HEqn().relax();
HEqn().solve();

The transient form of Maxwell equations. When I put the Source term there are compiler's error. Is there any manual or something for general treatment of source terms?

akidess September 22, 2010 06:58

Quote:

Originally Posted by libe (Post 276127)
Code:

...
volScalarField Source = A* Foam::cos(f * runTime.time().value());
...


What errors do you get?

libe September 22, 2010 07:31

When I am using the lines that you mentioned at the creatField.H i take the following message

createFields.H:50: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(const char [7], Foam::doubleScalar)’
/home/stagiere/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude/GeometricField.C:652: note: candidates are: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/stagiere/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude/GeometricField.C:617: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/stagiere/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude/GeometricField.C:587: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]

libe September 22, 2010 07:36

when i am using the code u mentioned at the solver file myMycro.C I take:

myMicro.C:57: error: conversion from ‘Foam::doubleScalar’ to non-scalar type ‘Foam::volScalarField’ requested
/home/stagiere/OpenFOAM/OpenFOAM-1.7.1/src/finiteVolume/lnInclude/initContinuityErrs.H:37: warning: unused variable ‘cumulativeContErr’
make: *** [Make/linux64GccDPOpt/myMicro.o] Error 1

akidess September 22, 2010 07:41

How are A and f defined? Is f a scalar and A a volScalarField?

libe September 22, 2010 07:47

for the moment i remove A and f i let only the cos(t) in order to avoid athor problems.i just examine a very simple form

akidess September 22, 2010 07:56

It can't work like that for two reasons:
1. You are trying to assign a scalar value to a matrix. This is giving you the compiler error. Use
Code:

volScalarField Source
    (
        IOobject
        (
            "Source",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        mesh,
        dimensionedScalar("Source", dimensionSet(0,0,0,0,0,0,0), cos(runTime.time().value()))
    );

2. Using this will probably give you a run time error because the dimensions are not correct. Fill in the proper dimensions in the dimensionSet above and all should be well.

- Anton

libe September 22, 2010 09:04

Thank u Anton very much :)

herbert September 22, 2010 09:14

Hi,

correct me if I'm wrong, but shouldn't Source be of type volVectorField? Just because it is a source term inside a vector equation.

Regards,
Stefan

rieuk September 23, 2010 03:03

I was thinking the same thing (volVectorField). Also, could someone explain what the difference between runtime.value() and runtime.time().value() is?

akidess September 23, 2010 07:30

Stefan: Yes, I overlooked that this is a vector equation, so I guess the source should be a volVectorField.

Rieuk: If I remember correct former will give you a dimensionedScalar, while the latter expression will give you a raw number.

rieuk September 23, 2010 09:12

Thanks Anton. I've been using runTime.value() all this time assuming it was dimensionless. However wmake gives no dimension errors when compiling...could this be giving me bad solutions?


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