Esempio n. 1
0
Foam::scalar checkUniformTimeStep(const scalarField& t)
{
    // check that a uniform time step has been applied
    scalar deltaT = -1.0;
    if (t.size() > 1)
    {
        for (label i = 1; i < t.size(); i++)
        {
            scalar dT = t[i] - t[i-1];
            if (deltaT < 0)
            {
                deltaT = dT;
            }

            if (mag(deltaT - dT) > SMALL)
            {
                FatalErrorIn("checkUniformTimeStep(const scalarField&)")
                    << "Unable to process data with a variable time step"
                    << exit(FatalError);
            }
        }
    }
    else
    {
        FatalErrorIn("checkUniformTimeStep(const scalarField&)")
            << "Unable to create FFT with a single value"
            << exit(FatalError);
    }

    return deltaT;
}
Foam::tmp<Foam::scalarField> Foam::GAMGInterface::agglomerateCoeffs
(
    const scalarField& fineCoeffs
) const
{
    tmp<scalarField> tcoarseCoeffs(new scalarField(size(), Zero));
    scalarField& coarseCoeffs = tcoarseCoeffs.ref();

    if (fineCoeffs.size() != faceRestrictAddressing_.size())
    {
        FatalErrorInFunction
            << "Size of coefficients " << fineCoeffs.size()
            << " does not correspond to the size of the restriction "
            << faceRestrictAddressing_.size()
            << abort(FatalError);
    }
    if (debug && max(faceRestrictAddressing_) > size())
    {
        FatalErrorInFunction
            << "Face restrict addressing addresses outside of coarse interface"
            << " size. Max addressing:" << max(faceRestrictAddressing_)
            << " coarse size:" << size()
            << abort(FatalError);
    }

    forAll(faceRestrictAddressing_, ffi)
    {
        coarseCoeffs[faceRestrictAddressing_[ffi]] += fineCoeffs[ffi];
    }

    return tcoarseCoeffs;
}
void Foam::dx<Type>::writeDXData
(
    const pointField& points,
    const scalarField& values,
    Ostream& os
) const
{
    // Write data
    os  << "object 3 class array type float rank 0 items "
        << values.size()
        << " data follows" << nl;

    forAll(values, elemI)
    {
        os << float(values[elemI]) << nl;
    }

    if (values.size() == points.size())
    {
        os  << nl << "attribute \"dep\" string \"positions\""
            << nl << nl;
    }
    else
    {
        os  << nl << "attribute \"dep\" string \"connections\""
            << nl << nl;
    }
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    argList::noParallel();
    #include "addDictOption.H"
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createFields.H"

    Info<< "Reading data file" << endl;
    CSV<scalar> pData("pressure", dict, "Data");

    // time history data
    const scalarField t(pData.x());

    // pressure data
    const scalarField p(pData.y());

    if (t.size() < N)
    {
        FatalErrorIn(args.executable())
            << "Block size N = " << N
            << " is larger than number of data = " << t.size()
            << exit(FatalError);
    }

    Info<< "    read " << t.size() << " values" << nl << endl;


    Info<< "Creating noise FFT" << endl;
    noiseFFT nfft(checkUniformTimeStep(t), p);

    nfft -= pRef;

    fileName baseFileName(pData.fName().lessExt());

    graph Pf(nfft.RMSmeanPf(N, min(nfft.size()/N, nw)));
    Info<< "    Creating graph for " << Pf.title() << endl;
    Pf.write(baseFileName + graph::wordify(Pf.title()), graphFormat);

    graph Lf(nfft.Lf(Pf));
    Info<< "    Creating graph for " << Lf.title() << endl;
    Lf.write(baseFileName + graph::wordify(Lf.title()), graphFormat);

    graph Ldelta(nfft.Ldelta(Lf, f1, fU));
    Info<< "    Creating graph for " << Ldelta.title() << endl;
    Ldelta.write(baseFileName + graph::wordify(Ldelta.title()), graphFormat);

    graph Pdelta(nfft.Pdelta(Pf, f1, fU));
    Info<< "    Creating graph for " << Pdelta.title() << endl;
    Pdelta.write(baseFileName + graph::wordify(Pdelta.title()), graphFormat);

    Info<< nl << "End\n" << endl;

    return 0;
}
Esempio n. 5
0
Foam::scalar Foam::lduMatrix::solver::normFactor
(
    const scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
    scalarField wA(x.size());
    scalarField tmpField(x.size());

    matrix_.Amul(wA, x, interfaceBouCoeffs_, interfaces_, cmpt);

    return normFactor(x, b, wA, tmpField);
}
void Foam::GAMGPreconditioner::precondition
(
    scalarField& wA,
    const scalarField& rA,
    const direction cmpt
) const
{
    wA = 0.0;
    scalarField AwA(wA.size());
    scalarField finestCorrection(wA.size());
    scalarField finestResidual(rA);

    // Create coarse grid correction fields
    PtrList<scalarField> coarseCorrX;

    // Create coarse grid sources
    PtrList<scalarField> coarseB;

    // Create the smoothers for all levels
    PtrList<lduSmoother> smoothers;

    // Initialise the above data structures
    GAMG_.initVcycle(coarseCorrX, coarseB, smoothers);

    for (label cycle=0; cycle<nVcycles_; cycle++)
    {
        GAMG_.Vcycle
        (
            smoothers,
            wA,
            rA,
            AwA,
            finestCorrection,
            finestResidual,
            coarseCorrX,
            coarseB,
            cmpt
        );

        if (cycle < nVcycles_ - 1)
        {
            // Calculate finest level residual field
            matrix_.Amul(AwA, wA, coupleBouCoeffs_, interfaces_, cmpt);
            finestResidual = rA;
            finestResidual -= AwA;
        }
    }
}
Esempio n. 7
0
Foam::scalar Foam::lduMatrix::solver::normFactor
(
    const scalarField& x,
    const scalarField& b,
    const scalarField& Ax,
    scalarField& tmpField,
    const direction cmpt
) const
{
    // Calculate A dot reference value of x
//     matrix_.sumA(tmpField, coupleBouCoeffs_, interfaces_);
//     tmpField *= gAverage(x);

    // Calculate normalisation factor using full multiplication
    // with mean value.  HJ, 5/Nov/2007
    scalar xRef = gAverage(x);
    matrix_.Amul
    (
        tmpField,
        scalarField(x.size(), xRef),
        coupleBouCoeffs_,
        interfaces_,
        cmpt
    );

    return gSum(mag(Ax - tmpField) + mag(b - tmpField)) + matrix_.small_;

    // At convergence this simpler method is equivalent to the above
    // return 2*gSumMag(b) + matrix_.small_;
}
Foam::lduSolverPerformance Foam::gmresSolver::solve
(
    scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
    // Prepare solver performance
    lduSolverPerformance solverPerf(typeName, fieldName());

    scalarField wA(x.size());
    scalarField rA(x.size());

    // Calculate initial residual
    matrix_.Amul(wA, x, coupleBouCoeffs_, interfaces_, cmpt);

    // Use rA as scratch space when calculating the normalisation factor
    scalar normFactor = this->normFactor(x, b, wA, rA, cmpt);

    if (lduMatrix::debug >= 2)
    {
        Info<< "   Normalisation factor = " << normFactor << endl;
    }

    // Calculate residual
    forAll (rA, i)
    {
        rA[i] = b[i] - wA[i];
    }
Esempio n. 9
0
void Foam::DILUPreconditioner::calcReciprocalD
(
    scalarField& rD,
    const lduMatrix& matrix
)
{
    scalar* __restrict__ rDPtr = rD.begin();

    const label* const __restrict__ uPtr =
        matrix.lduAddr().upperAddr().begin();
    const label* const __restrict__ lPtr =
        matrix.lduAddr().lowerAddr().begin();

    const scalar* const __restrict__ upperPtr = matrix.upper().begin();
    const scalar* const __restrict__ lowerPtr = matrix.lower().begin();

    register label nFaces = matrix.upper().size();
    for (register label face=0; face<nFaces; face++)
    {
        rDPtr[uPtr[face]] -= upperPtr[face]*lowerPtr[face]/rDPtr[lPtr[face]];
    }


    // Calculate the reciprocal of the preconditioned diagonal
    register label nCells = rD.size();

    for (register label cell=0; cell<nCells; cell++)
    {
        rDPtr[cell] = 1.0/rDPtr[cell];
    }
}
void Foam::DILUPreconditioner::calcReciprocalD
(
    scalarField& rD,
    const lduMatrix& matrix
)
{
    scalar* __restrict__ rDPtr = rD.begin();

    const label* const __restrict__ uPtr = matrix.lduAddr().upperAddr().begin();
    const label* const __restrict__ lPtr = matrix.lduAddr().lowerAddr().begin();

    const scalar* const __restrict__ upperPtr = matrix.upper().begin();
    const scalar* const __restrict__ lowerPtr = matrix.lower().begin();

    label nFaces = matrix.upper().size();
    for (label face=0; face<nFaces; face++)
    {
        Pout<< "Adapting diagonal for cell:" << uPtr[face]
            << " contributions from cell " << lPtr[face]
            << " from " << rDPtr[uPtr[face]];

        rDPtr[uPtr[face]] -= upperPtr[face]*lowerPtr[face]/rDPtr[lPtr[face]];

        Pout<< " to " << rDPtr[uPtr[face]] << endl;
    }


    // Calculate the reciprocal of the preconditioned diagonal
    label nCells = rD.size();

    for (label cell=0; cell<nCells; cell++)
    {
        rDPtr[cell] = 1.0/rDPtr[cell];
    }
}
void Foam::processorGAMGInterfaceField::updateInterfaceMatrix
(
    const scalarField&,
    scalarField& result,
    const lduMatrix&,
    const scalarField& coeffs,
    const direction cmpt,
    const Pstream::commsTypes commsType,
    const bool switchToLhs
) const
{
    scalarField pnf
    (
        procInterface_.compressedReceive<scalar>(commsType, coeffs.size())
    );
    transformCoupleField(pnf, cmpt);

    const unallocLabelList& faceCells = procInterface_.faceCells();

    if (switchToLhs)
    {
        forAll(faceCells, elemI)
        {
            result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
        }
    }
Foam::lduSolverPerformance Foam::cufflink_DiagPCG_Parallel::solve
(
    scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
   
	if (!Pstream::parRun()) {
		FatalErrorIn("cufflink:\nMulti-GPU Solver cannot be run serially.  Choose the serial version of the solver")<< "Fatal Error"<< abort(FatalError);
	}

	OFSolverPerformance OFSP;//container for solver performance

	#include "../CFL_Headers/getGPUStorage.H"

	// --- Setup class containing solver performance data
    lduSolverPerformance solverPerf("cufflink_DiagPCG_Parallel",fieldName());

    register label nCells = x.size();
    register label NFaces = matrix().lower().size();
    OFSP.nCells = nCells;
    OFSP.nFaces = NFaces;
    OFSP.debugCusp = false;
    
    if (lduMatrix::debug >= 2) {
    	OFSP.debugCusp = true;
    }

//interface gathering

	//used when launching kernals in machines with multiple gpus
	int gpusPerMachine = readInt(dict().lookup("gpusPerMachine"));

	//get all the interface information
	#include "../CFL_Headers/getInterfaces.H"

	OFInterfaces.gpusPerMachine = gpusPerMachine;

	if(!OFInterfaces.checkGPUCount(OFInterfaces.gpusPerMachine)) {
		FatalErrorIn("checkGPUCount:\nThe number of GPUs per machine is not correct.\nChange the gpusPerMachine variable in fvSolution")<< "Fatal Error"<< abort(FatalError);
	}
//end interface gathering

	#include "../CFL_Headers/initializeCusp.H"

	//set the device
	cudaError_t cudareturn; 
	cudareturn = cudaSetDevice(Pstream::myProcNo() % (gpusPerMachine));
	if (cudareturn == cudaErrorInvalidDevice){ perror("cudaSetDevice returned  cudaErrorInvalidDevice");  } 

	CFL_DiagPCG_Parallel(&CES, &OFSP, &OFInterfaces);//call the CUDA code to solve the system
	
	thrust::copy(CES.X.begin(),CES.X.end(),x.begin());//copy the x vector back to Openfoam
	solverPerf.initialResidual() = OFSP.iRes;//return initial residual
	solverPerf.finalResidual() = OFSP.fRes;//return final residual
	solverPerf.nIterations() = OFSP.nIterations;//return the number of iterations
	//solverPerf.checkConvergence(tolerance(), relTolerance()) ; what should be passed here and does this waste time?
    return solverPerf;
}
Foam::scalarField Foam::CompositionModel<CloudType>::X
(
    const label phaseI,
    const scalarField& Y
) const
{
    const phaseProperties& props = phaseProps_[phaseI];
    scalarField X(Y.size(), 0.0);
    scalar WInv = 0.0;
    switch (props.phase())
    {
        case phaseProperties::GAS:
        {
            forAll(Y, i)
            {
                label gid = props.globalIds()[i];
                WInv += Y[i]/thermo_.carrier().W(gid);
                X[i] = Y[i]/thermo_.carrier().W(gid);
            }
            break;
        }
        case phaseProperties::LIQUID:
        {
            forAll(Y, i)
            {
                label gid = props.globalIds()[i];
                WInv += Y[i]/thermo_.liquids().properties()[gid].W();
                X[i] += Y[i]/thermo_.liquids().properties()[gid].W();
            }
            break;
        }
Foam::lduSolverPerformance Foam::bicgStabSolver::solve
(
    scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
    // Prepare solver performance
    lduSolverPerformance solverPerf(typeName, fieldName());

    scalarField p(x.size());
    scalarField r(x.size());

    // Calculate initial residual
    matrix_.Amul(p, x, coupleBouCoeffs_, interfaces_, cmpt);

    scalar normFactor = this->normFactor(x, b, p, r, cmpt);

    if (lduMatrix::debug >= 2)
    {
        Info<< "   Normalisation factor = " << normFactor << endl;
    }

    // Calculate residual
    forAll (r, i)
    {
        r[i] = b[i] - p[i];
    }
Esempio n. 15
0
Foam::lduSolverPerformance Foam::cufflink_CG::solve
(
    scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
	OFSolverPerformance OFSP;//container for solver performance

	#include "../CFL_Headers/getGPUStorage.H"

	// --- Setup class containing solver performance data
    lduSolverPerformance solverPerf("cufflink_CG",fieldName());

    register label nCells = x.size();
    register label NFaces = matrix().lower().size();
    OFSP.nCells = nCells;
    OFSP.nFaces = NFaces;
    OFSP.debugCusp = false;
    
    if (lduMatrix::debug >= 2) {
         OFSP.debugCusp = true;
    }

	#include "../CFL_Headers/initializeCusp.H"

	CFL_CG(&CES, &OFSP);//call the CUDA code to solve the system
	
	thrust::copy(CES.X.begin(),CES.X.end(),x.begin());//copy the x vector back to Openfoam
	solverPerf.initialResidual() = OFSP.iRes;//return initial residual
	solverPerf.finalResidual() = OFSP.fRes;//return final residual
	solverPerf.nIterations() = OFSP.nIterations;//return the number of iterations
	//solverPerf.checkConvergence(tolerance(), relTolerance()) ; what should be passed here and does this waste time?
    return solverPerf;
}
void Foam::DILUPreconditioner::precondition
(
    scalarField& wA,
    const scalarField& rA,
    const direction
) const
{
    scalar* __restrict__ wAPtr = wA.begin();
    const scalar* __restrict__ rAPtr = rA.begin();
    const scalar* __restrict__ rDPtr = rD_.begin();

    const label* const __restrict__ uPtr =
        solver_.matrix().lduAddr().upperAddr().begin();
    const label* const __restrict__ lPtr =
        solver_.matrix().lduAddr().lowerAddr().begin();
    const label* const __restrict__ losortPtr =
        solver_.matrix().lduAddr().losortAddr().begin();

    const scalar* const __restrict__ upperPtr =
        solver_.matrix().upper().begin();
    const scalar* const __restrict__ lowerPtr =
        solver_.matrix().lower().begin();

    label nCells = wA.size();
    label nFaces = solver_.matrix().upper().size();
    label nFacesM1 = nFaces - 1;

    for (label cell=0; cell<nCells; cell++)
    {
        wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
    }


    label sface;

    for (label face=0; face<nFaces; face++)
    {
        sface = losortPtr[face];

        Pout<< "For face:" << sface
            << " adapting cell:" << uPtr[sface]
            << " for contributions from:" << lPtr[sface]
            << endl;

        wAPtr[uPtr[sface]] -=
            rDPtr[uPtr[sface]]*lowerPtr[sface]*wAPtr[lPtr[sface]];
    }

    for (label face=nFacesM1; face>=0; face--)
    {
        Pout<< "For face:" << face
            << " adapting cell:" << lPtr[face]
            << " for contributions from:" << uPtr[face]
            << endl;

        wAPtr[lPtr[face]] -=
            rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
    }
}
void Foam::processorGAMGInterfaceField::updateInterfaceMatrix
(
    solveScalarField& result,
    const bool add,
    const solveScalarField&,
    const scalarField& coeffs,
    const direction cmpt,
    const Pstream::commsTypes commsType
) const
{
    if (updatedMatrix())
    {
        return;
    }

    if
    (
        commsType == Pstream::commsTypes::nonBlocking
     && !Pstream::floatTransfer
    )
    {
        // Fast path.
        if
        (
            outstandingRecvRequest_ >= 0
         && outstandingRecvRequest_ < Pstream::nRequests()
        )
        {
            UPstream::waitRequest(outstandingRecvRequest_);
        }
        // Recv finished so assume sending finished as well.
        outstandingSendRequest_ = -1;
        outstandingRecvRequest_ = -1;

        // Consume straight from scalarReceiveBuf_

        // Transform according to the transformation tensor
        transformCoupleField(scalarReceiveBuf_, cmpt);

        // Multiply the field by coefficients and add into the result
        addToInternalField(result, !add, coeffs, scalarReceiveBuf_);
    }
    else
    {
        solveScalarField pnf
        (
            procInterface_.compressedReceive<solveScalar>
            (
                commsType,
                coeffs.size()
            )
        );
        transformCoupleField(pnf, cmpt);

        addToInternalField(result, !add, coeffs, pnf);
    }

    const_cast<processorGAMGInterfaceField&>(*this).updatedMatrix() = true;
}
// y = ax + b
linearLeastSquaresFit::linearLeastSquaresFit
(
    const scalarField& x,
    const scalarField& y,         
//     scalarField sig,
//     label mwt,
    scalar& a,
    scalar& b
//     scalar& siga,
//     scalar& sigb,
//     scalar& chi2,
//     scalar& q
)

{

   
    a = 0.0;
    label nData = x.size();
    if(nData > 0)
    { 
    scalar sx= 0.0;
    scalar sy= 0.0;
    scalar ss = 0.0;
    scalar sxoss = 0.0;
    scalar t =0.0;
    scalar st2 =0.0;
    
    for (label i=0; i < nData; i++)
    {
        sx += x[i];
        sy += y[i];
    }
    
    ss = nData;
    
    sxoss=sx/ss;
    
    for (label i=0; i < nData; i++)
    {
        t = x[i]-sxoss;
        st2 += t*t;
        a += t*y[i];
    }
    
    a /= st2;
    b=(sy-(sx*a))/ss;
//     siga=sqrt((1.0+sx*sx/(ss*st2))/ss);
//     sigb=sqrt(1.0/st2);    
//     chi2=0.0;
//     q=0.0;
    }
    else
    {
	Info << "WARNING: least-squares fit has no data" << endl;
    }
}
void Foam::equationReader::evaluateScalarField
(
    scalarField& resultField,
    const label equationIndex,
    const label geoIndex
) const
{
#   ifdef FULLDEBUG
        const equation& eqn(operator[](equationIndex));
        // Index checking
        const labelList& maxFieldSizes(eqn.maxFieldSizes());
        if (geoIndex < 0)
        {
            FatalErrorIn("equationReader::evaluateScalarField")
                << "Evaluating " << eqn.name() << ": geoIndex (" << geoIndex
                << ") cannot be negative."
                << abort(FatalError);
        }
        else if (maxFieldSizes.size() > 0)
        {
            if (geoIndex >= maxFieldSizes.size())
            {
                FatalErrorIn("equationReader::evaluateScalarField")
                    << "Evaluating " << eqn.name() << ": geoIndex ("
                    << geoIndex << ") out of range (0 .. "
                    << maxFieldSizes.size() - 1 << ")."
                    << abort(FatalError);
            }
            else if (resultField.size() != maxFieldSizes[geoIndex])
            {
                FatalErrorIn("equationReader::evaluateScalarField")
                    << "Evaluating " << eqn.name() << ": field size mismatch. "
                    << "result.size() = " << resultField.size() << ", "
                    << "expected = " << maxFieldSizes[geoIndex] - 1 << "."
                    << abort(FatalError);
            }
        }
#   endif
    geoIndex_ = geoIndex;
    if (resultField.size())
    {
        internalEvaluateScalarField(resultField, equationIndex, 0);
    }
}
Esempio n. 20
0
void Foam::SIBS::polyExtrapolate
(
    const label iest,
    const scalar xest,
    const scalarField& yest,
    scalarField& yz,
    scalarField& dy,
    scalarField& x,
    scalarRectangularMatrix& d
) const
{
    label n = yz.size();

    x[iest] = xest;

    for (label j=0; j<n; j++)
    {
        dy[j] = yz[j] = yest[j];
    }

    if (iest == 0)
    {
        for (label j=0; j<n; j++)
        {
            d(j, 0) = yest[j];
        }
    }
    else
    {
        scalarField c(yest);

        for (label k1=0; k1<iest; k1++)
        {
            scalar delta = 1.0/(x[iest - k1 - 1] - xest);
            scalar f1 = xest*delta;
            scalar f2 = x[iest - k1 - 1]*delta;

            for (label j=0; j<n; j++)
            {
                scalar q = d[j][k1];
                d[j][k1] = dy[j];
                delta = c[j] - q;
                dy[j] = f1*delta;
                c[j] = f2*delta;
                yz[j] += dy[j];
            }
        }

        for (label j=0; j<n; j++)
        {
            d[j][iest] = dy[j];
        }
    }
}
Foam::tmp<Foam::scalarField> Foam::energyRegionCoupledFvPatchScalarField::
weights() const
{
    const fvPatch& patch = regionCoupledPatch_.patch();

    const scalarField deltas
    (
        patch.nf() & patch.delta()
    );

    const scalarField alphaDelta(kappa()/deltas);

    const fvPatch& nbrPatch = regionCoupledPatch_.neighbFvPatch();

    const energyRegionCoupledFvPatchScalarField& nbrField =
    refCast
    <
        const energyRegionCoupledFvPatchScalarField
    >
    (
        nbrPatch.lookupPatchField<volScalarField, scalar>("T")
    );

    // Needed in the first calculation of weights
    nbrField.setMethod();

    const scalarField nbrAlpha
    (
        regionCoupledPatch_.regionCoupledPatch().interpolate
        (
            nbrField.kappa()
        )
    );

    const scalarField nbrDeltas
    (
        regionCoupledPatch_.regionCoupledPatch().interpolate
        (
            nbrPatch.nf() & nbrPatch.delta()
        )
    );

    const scalarField nbrAlphaDelta(nbrAlpha/nbrDeltas);

    tmp<scalarField> tw(new scalarField(deltas.size()));
    scalarField& w = tw();

    forAll(alphaDelta, faceI)
    {
        scalar di = alphaDelta[faceI];
        scalar dni = nbrAlphaDelta[faceI];

        w[faceI] = di/(di + dni);
    }
Esempio n. 22
0
void SimpleDistribution<Type>::calc(
    const Field<Type> &values,
    const scalarField &weights
)
{
    if(values.size()!=weights.size()) {
        FatalErrorIn("SimpleDistribution::calc")
            << "Size " << values.size() << " of the values and size "
                << weights.size() << " of the weights differ"
                << endl
                << exit(FatalError);
    }

    this->clear();
    forAll(values,i) {
        this->add(
            values[i],
            pTraits<Type>::one*weights[i]
        );
    }
tmp<Field<Type> > swakDataEntry<Type>::value
(
    const scalarField& x
) const
{
    tmp<Field<Type> > tfld(new Field<Type>(x.size()));
    Field<Type>& fld = const_cast<Field<Type>&>(tfld());

    forAll(x, i)
    {
        fld[i] = this->value(x[i]);
    }
Esempio n. 24
0
Foam::tmp<Foam::Field<Type> > Foam::DataEntry<Type>::value
(
    const scalarField& x
) const
{
    tmp<Field<Type> > tfld(new Field<Type>(x.size()));
    Field<Type>& fld = tfld();

    forAll(x, i)
    {
        fld[i] = this->value(x[i]);
    }
Esempio n. 25
0
void writeEnsDataBinary
(
    const scalarField& sf,
    std::ofstream& ensightFile
)
{
    if (sf.size())
    {
        List<float> temp(sf.size());

        forAll(sf, i)
        {
            temp[i] = float(sf[i]);
        }

        ensightFile.write
        (
            reinterpret_cast<char*>(temp.begin()),
            sf.size()*sizeof(float)
        );
    }
Esempio n. 26
0
Field<Type> interpolateXY
(
    const scalarField& xNew,
    const scalarField& xOld,
    const Field<Type>& yOld
)
{
    Field<Type> yNew(xNew.size());

    forAll(xNew, i)
    {
        yNew[i] = interpolateXY(xNew[i], xOld, yOld);
    }
Esempio n. 27
0
Foam::lduSolverPerformance Foam::mpeAmgSolver::solve
(
    scalarField& x,
    const scalarField& b,
    const direction cmpt
) const
{
    // Prepare solver performance
    lduSolverPerformance solverPerf(typeName, fieldName());

    scalar normFactor = this->normFactor(x, b, cmpt);

    // Calculate initial residual
    solverPerf.initialResidual() =
        gSumMag(amg_.residual(x, b, cmpt))/normFactor;

    solverPerf.finalResidual() = solverPerf.initialResidual();


    // Solver loop

    if (!stop(solverPerf))
    {
        // Krylov vectors
        typedef FieldField<Field, scalar> scalarFieldField;

        scalarFieldField xSave(kDimension_ + 1);

        forAll (xSave, i)
        {
            xSave.set(i, new scalarField(x.size()));
        }

        scalarFieldField xFirstDiffs(kDimension_ - 1);

        forAll (xFirstDiffs, i)
        {
            xFirstDiffs.set(i, new scalarField(x.size()));
        }
Esempio n. 28
0
Foam::tmp<Foam::scalarField> Foam::lduMatrix::residual
(
    const scalarField& psi,
    const scalarField& source,
    const FieldField<Field, scalar>& interfaceBouCoeffs,
    const lduInterfaceFieldPtrsList& interfaces,
    const direction cmpt
) const
{
    tmp<scalarField> trA(new scalarField(psi.size()));
    residual(trA.ref(), psi, source, interfaceBouCoeffs, interfaces, cmpt);
    return trA;
}
Esempio n. 29
0
void Foam::binaryTree<CompType, ThermoType>::binaryTreeSearch
(
    const scalarField& phiq,
    bn* node,
    chP*& nearest
)
{
    if (size_ > 1)
    {
        scalar vPhi=0.0;
        const scalarField& v = node->v();
        const scalar& a = node->a();
        // compute v*phi
        for (label i=0; i<phiq.size(); i++) vPhi += phiq[i]*v[i];


        if (vPhi > a) // on right side (side of the newly added point)
        {
            if (node->nodeRight()!=nullptr)
            {
                binaryTreeSearch(phiq, node->nodeRight(), nearest);
            }
            else // the terminal node is reached, store leaf on the right
            {
                nearest = node->leafRight();
                return;
            }
        }
        else // on left side (side of the previously stored point)
        {
            if (node->nodeLeft()!=nullptr)
            {
                binaryTreeSearch(phiq, node->nodeLeft(), nearest);
            }
            else // the terminal node is reached, return element on right
            {
                nearest = node->leafLeft();
                return;
            }
        }
    }
    // only one point stored (left element of the root)
    else if (size_ == 1)
    {
        nearest = root_->leafLeft();
    }
    else // no point stored
    {
        nearest = nullptr;
    }
}
Esempio n. 30
0
void Foam::ReactingCloud<ParcelType>::checkSuppliedComposition
(
    const scalarField& YSupplied,
    const scalarField& Y,
    const word& YName
)
{
    if (YSupplied.size() != Y.size())
    {
        FatalErrorIn
        (
            "ReactingCloud<ParcelType>::checkSuppliedComposition"
            "("
                "const scalarField&, "
                "const scalarField&, "
                "const word&"
            ")"
        )   << YName << " supplied, but size is not compatible with "
            << "parcel composition: " << nl << "    "
            << YName << "(" << YSupplied.size() << ") vs required composition "
            << YName << "(" << Y.size() << ")" << nl
            << abort(FatalError);
    }
}