Exemple #1
0
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{

    Info<< "\tdomain volume = " << gSum(mesh.V()) << endl;

    const cellZoneMesh& cellZones = mesh.cellZones();
    scalar cellZoneVolTotal(0);
    if (cellZones.size())
    {
        Info  << "cellZones:" << endl;
        forAll(cellZones, i)
        {
            const cellZone& zone = mesh.cellZones()[i];
            const cellZoneMesh& zoneMesh = zone.zoneMesh();
            const labelList& cellsZone = zoneMesh[i];
            scalar cellZoneVol(0);
            //float cellZoneVol=0.0;
            forAll(cellsZone, cI)
            { 
                cellZoneVol += mesh.V()[cellsZone[cI]];
            }
            Info  << '\t' << zone.name() << " volume = " << cellZoneVol << endl;
            cellZoneVolTotal += cellZoneVol;
        }
    }
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
    IOobject phiHeader
    (
        "phi",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );

    IOobject faceIbMaskHeader
    (
        "faceIbMask",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );

    if (phiHeader.headerOk() && faceIbMaskHeader.headerOk())
    {
        Info<< "    Reading phi" << endl;
        surfaceScalarField phi(phiHeader, mesh);

        Info<< "    Reading faceIbMask" << endl;
        surfaceScalarField faceIbMask(faceIbMaskHeader, mesh);

        volScalarField contErr = fvc::div(faceIbMask*phi);

        scalar sumLocalContErr = runTime.deltaT().value()*
            mag(contErr)().weightedAverage(mesh.V()).value();

        scalar globalContErr = runTime.deltaT().value()*
            contErr.weightedAverage(mesh.V()).value();

        Info<< "IB time step continuity errors : sum local = "
            << sumLocalContErr
            << ", global = " << globalContErr
            << endl;

        volScalarField magContErr
        (
            "magContErr",
            mag(contErr)
        );
        magContErr.write();

    }
    else
    {
        Info<< "    No phi or faceIbMask" << endl;
    }

}
Foam::anisotropicFilter::anisotropicFilter
(
    const fvMesh& mesh,
    const dictionary& bd
)
:
    LESfilter(mesh),
    widthCoeff_(readScalar(bd.subDict(type() + "Coeffs").lookup("widthCoeff"))),
    coeff_
    (
        IOobject
        (
            "anisotropicFilterCoeff",
            mesh.time().timeName(),
            mesh
        ),
        mesh,
        dimensionedVector("zero", dimLength*dimLength, Zero),
        calculatedFvPatchScalarField::typeName
    )
{
    for (direction d=0; d<vector::nComponents; d++)
    {
        coeff_.internalField().replace
        (
            d,
            (1/widthCoeff_)*
            sqr
            (
                2.0*mesh.V()
               /fvc::surfaceSum(mag(mesh.Sf().component(d)))().internalField()
            )
        );
    }
}
Exemple #4
0
Foam::anisotropicFilter::anisotropicFilter
(
    const fvMesh& mesh,
    scalar widthCoeff
)
:
    LESfilter(mesh),
    widthCoeff_(widthCoeff),
    coeff_
    (
        IOobject
        (
            "anisotropicFilterCoeff",
            mesh.time().timeName(),
            mesh
        ),
        mesh,
        dimensionedVector("zero", dimLength*dimLength, vector::zero),
        calculatedFvPatchVectorField::typeName
    )
{
    for (direction d=0; d<vector::nComponents; d++)
    {
        coeff_.internalField().replace
        (
            d,
            (2.0/widthCoeff_)*mesh.V()
           /fvc::surfaceSum(mag(mesh.Sf().component(d)))().internalField()
        );
    }
}
Exemple #5
0
Foam::Kmesh::Kmesh(const fvMesh& mesh)
:
    vectorField(mesh.V().size()),
    nn_(vector::dim)
{
    boundBox box = mesh.bounds();
    l_ = box.span();

    vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
    vector cellL = 2*(box.max() - cornerCellCentre);

    vector rdeltaByL;
    label nTot = 1;

    forAll(nn_, i)
    {
        nn_[i] = label(l_[i]/cellL[i] + 0.5);
        nTot *= nn_[i];

        if (nn_[i] > 1)
        {
            l_[i] -= cellL[i];
        }

        rdeltaByL[i] = nn_[i]/(l_[i]*l_[i]);
    }
Foam::scalar Foam::compressibleCourantNo
(
    const fvMesh& mesh,
    const Time& runTime,
    const volScalarField& rho,
    const surfaceScalarField& phi
)
{
    scalarField sumPhi
    (
        fvc::surfaceSum(mag(phi))().primitiveField()
      / rho.primitiveField()
    );

    scalar CoNum = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue();

    scalar meanCoNum =
        0.5*(gSum(sumPhi)/gSum(mesh.V().field()))*runTime.deltaTValue();

    Info<< "Region: " << mesh.name() << " Courant Number mean: " << meanCoNum
        << " max: " << CoNum << endl;

    return CoNum;
}
void Foam::ignitionSite::findIgnitionCells(const fvMesh& mesh)
{
    // Bit tricky: generate C and V before shortcutting if cannot find
    // cell locally. mesh.C generation uses parallel communication.
    const volVectorField& centres = mesh.C();
    const scalarField& vols = mesh.V();

    label ignCell = mesh.findCell(location_);
    if (ignCell == -1)
    {
        return;
    }

    scalar radius = diameter_/2.0;

    cells_.setSize(1);
    cellVolumes_.setSize(1);

    cells_[0] = ignCell;
    cellVolumes_[0] = vols[ignCell];

    scalar minDist = GREAT;
    label nIgnCells = 1;

    forAll(centres, celli)
    {
        scalar dist = mag(centres[celli] - location_);

        if (dist < minDist)
        {
            minDist = dist;
        }

        if (dist < radius && celli != ignCell)
        {
            cells_.setSize(nIgnCells+1);
            cellVolumes_.setSize(nIgnCells+1);

            cells_[nIgnCells] = celli;
            cellVolumes_[nIgnCells] = vols[celli];

            nIgnCells++;
        }
    }
Foam::laplaceFilter::laplaceFilter(const fvMesh& mesh, const dictionary& bd)
:
    LESfilter(mesh),
    widthCoeff_(readScalar(bd.subDict(type() + "Coeffs").lookup("widthCoeff"))),
    coeff_
    (
        IOobject
        (
            "laplaceFilterCoeff",
            mesh.time().timeName(),
            mesh
        ),
        mesh,
        dimensionedScalar("zero", dimLength*dimLength, 0),
        calculatedFvPatchScalarField::typeName
    )
{
    coeff_.ref() = pow(mesh.V(), 2.0/3.0)/widthCoeff_;
}
Foam::laplaceFilter::laplaceFilter(const fvMesh& mesh, scalar widthCoeff)
:
    LESfilter(mesh),
    widthCoeff_(widthCoeff),
    coeff_
    (
        IOobject
        (
            "laplaceFilterCoeff",
            mesh.time().timeName(),
            mesh
        ),
        mesh,
        dimensionedScalar("zero", dimLength*dimLength, 0),
        calculatedFvPatchScalarField::typeName
    )
{
    coeff_.ref() = pow(mesh.V(), 2.0/3.0)/widthCoeff_;
}
void Foam::calcTypes::average::writeAverageField
(
    const IOobject& header,
    const fvMesh& mesh,
    bool& processed
)
{
    typedef GeometricField<Type, fvPatchField, volMesh> fieldType;

    if (header.headerClassName() == fieldType::typeName)
    {
        Info<< "    Reading " << header.name() << endl;
        fieldType field(header, mesh);

        dimensioned<Type> avg ("avg", field.dimensions(), pTraits<Type>::zero);
        
        avg = field.weightedAverage(mesh.V());;

        Info<< "    Calculating average(" << header.name() << "): " << avg << endl;

        processed = true;
    }
}
Exemple #11
0
void printIntegrate
(
    const fvMesh& mesh,
    const IOobject& fieldHeader,
    bool& done
)
{
    if (!done && fieldHeader.headerClassName() == FieldType::typeName)
    {
        Info<< "    Reading " << fieldHeader.headerClassName() << " "
            << fieldHeader.name() << endl;

        FieldType field(fieldHeader, mesh);

        Info<< "    Integral of " << fieldHeader.name()
            << " over full fluid volume = "
            << gSum(mesh.V()*field.internalField()) << " "
            << field.dimensions()*dimVolume
            << nl;

        done = true;
    }
}
/*
 *  Here remind you that you are in the namespace Foam by 
 *
 *  Foam::calc(... ... ...)
 *
 *  Evidence : in calc.H function calc is { } by namespace Foam
 */
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
	const word finalTimeStep("150.4");
    IOobject UheaderMean
    (
        "UMean",
        //runTime.timeName(),
		//word('0.5'),
		finalTimeStep,
        mesh,
        IOobject::MUST_READ
    );

    if (UheaderMean.headerOk())
    {
        Info<< "    Reading U_mean" << " @ time step : " << finalTimeStep<< endl;
        volVectorField UMean(UheaderMean, mesh);

        volScalarField KEMean
        (
            IOobject
            (
                "KEMean",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
			0.5 * UMean & UMean
        );

		Info<< "    Summing up : gSum(KEMean) = "<< gSum(KEMean) << endl;
		Info<< "    Summing up :  Sum(KEMean) = "<<  sum(KEMean) << endl;

		Info<< "    Finish Reading U_mean" << endl;

		IOobject Uheader
		(
			"U",
			runTime.timeName(),
			mesh,
			IOobject::MUST_READ
		);

		if (Uheader.headerOk())
		{
			Info<< "    Reading U" << endl;
			volVectorField U(Uheader, mesh);

			volScalarField KE
			(
				IOobject
				(
					"KE",
					runTime.timeName(),
					mesh,
					IOobject::NO_READ,
					IOobject::NO_WRITE
				),
				0.5 * U & U
			);

			volScalarField tKE
			(
				IOobject
				(
					"tKE",
					runTime.timeName(),
					mesh,
					IOobject::NO_READ,
					IOobject::NO_WRITE
				),
				0.5 * (U - UMean) & (U - UMean)
			);

			Info<< "runTime.timeName() : "<< runTime.timeName()
					<< endl;

			Info<< "    Writing -Kinetic Energy : KE " << endl;
			//KE.write();

			Info<< "    Summing up : gSum(TTKE) = "<< gSum(KE)-gSum(KEMean) << endl;
			Info<< "    Summing up :  Sum(TTKE) = "<< sum(KE)-sum(KEMean) << endl;
			Info<< "    Turbulent intensity = "<< (gSum(KE)-gSum(KEMean))/gSum(KEMean)*100 << "%" << endl;
			Info<< "    Turbulent intensity = "<< (sum(KE)-sum(KEMean))/sum(KEMean)*100 << "%" << endl;

			Info<< "    Summing up : gSum(tKE) = "<< gSum(tKE) << endl;
			Info<< "    Summing up :  Sum(tKE) = "<< sum(tKE) << endl;
			Info<< "    Turbulent intensity = "<< gSum(tKE)/gSum(KEMean)*100 << "%" << endl;
			Info<< "    Turbulent intensity = "<< sum(tKE)/sum(KEMean)*100 << "%" << endl;

			scalar turbulentIntensity = ((sum(KE)-sum(KEMean))/sum(KEMean)*100).value();
			scalar turbulentIntensity1 = (sum(tKE)/sum(KEMean)*100).value();
			scalar waKE = KE.weightedAverage(mesh.V()).value();
			Info<< "    Summing up : weighted average of KE = "
					<<  waKE  << nl
					/*
					<< "WeightedAverage : here the weight is cellVolume/TotalVolume" << nl
					<< "Note that this is verified by paraview - Filter - intergate " << nl
					<< "which is a volumic integration. Divide the paraview calculation " << nl
					<< "by volume, you will get the same as here" << endl;
					*/
					<< endl;

			const scalar totalVol = gSum(mesh.V());
			Info<< "    totalVol              = "<< totalVol << endl;

			fileName writePathRoot("./");
			mkDir(writePathRoot/"fieldStatistics");
			//OFstream KineticEnergy(fileName(writePathRoot/"fieldStatistics"/"KineticEnergy"),ios_base::app);  // ios_base::app not found
			ofstream KineticEnergy(fileName(writePathRoot/"fieldStatistics"/"TurbulentKineticEnergy1").c_str(), ios_base::app);
			if (Pstream::master())
			{
				//std::cout << runTime.timeName().c_str() << " " << waKE << "\n" << std::endl;
				KineticEnergy << runTime.timeName().c_str() 
						<< " " << waKE 
						<< " " << turbulentIntensity
						<< " " << turbulentIntensity1
						<< std::endl; // This is the right and safest way to do

				//KineticEnergy << runTime.timeName().c_str() << " " << waKE << endl;  // same as Foam::endl : no error in compilation but "endl" will not work as expected.
				//KineticEnergy << runTime.timeName().c_str() << " " << waKE << Foam::endl;
			}
		}
		else
		{
			Info<< "    No U" << endl;
		}
    }
    else
    {
    	Info<< "	no U_mean @ time step " << finalTimeStep << endl;
    }

	Info<< "Using appending mode in writting data, be sure that the old data is erased !" << endl;

    Info<< "\nEnd\n" << endl;
}
Exemple #13
0
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
    bool writeResults = !args.optionFound("noWrite");

    IOobject phiHeader
    (
        "phi",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );

    if (phiHeader.headerOk())
    {
        volScalarField Co
        (
            IOobject
            (
                "Co",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ
            ),
            mesh,
            dimensionedScalar("0", dimless, 0),
            zeroGradientFvPatchScalarField::typeName
        );

        Info<< "    Reading phi" << endl;
        surfaceScalarField phi(phiHeader, mesh);

        if (phi.dimensions() == dimensionSet(1, 0, -1, 0, 0))
        {
            Info<< "    Calculating compressible Co" << endl;

            Info<< "    Reading rho" << endl;
            volScalarField rho
            (
                IOobject
                (
                    "rho",
                    runTime.timeName(),
                    mesh,
                    IOobject::MUST_READ
                ),
                mesh
            );

            Co.dimensionedInternalField() =
                (0.5*runTime.deltaT())
               *fvc::surfaceSum(mag(phi))().dimensionedInternalField()
               /(rho*mesh.V());
            Co.correctBoundaryConditions();
        }
        else if (phi.dimensions() == dimensionSet(0, 3, -1, 0, 0))
        {
            Info<< "    Calculating incompressible Co" << endl;

            Co.dimensionedInternalField() =
                (0.5*runTime.deltaT())
               *fvc::surfaceSum(mag(phi))().dimensionedInternalField()
               /mesh.V();
            Co.correctBoundaryConditions();
        }
        else
        {
            FatalErrorIn(args.executable())
                << "Incorrect dimensions of phi: " << phi.dimensions()
                << abort(FatalError);
        }

        Info<< "Co max : " << max(Co).value() << endl;

        if (writeResults)
        {
            Co.write();
        }
    }
    else
    {
        Info<< "    No phi" << endl;
    }

    Info<< "\nEnd\n" << endl;
}
Exemple #14
0
/*
 *  Here remind you that you are in the namespace Foam by 
 *
 *  Foam::calc(... ... ...)
 *
 *  Evidence : in calc.H function calc is { } by namespace Foam
 */
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
    IOobject Uheader
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );

    if (Uheader.headerOk())
    {
        Info<< "    Reading U" << endl;
        volVectorField U(Uheader, mesh);

        volScalarField KE
        (
            IOobject
            (
                "KE",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
			0.5 * U & U
        );

        Info<< "    Writing -Kinetic Energy : KE " << endl;
        //KE.write();

		Info<< "    Summing up : gSum(KE) = "<< gSum(KE) << endl;
		Info<< "    Summing up :  Sum(KE) = "<< sum(KE) << endl;

		scalar waKE = KE.weightedAverage(mesh.V()).value();
		Info<< "    Summing up : weighted average of KE = "
				<<  waKE  << nl
				/*
				<< "WeightedAverage : here the weight is cellVolume/TotalVolume" << nl
				<< "Note that this is verified by paraview - Filter - intergate " << nl
				<< "which is a volumic integration. Divide the paraview calculation " << nl
				<< "by volume, you will get the same as here" << endl;
				*/
				<< endl;

		const scalar totalVol = gSum(mesh.V());
		Info<< "    totalVol              = "<< totalVol << endl;

		fileName writePathRoot("./");
    	mkDir(writePathRoot/"fieldStatistics");
    	//OFstream KineticEnergy(fileName(writePathRoot/"fieldStatistics"/"KineticEnergy"),ios_base::app);  // ios_base::app not found
		ofstream KineticEnergy(fileName(writePathRoot/"fieldStatistics"/"KineticEnergy").c_str(), ios_base::app);
		if (Pstream::master())
		{
			//std::cout << runTime.timeName().c_str() << " " << waKE << "\n" << std::endl;
    		KineticEnergy << runTime.timeName().c_str() << " " << waKE << std::endl; // This is the right and safest way to do

    		//KineticEnergy << runTime.timeName().c_str() << " " << waKE << endl;  // same as Foam::endl : no error in compilation but "endl" will not work as expected.
    		//KineticEnergy << runTime.timeName().c_str() << " " << waKE << Foam::endl;  
		}
    }
    else
    {
        Info<< "    No U" << endl;
    }

	Info<< "Using appending mode in writting data, be sure that the old data is erased !" << endl;

    Info<< "\nEnd\n" << endl;
}