CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Calculate a quantity based on another quantity solved by Openfoam. (https://www.cfd-online.com/Forums/openfoam/110876-calculate-quantity-based-another-quantity-solved-openfoam.html)

hz283 December 23, 2012 14:26

Calculate a quantity based on another quantity solved by Openfoam.
 
Dear All,

I would like to calculate and output a quantity based on a scalar and added the following lines in createFields.H:

volScalarField vc
(
IOobject
(
"vc",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
0.1*mag(fvc::grad(c))*mag(fvc::grad(c))
);


I added several lines to solve the goeverning equation to obtain the scalar fields c. I can confirm that the solutions of c is correct. However, for vc, I found that the above lines did not work at all. Does anybody know what is the problem behind it?

Thank you very much.
h

fumiya December 23, 2012 19:13

Hi,

Do you update the vc value at each time or iteration?
vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));

Best regards,
fumiya

hz283 December 23, 2012 19:18

Hi,

that quantity should be calculated each time step, but I found that its value always failed to be updated suing the expression. I did not figure it out about this. Thank you very much.

best regards,
h

fumiya December 23, 2012 19:33

Hi,

I think you can update the vc field at each time step
if you add the following line in the time loop.
Code:

vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));
Best regards,
fumiya

hz283 December 23, 2012 19:42

Hi,

Thank you very much for your suggestion. If I adopt your method, but if I still want to output this quantity, maybe I need to add the following lines in createFields.H:

volScalarField vc
(
IOobject
(
"vc",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
mesh
);

But When I do this, compilation is successful, but when I run the code, some error information appears as follows:

#0 Foam::error::printStack(Foam::Ostream&) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#1 Foam::sigFpe::sigHandler(int) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#2 ?? in "/lib64/libc.so.6"
#3 Foam::divide(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#4 void Foam::divide<Foam::fvsPatchField>(Foam::FieldField <Foam::fvsPatchField, double>&, Foam::FieldField<Foam::fvsPatchField, double> const&, Foam::FieldField<Foam::fvsPatchField, double> const&) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libcompressibleRASModels.so"
#5 Foam::tmp<Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> > Foam::operator/<Foam::fvsPatchField, Foam::surfaceMesh>(Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::tmp<Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> > const&) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libcompressibleRASModels.so"
#6 Foam::fv::backwardDdtScheme<Foam::Vector<double> >::fvcDdtPhiCorr(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) in "/users/abc/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64Gcc45DPOpt/lib/libfiniteVolume.so"
#7 Foam::tmp<Foam::GeometricField<Foam::flux<Foam::Ve ctor<double> >::type, Foam::fvsPatchField, Foam::surfaceMesh> > Foam::fvc::ddtPhiCorr<Foam::Vector<double> >(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::flux<Foam::Vector<doubl e> >::type, Foam::fvsPatchField, Foam::surfaceMesh> const&) in "/users/abc/OpenFOAM/abc-2.1.1/platforms/linux64Gcc45DPOpt/bin/cmcPimpleFoam"
#8 main in "/users/abc/OpenFOAM/abc-2.1.1/platforms/linux64Gcc45DPOpt/bin/cmcPimpleFoam"
#9 __libc_start_main in "/lib64/libc.so.6"
#10 Foam::UOPstream::write(char) in "/users/abc/OpenFOAM/abc-2.1.1/platforms/linux64Gcc45DPOpt/bin/cmcPimpleFoam"
Floating point exception

fumiya December 23, 2012 19:54

Hi,

How about if you use the code in your post #1 with my suggestion?

In the createFields.H

volScalarField vc
(
IOobject
(
"vc",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
0.1*mag(fvc::grad(c))*mag(fvc::grad(c))
);


and in the time loop
vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));

Best regards,
fumiya

hz283 December 23, 2012 20:00

Hi fumiya,

I tried the method mentioned post #6, but the error info is totally the same as those in post #5. I do know why these errors appear. Do you have further suggestions?

best
h

fumiya December 23, 2012 20:30

Hi hz283,

I have confirmed that the scalarTransportFoam added the lines in the
post #6 runs well without error.

If you can post the solver and case, I think you will get further suggestions.

Best regards,
fumiya

hz283 December 24, 2012 09:36

Hi fumiya,

In the createFields.H, if I use the following instead of IOobject, the code can run successfully:

volScalarFields("vc", 0.1*mag(fvc::grad(c))*mag(fvc::grad(c))).

This indicates that the Input/Output is not correct. But I still do not know about the cause.

Merry Xmas.
h

hz283 December 26, 2012 15:17

Quote:

Originally Posted by fumiya (Post 398828)
Hi,

How about if you use the code in your post #1 with my suggestion?

In the createFields.H

volScalarField vc
(
IOobject
(
"vc",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
0.1*mag(fvc::grad(c))*mag(fvc::grad(c))
);


and in the time loop
vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));

Best regards,
fumiya

Hi fumiya,

If I add the following lines in createFields.H:
volScalarField vc
(
IOobject
(
"vc",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
0.1*mag(fvc::grad(c))*mag(fvc::grad(c))
);


But If I donot have the following lines in the time loop:
vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));

It seems that the quantity will only calculated once just in the beginning and will not be updated with the time advancement. Is my understanding correct about this?

Thanks.


fumiya December 27, 2012 02:47

Hi hz283,

I think you are correct.
We have to add the following line
vc = 0.1*mag(fvc::grad(c))*mag(fvc::grad(c));

in the time loop in order to update the value vc.

fumiya


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