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/)
-   -   Create a scalar from a volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/162861-create-scalar-volscalarfield.html)

agustinvo November 19, 2015 05:45

Create a scalar from a volScalarField
 
Hello

I want to modify a boundary condition, where you have to give the density as a scalar, but since in my case, the density will change, I want to use my own density.

I thought it was ok like this, but in my simulation I got this error:
Code:

Starting time loop

Time = 1

DILUPBiCG:  Solving for Ux, Initial residual = 1, Final residual = 1.723949e-12, No Iterations 3
DILUPBiCG:  Solving for Uy, Initial residual = 1, Final residual = 4.017873e-11, No Iterations 1
aqui
DILUPBiCG:  Solving for T, Initial residual = 1, Final residual = 6.385874e-11, No Iterations 4
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigSegv::sigHandler(int) at ??:?
#2 
 at sigaction.c:?
#3  Foam::multiply(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) at ??:?
#4  Foam::operator*(Foam::UList<double> const&, Foam::tmp<Foam::Field<double> > const&) at ??:?
#5 Foam::nonUniformDensityHydrostaticPressureFvPatchScalarField::updateCoeffs() at ??:?
#6  Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricBoundaryField::updateCoeffs() at ??:?
#7  Foam::fvMatrix<double>::fvMatrix(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::dimensionSet const&) at ??:?
#8  Foam::fv::gaussLaplacianScheme<double, double>::fvmLaplacianUncorrected(Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) at ??:?
#9  Foam::fv::gaussLaplacianScheme<double, double>::fvmLaplacian(Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) at ??:?
#10 
 at ??:?
#11 
 at ??:?
#12 
 at ??:?
#13  __libc_start_main at ??:?
#14 
 at ??:?
Segmentation fault

So I went there to check what is going on.

There, I have:
Code:

void Foam::nonUniformDensityHydrostaticPressureFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const uniformDimensionedVectorField& g =
        db().lookupObject<uniformDimensionedVectorField>("g");
 
    const volScalarField& rho_ =
        db().lookupObject<volScalarField>("rho");


    operator==
    (
        pRefValue_
      + rho_*((g.value() & patch().Cf()) - (g.value() & pRefPoint_))
    );

    fixedValueFvPatchScalarField::updateCoeffs();
}

But in the non-modified BC, rho_ is declared as a scalar, and I am using a volScalarField.

Do you know how can I change this, it means, create a scalar from a volScalarField?

Thank you everybody!

hk318i November 20, 2015 18:18

I am afraid that your question is not clear for me. However based on this code, you are reading the complete density field rho_ and using it to calculate the BC. I am really surprised that you managed to compile this code. If you would like to read a rho value as scalar try to read it as scalar from the BC dictionary and use it in your calculations.

Bw,
Hassan

agustinvo November 24, 2015 10:33

Hi Hassan,

as you say I am reading all the rho field, as a volScalar. I don't know how to take from there the scalar values of the boundary, in order to use them in the code.


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