Example #1
0
/*
   In:  tau (lattice parameter)
   Out: g2 -> g[0]
        g3 -> g[1]
*/
void compute_invariants(gsl_complex tau, gsl_complex *g)
{
  gsl_complex q, q14;
  gsl_complex t2,t3,t24,t34;
  gsl_complex g3_term1, g3_term2;
  gsl_complex g2, g3;

  q = gsl_complex_exp(gsl_complex_mul_imag(tau,M_PI));
  q14 = gsl_complex_exp(gsl_complex_mul_imag(tau,M_PI_4));

  t2=theta20(q,q14);
  t3=theta30(q);
  t24 = pow4(t2);
  t34 = pow4(t3);

  g2 = gsl_complex_mul_real(gsl_complex_sub(gsl_complex_add(gsl_complex_mul(t24,t24),gsl_complex_mul(t34,t34)),gsl_complex_mul(t24,t34)),_CONST_43PI4);

  g3_term1 = gsl_complex_add(gsl_complex_mul(t24,gsl_complex_mul(t24,t24)),gsl_complex_mul(t34,gsl_complex_mul(t34,t34)));
  
  g3_term2 = gsl_complex_mul(gsl_complex_add(t24,t34),gsl_complex_mul(t24,t34));

  g3 = gsl_complex_sub( gsl_complex_mul_real(g3_term1, _CONST_827PI6),
			gsl_complex_mul_real(g3_term2, _CONST_49PI6) );

  g[0] = g2;
  g[1] = g3;
}
Example #2
0
Foam::tmp<Foam::volScalarField> Foam::XiEqModels::SCOPEBlend::XiEq() const
{
    return pow
    (
        pow4(1.0/XiEqModelL_->XiEq()) + pow4(1.0/XiEqModelH_->XiEq()),
        -0.25
    );
}
Example #3
0
tmp<volScalarField> gammaSST<BasicTurbulenceModel>::F1(const volScalarField& CDkOmega) const
{
  return max(
	     kOmegaSST<BasicTurbulenceModel>::F1(CDkOmega),
	     exp(-sqr(pow4(this->y_*sqrt(this->k_)/(scalar(120)*this->nu()))))
	     );
}
Example #4
0
KFR_SINTRIN T weight_a_unnorm(T f)
{
    const T f2  = pow2(f);
    const T nom = pow2(12200) * pow4(f);
    const T den = (f2 + pow2(20.6)) * (sqrt((f2 + pow2(107.7)) * (f2 + pow2(737.9)))) * (f2 + pow2(12200));
    return nom / den;
}
Example #5
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Tenneti::CdRe() const
{
    volScalarField alpha1
    (
        max(pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField alpha2
    (
        max(scalar(1) - pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField F0
    (
        5.81*alpha1/pow3(alpha2) + 0.48*pow(alpha1, 1.0/3.0)/pow4(alpha2)
    );

    volScalarField F1
    (
        pow(alpha1, 3)*max(pair_.Re(), residualRe_)
       *(0.95 + 0.61*pow3(alpha1)/sqr(alpha2))
    );

    // Tenneti et al. correlation includes the mean pressure drag.
    // This was removed here by multiplying F by alpha2 for consistency with
    // the formulation used in OpenFOAM
    return
        SchillerNaumann_->CdRe()/(alpha2*max(pair_.Re(), residualRe_)) +
        24.0*sqr(alpha2)*(F0 + F1);
}
void Foam::MarshakRadiationFvPatchScalarField::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    // Since we're inside initEvaluate/evaluate there might be processor
    // comms underway. Change the tag we use.
    int oldTag = UPstream::msgType();
    UPstream::msgType() = oldTag+1;

    // Temperature field
    const scalarField& Tp =
        patch().lookupPatchField<volScalarField, scalar>(TName_);

    // Re-calc reference value
    refValue() = 4.0*constant::physicoChemical::sigma.value()*pow4(Tp);

    // Diffusion coefficient - created by radiation model's ::updateCoeffs()
    const scalarField& gamma =
        patch().lookupPatchField<volScalarField, scalar>("gammaRad");

    const scalarField temissivity = emissivity();

    const scalarField Ep(temissivity/(2.0*(2.0 - temissivity)));

    // Set value fraction
    valueFraction() = 1.0/(1.0 + gamma*patch().deltaCoeffs()/Ep);

    // Restore tag
    UPstream::msgType() = oldTag;

    mixedFvPatchScalarField::updateCoeffs();
}
Foam::MarshakRadiationFixedTMixedFvPatchScalarField::
MarshakRadiationFixedTMixedFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    mixedFvPatchScalarField(p, iF),
    Trad_("Trad", dict, p.size()),
    emissivity_(readScalar(dict.lookup("emissivity")))
{
    refValue() = 4.0*radiation::sigmaSB.value()*pow4(Trad_);
    refGrad() = 0.0;

    if (dict.found("value"))
    {
        fvPatchScalarField::operator=
        (
            scalarField("value", dict, p.size())
        );
    }
    else
    {
        fvPatchScalarField::operator=(refValue());
    }
}
Example #8
0
Foam::tmp<Foam::volScalarField> Foam::liftModels::LegendreMagnaudet::Cl() const
{
    volScalarField Re(max(pair_.Re(), residualRe_));

    volScalarField Sr
    (
        sqr(pair_.dispersed().d())
       /(
            Re
           *pair_.continuous().nu()
        )
       *mag(fvc::grad(pair_.continuous().U()))
    );

    volScalarField ClLowSqr
    (
        sqr(6.0*2.255)
       *sqr(Sr)
       /(
            pow4(constant::mathematical::pi)
           *Re
           *pow3(Sr + 0.2*Re)
        )
    );

    volScalarField ClHighSqr
    (
        sqr(0.5*(Re + 16.0)/(Re + 29.0))
    );

    return sqrt(ClLowSqr + ClHighSqr);
}
Example #9
0
int main(void){
    int x;
    printf("整数を入力してください:");
    scanf("%d",&x);
    printf("4乗値は %d です\n",pow4(x));

    return 0;
}
Foam::scalar Foam::ThermoParcel<ParcelType>::calcHeatTransfer
(
    TrackData& td,
    const scalar dt,
    const label cellI,
    const scalar Re,
    const scalar Pr,
    const scalar kappa,
    const scalar d,
    const scalar rho,
    const scalar T,
    const scalar cp,
    const scalar NCpW,
    const scalar Sh,
    scalar& dhsTrans
)
{
    if (!td.cloud().heatTransfer().active())
    {
        return T;
    }

    // Calc heat transfer coefficient
    scalar htc = td.cloud().heatTransfer().htc(d, Re, Pr, kappa, NCpW);

    if (mag(htc) < ROOTVSMALL && !td.cloud().radiation())
    {
        return max(T + dt*Sh/(this->volume(d)*rho*cp), td.constProps().TMin());
    }

    const scalar As = this->areaS(d);
    scalar ap = Tc_ + Sh/As/htc;
    scalar bp = 6.0*(Sh/As + htc*(Tc_ - T));
    if (td.cloud().radiation())
    {
        const scalarField& G =
            td.cloud().mesh().objectRegistry::template
            lookupObject<volScalarField>("G");

        const scalar Gc = G[cellI];
        const scalar sigma = radiation::sigmaSB.value();
        const scalar epsilon = td.constProps().epsilon0();

        ap = (ap + epsilon*Gc/(4.0*htc))/(1.0 + epsilon*sigma*pow3(T)/htc);
        bp += 6.0*(epsilon*(Gc/4.0 - sigma*pow4(T)));
    }
    bp /= rho*d*cp*(ap - T);

    // Integrate to find the new parcel temperature
    IntegrationScheme<scalar>::integrationResult Tres =
        td.cloud().TIntegrator().integrate(T, dt, ap, bp);

    scalar Tnew = max(Tres.value(), td.constProps().TMin());

    dhsTrans += dt*htc*As*(0.5*(T + Tnew) - Tc_);

    return Tnew;
}
Example #11
0
Foam::tmp<Foam::volScalarField> Foam::diameterModels::IATEsource::Mo() const
{
    const uniformDimensionedVectorField& g =
        phase().U().db().lookupObject<uniformDimensionedVectorField>("g");

    return
        mag(g)*pow4(otherPhase().nu())*sqr(otherPhase().rho())
       *(otherPhase().rho() - phase().rho())
       /pow3(fluid().sigma());
}
void Foam::radialActuationDiskSource::
addRadialActuationDiskAxialInertialResistance
(
    vectorField& Usource,
    const labelList& cells,
    const scalarField& Vcells,
    const RhoFieldType& rho,
    const vectorField& U
) const
{
    scalar a = 1.0 - Cp_/Ct_;
    scalarField T(cells.size());
    scalarField Tr(cells.size());
    const vector uniDiskDir = diskDir_/mag(diskDir_);


    tensor E(tensor::zero);
    E.xx() = uniDiskDir.x();
    E.yy() = uniDiskDir.y();
    E.zz() = uniDiskDir.z();

    const Field<vector> zoneCellCentres(mesh().cellCentres(), cells);
    const Field<scalar> zoneCellVolumes(mesh().cellVolumes(), cells);

    const vector avgCentre = gSum(zoneCellVolumes*zoneCellCentres)/V();
    const scalar maxR = mag(max(zoneCellCentres - avgCentre));

    scalar intCoeffs =
        coeffs_[0]
      + coeffs_[1]*sqr(maxR)/2.0
      + coeffs_[2]*pow4(maxR)/3.0;

    forAll(cells, i)
    {
        T[i] = 2.0*rho[cells[i]]*diskArea_*mag(U[cells[i]])*a/(1.0 - a);

        scalar r = mag(mesh().cellCentres()[cells[i]] - avgCentre);

        Tr[i] =
            T[i]*(coeffs_[0] + coeffs_[1]*sqr(r) + coeffs_[2]*pow4(r))
           /intCoeffs;
    }
Example #13
0
Vlasov::Vlasov(Grid *_grid, Parallel *_parallel, Setup *_setup, FileIO *fileIO, Geometry *_geo, FFTSolver *_fft, Benchmark *_bench, Collisions *_coll)

: fft(_fft), bench(_bench), parallel(_parallel), grid(_grid), setup(_setup), geo(_geo), coll(_coll)

, _kw_12_dx_dx( 1./(12.*dx*dx)   )
, _kw_12_dv   ( 1./(12.*dv)      )
, _kw_12_dx   ( 1./(12.*dx)      )
, _kw_12_dz   ( 1./(12.*dz)      )
, _kw_12_dv_dv( 1./(12.*dv*dv)   )
, _kw_16_dx4  ( 1./(16.*pow4(dx)))

{
  ArrayPhase = nct::allocate(grid->RsLD, grid->RmLB, grid->RzLB, grid->RkyLD, grid->RxLB, grid->RvLB);
  ArrayPhase(&f0, &f, &fss, &fs, &f1, &ft, &Coll);
   
  ArrayXi = nct::allocate(grid->RzLB , grid->RkyLD, grid->RxLB4, grid->RvLB)(&Xi);
  ArrayG  = nct::allocate(grid->RzLB , grid->RkyLD, grid->RxLB , grid->RvLB)(&G );
  ArrayNL = nct::allocate(grid->RkyLD, grid->RxLD , grid->RvLD)(&nonLinearTerm);
   
  // allocate boundary (MPI) buffers
  int BoundX_num =    2 * Nky * NzLD * NvLD * NmLD * NsLD;
  int BoundZ_num = NxLD * Nky *    2 * NvLD * NmLD * NsLD;
  int BoundV_num = NxLD * Nky * NzLD *    2 * NmLD * NsLD;
  // do not allocate for M if not used
  int BoundM_num = (NmLlD == NmLlB) ? 0 : NxLD * Nky * NzLD * NvLD *    2 * NsLD;

  ArrayBoundX = nct::allocate(nct::Range(0 , BoundX_num ))(&SendXu, &SendXl, &RecvXl, &RecvXu);
  ArrayBoundZ = nct::allocate(nct::Range(0 , BoundZ_num ))(&SendZu, &SendZl, &RecvZl, &RecvZu);
  ArrayBoundV = nct::allocate(nct::Range(0 , BoundV_num ))(&SendVu, &SendVl, &RecvVl, &RecvVu);
  ArrayBoundM = nct::allocate(nct::Range(0 , BoundM_num ))(&SendMu, &SendMl, &RecvMl, &RecvMu);
  
  equation_type       = setup->get("Vlasov.Equation"   , "ES");        
  doNonLinear         = setup->get("Vlasov.doNonLinear", 0      );
  doNonLinearParallel = setup->get("Vlasov.doNonLinearParallel", 0);
  removeZF            = setup->get("Vlasov.removeZF", 0);

  const std::string dir_string[] = { "X", "Y", "Z", "V", "M", "S" };
  for(int dir = DIR_X; dir <= DIR_S; dir++) hyp_visc[dir] = setup->get("Vlasov.HyperViscosity." + dir_string[dir], 0.0);
   
  dataOutputF1      = Timing( setup->get("DataOutput.Vlasov.Step", -1),
                              setup->get("DataOutput.Vlasov.Time", -1.));

  // Parse operators
  ArrayKrook = nct::allocate(grid->RxGD)(&krook);  
  FunctionParser krook_parser = setup->getFParser();
  krook_parser.Parse(setup->get("Vlasov.Krook", "0."), "x");
  for(int x = NxGlD; x <= NxGuD; x++) krook[x] = krook_parser.Eval(&X[x]); 

  ///
  Xi_max[:] = 0.;

  initData(setup, fileIO);
}
void Foam::fv::radialActuationDiskSource::
addRadialActuationDiskAxialInertialResistance
(
    vectorField& Usource,
    const labelList& cells,
    const scalarField& Vcells,
    const RhoFieldType& rho,
    const vectorField& U
) const
{
    scalar a = 1.0 - Cp_/Ct_;
    scalarField Tr(cells.size());
    const vector uniDiskDir = diskDir_/mag(diskDir_);

    tensor E(Zero);
    E.xx() = uniDiskDir.x();
    E.yy() = uniDiskDir.y();
    E.zz() = uniDiskDir.z();

    const Field<vector> zoneCellCentres(mesh().cellCentres(), cells);
    const Field<scalar> zoneCellVolumes(mesh().cellVolumes(), cells);

    const vector avgCentre = gSum(zoneCellVolumes*zoneCellCentres)/V();
    const scalar maxR = gMax(mag(zoneCellCentres - avgCentre));

    scalar intCoeffs =
        radialCoeffs_[0]
      + radialCoeffs_[1]*sqr(maxR)/2.0
      + radialCoeffs_[2]*pow4(maxR)/3.0;

    vector upU = vector(VGREAT, VGREAT, VGREAT);
    scalar upRho = VGREAT;
    if (upstreamCellId_ != -1)
    {
        upU =  U[upstreamCellId_];
        upRho = rho[upstreamCellId_];
    }
    reduce(upU, minOp<vector>());
    reduce(upRho, minOp<scalar>());

    scalar T = 2.0*upRho*diskArea_*mag(upU)*a*(1.0 - a);
    forAll(cells, i)
    {
        scalar r2 = magSqr(mesh().cellCentres()[cells[i]] - avgCentre);

        Tr[i] =
            T
           *(radialCoeffs_[0] + radialCoeffs_[1]*r2 + radialCoeffs_[2]*sqr(r2))
           /intCoeffs;

        Usource[cells[i]] += ((Vcells[cells[i]]/V_)*Tr[i]*E) & upU;
    }
void v2WallFunctionFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const label patchi = patch().index();

    const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
    (
        IOobject::groupName
        (
            turbulenceModel::propertiesName,
            internalField().group()
        )
    );
    const scalarField& y = turbModel.y()[patchi];

    const tmp<volScalarField> tk = turbModel.k();
    const volScalarField& k = tk();

    const tmp<scalarField> tnuw = turbModel.nu(patchi);
    const scalarField& nuw = tnuw();

    const scalar Cmu25 = pow025(Cmu_);

    scalarField& v2 = *this;

    // Set v2 wall values
    forAll(v2, facei)
    {
        label celli = patch().faceCells()[facei];

        scalar uTau = Cmu25*sqrt(k[celli]);

        scalar yPlus = uTau*y[facei]/nuw[facei];

        if (yPlus > yPlusLam_)
        {
            scalar Cv2 = 0.193;
            scalar Bv2 = -0.94;
            v2[facei] = Cv2/kappa_*log(yPlus) + Bv2;
        }
        else
        {
            scalar Cv2 = 0.193;
            v2[facei] = Cv2*pow4(yPlus);
        }

        v2[facei] *= sqr(uTau);
    }
void Foam::equationReader::evalScalarFieldPow4
(
    const equationReader * eqnReader,
    const label index,
    const label i,
    const label storageOffset,
    label& storeIndex,
    scalarField& x,
    const scalarField& source
) const
{
    pow4(x, x);
}
Foam::tmp<Foam::volScalarField>
Foam::kineticTheoryModels::radialModels::CarnahanStarling::g0prime
(
    const volScalarField& alpha,
    const dimensionedScalar& alphaMinFriction,
    const dimensionedScalar& alphaMax
) const
{
    return
        2.5/sqr(1.0 - alpha)
      + 4.0*alpha/pow3(1.0 - alpha)
      + 1.5*sqr(alpha)/pow4(1.0 - alpha);
}
Example #18
0
static char *TupleToStr(int t)
	{
	static char s[K];

	for (int i = 0; i < K; ++i)
		{
		unsigned Letter = (t/(pow4(i)))%4;
		assert(Letter >= 0 && Letter < 4);
		s[K-i-1] = LetterToChar(Letter);
		}

	return s;
	}
void Foam::equationReader::evalDimsPow4
(
    const equationReader * eqnReader,
    const label index,
    const label i,
    const label storageOffset,
    label& storeIndex,
    dimensionSet& xDims,
    dimensionSet sourceDims
) const
{
    xDims.reset(pow4(xDims));
}
Example #20
0
static void AllocateIndex(int Diameter, int k)
	{
	KmerIndexCount = pow4(k);
	KmerWindowCount = Diameter - k + 1;

	Entries = all(INDEX_ENTRY, KmerWindowCount);

	zero(Entries, INDEX_ENTRY, KmerWindowCount);

	Heads = all(INDEX_ENTRY *, KmerIndexCount);
	Tails = all(INDEX_ENTRY *, KmerIndexCount);

	zero(Heads, INDEX_ENTRY *, KmerIndexCount);
	zero(Tails, INDEX_ENTRY *, KmerIndexCount);

	for (int i = 0; i < KmerWindowCount; ++i)
		AddToFreeList(&(Entries[i]));
	}
void matrix_derivatives(double *I, double sigma, double *Ix, double *Iy, int *sizeI) {
/* This function calculates a gaussian based x and y derivative of a 2D image */
    int k_min, k_max, k_size, kx, ky, ix, iy, i, j, index, index2;
    double val, valx, valy, *DGaussx, *DGaussy;
    /* Calculate kernel variables */
    k_min=(int)floor(-3*sigma);
    k_max=(int)ceil(3*sigma);
    k_size=k_max-k_min+1;
    /* Reserve memory to store kernels */
    DGaussx= (double*)malloc( k_size*k_size*sizeof(double) );
    DGaussy= (double*)malloc( k_size*k_size*sizeof(double) );
    /* Make Gaussian derivative kernels */
    for(j=0; j<k_size; j++) {
        ky = -(j+k_min);
        for(i=0; i<k_size; i++) {
            kx = -(i+k_min);
            val=-(kx/(2.0*PI*pow4(sigma)))*exp(-(pow2(kx)+pow2(ky))/(2.0*pow2(sigma)));
            DGaussx[i+j*k_size]=val; DGaussy[j+i*k_size]=val;
        }
    }
    /* Imfilter the whole image with the gaussian kernels */
    for(iy=0; iy<sizeI[1]; iy++) {
        for(ix=0; ix<sizeI[0]; ix++) {
            valx=0; valy=0;
            for(j=0; j<k_size; j++) {
                ky = iy+(j+k_min);
                for(i=0; i<k_size; i++) {
                    kx = ix+(i+k_min);
                    if((kx>=0)&&(ky>=0)&&(kx<sizeI[0])&&(ky<sizeI[1])) {
                        index = kx+ky*sizeI[0]; index2 = i+j*k_size;
                        valx+=I[index]*DGaussx[index2];
                        valy+=I[index]*DGaussy[index2];
                    }
                }
            }
            index=ix + iy*sizeI[0];
            Ix[index]=valx; Iy[index]=valy;
        }
    }
    /* Remove from kernels from memory */
    free(DGaussx); free(DGaussy);
}
void Foam::MarshakRadiationFixedTMixedFvPatchScalarField::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    // Re-calc reference value
    refValue() = 4.0*radiation::sigmaSB.value()*pow4(Trad_);

    // Diffusion coefficient - created by radiation model's ::updateCoeffs()
    const scalarField& gamma =
        patch().lookupPatchField<volScalarField, scalar>("gammaRad");

    const scalar Ep = emissivity_/(2.0*(2.0 - emissivity_));

    // Set value fraction
    valueFraction() = 1.0/(1.0 + gamma*patch().deltaCoeffs()/Ep);

    mixedFvPatchScalarField::updateCoeffs();
}
Foam::MarshakRadiationFixedTemperatureFvPatchScalarField::
MarshakRadiationFixedTemperatureFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    mixedFvPatchScalarField(p, iF),
    radiationCoupledBase(p, dict),
    Trad_("Trad", dict, p.size())
{
    // refValue updated on each call to updateCoeffs()
    refValue() = 4.0*constant::physicoChemical::sigma.value()*pow4(Trad_);

    // zero gradient
    refGrad() = 0.0;

    valueFraction() = 1.0;

    fvPatchScalarField::operator=(refValue());
}
Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
greyDiffusiveRadiationMixedFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
    :
    mixedFvPatchScalarField(p, iF),
    TName_(dict.lookup("T")),
    emissivity_(readScalar(dict.lookup("emissivity")))
{
    if (dict.found("refValue"))
    {
        fvPatchScalarField::operator=
        (
            scalarField("value", dict, p.size())
        );
        refValue() = scalarField("refValue", dict, p.size());
        refGrad() = scalarField("refGradient", dict, p.size());
        valueFraction() = scalarField("valueFraction", dict, p.size());
    }
    else
    {
        // No value given. Restart as fixedValue b.c.

        const scalarField& Tp =
            patch().lookupPatchField<volScalarField, scalar>(TName_);

        refValue() =
            emissivity_*4.0*radiation::sigmaSB.value()*pow4(Tp)
            /Foam::mathematicalConstant::pi;

        refGrad() = 0.0;
        valueFraction() = 1.0;

        fvPatchScalarField::operator=(refValue());
    }
}
Foam::radiation::blackBodyEmission::blackBodyEmission
(
    const label nLambda,
    const volScalarField& T
)
:
    table_
    (
        emissivePowerTable,
        interpolationTable<scalar>::CLAMP,
        "blackBodyEmissivePower"
    ),
    C1_("C1", dimensionSet(1, 4, 3, 0, 0, 0, 0), 3.7419e-16),
    C2_("C2", dimensionSet(0, 1, 0, 1, 0, 0, 0), 14.388e-6),
    bLambda_(nLambda),
    T_(T)
{
    forAll(bLambda_, lambdaI)
    {
        bLambda_.set
        (
            lambdaI,
            new volScalarField
            (
                IOobject
                (
                    "bLambda_" + Foam::name(lambdaI) ,
                    T.mesh().time().timeName(),
                    T.mesh(),
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                radiation::sigmaSB*pow4(T)
            )
        );

    }
Example #26
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Tenneti::CdRe() const
{
    volScalarField alpha1
    (
        max(pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField alpha2
    (
        max(pair_.continuous(), pair_.continuous().residualAlpha())
    );

    volScalarField Res(alpha2*pair_.Re());

    volScalarField CdReIsolated
    (
        neg(Res - 1000)*24*(1 + 0.15*pow(Res, 0.687))
      + pos0(Res - 1000)*0.44*max(Res, residualRe_)
    );

    volScalarField F0
    (
        5.81*alpha1/pow3(alpha2) + 0.48*pow(alpha1, 1.0/3.0)/pow4(alpha2)
    );

    volScalarField F1
    (
        pow3(alpha1)*Res*(0.95 + 0.61*pow3(alpha1)/sqr(alpha2))
    );

    // Tenneti et al. correlation includes the mean pressure drag.
    // This was removed here by multiplying F by alpha2 for consistency with
    // the formulation used in OpenFOAM
    return
        CdReIsolated + 24*sqr(alpha2)*(F0 + F1);
}
void QFFitFunctionFCSDistributionDIntGaussian::calcParameter(double* data, double* error) const {
    //int comp=data[FCSDLG_n_components];
    //int nonfl_comp=data[FCSDLG_n_nonfluorescent];
    double N=data[FCSDLG_n_particle];
    double eN=0;
    //double nf_tau1=data[FCSDLG_nonfl_tau1];
    double enf_tau1=0;
    double nf_theta1=data[FCSDLG_nonfl_theta1];
    double enf_theta1=0;
    //double nf_tau2=data[FCSDLG_nonfl_tau2];
    double enf_tau2=0;
    double nf_theta2=data[FCSDLG_nonfl_theta2];
    double enf_theta2=0;
    double D1=data[FCSDLG_diff_coeff1]/1.0e6;
    double eD1=0;
    double gamma=data[FCSDLG_focus_struct_fac];
    double egamma=0;
    //double gamma2=sqr(gamma);
    double wxy=data[FCSDLG_focus_width]/1.0e3;
    double ewxy=0;
    //double offset=data[FCSDLG_offset];
    double eoffset=0;
    double cps=data[FCSDLG_count_rate];
    double ecps=0;
    //double cpm=data[FCSDLG_cpm];
    double ecpm=0;

    if (error) {
        eN=error[FCSDLG_n_particle];
        enf_tau1=error[FCSDLG_nonfl_tau1]/1.0e6;
        enf_theta1=error[FCSDLG_nonfl_theta1];
        enf_tau2=error[FCSDLG_nonfl_tau2]/1.0e6;
        enf_theta2=error[FCSDLG_nonfl_theta2];
        eD1=error[FCSDLG_diff_tau1]/1.0e6;
        egamma=error[FCSDLG_focus_struct_fac];
        ewxy=error[FCSDLG_focus_width]/1.0e3;
        eoffset=error[FCSDLG_offset];
        ecps=error[FCSDLG_count_rate];
        ecpm=error[FCSDLG_cpm];
    }

    // correct for invalid fractions
    if (nf_theta1>1.0) nf_theta1=1.0;
    if (nf_theta2>1.0) nf_theta2=1.0;
    if (nf_theta1+nf_theta2>1.0) {
        nf_theta2=1.0-nf_theta1;
    }
    data[FCSDLG_nonfl_theta1]=nf_theta1;
    data[FCSDLG_nonfl_theta2]=nf_theta2;


    // calculate 1/N
    data[FCSDLG_1n_particle]=1.0/N;
    if (error) error[FCSDLG_1n_particle]=fabs(eN/N/N);

    // calculate Veff = pi^(3/2) * gamma * wxy^3
    const double pi32=sqrt(cube(M_PI));
    data[FCSDLG_focus_volume]=pi32*gamma*cube(wxy);
    if (error) error[FCSDLG_focus_volume]=sqrt(sqr(egamma*pi32*cube(wxy))+sqr(ewxy*3.0*pi32*gamma*sqr(wxy)));

    // calculate C = N / Veff
    const double pim32=1.0/sqrt(cube(M_PI));
    if (data[FCSDLG_focus_volume]!=0) data[FCSDLG_concentration]=N/data[FCSDLG_focus_volume]/(NAVOGADRO * 1.0e-24); else data[FCSDLG_concentration]=0;
    if (error) {
        if ((wxy!=0)&&(gamma!=0)) error[FCSDLG_concentration]=sqrt( sqr(egamma*pim32*N/cube(wxy)/sqr(gamma)) + sqr(ewxy*3.0*pim32*N/gamma/pow4(wxy)) + sqr(eN*pim32/gamma/cube(wxy)) )/(NAVOGADRO * 1.0e-24);
        else error[FCSDLG_concentration]=0;
    }

    // calculate D1 = wxy^2 / (4*tauD1)
    if (D1!=0) data[FCSDLG_diff_tau1]=sqr(wxy)/4.0/D1; else data[FCSDLG_diff_tau1]=0;
    if (error) {
        if (D1!=0) error[FCSDLG_diff_tau1]=sqrt( sqr(eD1*sqr(wxy)/sqr(D1)/4.0) + sqr(ewxy*2.0*wxy/D1/4.0) );
        else error[FCSDLG_diff_tau1]=0;
    }

    // calculate CPM = CPS/N
    data[FCSDLG_cpm]=(cps-data[FCSDiff_background])/N;
    error[FCSDLG_cpm]=sqrt(sqr(ecps/N)+sqr(eN*(cps-data[FCSDiff_background])/sqr(N)));
}
void QFFitFunctionFCSMultiDiffusion::calcParameter(double* data, double* error) const {
    int comp=data[FCSMULTI_n_components];
    //int nonfl_comp=data[FCSMULTI_n_nonfluorescent];
    double N=data[FCSMULTI_n_particle];
    double eN=0;
    //double nf_tau1=data[FCSMULTI_nonfl_tau1];
    double enf_tau1;//=0;
    double nf_theta1=data[FCSMULTI_nonfl_theta1];
    double enf_theta1;//=0;
    //double nf_tau2=data[FCSMULTI_nonfl_tau2];
    double enf_tau2;//=0;
    double nf_theta2=data[FCSMULTI_nonfl_theta2];
    double enf_theta2;//=0;
    double rho1=1.0;
    double erho1=0;
    double tauD1=data[FCSMULTI_diff_tau1];
    double etauD1=0;
    double rho2=data[FCSMULTI_diff_rho2];
    double erho2=0;
    double tauD2=data[FCSMULTI_diff_tau2];
    double etauD2=0;
    double rho3=data[FCSMULTI_diff_rho3];
    double erho3=0;
    double tauD3=data[FCSMULTI_diff_tau3];
    double etauD3=0;
    double gamma=data[FCSMULTI_focus_struct_fac];
    double egamma=0;
    //double gamma2=sqr(gamma);
    double wxy=data[FCSMULTI_focus_width]/1.0e3;
    double ewxy=0;
    //double offset=data[FCSMULTI_offset];
    double eoffset=0;
    double alpha1=data[FCSMULTI_diff_alpha1];
    double ealpha1=0;
    double alpha2=data[FCSMULTI_diff_alpha2];
    double ealpha2=0;
    double alpha3=data[FCSMULTI_diff_alpha3];
    double ealpha3=0;
    double cps=data[FCSMULTI_count_rate];
    double ecps=0;
    double background=data[FCSMULTI_background];
    double ebackground=0;
    //double cpm=data[FCSMULTI_cpm];
    double ecpm=0;

    if (error) {
        eN=error[FCSMULTI_n_particle];
        enf_tau1=error[FCSMULTI_nonfl_tau1];
        enf_theta1=error[FCSMULTI_nonfl_theta1];
        enf_tau2=error[FCSMULTI_nonfl_tau2];
        enf_theta2=error[FCSMULTI_nonfl_theta2];
        erho1=0;
        etauD1=error[FCSMULTI_diff_tau1];
        erho2=error[FCSMULTI_diff_rho2];
        etauD2=error[FCSMULTI_diff_tau2];
        erho3=error[FCSMULTI_diff_rho3];
        etauD3=error[FCSMULTI_diff_tau3];
        egamma=error[FCSMULTI_focus_struct_fac];
        ewxy=error[FCSMULTI_focus_width]/1.0e3;
        eoffset=error[FCSMULTI_offset];
        ealpha1=error[FCSMULTI_diff_alpha1];
        ealpha2=error[FCSMULTI_diff_alpha2];
        ealpha3=error[FCSMULTI_diff_alpha3];
        ecps=error[FCSMULTI_count_rate];
        ecpm=error[FCSMULTI_cpm];
        ebackground=error[FCSMULTI_background];
    }

    // correct for invalid fractions
    if (nf_theta1>1.0) nf_theta1=1.0;
    if (nf_theta2>1.0) nf_theta2=1.0;
    if (nf_theta1+nf_theta2>1.0) {
        nf_theta2=1.0-nf_theta1;
    }
    data[FCSMULTI_nonfl_theta1]=nf_theta1;
    data[FCSMULTI_nonfl_theta2]=nf_theta2;

    // calculate diffusion fractions
    if (comp==1) {
        rho1=1.0;
        erho1=0;
        rho2=0;
        erho2=0;
        rho3=0;
        erho3=0;
    } else if (comp==2) {
        if (rho2>1.0) rho2=1.0;
        if (rho2<0.0) rho2=0.0;
        rho1=1.0-rho2;
        erho1=erho2;
        rho3=0;
        erho3=0;
    } else if (comp==3) {
        if (rho2>1.0) rho2=1.0;
        if (rho2<0.0) rho2=0.0;
        if (rho3>1.0) rho3=1.0;
        if (rho3<0.0) rho3=0.0;
        if (rho2+rho3>1.0) {
            rho1=0;
            rho2=rho3=0.5;
        }
        rho1=1.0-rho2-rho3;
        erho1=sqrt(erho2*erho2+erho3*erho3);
    }

    data[FCSMULTI_diff_rho1]=rho1;
    data[FCSMULTI_diff_rho2]=rho2;
    data[FCSMULTI_diff_rho3]=rho3;
    if (error) {
        error[FCSMULTI_diff_rho1]=erho1;
        error[FCSMULTI_diff_rho2]=erho2;
        error[FCSMULTI_diff_rho3]=erho3;
    }


    // reread to variables after sort
    //rho1=data[FCSMULTI_diff_rho1];
    tauD1=data[FCSMULTI_diff_tau1]/1.0e6;
    //rho2=data[FCSMULTI_diff_rho2];
    tauD2=data[FCSMULTI_diff_tau2]/1.0e6;
    //rho3=data[FCSMULTI_diff_rho3];
    tauD3=data[FCSMULTI_diff_tau3]/1.0e6;
    alpha1=data[FCSMULTI_diff_alpha1];
    alpha2=data[FCSMULTI_diff_alpha2];
    alpha3=data[FCSMULTI_diff_alpha3];
    if (error) {
        //erho1=error[FCSMULTI_diff_rho1];
        etauD1=error[FCSMULTI_diff_tau1]/1.0e6;
        //erho2=error[FCSMULTI_diff_rho2];
        etauD2=error[FCSMULTI_diff_tau2]/1.0e6;
        //erho3=error[FCSMULTI_diff_rho3];
        etauD3=error[FCSMULTI_diff_tau3]/1.0e6;
        ealpha1=error[FCSMULTI_diff_alpha1];
        ealpha2=error[FCSMULTI_diff_alpha2];
        ealpha3=error[FCSMULTI_diff_alpha3];
    }

    // calculate 1/N
    data[FCSMULTI_1n_particle]=1.0/N;
    if (error) error[FCSMULTI_1n_particle]=fabs(eN/N/N);

    // calculate Veff = pi^(3/2) * gamma * wxy^3
    const double pi32=sqrt(cube(M_PI));
    data[FCSMULTI_focus_volume]=pi32*gamma*cube(wxy);
    if (error) error[FCSMULTI_focus_volume]=sqrt(sqr(egamma*pi32*cube(wxy))+sqr(ewxy*3.0*pi32*gamma*sqr(wxy)));

    // calculate C = N / Veff
    const double pim32=1.0/sqrt(cube(M_PI));
    if (data[FCSMULTI_focus_volume]!=0) data[FCSMULTI_concentration]=N/data[FCSMULTI_focus_volume]/(NAVOGADRO * 1.0e-24); else data[FCSMULTI_concentration]=0;
    if (error) {
        if ((wxy!=0)&&(gamma!=0)) error[FCSMULTI_concentration]=sqrt( sqr(egamma*pim32*N/cube(wxy)/sqr(gamma)) + sqr(ewxy*3.0*pim32*N/gamma/pow4(wxy)) + sqr(eN*pim32/gamma/cube(wxy)) )/(NAVOGADRO * 1.0e-24);
        else error[FCSMULTI_concentration]=0;
    }

    // calculate CPM = (CPS-background)/N
    data[FCSMULTI_cpm]=(cps-background)/N;
    error[FCSMULTI_cpm]=sqrt(sqr(ecps/N)+sqr(ebackground/N)+sqr(eN*(cps-background)/sqr(N)));

}
Example #29
0
static void fill_table(t_tabledata *td,int tp,const t_forcerec *fr)
{
  /* Fill the table according to the formulas in the manual.
   * In principle, we only need the potential and the second
   * derivative, but then we would have to do lots of calculations
   * in the inner loop. By precalculating some terms (see manual)
   * we get better eventual performance, despite a larger table.
   *
   * Since some of these higher-order terms are very small,
   * we always use double precision to calculate them here, in order
   * to avoid unnecessary loss of precision.
   */
#ifdef DEBUG_SWITCH
  FILE *fp;
#endif
  int  i;
  double reppow,p;
  double r1,rc,r12,r13;
  double r,r2,r6,rc6;
  double expr,Vtab,Ftab;
  /* Parameters for David's function */
  double A=0,B=0,C=0,A_3=0,B_4=0;
  /* Parameters for the switching function */
  double ksw,swi,swi1;
  /* Temporary parameters */
  gmx_bool bSwitch,bShift;
  double ewc=fr->ewaldcoeff;
  double isp= 0.564189583547756;
   
  bSwitch = ((tp == etabLJ6Switch) || (tp == etabLJ12Switch) || 
	     (tp == etabCOULSwitch) ||
	     (tp == etabEwaldSwitch) || (tp == etabEwaldUserSwitch));
  bShift  = ((tp == etabLJ6Shift) || (tp == etabLJ12Shift) || 
	     (tp == etabShift));

  reppow = fr->reppow;

  if (tprops[tp].bCoulomb) {
    r1 = fr->rcoulomb_switch;
    rc = fr->rcoulomb;
  } 
  else {
    r1 = fr->rvdw_switch;
    rc = fr->rvdw;
  }
  if (bSwitch)
    ksw  = 1.0/(pow5(rc-r1));
  else
    ksw  = 0.0;
  if (bShift) {
    if (tp == etabShift)
      p = 1;
    else if (tp == etabLJ6Shift) 
      p = 6; 
    else 
      p = reppow;
    
    A = p * ((p+1)*r1-(p+4)*rc)/(pow(rc,p+2)*pow2(rc-r1));
    B = -p * ((p+1)*r1-(p+3)*rc)/(pow(rc,p+2)*pow3(rc-r1));
    C = 1.0/pow(rc,p)-A/3.0*pow3(rc-r1)-B/4.0*pow4(rc-r1);
    if (tp == etabLJ6Shift) {
      A=-A;
      B=-B;
      C=-C;
    }
    A_3=A/3.0;
    B_4=B/4.0;
  }
  if (debug) { fprintf(debug,"Setting up tables\n"); fflush(debug); }
    
#ifdef DEBUG_SWITCH
  fp=xvgropen("switch.xvg","switch","r","s");
#endif
  
  for(i=td->nx0; (i<td->nx); i++) {
    r     = td->x[i];
    r2    = r*r;
    r6    = 1.0/(r2*r2*r2);
    if (gmx_within_tol(reppow,12.0,10*GMX_DOUBLE_EPS)) {
      r12 = r6*r6;
    } else {
      r12 = pow(r,-reppow);   
    }
    Vtab  = 0.0;
    Ftab  = 0.0;
    if (bSwitch) {
      /* swi is function, swi1 1st derivative and swi2 2nd derivative */
      /* The switch function is 1 for r<r1, 0 for r>rc, and smooth for
       * r1<=r<=rc. The 1st and 2nd derivatives are both zero at
       * r1 and rc.
       * ksw is just the constant 1/(rc-r1)^5, to save some calculations...
       */ 
      if(r<=r1) {
	swi  = 1.0;
	swi1 = 0.0;
      } else if (r>=rc) {
	swi  = 0.0;
	swi1 = 0.0;
      } else {
	swi      = 1 - 10*pow3(r-r1)*ksw*pow2(rc-r1) 
	  + 15*pow4(r-r1)*ksw*(rc-r1) - 6*pow5(r-r1)*ksw;
	swi1     = -30*pow2(r-r1)*ksw*pow2(rc-r1) 
	  + 60*pow3(r-r1)*ksw*(rc-r1) - 30*pow4(r-r1)*ksw;
      }
    }
    else { /* not really needed, but avoids compiler warnings... */
      swi  = 1.0;
      swi1 = 0.0;
    }
#ifdef DEBUG_SWITCH
    fprintf(fp,"%10g  %10g  %10g  %10g\n",r,swi,swi1,swi2);
#endif

    rc6 = rc*rc*rc;
    rc6 = 1.0/(rc6*rc6);

    switch (tp) {
    case etabLJ6:
      /* Dispersion */
      Vtab  = -r6;
      Ftab  = 6.0*Vtab/r;
      break;
    case etabLJ6Switch:
    case etabLJ6Shift:
      /* Dispersion */
      if (r < rc) {      
	Vtab  = -r6;
	Ftab  = 6.0*Vtab/r;
      }
      break;
    case etabLJ12:
      /* Repulsion */
      Vtab  = r12;
      Ftab  = reppow*Vtab/r;
      break;
    case etabLJ12Switch:
    case etabLJ12Shift:
      /* Repulsion */
      if (r < rc) {                
	Vtab  = r12;
	Ftab  = reppow*Vtab/r;
      }  
      break;
	case etabLJ6Encad:
        if(r < rc) {
            Vtab  = -(r6-6.0*(rc-r)*rc6/rc-rc6);
            Ftab  = -(6.0*r6/r-6.0*rc6/rc);
        } else { /* r>rc */ 
            Vtab  = 0;
            Ftab  = 0;
        } 
        break;
    case etabLJ12Encad:
        if(r < rc) {
            Vtab  = r12-12.0*(rc-r)*rc6*rc6/rc-1.0*rc6*rc6;
            Ftab  = 12.0*r12/r-12.0*rc6*rc6/rc;
        } else { /* r>rc */ 
            Vtab  = 0;
            Ftab  = 0;
        } 
        break;        
    case etabCOUL:
      Vtab  = 1.0/r;
      Ftab  = 1.0/r2;
      break;
    case etabCOULSwitch:
    case etabShift:
      if (r < rc) { 
	Vtab  = 1.0/r;
	Ftab  = 1.0/r2;
      }
      break;
    case etabEwald:
    case etabEwaldSwitch:
      Vtab  = gmx_erfc(ewc*r)/r;
      Ftab  = gmx_erfc(ewc*r)/r2+2*exp(-(ewc*ewc*r2))*ewc*isp/r;
      break;
    case etabEwaldUser:
    case etabEwaldUserSwitch:
      /* Only calculate minus the reciprocal space contribution */
      Vtab  = -gmx_erf(ewc*r)/r;
      Ftab  = -gmx_erf(ewc*r)/r2+2*exp(-(ewc*ewc*r2))*ewc*isp/r;
      break;
    case etabRF:
    case etabRF_ZERO:
      Vtab  = 1.0/r      +   fr->k_rf*r2 - fr->c_rf;
      Ftab  = 1.0/r2     - 2*fr->k_rf*r;
      if (tp == etabRF_ZERO && r >= rc) {
	Vtab = 0;
	Ftab = 0;
      }
      break;
    case etabEXPMIN:
      expr  = exp(-r);
      Vtab  = expr;
      Ftab  = expr;
      break;
    case etabCOULEncad:
        if(r < rc) {
            Vtab  = 1.0/r-(rc-r)/(rc*rc)-1.0/rc;
            Ftab  = 1.0/r2-1.0/(rc*rc);
        } else { /* r>rc */ 
            Vtab  = 0;
            Ftab  = 0;
        } 
        break;
    default:
      gmx_fatal(FARGS,"Table type %d not implemented yet. (%s,%d)",
		  tp,__FILE__,__LINE__);
    }
    if (bShift) {
      /* Normal coulomb with cut-off correction for potential */
      if (r < rc) {
	Vtab -= C;
	/* If in Shifting range add something to it */
	if (r > r1) {
	  r12 = (r-r1)*(r-r1);
	  r13 = (r-r1)*r12;
	  Vtab  += - A_3*r13 - B_4*r12*r12;
	  Ftab  +=   A*r12 + B*r13;
	}
      }
    }

    if (ETAB_USER(tp)) {
      Vtab += td->v[i];
      Ftab += td->f[i];
    }

    if ((r > r1) && bSwitch) {
      Ftab = Ftab*swi - Vtab*swi1;
      Vtab = Vtab*swi;
    }  
    
    /* Convert to single precision when we store to mem */
    td->v[i]  = Vtab;
    td->f[i]  = Ftab;
  }

  /* Continue the table linearly from nx0 to 0.
   * These values are only required for energy minimization with overlap or TPI.
   */
  for(i=td->nx0-1; i>=0; i--) {
    td->v[i] = td->v[i+1] + td->f[i+1]*(td->x[i+1] - td->x[i]);
    td->f[i] = td->f[i+1];
  }

#ifdef DEBUG_SWITCH
  gmx_fio_fclose(fp);
#endif
}
Example #30
0
File: math.hpp Project: igagis/utki
/**
 * @brief Calculate x^5.
 */
template <typename T> inline T pow5(T x)noexcept{
	return pow4(x) * x;
}