Example #1
0
Foam::scalar Foam::thoboisValve::lift(const scalar theta) const
{
    return interpolateXY
    (
        adjustCrankAngle(theta),
        liftProfile_.x(),
        liftProfile_.y()
    );
}
Example #2
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);
    }
Foam::scalar Foam::accordionValve::lift(const scalar theta) const
{

    label curCycle = theta/720.0;
    scalar curTheta = theta - curCycle * 720.0;

    return interpolateXY
    (
        curTheta,
        liftProfile_.x(),
        liftProfile_.y()
    );
}
void engineTimeVaryingUniformFixedValueFvPatchField<sphericalTensor>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    checkTable();

    operator==
    (
        interpolateXY
        (
//            this->db().time().value(),
            engineDB_.theta(),
            timeDataPtr_().x(),
            timeDataPtr_().y()
        )*sphericalTensor::I
    );

    fixedValueFvPatchField<sphericalTensor>::updateCoeffs();
}
int main(int argc, char *argv[])
{

#   include "setRootCase.H"
#   include "createTime.H"

    instantList Times = runTime.times();
#   include "checkTimeOptions.H"
    runTime.setTime(Times[startTime],startTime);
#   include "createMesh.H"

    typedef VectorSpace<Vector<scalar>,scalar,4> quad;
    typedef VectorSpace<Vector<scalar>,scalar,6> hex;
    
    //read setDiscreteFieldsDictionary

    IOdictionary setDiscreteFieldsDict
      (
       IOobject
       (
	"setDiscreteFieldsDict",
	runTime.system(),
	mesh,
	IOobject::MUST_READ,
	IOobject::NO_WRITE
	)
       );
    // read pointer lists of each "Fields"
    PtrList<entry> parts=setDiscreteFieldsDict.lookup("Fields");

    forAll(parts,partI) {
      const dictionary &part=parts[partI].dict();
      Info <<part <<endl;

      // "field" ,"type", and "profile" are required in setDiscreteFieldsDict
      word field=part["field"];

      word type=part["type"];

      // "direction", "internal", and "patchNames" are option
      string direction="x";
      if (part.found("direction")) {
	direction=part["direction"];
      }

      bool internal=true;
      if (part.found("internal")) {
	internal=readBool(part["internal"]);
      }
      
      wordList patchNames;      
      if (part.found("patchNames")){
	patchNames=wordList(part.lookup("patchNames"));
      }

      const string &time = runTime.timeName();
      Info <<"time " <<time <<"\n";

      // for scalar field
      if(type=="scalar"){
        Info << "set " <<field <<endl;

        // read profile
	List<quad> profile(part.lookup("profile"));
	scalarField posX(profile.size());
	scalarField posY(profile.size());
	scalarField posZ(profile.size());
	scalarField fX(profile.size());
	forAll(profile,i)
	  {
	    posX[i]=profile[i][0];
	    posY[i]=profile[i][1];
	    posZ[i]=profile[i][2];
	    fX[i]=profile[i][3];
	  }
        // read target field (scalar)
	volScalarField tmpField
	  (
	   IOobject
	   (
	    field,
	    time,
	    mesh,
	    IOobject::MUST_READ,
	    IOobject::AUTO_WRITE
	    ),
	   mesh
	   );
	
	//read cellCenter of targetMesh
	volVectorField center=tmpField.mesh().C();

	//internalField
	if(internal){
          scalarField &Ifield = tmpField.internalField();
          scalarField Icenter(Ifield.size());
          scalarField newIField(Ifield.size());
          if(direction=="x"){
            Icenter = center.internalField().component(vector::X);
            newIField = interpolateXY(Icenter,posX,fX);
          }	
          else if(direction=="y"){
            Icenter = center.internalField().component(vector::Y);
            newIField = interpolateXY(Icenter,posY,fX);
          }	
          else if(direction=="z"){
            Icenter = center.internalField().component(vector::Z);
            newIField  = interpolateXY(Icenter,posZ,fX);
          }	
          Ifield = newIField;
        }
	//patch
	forAll(patchNames,patchNameI)
	  {
	    label patchID=mesh.boundaryMesh().findPatchID(patchNames[patchNameI]);
	    scalarField &Pfield = tmpField.boundaryField()[patchID];
	    scalarField newPField(Pfield.size());
	    scalarField Pcenter(Pfield.size());
	    if(direction=="x"){
	      Pcenter = center.boundaryField()[patchID].component(vector::X);
	      newPField = interpolateXY(Pcenter,posX,fX);
	    }	
	    else if(direction=="y"){
	      Pcenter = center.boundaryField()[patchID].component(vector::Y);
	      newPField = interpolateXY(Pcenter,posY,fX);
	    }	
	    else if(direction=="z"){
	      Pcenter = center.boundaryField()[patchID].component(vector::Z);
	      newPField = interpolateXY(Pcenter,posZ,fX);
	    }	
	    Pfield = newPField;
	  }
void engineTimeVaryingTotalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up)
{
    if (updated())
    {
        return;
    }

    checkTable();

    p0_=
    (
        interpolateXY
        (
            engineDB_.theta(),
            timeDataPtr_().x(),
            timeDataPtr_().y()
        )
    );

    const fvsPatchField<scalar>& phip =
        lookupPatchField<surfaceScalarField, scalar>(phiName_);

    if (psiName_ == "none" && rhoName_ == "none")
    {
        operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
    }
    else if (rhoName_ == "none")
    {
        const fvPatchField<scalar>& psip =
            lookupPatchField<volScalarField, scalar>(psiName_);

        if (gamma_ > 1.0)
        {
            scalar gM1ByG = (gamma_ - 1.0)/gamma_;

            operator==
            (
                p0_
               /pow
                (
                    (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
                    1.0/gM1ByG
                )
            );
        }
        else
        {
            operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
        }
    }
    else if (psiName_ == "none")
    {
        const fvPatchField<scalar>& rho =
            lookupPatchField<volScalarField, scalar>(rhoName_);

        operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
    }
    else
    {
        FatalErrorIn
        (
            "engineTimeVaryingTotalPressureFvPatchScalarField::updateCoeffs()"
        )   << " rho or psi set inconsitently, rho = " << rhoName_
            << ", psi = " << psiName_ << '.' << nl
            << "    Set either rho or psi or neither depending on the "
               "definition of total pressure." << nl
            << "    Set the unused variables to 'none'."
            << "\n    on patch " << this->patch().name()
            << " of field " << this->dimensionedInternalField().name()
            << " in file " << this->dimensionedInternalField().objectPath()
            << exit(FatalError);
    }

    fixedValueFvPatchScalarField::updateCoeffs();
}