tmp<Field<Type> > domainScalingFvPatchField<Type>::patchNeighbourField() const
{     
    const domainScalingFvPatch& shadowPatch = domainScalingPatch_.shadow();
    
    tmp<Field<Type> > tresult
    (
            new Field<Type>
            (
                    shadowPatch.size(),
                    pTraits<Type>::zero
            )
    );
    
    Field<Type>&  firstField = tresult() ;
    
    const Field<Type>& iField =  this->internalField();

    const unallocLabelList& sfc = shadowPatch.faceCells();
    
    forAll(firstField, i)
    {
        firstField[i] = iField[sfc[i]];
    }
    
  //  Info << firstField << endl;
    firstField = shadowPatch.interpolateToShadow(firstField);
   // Info << firstField << endl;
    return (tresult);
    
}
Пример #2
0
Foam::tmp<Foam::Field<Type>> Foam::GAMGInterface::interfaceInternalField
(
    const UList<Type>& iF
) const
{
    tmp<Field<Type>> tresult(new Field<Type>(size()));
    interfaceInternalField(iF, tresult());
    return tresult;
}
Пример #3
0
Foam::tmp<Foam::labelField> Foam::GAMGInterface::interfaceInternalField
(
    const labelUList& internalData
) const
{
    tmp<labelField> tresult(new labelField(size()));
    labelField& result = tresult();

    forAll(result, elemI)
    {
        result[elemI] = internalData[faceCellsHost_[elemI]];
    }

    return tresult;
}
Foam::tmp<Foam::volScalarField> Foam::BurgersViscoelastic::E(scalar t) const
{
    scalar E = 0.0;

    if(t>=0)
    {
        scalar p1 = eta1_.value()/k1_.value()
            + eta1_.value()/k2_.value()
            + eta2_.value()/k2_.value();

        scalar p2 = eta1_.value()*eta2_.value()/(k1_.value()*k2_.value());

        scalar q1 = eta1_.value();

        scalar q2 = eta1_.value()*eta2_.value()/k2_.value();

        scalar A = sqrt(sqr(p1) - 4*p2);

        scalar r1 = (p1 - A)/(2*p2);

        scalar r2 = (p1 + A)/(2*p2);

        E = (q1 - q2*r1)*exp(-r1*t)/A - (q1 - q2*r2)*exp(-r2*t)/A;
    }


    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "E",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            dimensionedScalar("E", k1_.dimensions(), E),
            zeroGradientFvPatchScalarField::typeName
        )
    );

    tresult().correctBoundaryConditions();

    return tresult;
}
Foam::tmp<Foam::surfaceVectorField>
Foam::dugdaleCohesiveLaw::interfaceTraction
(
 surfaceVectorField n,
 volVectorField U,
 volTensorField gradU,
 volScalarField mu,
 volScalarField lambda
 ) const
{
  notImplemented(type() + "::interfaceTraction()");

    tmp<surfaceVectorField> tresult
    (
        new surfaceVectorField
        (
            IOobject
            (
            "interfaceTraction",
            mesh().time().timeName(),
            mesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
            mesh(),
            dimensionedVector("zero", dimForce/dimArea, vector(0, 0, 0))
    )
    );

    return tresult;
}
Пример #6
0
Foam::tmp<Foam::scalarField> Foam::cellQuality::nonOrthogonality() const
{
    tmp<scalarField> tresult
    (
        new scalarField
        (
            mesh_.nCells(), 0.0
        )
    );

    scalarField& result = tresult.ref();

    scalarField sumArea(mesh_.nCells(), 0.0);

    const vectorField& centres = mesh_.cellCentres();
    const vectorField& areas = mesh_.faceAreas();

    const labelList& own = mesh_.faceOwner();
    const labelList& nei = mesh_.faceNeighbour();

    forAll(nei, facei)
    {
        vector d = centres[nei[facei]] - centres[own[facei]];
        vector s = areas[facei];
        scalar magS = mag(s);

        scalar cosDDotS =
            radToDeg(Foam::acos(min(1.0, (d & s)/(mag(d)*magS + vSmall))));

        result[own[facei]] = max(cosDDotS, result[own[facei]]);

        result[nei[facei]] = max(cosDDotS, result[nei[facei]]);
    }
Пример #7
0
Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::indicator
(
    const label i
) const
{
    const scalarField& mat = materials_.internalField();

    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "indicator",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            dimless,
            zeroGradientFvPatchScalarField::typeName
        )
    );

    volScalarField& result = tresult();

    forAll (mat, matI)
    {
        if (mat[matI] > i - SMALL && mat[matI] < i + SMALL)
        {
            result[matI] = 1.0;
        }
        else
        {
            result[matI] = 0.0;
        }
    }

    result.correctBoundaryConditions();

    return tresult;
}
Foam::tmp<Foam::scalarField> Foam::multiMaterialCohesiveLaw::indicator
(
    const label i
) const
{
    const scalarField& mat = materials_.internalField();

    tmp<scalarField> tresult(new scalarField(mat.size(), 0.0));
    scalarField& result = tresult();

    forAll (mat, matI)
    {
        if (mat[matI] > i - SMALL && mat[matI] < i + 1 - SMALL)
        {
            result[matI] = 1.0;
        }
    }

    return tresult;
}
Foam::tmp<Foam::Field<Type> >
Foam::regionModels::regionModel::mapRegionPatchInternalField
(
    const regionModel& nbrRegion,
    const word& fieldName,
    const label regionPatchI,
    const bool flip
) const
{
    typedef GeometricField<Type, fvPatchField, volMesh> fieldType;

    const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();

    if (nbrRegionMesh.foundObject<fieldType>(fieldName))
    {
        const label nbrPatchI = nbrCoupledPatchID(nbrRegion, regionPatchI);

        int oldTag = UPstream::msgType();
        UPstream::msgType() = oldTag + 1;

        const AMIPatchToPatchInterpolation& ami =
            interRegionAMI(nbrRegion, regionPatchI, nbrPatchI, flip);

        const fieldType& nbrField =
            nbrRegionMesh.lookupObject<fieldType>(fieldName);

        const fvPatchField<Type>& nbrFieldp =
            nbrField.boundaryField()[nbrPatchI];

        tmp<Field<Type> > tresult
        (
            ami.interpolateToSource(nbrFieldp.patchInternalField())
        );

        UPstream::msgType() = oldTag;

        return tresult;
    }
    else
    {
        const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];

        return
            tmp<Field<Type> >
            (
                new Field<Type>
                (
                    p.size(),
                    pTraits<Type>::zero
                )
            );
    }
}
Пример #10
0
Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
(
    const vectorField& global,
    bool translate
) const
{
    const vectorField lc(coordinateSystem::globalToLocal(global, translate));
    const scalarField r(mag(lc));

    tmp<vectorField> tresult(new vectorField(lc.size()));
    vectorField& result = tresult();

    result.replace
    (
        vector::X, r

    );

    result.replace
    (
        vector::Y,
        atan2
        (
            lc.component(vector::Y),
            lc.component(vector::X)
        )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
    );

    result.replace
    (
        vector::Z,
        acos
        (
            lc.component(vector::Z)/(r + SMALL)
        )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
    );

    return tresult;
}
Пример #11
0
tmp<GeometricField<Type, fvPatchField, volMesh> > cellReduce
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
    const CombineOp& cop
)
{
    typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;

    const fvMesh& mesh = ssf.mesh();

    tmp<volFieldType> tresult
    (
        new volFieldType
        (
            IOobject
            (
                "cellReduce(" + ssf.name() + ')',
                ssf.instance(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensioned<Type>("0", ssf.dimensions(), pTraits<Type>::zero),
            zeroGradientFvPatchField<Type>::typeName
        )
    );

    volFieldType& result = tresult();

    const labelUList& own = mesh.owner();
    const labelUList& nbr = mesh.neighbour();

    forAll(own, i)
    {
        label cellI = own[i];
        cop(result[cellI], ssf[i]);
    }
Пример #12
0
Foam::tmp<Foam::volScalarField> Foam::PronyViscoelastic::rho(scalar t) const
{
    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "rho",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            rho_,
            zeroGradientFvPatchScalarField::typeName
        )
    );

    tresult().correctBoundaryConditions();
    return tresult;
}
Пример #13
0
Foam::tmp<Foam::volScalarField> Foam::PronyViscoelastic::E(scalar t) const
{
    scalar E = 0.0;

    E = k_[0];

    for(int i=1; i<k_.size(); i++)
    {
        E += k_[i]*exp(-t/tau_[i]);
    }
    
    if(t < 0)
    {
        E = 0;
    }

    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "E",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            dimensionedScalar("E", kDimensions_, E),
            zeroGradientFvPatchScalarField::typeName
        )
    );

    tresult().correctBoundaryConditions();
    return tresult;
}
Foam::tmp<Foam::volScalarField> Foam::linearElastic::E() const
{
    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "E",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            E_,
            zeroGradientFvPatchScalarField::typeName
        )
    );

    tresult().correctBoundaryConditions();

    return tresult;
}
Foam::tmp<Foam::volScalarField> Foam::constantThermal::k() const
{
    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                "k",
                mesh().time().timeName(),
                mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh(),
            k_,
            zeroGradientFvPatchScalarField::typeName
        )
    );

    tresult().correctBoundaryConditions();

    return tresult;
}
Foam::tmp<GeoFieldType>
Foam::functionObjects::subtract::calcFieldType() const
{
    tmp<GeoFieldType> tresult
    (
        lookupObject<GeoFieldType>(fieldNames_[0])
      - lookupObject<GeoFieldType>(fieldNames_[1])
    );

    for (label i=2; i<fieldNames_.size(); i++)
    {
        tresult.ref() -= lookupObject<GeoFieldType>(fieldNames_[i]);
    }

    return tresult;
}
Foam::tmp<Foam::Field<Type> >
Foam::regionModels::regionModel::mapRegionPatchField
(
    const regionModel& nbrRegion,
    const label regionPatchI,
    const label nbrPatchI,
    const Field<Type>& nbrField,
    const bool flip
) const
{
    int oldTag = UPstream::msgType();
    UPstream::msgType() = oldTag + 1;

    const AMIPatchToPatchInterpolation& ami =
        interRegionAMI(nbrRegion, regionPatchI, nbrPatchI, flip);

    tmp<Field<Type> > tresult(ami.interpolateToSource(nbrField));

    UPstream::msgType() = oldTag;

    return tresult;
}
tmp<Field<Type> > ggiGAMGInterface::fastReduce(const UList<Type>& ff) const
{
    // Algorithm
    // Local processor contains faceCells part of the zone and requires
    // zoneAddressing part.
    // For fast communications, each processor will send the faceCells and
    // zoneAddressing to the master.  Master will assemble global zone
    // and send off messages to all processors containing only
    // the required data
    // HJ, 24/Jun/2011

    if (ff.size() != this->size())
    {
        FatalErrorIn
        (
            "tmp<Field<Type> > ggiGAMGInterface::fastReduce"
            "("
            "    const UList<Type>& ff"
            ") const"
        )   << "Wrong field size.  ff: " << ff.size()
            << " interface: " << this->size()
            << abort(FatalError);
    }

    if (localParallel() || !Pstream::parRun())
    {
        // Field remains identical: no parallel communications required
        tmp<Field<Type> > tresult(new Field<Type>(ff));

        return tresult;
    }

    // Execute reduce if not already done
    if (!initReduce_)
    {
        initFastReduce();
    }

    if (Pstream::master())
    {
        // Master collects information and distributes data.
        Field<Type> expandField(zoneSize(), pTraits<Type>::zero);

        // Insert master processor
        const labelList& za = zoneAddressing();

        forAll (za, i)
        {
            expandField[za[i]] = ff[i];
        }

        // Master receives and inserts data from all processors for which
        // receiveAddr contains entries
        for (label procI = 1; procI < Pstream::nProcs(); procI++)
        {
            const labelList& curRAddr = receiveAddr_[procI];

            if (!curRAddr.empty())
            {
                Field<Type> receiveBuf(curRAddr.size());

                // Opt: reconsider mode of communication
                IPstream::read
                (
                    Pstream::blocking,
                    procI,
                    reinterpret_cast<char*>(receiveBuf.begin()),
                    receiveBuf.byteSize()
                );

                // Insert received information
                forAll (curRAddr, i)
                {
                    expandField[curRAddr[i]] = receiveBuf[i];
                }
            }
        }

        // Expanded field complete, send required data to other processors
        for (label procI = 1; procI < Pstream::nProcs(); procI++)
        {
            const labelList& curSAddr = sendAddr_[procI];

            if (!curSAddr.empty())
            {
                Field<Type> sendBuf(curSAddr.size());

                forAll (curSAddr, i)
                {
                    sendBuf[i] = expandField[curSAddr[i]];
                }

                // Opt: reconsider mode of communication
                OPstream::write
                (
                    Pstream::blocking,
                    procI,
                    reinterpret_cast<const char*>(sendBuf.begin()),
                    sendBuf.byteSize()
                );
            }
        }
Foam::tmp<Foam::Field<Type> >
Foam::BlockLduMatrix<Type>::decoupledH(const Field<Type>& x) const
{
    typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
    typedef typename TypeCoeffField::linearTypeField linearTypeField;

    // Create result
    tmp<Field<Type> > tresult
    (
        new Field<Type>(lduAddr().size(), pTraits<Type>::zero)
    );
    Field<Type>& result = tresult();

    const unallocLabelList& u = lduAddr().upperAddr();
    const unallocLabelList& l = lduAddr().lowerAddr();

    const TypeCoeffField& Upper = this->upper();

    // Create multiplication function object
    typename BlockCoeff<Type>::multiply mult;

    // Lower multiplication

    if (symmetric())
    {
        if (Upper.activeType() == blockCoeffBase::SCALAR)
        {
            const scalarTypeField& activeUpper = Upper.asScalar();

            for (register label coeffI = 0; coeffI < u.size(); coeffI++)
            {
                result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
            }
        }
        else if (Upper.activeType() == blockCoeffBase::LINEAR)
        {
            const linearTypeField& activeUpper = Upper.asLinear();

            for (register label coeffI = 0; coeffI < u.size(); coeffI++)
            {
                result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
            }
        }
    }
    else // Asymmetric matrix
    {
        const TypeCoeffField& Lower = this->lower();

        if (Lower.activeType() == blockCoeffBase::SCALAR)
        {
            const scalarTypeField& activeLower = Lower.asScalar();

            for (register label coeffI = 0; coeffI < u.size(); coeffI++)
            {
                result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
            }
        }
        else if (Lower.activeType() == blockCoeffBase::LINEAR)
        {
            const linearTypeField& activeLower = Lower.asLinear();

            for (register label coeffI = 0; coeffI < u.size(); coeffI++)
            {
                result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
            }
        }
    }


    // Upper multiplication

    if (Upper.activeType() == blockCoeffBase::SCALAR)
    {
        const scalarTypeField& activeUpper = Upper.asScalar();

        for (register label coeffI = 0; coeffI < u.size(); coeffI++)
        {
            result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
        }
    }
    else if (Upper.activeType() == blockCoeffBase::LINEAR)
    {
        const linearTypeField& activeUpper = Upper.asLinear();

        for (register label coeffI = 0; coeffI < u.size(); coeffI++)
        {
            result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
        }
    }

    return tresult;
}
Foam::tmp<Foam::volScalarField> Foam::fluentDataConverter::convertField
(
    const word& fieldName,
    const label unitNumber,
    const dimensionedScalar& defaultValue
) const
{
    // Create field
    Info << "Creating field " << fieldName << " for unit "<< unitNumber << endl;

    tmp<volScalarField> tresult
    (
        new volScalarField
        (
            IOobject
            (
                fieldName,
                mesh_.time().timeName(),
                mesh_,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh_,
            defaultValue
        )
    );
    volScalarField& result = tresult();

    SLList<label>::const_iterator fieldIDIter = fieldID_.begin();
    SLList<label>::const_iterator zoneIDIter = zoneID_.begin();
    SLList<label>::const_iterator firstIDIter = firstID_.begin();
    SLList<label>::const_iterator lastIDIter = lastID_.begin();
    SLPtrList<FieldField<Field, scalar> >::const_iterator zoneDataIter =
        zoneData_.begin();

    for
    (
        ;
        fieldIDIter != fieldID_.end();

        ++fieldIDIter,
        ++zoneIDIter,
        ++firstIDIter,
        ++lastIDIter,
        ++zoneDataIter
    )
    {
        // Look for field index
        if (fieldIDIter() == unitNumber)
        {
            Info<< "Found field ID for zone " << zoneIDIter();

            word patchName = zoneToPatchName_[zoneIDIter()];

            // Internal Field
            if
            (
                patchName == "unknown"
             && zoneDataIter()[0].size() == mesh_.nCells()
            )
            {
                Info<< " internal cell zone.  Size = "
                    << mesh_.nCells() << endl;
                result.internalField() = zoneDataIter()[0];
            }
            else
            {
                label patchID = mesh_.boundaryMesh().findPatchID(patchName);

                if (patchID > -1)
                {
                    Info<< " and patch " << patchName
                        << " with id " << patchID << endl;

                    result.boundaryField()[patchID] == zoneDataIter()[0];
                }
                else
                {
                    Info<< " and patch not found" << endl;
                }
            }
        }
    }

    return tresult;
}