Example #1
0
			static libmaus2::autoarray::AutoArray<char> loadFile(std::istream & in)
			{
				libmaus2::autoarray::AutoArray<char> C(1);
				uint64_t p = 0;
				
				while ( in )
				{
					in.read(C.begin() + p, C.size()-p);
					
					if ( ! in.gcount() )
						break;

					p += in.gcount();
					
					if ( p == C.size() )
					{
						libmaus2::autoarray::AutoArray<char> Cn(2*C.size(),false);
						std::copy(C.begin(),C.end(),Cn.begin());
						C = Cn;
					}
				}
				
				libmaus2::autoarray::AutoArray<char> Cn(p,false);
				std::copy(C.begin(),C.begin()+p,Cn.begin());
				
				return Cn;
			}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::cyclicGgiFvPatch::delta() const
{
    if (cyclicGgiPolyPatch_.master())
    {
        tmp<vectorField> tDelta =
            cyclicGgiPolyPatch_.reconFaceCellCentres() - Cn();

        if (bridgeOverlap())
        {
            vectorField bridgeDeltas = Cf() - Cn();

            bridge(bridgeDeltas, tDelta());
        }

        return tDelta;
    }
    else
    {
        tmp<vectorField> tDelta = interpolate
        (
            shadow().Cn() - cyclicGgiPolyPatch_.shadow().reconFaceCellCentres()
        );

        if (bridgeOverlap())
        {
            vectorField bridgeDeltas = Cf() - Cn();

            bridge(bridgeDeltas, tDelta());
        }

        return tDelta;
    }
}
Example #3
0
CodecStatus_t Codec_MmeAudio_c::GetAttribute(const char *Attribute, PlayerAttributeDescriptor_t *Value)
{
	//report( severity_error, "Codec_MmeAudio_c::GetAttribute Enter\n");
	if (0 == strcmp(Attribute, "sample_frequency"))
	{
		enum eAccFsCode SamplingFreqCode = (enum eAccFsCode) AudioDecoderStatus.SamplingFreq;
		Value->Id                        = SYSFS_ATTRIBUTE_ID_INTEGER;
		if (SamplingFreqCode < ACC_FS_reserved)
			Value->u.Int = Codec_MmeAudio_c::ConvertCodecSamplingFreq(SamplingFreqCode);
		else
			Value->u.Int = 0;
		return CodecNoError;
	}
	else if (0 == strcmp(Attribute, "number_channels"))
	{
#if 0
		int lfe_mask = ((int) ACC_MODE20t_LFE - (int) ACC_MODE20t);
		int low_channel = 0;
		int number_channels = 0;
		Value->Id                        = SYSFS_ATTRIBUTE_ID_INTEGER;
		if (AudioDecoderStatus.DecAudioMode & lfe_mask) low_channel = 1;
		number_channels = GetNumberOfChannelsFromAudioConfiguration((enum eAccAcMode)(AudioDecoderStatus.DecAudioMode & ~lfe_mask));
		Value->u.Int = number_channels + low_channel;
#else
#define C(f,b) case ACC_MODE ## f ## b: Value->u.ConstCharPointer = #f "/" #b ".0"; break; case ACC_MODE ## f ## b ## _LFE: Value->u.ConstCharPointer = #f "/" #b ".1"; break
#define Cn(f,b) case ACC_MODE ## f ## b: Value->u.ConstCharPointer = #f "/" #b ".0"; break
#define Ct(f,b) case ACC_MODE ## f ## b ## t: Value->u.ConstCharPointer = #f "/" #b ".0"; break; case ACC_MODE ## f ## b ## t_LFE: Value->u.ConstCharPointer = #f "/" #b ".1"; break
		Value->Id = SYSFS_ATTRIBUTE_ID_CONSTCHARPOINTER;
		switch ((enum eAccAcMode)(AudioDecoderStatus.DecAudioMode))
		{
				Ct(2, 0);
				C(1, 0);
				C(2, 0);
				C(3, 0);
				C(2, 1);
				C(3, 1);
				C(2, 2);
				C(3, 2);
				C(2, 3);
				C(3, 3);
				C(2, 4);
				C(3, 4);
				Cn(4, 2);
				Cn(4, 4);
				Cn(5, 2);
				Cn(5, 3);
			default:
				Value->u.ConstCharPointer = "UNKNOWN";
		}
#endif
		return CodecNoError;
	}
	else
	{
		CODEC_ERROR("This attribute does not exist.\n");
		return CodecError;
	}
	return CodecNoError;
}
Cn Analitza::calc(Object* root)
{
	Q_ASSERT(root && root->type()!=Object::none);
	Cn ret=Cn(0.);
	Ci *a;
	
	switch(root->type()) {
		case Object::container:
			ret = operate((Container*) root);
			break;
		case Object::value:
			ret=(Cn*) root;
			break;
		case Object::variable:
			a=(Ci*) root;
			
			if(m_vars->contains(a->name()))
				ret = calc(m_vars->value(a->name()));
			else if(a->isFunction())
				m_err << i18n("The function <em>%1</em> doesn't exist").arg(a->name());
			else
				m_err << i18n("The variable <em>%1</em> doesn't exist").arg(a->name());
			
			break;
		case Object::oper:
		default:
			break;
	}
	return ret;
}
// Calculates the total probability flux leaving the domain at time t
const Real FirstPassageGreensFunction1DRad::flux_tot (const Real t) const
{
    Real An;
    double sum = 0, term = 0, prev_term = 0;
    const double D(this->getD());

    int n=1;

    do
    {
        if ( n >= MAX_TERMEN )
        {
            std::cerr << "Too many terms needed for GF1DRad::flux_tot. N: "
                      << n << std::endl;
            break;
        }

        An = this->a_n(n);
        prev_term = term;
        term = An * An * Cn(An, t) * this->An(An) * Bn(An);
        n++;
        sum += term;
    }
    while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
            fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
            n <= MIN_TERMEN );

    return sum*2.0*D;
}
Example #6
0
// Calculates the total probability flux leaving the domain at time t
// This is simply the negative of the time derivative of the survival prob.
// at time t [-dS(t')/dt' for t'=t].
Real
GreensFunction1DRadAbs::flux_tot (Real t) const
{
    Real root_n;
    const Real D(this->getD());
    const Real v(this->getv());
    const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D);

    const Real D2 = D*D;
    const Real v2Dv2D = v*v/4.0/D2;
    double sum = 0, term = 0, prev_term = 0;
    int n=1;

    do
    {
	if ( n >= MAX_TERMS )
	{
	    std::cerr << "Too many terms needed for GF1DRad::flux_tot. N: "
	              << n << std::endl;
	    break;
	}

	root_n = this->root_n(n);
	prev_term = term;
	term = (root_n * root_n + v2Dv2D) * Cn(root_n, t) * An(root_n) * Bn(root_n);
	n++;
	sum += term;
    }
    while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
	fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
	n <= MIN_TERMS );

    return 2.0*D*exp(vexpo)*sum;
}
// Calculates the probability of finding the particle inside the domain at
// time t, the survival probability The domein is from -r to r (r0 is in
// between!!)
const Real FirstPassageGreensFunction1DRad::p_survival (const Real t) const
{
    const Real D(this->getD());

    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    if (t == 0 || D == 0)
    {
        // if there was no time or no movement the particle was always
        // in the domain
        return 1.0;
    }


    Real An;
    Real sum = 0, term = 0, term_prev = 0;
    int n = 1;

    do
    {
        An = this->a_n(n);
        term_prev = term;
        term = Cn(An, t) * this->An(An) * Bn(An);
        sum += term;
        n++;
    }
    // Is 1.0 a good measure for the scale of probability or will this
    // fail at some point?
    while ( fabs(term/sum) > EPSILON*1.0 ||
            fabs(term_prev/sum) > EPSILON*1.0 ||
            n <= MIN_TERMEN);

    return 2.0*sum;
}
// Calculates the probability density of finding the particle at location r at
// time t.
const Real FirstPassageGreensFunction1DRad::prob_r (const Real r, const Real t)
const
{
    const Real L(this->getL());
    const Real D(this->getD());
    const Real h(this->getk()/D);
    const Real r0(this->getr0());

    THROW_UNLESS( std::invalid_argument, t >= 0.0 );
    THROW_UNLESS( std::invalid_argument, 0 <= r && r <= L);

    // if there was no time or no movement
    if (t == 0 || D == 0)
    {
        // the probability density function is a delta function
        if (r == r0)
        {
            return INFINITY;
        }
        else
        {
            return 0.0;
        }
    }

    // if you're looking on the boundary
    if ( fabs (r - L) < EPSILON*L )
    {
        return 0.0;
    }

    Real root_n, An_r;
    Real sum = 0, term = 0, prev_term = 0;
    int n=1;

    do
    {
        if ( n >= MAX_TERMEN )
        {
            std::cerr << "Too many terms needed for GF1DRad::prob_r. N: "
                      << n << std::endl;
            break;
        }

        root_n = this->a_n(n);
        An_r = root_n*r;

        prev_term = term;
        term = Cn(root_n, t) * An(root_n) * (root_n*cos(An_r) + h*sin(An_r));
        sum += term;

        n++;
    }
    // PDENS_TYPICAL is now 1e3, is this any good?!
    while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
            fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
            n <= MIN_TERMEN );

    return 2.0*sum;
}
// Make patch weighting factors
void Foam::mixingPlaneFvPatch::makeWeights(scalarField& w) const
{
    // Calculation of weighting factors is performed from the master
    // position, using reconstructed shadow cell centres
    if (mixingPlanePolyPatch_.master())
    {
        vectorField n = nf();

        // Note: mag in the dot-product.
        // For all valid meshes, the non-orthogonality will be less that
        // 90 deg and the dot-product will be positive.  For invalid
        // meshes (d & s <= 0), this will stabilise the calculation
        // but the result will be poor.  HJ, 24/Aug/2011
        scalarField nfc =
            mag(n & (mixingPlanePolyPatch_.reconFaceCellCentres() - Cf()));

        w = nfc/(mag(n & (Cf() - Cn())) + nfc);
    }
    else
    {
        // Pick up weights from the master side
        scalarField masterWeights(shadow().size());
        shadow().makeWeights(masterWeights);

        scalarField oneMinusW = 1 - masterWeights;

        w = interpolate(oneMinusW);
    }
}
Cn Analitza::calculate()
{
	if(m_exp.isCorrect())
		return calc(m_exp.m_tree);
	else {
		m_err << i18n("Must specify an operation");
		return Cn(0.);
	}
}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::regionCoupleFvPatch::delta() const
{
    if (rcPolyPatch_.coupled())
    {
        if (rcPolyPatch_.master())
        {
            tmp<vectorField> tDelta =
                rcPolyPatch_.reconFaceCellCentres() - Cn();

            if (bridgeOverlap())
            {
                vectorField bridgeDeltas = Cf() - Cn();

                bridge(bridgeDeltas, tDelta());
            }

            return tDelta;
        }
        else
        {
            tmp<vectorField> tDelta = interpolate
            (
                shadow().Cn() - rcPolyPatch_.shadow().reconFaceCellCentres()
            );

            if (bridgeOverlap())
            {
                vectorField bridgeDeltas = Cf() - Cn();

                bridge(bridgeDeltas, tDelta());
            }

            return tDelta;
        }
    }
    else
    {
        return fvPatch::delta();
    }
}
Example #12
0
    void testWriteRead3()
    {
      const char *filename = "TestMRR.testWriteRead3.txt";

      MRR stdfRecIn;
      
      *((U4*)(&(stdfRecIn["FINISH_T"]))) = 0xffffffff;
      stdfRecIn["DISP_COD"] = C1('F');
      *((Cn*)(&(stdfRecIn["USR_DESC"]))) = Cn("sss");
      *((Cn*)(&(stdfRecIn["EXC_DESC"]))) = Cn("fff");
      std::ofstream outfile(filename, std::ofstream::binary);
      stdfRecIn.write(outfile);
      outfile.close();

      MRR stdfRecOut;
      std::ifstream infile(filename, std::ifstream::binary);
      stdfRecOut.read(infile);
      outfile.close();

      TS_ASSERT_EQUALS(stdfRecIn.storage(), stdfRecOut.storage())
      std::vector<std::basic_string<char> > str;
      stdfRecOut.to_string(str);
      TS_ASSERT_EQUALS(str[0], "13");
      TS_ASSERT_EQUALS(str[1], "1");
      TS_ASSERT_EQUALS(str[2], "20");
      TS_ASSERT_EQUALS(str[3], "4294967295");
      TS_ASSERT_EQUALS(str[4], "F");
      TS_ASSERT_EQUALS(str[5], "sss");
      TS_ASSERT_EQUALS(str[6], "fff");

      TS_ASSERT_EQUALS(stdfRecIn["FINISH_T"].to_string(), "4294967295");
      TS_ASSERT_EQUALS(stdfRecIn["DISP_COD"].to_string(), "F");
      TS_ASSERT_EQUALS(stdfRecIn["USR_DESC"].to_string(), "sss");
      TS_ASSERT_EQUALS(stdfRecIn["EXC_DESC"].to_string(), "fff");
      
     // stdfRecOut.find("DISP_COD");
    }
Example #13
0
inline void RocketGeometry::Display()
{
   double v = 30;
   double t = 273.15 + 20;
   double rho = 1.225;
   double r = Reynolds(rho, v, ltr, t);
   double a = 0.01;
   double m = Mach(v, t);
   double cf = ViscousDrag(r);
   double xcp = Xcp(a);
   double cn = Cn(a, r, m);
   double ca = Ca(a, r, m, cn);

   std::cout << "Rocket Geometry: "
      << "\n\nPlanform Areas"
      << "\n - ApN: " << ApN()
      << "\n - ApB: " << ApB()
      << "\n - ApT: " << ApT()
      << "\n - ApF: " << ApF()
      << "\n - Afe: " << Afe()
      << "\n - Afp: " << Afp()
      << "\n\nStability Derivatives"
      << "\n - CnaN: " << NCnaN()
      << "\n - CnaB: " << NCnaB()
      << "\n - CnaT: " << NCnaT()
      << "\n - CnaF: " << NCnaF()
      << "\n\nNorm Force CP"
      << "\n - NcpN: " << NXcpN()
      << "\n - NcpB: " << NXcpB()
      << "\n - NcpT: " << NXcpT()
      << "\n - NcpF: " << NXcpF()
      << "\n\nLift Force CP"
      << "\n - LcpN: " << LXcpN()
      << "\n - LcpB: " << LXcpB()
      << "\n - LcpT: " << LXcpT()
      << "\n - LcpF: " << LXcpF()
      << "\n\nDrag Force"
      << "\n - DragB: " << DragBody(cf)
      << "\n - DragA: " << DragBase(DragBody(cf))
      << "\n - DragF: " << DragFin(cf)
      << "\n - DragI: " << DragInterference(cf)
      << "\n - DragBA: " << DragAlphaBody(a)
      << "\n - DragFA: " << DragAlphaFin(a)
      << "\n\nResults"
      << "\n - Cn: " << cn
      << "\n - Ca: " << ca
      << "\n - Xcp: " << xcp
      << std::endl;
}
bool Container::equalTree(Object const* o1, Object const * o2)
{
	Q_ASSERT(o1 && o2);
	if(o1==o2)
		return true;
	bool eq= o1->type()==o2->type();
	switch(o2->type()) {
		case Object::variable:
			eq = eq && Ci(o2)==Ci(o1);
			break;
		case Object::value:
			eq = eq && Cn(o2)==Cn(o1);
			break;
		case Object::container:
			eq = eq && Container(o2)==Container(o1);
			break;
		case Object::oper:
			eq = eq && Operator(o2)==Operator(o1);
			break;
		default:
			break;
	}
	return eq;
}
// Make patch weighting factors
void Foam::regionCoupleFvPatch::makeWeights(scalarField& w) const
{
    if (rcPolyPatch_.coupled())
    {
        if (rcPolyPatch_.master())
        {
            vectorField n = nf();

            // Note: mag in the dot-product.
            // For all valid meshes, the non-orthogonality will be less than
            // 90 deg and the dot-product will be positive.  For invalid
            // meshes (d & s <= 0), this will stabilise the calculation
            // but the result will be poor.  HJ, 24/Aug/2011
            scalarField nfc =
                mag(n & (rcPolyPatch_.reconFaceCellCentres() - Cf()));

            w = nfc/(mag(n & (Cf() - Cn())) + nfc);

            if (bridgeOverlap())
            {
                // Set overlap weights to 0.5 and use mirrored neighbour field
                // for interpolation.  HJ, 21/Jan/2009
                bridge(scalarField(size(), 0.5), w);
            }
        }
        else
        {
            // Pick up weights from the master side
            scalarField masterWeights(shadow().size());
            shadow().makeWeights(masterWeights);

            scalarField oneMinusW = 1 - masterWeights;

            w = interpolate(oneMinusW);

            if (bridgeOverlap())
            {
                // Set overlap weights to 0.5 and use mirrored neighbour field
                // for interpolation.  HJ, 21/Jan/2009
                bridge(scalarField(size(), 0.5), w);
            }
        }
    }
    else
    {
        fvPatch::makeWeights(w);
    }
}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::mixingPlaneFvPatch::delta() const
{
    if (mixingPlanePolyPatch_.master())
    {
        return mixingPlanePolyPatch_.reconFaceCellCentres() - Cn();
    }
    else
    {
        tmp<vectorField> tDelta = interpolate
        (
            shadow().Cn()
          - mixingPlanePolyPatch_.shadow().reconFaceCellCentres()
        );

        return tDelta;
    }
}
// Make patch weighting factors
void Foam::cyclicGgiFvPatch::makeWeights(scalarField& w) const
{
    // Calculation of weighting factors is performed from the master
    // position, using reconstructed shadow cell centres
    // HJ, 2/Aug/2007
    if (cyclicGgiPolyPatch_.master())
    {
        vectorField n = nf();

        // Note: mag in the dot-product.
        // For all valid meshes, the non-orthogonality will be less that
        // 90 deg and the dot-product will be positive.  For invalid
        // meshes (d & s <= 0), this will stabilise the calculation
        // but the result will be poor.  HJ, 24/Aug/2011
        scalarField nfc =
            mag
            (
                n & (cyclicGgiPolyPatch_.reconFaceCellCentres() - Cf())
            );

        w = nfc/(mag(n & (Cf() - Cn())) + nfc);

        if (bridgeOverlap())
        {
            // Set overlap weights to 0.5 and use mirrored neighbour field
            // for interpolation.  HJ, 21/Jan/2009
            bridge(scalarField(size(), 0.5), w);
        }
    }
    else
    {
        // Pick up weights from the master side
        scalarField masterWeights(shadow().size());
        shadow().makeWeights(masterWeights);

        w = interpolate(1 - masterWeights);

        if (bridgeOverlap())
        {
            // Set overlap weights to 0.5 and use mirrored neighbour field
            // for interpolation.  HJ, 21/Jan/2009
            bridge(scalarField(size(), 0.5), w);
        }
    }
}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::overlapGgiFvPatch::delta() const
{
    if (overlapGgiPolyPatch_.master())
    {
        return overlapGgiPolyPatch_.reconFaceCellCentres() - Cn();
    }
    else
    {
//         vectorField masterDelta = shadow().Cn()
//             - overlapGgiPolyPatch_.shadow().reconFaceCellCentres();

//         return interpolate(masterDelta);

        return interpolate
        (
            shadow().Cn() - overlapGgiPolyPatch_.shadow().reconFaceCellCentres()
        );
    }
}
Example #19
0
Foam::tmp<Foam::vectorField> Foam::wedgeFvPatch::delta() const
{
    const vectorField nHat(nf());
    return nHat*(nHat & (Cf() - Cn()));
}
bool Neuron::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
{
	std::string strType = Std_CheckString(strDataType);
	
	if(Node::SetData(strDataType, strValue, false))
		return true;

	if(strType == "CM")
	{
		Cn(atof(strValue.c_str()));
		return true;
	}

	if(strType == "GM")
	{
		Gn(atof(strValue.c_str()));
		return true;
	}

	if(strType == "VTH")
	{
		Vth(atof(strValue.c_str()));
		return true;
	}

	if(strType == "VREST")
	{
		Vrest(atof(strValue.c_str()));
		return true;
	}

	if(strType == "RELATIVEACCOMMODATION")
	{
		RelativeAccommodation(atof(strValue.c_str()));
		return true;
	}

	if(strType == "ACCOMMODATIONTIMECONSTANT")
	{
		AccommodationTimeConstant(atof(strValue.c_str()));
		return true;
	}

	if(strType == "VNOISEMAX")
	{
		VNoiseMax(atof(strValue.c_str()));
		return true;
	}

	if(strType == "FMIN")
	{
		Fmin(atof(strValue.c_str()));
		return true;
	}

	if(strType == "GAIN")
	{
		Gain(atof(strValue.c_str()));
		return true;
	}

	if(strType == "GAINTYPE")
	{
		GainType(Std_ToBool(strValue));
		return true;
	}

	if(strType == "ADDEXTERNALCURRENT")
	{
		AddExternalI(atof(strValue.c_str()));
		return true;
	}

	if(strType == "IINIT")
	{
		Iinit(atof(strValue.c_str()));
		return true;
	}

	if(strType == "INITTIME")
	{
		InitTime(atof(strValue.c_str()));
		return true;
	}

	//If it was not one of those above then we have a problem.
	if(bThrowError)
		THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);

	return false;
}
void Neuron::Load(CStdXml &oXml)
{
	int iCount, iIndex;

	Node::Load(oXml);

	oXml.IntoElem();  //Into Neuron Element

	m_arySynapses.RemoveAll();

	Enabled(oXml.GetChildBool("Enabled", true));

	Cn(oXml.GetChildFloat("Cn"));
	Gn(oXml.GetChildFloat("Gn"));
	Vrest(oXml.GetChildFloat("Vrest", 0));
	Vth(oXml.GetChildFloat("Vth"));
	Fmin(oXml.GetChildFloat("Fmin"));
	Gain(oXml.GetChildFloat("Gain"));
	ExternalI(oXml.GetChildFloat("ExternalI"));
	VNoiseMax(fabs(oXml.GetChildFloat("VNoiseMax", m_fltVNoiseMax)));
	Iinit(oXml.GetChildFloat("Iinit", m_fltIinit));
	InitTime(oXml.GetChildFloat("InitTime", m_fltInitTime));

	m_fltVndisp = m_fltVrest;
	m_fltVthdisp = m_fltVrest + m_fltVth;

	GainType(oXml.GetChildBool("GainType", true));

	m_aryVth[0] = m_aryVth[1] = m_fltVth;

	if(m_fltVNoiseMax != 0)
		UseNoise(true);
	else
		UseNoise(false);

	RelativeAccommodation(fabs(oXml.GetChildFloat("RelativeAccom", m_fltRelativeAccom)));
	AccommodationTimeConstant(fabs(oXml.GetChildFloat("AccomTimeConst", m_fltAccomTimeConst)));

	if(m_fltRelativeAccom != 0)
		UseAccom(true);
	else
		UseAccom(false);

	//*** Begin Loading Synapses. *****
	if(oXml.FindChildElement("Synapses", false))
	{
		oXml.IntoElem();  //Into Synapses Element

		iCount = oXml.NumberOfChildren();
		for(iIndex=0; iIndex<iCount; iIndex++)
		{
			oXml.FindChildByIndex(iIndex);
			LoadSynapse(oXml);
		}

		oXml.OutOfElem();
	}
	//*** End Loading Synapses. *****


	oXml.OutOfElem(); //OutOf Neuron Element
}
Cn Analitza::operate(Container* c)
{
	Q_ASSERT(c);
	Operator *op=0;
	Cn ret(0.);
	QList<Cn> numbers;
	
	if(c->containerType() > 100)
		qDebug() << "wow";
	
	if(c->m_params.isEmpty()) {
		m_err << i18n("Empty container: %1").arg(c->containerType());
		return Cn(0.);
	}
	
	if(c->m_params[0]->type() == Object::oper)
		op = (Operator*) c->m_params[0];
	
	if(op!= 0 && op->operatorType()==Object::sum)
		ret = sum(*c);
	else if(op!= 0 && op->operatorType()==Object::product)
		ret = product(*c);
	else switch(c->containerType()) {
		case Object::apply:
		case Object::math:
		case Object::bvar:
		case Object::uplimit:
		case Object::downlimit:
		{
			if(c->m_params[0]->type() == Object::variable) {
				Ci* var= (Ci*) c->m_params[0];
				
				if(var->isFunction())
					ret = func(c);
				else
					ret = calc(c->m_params[0]);
			} else {
				QList<Object*>::iterator it = c->m_params.begin();
				for(; it!=c->m_params.end(); it++) {
					if((*it)==0) {
						m_err << i18n("Null Object found");
						ret.setCorrect(false);
						return ret;
					} else if((*it)->type() != Object::oper) {
						numbers.append(calc(*it));
					}
				}
				
				if(op==0) {
					ret = numbers.first();
				} else if(op->nparams()>-1 && numbers.count()!=op->nparams() && op->operatorType()!=Object::minus) {
					m_err << i18n("Too much operators for <em>%1</em>").arg(op->operatorType());
					ret = Cn(0.);
				} else if(numbers.count()>=1 && op->type()==Object::oper) {
					if(numbers.count()>=2) {
						QList<Cn>::iterator it = numbers.begin();
						ret = *it;
						
						++it;
						for(; it != numbers.end(); ++it)
							reduce(op->operatorType(), &ret, *it, false);
						
					} else {
						ret=numbers.first();
						reduce(op->operatorType(), &ret, 0., true);
					}
				} else {
					ret = numbers.first();
				}
			}
		}
			break;
		case Object::declare:
		{
			if(c->m_params.count()<=1) {
				m_err << i18n("Need a var name and a value");
				return Cn(0.);
			}
			
			Ci *var = (Ci*) c->m_params[0];
			
			switch(c->m_params[1]->type()) {
				case Object::variable:
					m_vars->modify(var->name(), new Ci(c->m_params[1]));
					break;
				case Object::value:
					m_vars->modify(var->name(), new Cn(c->m_params[1]));
					break;
				case Object::oper:
					m_vars->modify(var->name(), new Operator(c->m_params[1]));
					break;
				case Object::container:
					m_vars->modify(var->name(), new Container(c->m_params[1]));
					break;
				case Object::none:
					m_err << i18n("Unvalid var type");
					break;
			}
		} break;
		case Object::lambda:
			ret = calc(c->m_params[c->m_params.count()-1]);
			break;
		case Object::cnone:
			break;
	}
	return ret;
}
Example #23
0
// Calculates the probability density of finding the particle at location r
// at time t.
Real
GreensFunction1DRadAbs::prob_r (Real r, Real t)
const
{
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );
    THROW_UNLESS( std::invalid_argument, (r-sigma) >= 0.0 && r <= a && (r0 - sigma) >= 0.0 && r0<=a );
    
    const Real sigma(this->getsigma());
    const Real a(this->geta());
    const Real L(this->geta()-this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());
    const Real h((this->getk()+this->getv()/2.0)/this->getD());
    
    const Real vexpo(-v*v*t/D/4.0 + v*(r-r0)/D/2.0);

    // if there was no time change or zero diffusivity => no movement
    if (t == 0 || D == 0)
    {
	// the probability density function is a delta function
	if (r == r0)
	{
	    return INFINITY;
	}
	else
	{
	    return 0.0;
	}
    }

    // if r is at the absorbing boundary
    if ( fabs(a-r) < EPSILON*L )
    {
	return 0.0;
    }

    Real root_n, root_n_r_s;
    Real sum = 0, term = 0, prev_term = 0;
    int n=1;

    do
    {
	if ( n >= MAX_TERMS )
	{
	    std::cerr << "Too many terms needed for GF1DRad::prob_r. N: "
	              << n << std::endl;
	    break;
	}

	root_n = this->root_n(n);
	root_n_r_s = root_n*(r-sigma);

	prev_term = term;
	term = Cn(root_n, t) * An(root_n) * (h*sin(root_n_r_s) + root_n*cos(root_n_r_s));
	sum += term;

	n++;
    }
    while (fabs(term/sum) > EPSILON*PDENS_TYPICAL || 
	fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
	n <= MIN_TERMS );

    return 2.0*exp(vexpo)*sum;
}