Exemplo n.º 1
0
void Foam::GAMGSolver::scale
(
    scalarField& field,
    scalarField& Acf,
    const lduMatrix& A,
    const FieldField<Field, scalar>& interfaceLevelBouCoeffs,
    const lduInterfaceFieldPtrsList& interfaceLevel,
    const scalarField& source,
    const direction cmpt
) const
{
    A.Amul
    (
        Acf,
        field,
        interfaceLevelBouCoeffs,
        interfaceLevel,
        cmpt
    );

    scalar scalingFactorNum = 0.0;
    scalar scalingFactorDenom = 0.0;

    forAll(field, i)
    {
        scalingFactorNum += source[i]*field[i];
        scalingFactorDenom += Acf[i]*field[i];
    }
Exemplo n.º 2
0
void Foam::GAMGSolver::scale
(
    scalargpuField& field,
    scalargpuField& Acf,
    const lduMatrix& A,
    const FieldField<gpuField, scalar>& interfaceLevelBouCoeffs,
    const lduInterfaceFieldPtrsList& interfaceLevel,
    const scalargpuField& source,
    const direction cmpt
) const
{
    A.Amul
    (
        Acf,
        field,
        interfaceLevelBouCoeffs,
        interfaceLevel,
        cmpt
    );

    scalar scalingFactorNum = 0.0;
    scalar scalingFactorDenom = 0.0;

    scalingFactorNum  = 
        thrust::reduce
        (
            thrust::make_transform_iterator
            (
                thrust::make_zip_iterator(thrust::make_tuple
                (
                    source.begin(),
                    field.begin()
                )),
                multiplyTupleFunctor()
            ),
            thrust::make_transform_iterator
            (
                thrust::make_zip_iterator(thrust::make_tuple
                (
                    source.end(),
                    field.end()
                )),
                multiplyTupleFunctor()
            ),
            0.0,
            thrust::plus<scalar>()
        );

    scalingFactorDenom  = 
        thrust::reduce
        (
            thrust::make_transform_iterator
            (
                thrust::make_zip_iterator(thrust::make_tuple
                (
                    Acf.begin(),
                    field.begin()
                )),
                multiplyTupleFunctor()
            ),
            thrust::make_transform_iterator
            (
                thrust::make_zip_iterator(thrust::make_tuple
                (
                    Acf.end(),
                    field.end()
                )),
                multiplyTupleFunctor()
            ),
            0.0,
            thrust::plus<scalar>()
        );

/*
    forAll(field, i)
    {
        scalingFactorNum += source[i]*field[i];
        scalingFactorDenom += Acf[i]*field[i];
    }
*/
    vector2D scalingVector(scalingFactorNum, scalingFactorDenom);
    A.mesh().reduce(scalingVector, sumOp<vector2D>());

    scalar sf = scalingVector.x()/stabilise(scalingVector.y(), VSMALL);

    if (debug >= 2)
    {
        Pout<< sf << " ";
    }

    const scalargpuField& D = A.diag();

/*
    forAll(field, i)
    {
        field[i] = sf*field[i] + (source[i] - sf*Acf[i])/D[i];
    }
*/

    thrust::transform
    (
        field.begin(),
        field.end(),
        thrust::make_zip_iterator(thrust::make_tuple
        (
            source.begin(),
            Acf.begin(),
            D.begin()
        )),
        field.begin(),
        GAMGSolverScaleFunctor(sf)
    );
}