Exemplo n.º 1
0
// 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;
}
Exemplo n.º 2
0
// Determine which event has occured, an escape or a reaction. Based on the
// fluxes through the boundaries at the given time. Beware: if t is not a
// first passage time you still get an answer!
GreensFunction1DRadAbs::EventKind
GreensFunction1DRadAbs::drawEventType( Real rnd, Real t )
const
{
    THROW_UNLESS( std::invalid_argument, rnd < 1.0 && rnd >= 0.0 );
    THROW_UNLESS( std::invalid_argument, t > 0.0 );
    // if t=0 nothing has happened => no event

    const Real a(this->geta());
    const Real L(this->geta()-this->getsigma());
    const Real r0(this->getr0());

    // if the radiative boundary is impermeable (k==0) or
    // the particle is at the absorbing boundary (at a) => IV_ESCAPE event
    if ( k == 0 || fabs(a-r0) < EPSILON*L )
    {
	return IV_ESCAPE;
    }

    // Else the event is sampled from the flux ratio
    const Real fluxratio (this->fluxRatioRadTot(t));

    if (rnd > fluxratio )
    {
	return IV_ESCAPE;
    }
    else
    {
	return IV_REACTION;
    }
}
Exemplo n.º 3
0
// Determine which event has occured, an escape or a reaction. Based on the
// fluxes through the boundaries at the given time. Beware: if t is not a
// first passage time you still get an answer!
const EventType
FirstPassageGreensFunction1DRad::drawEventType( const Real rnd, const Real t )
const
{
    const Real L(this->getL());
    const Real r0(this->getr0());

    THROW_UNLESS( std::invalid_argument, rnd < 1.0 && rnd >= 0.0 );
    // if t=0 nothing has happened->no event!!
    THROW_UNLESS( std::invalid_argument, t > 0.0 );

    if ( k == 0 || fabs( r0 - L ) < EPSILON*L )
    {
        return ESCAPE;
    }

    const Real fluxratio (this->fluxRatioRadTot(t));

    if (rnd > fluxratio )
    {
        return ESCAPE;
    }
    else
    {
        return REACTION;
    }
}
Exemplo n.º 4
0
int blan_fd_function_enable (struct usbd_function_instance *function_instance)
{
        struct usbd_class_network_channel_descriptor *channel = &blan_class_5 ;
        struct usb_network_private *npd = NULL;
        u32 recv_urb_flags;
#if 0
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
        struct usbd_class_ethernet_networking_descriptor *ethernet = &blan_class_4;
        char address_str[14];
        snprintf(address_str, 13, "%02x%02x%02x%02x%02x%02x",
                        local_dev_addr[0], local_dev_addr[1], local_dev_addr[2],
                        local_dev_addr[3], local_dev_addr[4], local_dev_addr[5]);
#else
        char address_str[20];
        sprintf(address_str, "%02x%02x%02x%02x%02x%02x",
                        local_dev_addr[0], local_dev_addr[1], local_dev_addr[2],
                        local_dev_addr[3], local_dev_addr[4], local_dev_addr[5]);
#endif
        ethernet->iMACAddress = usbd_alloc_string(address_str);
#endif
        struct usbd_class_ethernet_networking_descriptor *ethernet = &blan_class_4;
        char address_str[20];

        sprintf(address_str, "%02x%02x%02x%02x%02x%02x", 0, 0, 0, 0, 0, 0);
        ethernet->iMACAddress = usbd_alloc_string(function_instance, address_str);

        //channel->iName = usbd_alloc_string(function_instance, system_utsname.nodename);

        //TRACE_MSG3(NTT, "name: %s strings index imac: %d name: %d",
        //                system_utsname.nodename, ethernet->iMACAddress, channel->iName);

        #if defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC)
        recv_urb_flags = 0;
        #else /* defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC) */
        recv_urb_flags = USBD_URB_FAST_RETURN | USBD_URB_FAST_FINISH;
        #endif /* defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC) */


        THROW_IF(net_fd_function_enable(function_instance,
                        network_blan, net_fd_recv_urb_mdlm,
                        net_fd_start_xmit_mdlm,
                        blan_start_recv, recv_urb_flags
                        ), error);

        THROW_UNLESS((npd = function_instance->privdata), error);

        #if !defined(CONFIG_OTG_NETWORK_BLAN_CRC) && !defined(CONFIG_OTG_NETWORK_SAFE_CRC)
        THROW_UNLESS((npd->blan_recv_task = otg_task_init2("blanrcv", blan_start_recv_task, function_instance, NTT)), error);
        //npd->blan_recv_task->taskdebug = TRUE;
        otg_task_start(npd->blan_recv_task);
        #endif /* !defined(CONFIG_OTG_NETWORK_BLAN_CRC) && !defined(CONFIG_OTG_NETWORK_SAFE_CRC) */

        return 0;

        CATCH(error) {
                return -EINVAL;
        }
}
Exemplo n.º 5
0
/*! arc_udc_init
 */
static struct arcotg_udc *arc_udc_init (struct otg_dev *otg_dev)
{
        struct device           *device = otg_dev_get_drvdata(otg_dev);
        struct platform_device  *pdev = to_platform_device(device);

        struct fsl_usb2_platform_data *pdata = (struct fsl_usb2_platform_data*)pdev->dev.platform_data;

        struct otg_instance     *otg = otg_dev->otg_instance;
        struct pcd_instance     *pcd = otg_dev->pcd_instance;
        struct arcotg_udc       *udc = NULL;
        int                     timeout;


        /* Setting up the udc structure */
        THROW_UNLESS((udc = (struct arcotg_udc *) CKMALLOC(sizeof(struct arcotg_udc))), error);

        /* Allocate queue */
        THROW_UNLESS((udc->ep_qh = (struct ep_queue_head *) KMALLOC_ALIGN(    USB_MAX_PIPES * sizeof(struct ep_queue_head),
                                        GFP_KERNEL | GFP_DMA, 2 * 1024, (void **)&ep_qh_base)), error);
        THROW_UNLESS(ep_qh_base, error);
        THROW_UNLESS((udc->ep_dtd = (struct ep_td_struct *) CKMALLOC(USB_MAX_PIPES * sizeof(struct ep_td_struct))), error);

        /* Stop, reset and wait for the UDC to reset */
        UOG_USBCMD &= ~USB_CMD_RUN_STOP;
        UOG_USBCMD |= USB_CMD_CTRL_RESET;

        timeout = 10000000;     // XXX This needs to be fixed, should not need to resort to timeout
        while ((UOG_USBCMD & USB_CMD_CTRL_RESET) && --timeout) { continue; }
        if (timeout == 0) {
                printk(KERN_DEBUG "%s: TIMEOUT\n", __FUNCTION__);
                return NULL;
        }

        /* Setup UDC mode and disable lock out mode*/
        UOG_USBMODE |= USB_MODE_CTRL_MODE_DEVICE | USB_MODE_SETUP_LOCK_OFF;

        UOG_EPLISTADDR = virt_to_phys(udc->ep_qh);
        UOG_EPLISTADDR &= USB_EP_LIST_ADDRESS_MASK;

        /* Setup transceiver type, N.B. this must be done in one assignment */
        UOG_PORTSC1 = (UOG_PORTSC1 & ~PORTSCX_PHY_TYPE_SEL) | pdata->xcvr_type;

        #if !defined(CONFIG_OTG_HIGH_SPEED)
        UOG_PORTSC1 |= (0x01000000);
        #endif
	fsl_platform_set_vbus_power(pdata, 0);

        CATCH(error) {
                if (ep_qh_base) kfree(ep_qh_base);
                if (udc) {
                        if (udc->ep_dtd) LKFREE(udc->ep_dtd);
                        LKFREE(udc);
                }
                udc = NULL;
        }
        return udc;
}
Exemplo n.º 6
0
// 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;
}
Exemplo n.º 7
0
// Calculates the probability of finding the particle inside the domain
// at time t, the survival probability.
Real
GreensFunction1DRadAbs::p_survival (Real t) const
{
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );
  
    const Real D(this->getD());
    const Real v(this->getv());
    const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D);

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


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

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

    return 2.0*exp(vexpo)*sum;
}
const Real GreensFunction2DAbs::drawTheta(const Real rnd,
                                          const Real r,
                                          const Real t) const
{
    THROW_UNLESS(std::invalid_argument, 0.0<=rnd && rnd <= 1.0);

    if(rnd == 1e0)
        return 2e0 * M_PI;

    if(fabs(r) < CUTOFF)// r == 0e0 ?
    {
        throw std::invalid_argument(
                (boost::format("2DAbs::drawTheta r is too small: r=%f10") % r).str());
    }

    if(fabs(r-a) < CUTOFF)// r == a ?
    {
        //when R equal a, p_int_theta is zero at any theta
        throw std::invalid_argument(
                (boost::format("2DAbs::drawTheta r is nealy a: r=%f10, a=%f10") % r % a).str());
    }

    if(t == 0e0 || D == 0e0)
        return 0e0;

    Real int_2pi = p_int_2pi(r, t);

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * When t is too large, int_2pi become zero and drawR returns 2pi    *
     * at any value of rnd. To avoid this,  return rnd * theta / 2pi     *
     * because when t -> \infty the probability density function of theta*
     * become uniform distribution                                       *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    if(int_2pi == 0e0)
    {
        std::cout << dump();
        std::cout << "Warning: t is too large. t = " << t << std::endl;
    }

    p_theta_params params = {this, t, r, rnd * int_2pi};

    gsl_function F =
    {
        reinterpret_cast<double (*)(double, void*)>(&p_theta_F), &params
    };

    const Real low(0e0);
    const Real high(2e0 * M_PI);

    const gsl_root_fsolver_type* solverType(gsl_root_fsolver_brent);
    gsl_root_fsolver* solver(gsl_root_fsolver_alloc(solverType));

    const Real theta(findRoot(F, solver, low, high, 1e-18, 1e-12,
                              "GreensFunction2DAbsSym::drawTheta"));

    gsl_root_fsolver_free(solver);

    return theta;
}
const Real GreensFunction2DAbs::drawTime(const Real rnd) const
{
    THROW_UNLESS(std::invalid_argument, 0.0<=rnd && rnd <= 1.0);
    if(D == 0e0 || a == std::numeric_limits<Real>::infinity() || rnd == 1e0)
        return std::numeric_limits<Real>::infinity();
    if(a == r0 || rnd == 0e0)
        return 0e0;

    p_survival_params params = {this, rnd};

    gsl_function F = 
    {
        reinterpret_cast<double (*)(double, void*)>(&p_survival_F), &params
    };

    // this is not so accurate because
    // initial position is not the center of this system.
    const Real t_guess(a * a * 0.25 / D);
    Real value(GSL_FN_EVAL(&F, t_guess));
    Real low(t_guess);
    Real high(t_guess);

    // to determine high and low border
    if(value < 0.0)
    {
        do
        {
            high *= 1e1;
            value = GSL_FN_EVAL(&F, high);
            if(fabs(high) > t_guess * 1e6)
                throw std::invalid_argument("could not adjust higher border");
        }
        while(value <= 0e0);
    }
    else
    {
        Real value_prev = value;
        do
        {
            low *= 1e-1;
            value = GSL_FN_EVAL(&F, low);
            if(fabs(low) <= t_guess * 1e-6 || fabs(value - value_prev) < CUTOFF)
                throw std::invalid_argument("could not adjust lower border");
            value_prev = value;
        }
        while(value >= 0e0);
    }

    //find the root
    const gsl_root_fsolver_type* solverType(gsl_root_fsolver_brent);
    gsl_root_fsolver* solver(gsl_root_fsolver_alloc(solverType));

    const Real t(findRoot(F, solver, low, high, 1e-18, 1e-12,
                          "GreensFunction2DAbs::drawTime"));

    gsl_root_fsolver_free(solver);

    return t;
}
    void setr0(Real r0)
    {
	if ( this->a - this->sigma < 0.0 )
	{
	    // if the domain had zero size
	    THROW_UNLESS( std::invalid_argument,
	                  0.0 <= (r0-sigma) && (r0-sigma) <= EPSILON * l_scale );
	    this->r0 = 0.0;
	}
	else
	{
	    // The normal case
	    THROW_UNLESS( std::invalid_argument,
	                  0.0 <= (r0-sigma) && r0 <= this->a);
	    this->r0 = r0;
	}
    }
Exemplo n.º 11
0
/*! acm_l26_modinit - module init
 *
 * This is called immediately after the module is loaded or during
 * the kernel driver initialization if linked into the kernel.
 *
 */
static int acm_l26_modinit (void)
{
        BOOL tty_l26 = FALSE, tty_if = FALSE;
        int minor_numbers=1;
        /* register tty  and usb interface function drivers
         */
        TTY = otg_trace_obtain_tag();
        THROW_UNLESS(tty_l26 = BOOLEAN(!tty_l26_init(ACM_DRIVER_PROCFS_NAME, ACM_TTY_MINORS)), error);
        THROW_UNLESS(tty_if = BOOLEAN(!tty_if_init()), error);

        CATCH(error) {
                if (tty_l26) tty_l26_exit();
                if (tty_if) tty_if_exit();
                otg_trace_invalidate_tag(TTY);
                return -EINVAL;
        }
        return 0;
}
Exemplo n.º 12
0
/*! mcpc_l26_modinit - module init
 *
 * This is called immediately after the module is loaded or during
 * the kernel driver initialization if linked into the kernel.
 *
 */
STATIC int mcpc_l26_modinit (void)
{
    BOOL tty_l26 = FALSE, dun_if = FALSE, obex_if = FALSE, atcom_if = FALSE;

    TTY = otg_trace_obtain_tag();
    THROW_UNLESS (tty_l26 = BOOLEAN(!tty_l26_init("mcpc_if", 6)), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!dun_if_init()), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!obex_if_init()), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!atcom_if_init()), error);
    CATCH(error) {
        printk(KERN_ERR"%s: ERROR\n", __FUNCTION__);
        if (tty_l26) tty_l26_exit();
        if (dun_if) dun_if_exit();
        if (obex_if) obex_if_exit();
        if (atcom_if) atcom_if_exit();
        otg_trace_invalidate_tag(TTY);
        return -EINVAL;
    }
    return 0;
}
Exemplo n.º 13
0
// Calculates the amount of flux leaving the right boundary at time t
Real
GreensFunction1DAbsAbs::leavea(Real t) const
{
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());

    if ( fabs(r0-sigma) < L*EPSILON || fabs(a-r0) < L*EPSILON || L < 0.0 )
    {
	// The flux of a zero domain is INFINITY. Also if the particle 
	// started on the right boundary (leaking out immediately).
	return INFINITY;
    }
    else if ( t < EPSILON*this->t_scale )
    {
	// if t=0.0 the flux must be zero
	return 0.0;
    }


    Real sum = 0, term = 0, prev_term = 0;
    Real nPI;
    const Real D_L_sq(D/(L*L));
    const Real expo(-D_L_sq*t);		// exponent -D n^2 PI^2 t / l^2
    const Real r0s_L((r0-sigma)/L);
    const Real vexpo(-v*v*t/4.0/D + v*(a-r0)/2.0/D);
    
    Real n=1;
    do
     {
       if (n >= MAX_TERMS )
       {
	 std::cerr << "Too many terms for leaves. N: " << n << std::endl;
	 break;
       }
       
       nPI = n*M_PI;
       prev_term = term;
       term = nPI * exp(nPI*nPI*expo) * cos(nPI) * sin(nPI*r0s_L);
       sum += term;
       n++;
     }
     while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
	    fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
	    n < MIN_TERMS );
     
     return -2.0*D_L_sq * exp(vexpo) * sum;
}
Exemplo n.º 14
0
// This draws an eventtype of time t based on the flux through the left (z=sigma) 
// and right (z=a) boundary. Although not completely accurate, it returns an 
// IV_ESCAPE for an escape through the right boundary and a IV_REACTION for an 
// escape through the left boundary.
GreensFunction1DAbsAbs::EventKind
GreensFunction1DAbsAbs::drawEventType( Real rnd, Real t ) const
{
    THROW_UNLESS( std::invalid_argument, rnd < 1.0 && rnd >= 0.0 );
    THROW_UNLESS( std::invalid_argument, t > 0.0 );
    // if t=0 nothing has happened => no event

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());

    // For particles at the boundaries
    if ( fabs(a-r0) < EPSILON*L )
    {
	// if the particle started on the right boundary
	return IV_ESCAPE;
    }
    else if ( fabs(r0-sigma) < EPSILON*L )
    {
	// if the particle started on the left boundary
	return IV_REACTION;
    }

    const Real leaves_s (this->leaves(t));
    const Real leaves_a (this->leavea(t));
    const Real flux_total (leaves_s + leaves_a);
    const Real fluxratio (leaves_s/flux_total);

    if (rnd > fluxratio )
    {
	return IV_ESCAPE;
    }
    else
    {
	return IV_REACTION;
    }
}
Exemplo n.º 15
0
/* pcd_ocd_modinit - linux module initialization
 *
 * This needs to initialize the ocd, pcd and tcd drivers.  
 *
 * Specifically for each driver:
 *
 * 	obtain tag
 * 	pass ops table address to state machine and get instance address
 * 	call ops.mod_init
 *
 * Note that we automatically provide a default tcd_init if
 * none is set.
 */
static int pcd_ocd_modinit (void)
{
        printk(KERN_INFO"%s\n", __FUNCTION__);

        #if !defined(OTG_C99)
        pcd_global_init();
        #endif /* !defined(OTG_C99) */

        UNLESS(pcd_ops.pcd_init_func) pcd_ops.pcd_init_func = pcd_init_func;
        PCD = otg_trace_obtain_tag();
        THROW_UNLESS(pcd_instance = otg_set_pcd_ops(&pcd_ops), error);
        THROW_IF((pcd_ops.mod_init) ? pcd_ops.mod_init() : 0, error);

        OCD = otg_trace_obtain_tag();
        THROW_UNLESS(ocd_instance = otg_set_ocd_ops(&ocd_ops), error);
        THROW_IF((ocd_ops.mod_init) ? ocd_ops.mod_init() : 0, error);

        CATCH(error) {
                pcd_ocd_modexit();
                return -EINVAL;
        }
        return 0;
}
Exemplo n.º 16
0
/*! otg_task_init
 *@brief Create otg task structure, create workqueue, initialize it.
 *@param name - name of task or workqueue
 *@param proc - handler
 *@param data - parameter pointer for handler
 *@param tag-
 *@return initialized otg_task instance pointer
 */
struct otg_task *otg_task_init2(char *name, otg_task_proc_t proc, otg_task_arg_t data, otg_tag_t tag)
{
        struct otg_task *task;

        //TRACE_STRING(tag, "INIT: %s", name);

        RETURN_NULL_UNLESS((task = CKMALLOC(sizeof (struct otg_task))));

        task->tag = tag;
        task->data = data;
        task->name = name;
        task->proc = proc;

        #if defined(OTG_TASK_WORK)
        task->terminated = task->terminate = TRUE;
        #else /* defined(OTG_TASK_WORK) */
        task->terminated = task->terminate = FALSE;
        #if defined(LINUX26)
        THROW_UNLESS((task->work_queue = create_singlethread_workqueue(name)), error);
        #else /* LINUX26 */
        THROW_UNLESS((task->work_queue = create_workqueue(name)), error);
        #endif /* LINUX26 */
        init_MUTEX_LOCKED(&task->admin_sem);
        init_MUTEX_LOCKED(&task->work_sem);
        #endif /* defined(OTG_TASK_WORK) */

        INIT_WORK(&task->work, otg_task_proc, task);

        return task;

        CATCH(error) {
                printk(KERN_INFO"%s: ERROR\n", __FUNCTION__);
                if (task) LKFREE(task);
                return NULL;
        }
}
Exemplo n.º 17
0
void
SCOCacheMountPoint::scanNamespace(SCOCacheNamespace* nspace)
{
    VERIFY(initialised_);

    const fs::path p(path_ / nspace->getName().str());

    LOG_DEBUG(path_ << ": scanning mountpoint for namespace " <<
              nspace->getName() << "( " << p << ")");

    THROW_UNLESS(hasNamespace(nspace->getName()));

    fs::directory_iterator end;

    for (fs::directory_iterator it(p); it != end; ++it)
    {
       if (!fs::is_regular_file(it->status()))
       {
           LOG_WARN("ignoring non-file entry " << it->path());
           continue;
       }

       const std::string fname(it->path().filename().string());
       if (!SCO::isSCOString(fname))
       {
           LOG_WARN("ignoring non-SCO entry " << it->path());
           continue;
       }

       SCO scoName(fname);

       LOG_DEBUG(path_ << ": found SCO " << fname << " in " << p);

       CachedSCOPtr sco(new CachedSCO(nspace,
                                      scoName,
                                      this,
                                      it->path()));

       scoCache_.insertScannedSCO(sco);
   }

    LOG_DEBUG(path_ << ": namespace " << nspace->getName() << " scanned");
}
    // This also sets the scale
    void seta(Real a)
    {
	THROW_UNLESS( std::invalid_argument, (a-this->sigma) >= 0.0 && this->r0 <= a);

	// Use a typical domain size to determine if we are here 
	// defining a domain of size 0.
	if ( (a-this->sigma) < EPSILON*this->l_scale )
	{
	    // just some random value to show that the domain is zero
	    this->a = -1.0;
	}
	else
	{
	    // set the l_scale to the given one
	    this->l_scale = a-sigma;
	    // set the typical time scale (MSD = sqrt(2*d*D*t) )
	    this->t_scale = (l_scale*l_scale)/this->getD();
	    this->a = a;
	}
    }
Exemplo n.º 19
0
    // This also sets the scale
    void seta(Real a)
    {
	Real L( a - this->sigma );
	
	THROW_UNLESS( std::invalid_argument, L >= 0.0 && (this->r0 - sigma) <= L);

	// Use a typical domain size to determine if we are here
	// defining a domain of size 0.
	if ( L <= EPSILON * l_scale )
	{
	    // just some random value to show that the domain is zero
	    this->a = -INT_MAX;
	}
	else
	{   
	    // set the typical time scale (msd = sqrt(2*d*D*t) )
	    // this is needed by drawTime_f, do not get rid of it!
	    this->t_scale = (L*L)/this->getD();
	    // set a
	    this->a = a;
	}
    }
Exemplo n.º 20
0
void
ClientNG::ping(const std::vector<uint8_t>& out,
               std::vector<uint8_t>& in)
{
    auto b([&](mdsproto::Methods::PingParams::Builder& builder)
           {
               capnp::Data::Reader r(out.data(),
                                     out.size());
               builder.setData(r);
           });

    auto r([&](mdsproto::Methods::PingResults::Reader& reader)
           {
               auto data(reader.getData());
               THROW_UNLESS(data.size() <= in.size());
               memcpy(in.data(),
                      data.begin(),
                      data.size());
           });

    interact_<mdsproto::RequestHeader::Type::Ping>(std::move(b),
                                                   std::move(r));
}
Exemplo n.º 21
0
const Real GreensFunction2DAbs::drawR(const Real rnd, const Real t) const
{
    THROW_UNLESS(std::invalid_argument, 0.0<=rnd && rnd <= 1.0);

    if(a == r0)
        throw std::invalid_argument("a equal r0");

    if(t == 0e0 || D == 0e0)
        return r0;

    if(rnd == 1e0)
        return a;//!?

    Real p_surv(p_survival(t));
    assert(p_surv > 0e0);

    p_r_params params = {this, t, rnd * p_surv};

    gsl_function F =
    {
        reinterpret_cast<double (*)(double, void*)>(&p_r_F), &params
    };

    const Real low(0e0);
    const Real high(a);

    const gsl_root_fsolver_type* solverType(gsl_root_fsolver_brent);
    gsl_root_fsolver* solver(gsl_root_fsolver_alloc(solverType));

    const Real r(findRoot(F, solver, low, high, 1e-18, 1e-12,
                          "GreensFunction2DAbsSym::drawR"));

    gsl_root_fsolver_free(solver);

    return r;
}
const Real 
GreensFunction2DAbsSym::drawTime( const Real rnd ) const
{
  
    THROW_UNLESS( std::invalid_argument, rnd < 1.0 && rnd >= 0.0 );

    const Real a( geta() );

    if( getD() == 0.0 || a == std::numeric_limits<Real>::infinity() )
    {
            return std::numeric_limits<Real>::infinity();
    }
    if( a == 0.0 )
    {
            return 0.0;
    }

    p_survival_params params = { this, rnd };

    gsl_function F = 
    {
            reinterpret_cast<double (*)(double, void*)>( &p_survival_F ), &params 
    };

    //for (Real t=0.0001; t<=1; t+=0.0001)
    //{	std::cout << t << " " << GSL_FN_EVAL( &F, t) << std::endl;
    //}

    // Find a good interval to determine the first passage time in
    const Real t_guess( a * a / ( 4. * D ) );   // construct a guess: msd = sqrt (2*d*D*t)
    Real value( GSL_FN_EVAL( &F, t_guess ) );
    Real low( t_guess );
    Real high( t_guess );

    // scale the interval around the guess such that the function straddles
    if( value < 0.0 )               // if the guess was too low
    {
            do
            {       high *= 10;     // keep increasing the upper boundary until the function straddles
                    value = GSL_FN_EVAL( &F, high );

                    if( fabs( high ) >= t_guess * 1e6 )
                    {
//                            log_.warn("Couldn't adjust high. F(%.16g) = %.16g", high, value);
                            throw std::exception();
                    }
            }
            while ( value <= 0.0 );
    }
    else                            // if the guess was too high
    {
            Real value_prev( value );
            do
            {       low *= .1;      // keep decreasing the lower boundary until the function straddles
                    value = GSL_FN_EVAL( &F, low );     // get the accompanying value

                    if( fabs( low ) <= t_guess * 1e-6 || fabs( value - value_prev ) < CUTOFF )
                    {
//                            log_.warn("Couldn't adjust high. F(%.16g) = %.16g", low, value);
                            return low;
                    }
                    value_prev = value;
            }
            while ( value >= 0.0 );
    }

    // find the root
    const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );  // a new solver type brent
    gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );   // make a new solver instance
    const Real t( findRoot( F, solver, low, high, 1e-18, 1e-12,
                        "GreensFunction2DAbsSym::drawTime" ) );
    gsl_root_fsolver_free( solver );

    return t;
}
Exemplo n.º 23
0
 void seta( const Real a )
 {
     THROW_UNLESS( std::invalid_argument, a >= 0.0 );
     this->a = a;
 }
Exemplo n.º 24
0
// Draws the position of the particle at a given time from p(r,t), assuming 
// that the particle is still in the domain
Real
GreensFunction1DAbsAbs::drawR (Real rnd, Real t) const
{
    THROW_UNLESS( std::invalid_argument, 0.0 <= rnd && rnd < 1.0 );
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());

    // the trivial case: if there was no movement or the domain was zero
    if ( (D==0.0 && v==0.0) || L<0.0 || t==0.0)
    {
	return r0;
    }
    else
    {
	// if the initial condition is at the boundary, raise an error
	// The particle can only be at the boundary in the ABOVE cases
	THROW_UNLESS( std::invalid_argument,
	              (r0-sigma) >= L*EPSILON && (r0-sigma) <= L*(1.0-EPSILON) );
    }
    // else the normal case
    // From here on the problem is well defined


    // structure to store the numbers to calculate numbers for 1-S(t)
    struct drawR_params parameters;
    Real S_Cn_An;
    Real nPI;
    const Real expo (-D*t/(L*L));
    const Real r0s_L((r0-sigma)/L);
    const Real v2D(v/2.0/D);
    const Real Lv2D(L*v/2.0/D);
    const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D);	// exponent of the drift-prefactor, same as in survival prob.
    const Real S = 2.0*exp(vexpo)/p_survival(t);	// This is a prefactor to every term, so it also contains there
							// exponential drift-prefactor.

    // Construct the coefficients and the terms in the exponent and put them 
    // in the params structure
    int n=0;
    do
    {
	nPI = ((Real)(n+1))*M_PI;	    // note: summation starting with n=1, indexing with n=0, therefore we need n+1 here
	
	if(v==0.0)	S_Cn_An = S * exp(nPI*nPI*expo) * sin(nPI*r0s_L) / nPI;
	else		S_Cn_An = S * exp(nPI*nPI*expo) * sin(nPI*r0s_L) * nPI/(nPI*nPI + Lv2D*Lv2D);
	  // The rest is the z-dependent part, which has to be defined directly in drawR_f(z).
	  // Of course also the summation happens there because the terms now are z-dependent.
	  // The last term originates from the integrated prob. density including drift.
	  //
	  // In case of zero drift this expression becomes: 2.0/p_survival(t) * exp(nPI*nPI*expo) * sin(nPI*r0s_L) / nPI
	  
	// also store the values for the exponent, so they don't have to be recalculated in drawR_f
	parameters.S_Cn_An[n]= S_Cn_An;
	parameters.n_L[n]    = nPI/L;
	n++;
    }
    while (n<MAX_TERMS);

    // store the random number for the probability
    parameters.rnd = rnd ;
    // store the number of terms used
    parameters.terms = MAX_TERMS;
    
    // store needed constants
    parameters.H[0] = sigma;
    parameters.H[1] = v2D;

    // find the intersection on the y-axis between the random number and 
    // the function
    gsl_function F;
    F.function = &drawR_f;
    F.params = &parameters;

    // define a new solver type brent
    const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
    // make a new solver instance
    // TODO: incl typecast?
    gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );
    const Real r( findRoot( F, solver, sigma, a, L*EPSILON, EPSILON,
                            "GreensFunction1DAbsAbs::drawR" ) );

    // return the drawn time
    return r;
}
const Real 
GreensFunction2DAbsSym::drawR( const Real rnd, const Real t ) const 
{
  
    THROW_UNLESS( std::invalid_argument, rnd <= 1.0 && rnd >= 0.0 );
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    const Real a( geta() );
    const Real D( getD() );

    if( a == 0.0 || t == 0.0 || D == 0.0 )
    {
        return 0.0;
    }

    //const Real thresholdDistance( this->CUTOFF_H * sqrt( 4.0 * D * t ) );

    gsl_function F;
    Real psurv;

//  if( a <= thresholdDistance )	// if the domain is not so big, the boundaries are felt
//  {
        psurv = p_survival( t );
        //psurv = p_int_r( a, t );
        //printf("dr %g %g\n",psurv, p_survival( t ));
        //assert( fabs(psurv - p_int_r( a, t )) < psurv * 1e-8 );

        assert( psurv > 0.0 );

        F.function = reinterpret_cast<double (*)(double, void*)>( &p_r_F );
/*  }
    else				// if the domain is very big, just use the free solution
    {
        // p_int_r < p_int_r_free
        if( p_int_r_free( a, t ) < rnd )	// if the particle is outside the domain?
        {
            std::cerr << "p_int_r_free( a, t ) < rnd, returning a." 
                      << std::endl;
            return a;
        }

        psurv = 1.0;
        F.function = reinterpret_cast<double (*)(double, void*)>( &p_r_free_F );
    }
*/
    const Real target( psurv * rnd );
    p_r_params params = { this, t, target };

    F.params = &params;


    const Real low( 0.0 );
    const Real high( a );
    //const Real high( std::min( thresholdDistance, a ) );

    const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
    gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );

    const Real r( findRoot( F, solver, low, high, 1e-18, 1e-12,
                            "GreensFunction2DAbsSym::drawR" ) );
  
    gsl_root_fsolver_free( solver );

    return r;
}
Exemplo n.º 26
0
// Draws the first passage time from the propensity function.
// Uses the help routine drawT_f and structure drawT_params for some technical
// reasons related to the way to input a function and parameters required by
// the GSL library.
Real
GreensFunction1DAbsAbs::drawTime (Real rnd) const
{
    THROW_UNLESS( std::invalid_argument, 0.0 <= rnd && rnd < 1.0 );

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());
    
    if (D == 0.0 )
    {
	return INFINITY;
    }
    else if ( L < 0.0 || fabs(a-r0) < EPSILON*L || fabs(r0-sigma) > (1.0 - EPSILON)*L )
    {
	// if the domain had zero size
	return 0.0;
    }

    const Real expo(-D/(L*L));
    const Real r0s_L((r0-sigma)/L);
    // some abbreviations for terms appearing in the sums with drift<>0
    const Real sigmav2D(sigma*v/2.0/D);
    const Real av2D(a*v/2.0/D);
    const Real Lv2D(L*v/2.0/D);
    // exponent of the prefactor present in case of v<>0; has to be split because it has a t-dep. and t-indep. part
    const Real vexpo_t(-v*v/4.0/D);
    const Real vexpo_pref(-v*r0/2.0/D);

    // the structure to store the numbers to calculate the numbers for 1-S
    struct drawT_params parameters;
    Real Xn, exponent, prefactor;
    
    Real nPI;
    
    // Construct the coefficients and the terms in the exponent and put them 
    // into the params structure
    int n = 0;
    // a simpler sum has to be computed for the case w/o drift, so distinguish here
    if(v==0)
    {
      do
      {
	  nPI = ((Real)(n+1))*M_PI;	// why n+1 : this loop starts at n=0 (1st index of the arrays), while the sum starts at n=1 !
	  Xn = sin(nPI*r0s_L) * (1.0 - cos(nPI)) / nPI; 
	  exponent = nPI*nPI*expo;
	  
	  // store the coefficients in the structure
	  parameters.Xn[n] = Xn;	
	  // also store the values for the exponent
	  parameters.exponent[n]=exponent;
	  n++;
      }
      // TODO: Modify this later to include a cutoff when changes are small
      while (n<MAX_TERMS);
    }
    else	// case with drift<>0
    {
     do
      {
	  nPI = ((Real)(n+1))*M_PI;	// why n+1 : this loop starts at n=0 (1st index of the arrays), while the sum starts at n=1 !
	  Xn = (exp(sigmav2D) - cos(nPI)*exp(av2D)) * nPI/(Lv2D*Lv2D+nPI*nPI) * sin(nPI*r0s_L);
	  exponent = nPI*nPI*expo + vexpo_t;
	  
	  // store the coefficients in the structure
	  parameters.Xn[n] = Xn;	
	  // also store the values for the exponent
	  parameters.exponent[n]=exponent;
	  n++;
      }
       // TODO: Modify this later to include a cutoff when changes are small
      while (n<MAX_TERMS);
    }

    // the prefactor of the sum is also different in case of drift<>0 :
    if(v==0)	prefactor = 2.0*exp(vexpo_pref);
    else	prefactor = 2.0;
    parameters.prefactor = prefactor;
    
    parameters.rnd = rnd;
    parameters.terms = MAX_TERMS;
    parameters.tscale = this->t_scale;

    gsl_function F;
    F.function = &drawT_f;
    F.params = &parameters;

    // Find a good interval to determine the first passage time in
    const Real dist( std::min(r0-sigma, a-r0) );

    // construct a guess: MSD = sqrt (2*d*D*t)
    Real t_guess( dist * dist / ( 2.0 * D ) );
    // A different guess has to be made in case of nonzero drift to account for the displacement due to it
    // When drifting towards the closest boundary...
    if( ( r0-sigma >= L/2.0 && v > 0.0 ) || ( r0-sigma <= L/2.0 && v < 0.0 ) )	t_guess = sqrt(D*D/(v*v*v*v)+dist*dist/(v*v)) - D/(v*v);
    // When drifting away from the closest boundary...
    if( ( r0-sigma  < L/2.0 && v > 0.0 ) || ( r0-sigma  > L/2.0 && v < 0.0 ) )	t_guess = D/(v*v) - sqrt(D*D/(v*v*v*v)-dist*dist/(v*v));
    
    
    Real value( GSL_FN_EVAL( &F, t_guess ) );
    Real low( t_guess );
    Real high( t_guess );

    if( value < 0.0 )
    {
	// scale the interval around the guess such that the function 
	// straddles if the guess was too low
	do
	{
	    // keep increasing the upper boundary until the 
	    // function straddles
	    high *= 10.0;
	    value = GSL_FN_EVAL( &F, high );

	    if( fabs( high ) >= t_guess * 1e6 )
	    {
		std::cerr << "Couldn't adjust high. F(" << high << ") = "
		          << value << std::endl;
		throw std::exception();
	    }
	}
	while ( value <= 0.0 );
    }
    else
    {
	// if the guess was too high initialize with 2 so the test 
	// below survives the first iteration
	Real value_prev( 2.0 );
	do
	{
	    if( fabs( low ) <= t_guess * 1.0e-6 ||
	        fabs(value-value_prev) < EPSILON*this->t_scale )
	    {
		std::cerr << "Couldn't adjust low. F(" << low << ") = "
		          << value << " t_guess: " << t_guess << " diff: "
		          << (value - value_prev) << " value: " << value
		          << " value_prev: " << value_prev << " t_scale: "
		          << this->t_scale << std::endl;
		return low;
	    }

	    value_prev = value;
	    // keep decreasing the lower boundary until the 
	    // function straddles
	    low *= 0.1;
	    // get the accompanying value
	    value = GSL_FN_EVAL( &F, low );

	}
	while ( value >= 0.0 );
    }

    // find the intersection on the y-axis between the random number and 
    // the function
    // define a new solver type brent
    const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
    // make a new solver instance
    // TODO: incl typecast?
    gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );
    const Real t( findRoot( F, solver, low, high, EPSILON*t_scale, EPSILON,
                            "GreensFunction1DAbsAbs::drawTime" ) );

    // return the drawn time
    return t;
}
Exemplo n.º 27
0
/*! net_fd_recv_urb_ecm
 * @brief - callback to process a received URB
 *
 * @param urb - received urb
 * @param rc dummy
 * @return non-zero for failure.
 */
int net_fd_recv_urb_ecm(struct usbd_urb *urb, int rc)
{
        struct usbd_function_instance *function_instance = urb->function_instance;
        struct usb_network_private *npd = function_instance->privdata;
        void *os_data = NULL;
        u8 *os_buffer, *net_frame;
        int crc_bad = 0;
        int trim = 0;
        int len;
        u32 crc;
        #ifndef CONFIG_OTG_NETWORK_DOUBLE_OUT
        int endpoint_index = BULK_OUT_A;
        #else /* CONFIG_OTG_NETWORK_DOUBLE_OUT */
        int endpoint_index = BULK_OUT_A;
        #endif /* CONFIG_OTG_NETWORK_DOUBLE_OUT */
        int out_pkt_sz = usbd_endpoint_wMaxPacketSize(function_instance, endpoint_index, usbd_high_speed(function_instance));
        len = urb->actual_length;
        trim = 0;

        TRACE_MSG2(NTT, "status: %d actual_length: %d", urb->status, urb->actual_length);
        //RETURN_EINVAL_IF (urb->status == USBD_URB_OK);

        THROW_UNLESS((os_data = net_os_alloc_buffer(function_instance, &os_buffer, len)), error);
        net_frame = os_buffer;

        //TRACE_MSG2(NTT, "os_data: %x os_buffer: %x", os_data, os_buffer);


        /*
         * The CRC can be sent in two ways when the size of the transfer
         * ends up being a multiple of the packetsize:
         *
         *                                           |
         *                <data> <CRC><CRC><CRC><CRC>|<???>     case 1
         *                <data> <NUL><CRC><CRC><CRC>|<CRC>     case 2
         *           <data> <NUL><CRC><CRC><CRC><CRC>|          case 3
         *     <data> <NUL><CRC><CRC><CRC>|<CRC>     |          case 4
         *                                           |
         *
         * This complicates CRC checking, there are four scenarios:
         *
         *      1. length is 1 more than multiple of packetsize with a trailing byte
         *      2. length is 1 more than multiple of packetsize
         *      3. length is multiple of packetsize
         *      4. none of the above
         *
         * Finally, even though we always compute CRC, we do not actually throw
         * things away until and unless we have previously seen a good CRC.
         * This allows backwards compatibility with hosts that do not support
         * adding a CRC to the frame.
         *
         */

        // test if 1 more than packetsize multiple
        if (1 == (len % out_pkt_sz)) {
		#if defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC)
                // copy and CRC up to the packetsize boundary
                crc = crc32_copy(os_buffer, urb->buffer, len - 1, CRC32_INIT);
                os_buffer += len - 1;

                // if the CRC is good then this is case 1
                if (CRC32_GOOD != crc) {

                        crc = crc32_copy(os_buffer, urb->buffer + len - 1, 1, crc);
                        os_buffer += 1;

                        if (CRC32_GOOD != crc) {
                                //crc_errors[len%64]++;
                                TRACE_MSG2(NTT,"A CRC error %08x %03x", crc, urb->framenum);
                                THROW_IF(npd->seen_crc, crc_error);
                        }
                        else
                                npd->seen_crc = 1;
                }
                else
                        npd->seen_crc = 1;

		#endif /* defined(CONFIG_OTG_NETWORK_BLAN_CRC) ...*/
        }
        else {

		#if defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC)
                crc = crc32_copy(os_buffer, urb->buffer, len, CRC32_INIT);
                os_buffer += len;

                if (CRC32_GOOD != crc) {
                        //crc_errors[len%64]++;
                        TRACE_MSG2(NTT,"B CRC error %08x %03x", crc, urb->framenum);
                        THROW_IF(npd->seen_crc, crc_error);
                }
                else
                        npd->seen_crc = 1;
		#else /* !defined(CONFIG_OTG_NETWORK_BLAN_CRC) ...*/
                memcpy (os_buffer, urb->buffer, len);
		#endif /* !defined(CONFIG_OTG_NETWORK_BLAN_CRC) ...*/
        }
        // trim IFF we are paying attention to crc
        #if defined(CONFIG_OTG_NETWORK_BLAN_CRC) || defined(CONFIG_OTG_NETWORK_SAFE_CRC)
        if (npd->seen_crc)
                trim = 4;
        #endif /* defined(CONFIG_OTG_NETWORK_BLAN_CRC) ...*/


        if (net_fd_recv_buffer(function_instance, net_frame, len, os_data, crc_bad, trim)) {
                TRACE_MSG0(NTT, "FAILED");
                net_os_dealloc_buffer(function_instance, os_data, os_buffer);
        }

        // catch a simple error, just increment missed error and general error
        CATCH(error) {
                //TRACE_MSG4(NTT,"CATCH(error) urb: %p status: %d len: %d function: %p",
                //                urb, urb->status, urb->actual_length, function_instance);
                // catch a CRC error
                CATCH(crc_error) {
                        crc_bad = 1;
                }
        }
        return 0;
        //return usbd_start_out_urb (urb);
}
Exemplo n.º 28
0
// Calculates the probability of finding the particle inside the domain at 
// time t
Real
GreensFunction1DAbsAbs::p_survival (Real t) const
{
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());

    if ( fabs(r0-sigma) < L*EPSILON || fabs(a-r0) < L*EPSILON || L < 0.0 )
    {
	// The survival probability of a zero domain is zero
	return 0.0;
    }

    // Set values that are constant in this calculation
    const Real expo(-D*t/(L*L));   // part of the exponent -D n^2 PI^2 t / L^2
    const Real r0s(r0 - sigma);
    const Real r0s_L(r0s/L);
    
    // some abbreviations for terms appearing in the sums with drift<>0
    const Real sigmav2D(sigma*v/2.0/D);
    const Real av2D(a*v/2.0/D);
    const Real Lv2D(L*v/2.0/D);
    const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D);	// exponent of the drift-prefactor
    

    // Initialize summation
    Real sum = 0, term = 0, prev_term = 0;
    Real nPI;


    // Sum
    Real n=1;
    // different calculations depending on whether v=0 or not
    if(v==0.0)	// case without drift (v==0); in this case the summation is simpler, so do the complicated caluclation only if necessary
    {
      do
      {
	  if (n >= MAX_TERMS )
	  {
	      std::cerr << "Too many terms for p_survival. N: " << n << std::endl;
	      break;
	  }
	  
	  prev_term = term;
	  nPI = (double)n*M_PI;
	  term = exp(nPI*nPI*expo) * sin(nPI*r0s_L) * (1.0 - cos(nPI)) / nPI;
	  sum += term;
	  n++;
      }
      // Is 1 a good measure or will this fail at some point?
      while (	fabs(term/sum) > EPSILON*1.0 ||
		fabs(prev_term/sum) > EPSILON*1.0 ||
		n < MIN_TERMS );

      sum = 2.0*sum;	// This is a prefactor of every term, so do only one multiplication here
    }
    else	// case with drift (v<>0)
    {
      do
      {
	  if (n >= MAX_TERMS )
	  {
	      std::cerr << "Too many terms for p_survival. N: " << n << std::endl;
	      break;
	  }
	  
	  nPI = (double)n*M_PI;
	  prev_term = term;
	  term = exp(nPI*nPI*expo) * (exp(sigmav2D) - cos(nPI)*exp(av2D)) * nPI/(Lv2D*Lv2D+nPI*nPI) * sin(nPI*r0s_L);
	  sum += term;
	  n++;
      }
      // TODO: Is 1 a good measure or will this fail at some point?
      while (	fabs(term/sum) > EPSILON*1.0 ||
		fabs(prev_term/sum) > EPSILON*1.0 ||
		n < MIN_TERMS );
      
      sum = 2.0*exp(vexpo) * sum;	// prefactor containing the drift

    }

    return sum;
}
Exemplo n.º 29
0
/*!
 * generic_cf_register()
 *
 */
void generic_cf_register(struct generic_config *config, char *match)
{
        char *cp, *sp, *lp;
        int i;
        char **interface_list = NULL; 
        int interfaces = 0;

        //printk(KERN_INFO"%s: Driver: \"%s\" idVendor: %04x idProduct: %04x interface_names: \"%s\" match: \"%s\"\n", 
        //                __FUNCTION__,
        //                config->composite_driver.driver.name, MODPARM(idVendor), MODPARM(idProduct), config->interface_names, 
        //                match ? match : "");

        TRACE_MSG5(GENERIC, "Driver: \"%s\" idVendor: %04x idProduct: %04x interface_names: \"%s\" match: \"%s\"",
                        config->composite_driver.driver.name, MODPARM(idVendor), MODPARM(idProduct), config->interface_names, 
                        match ? match : "");


        RETURN_IF (match && strlen(match) && strcmp(match, config->composite_driver.driver.name));

        //printk(KERN_INFO"%s: MATCHED\n", __FUNCTION__); 

        /* decompose interface names to construct interface_list 
         */
        RETURN_UNLESS (config->interface_names && strlen(config->interface_names));

        /* count interface names and allocate _interface_names array
         */
        for (cp = sp = config->interface_names, interfaces = 0; cp && *cp; ) {
                for (; *cp && *cp == ':'; cp++);        // skip white space
                sp = cp;                                // save start of token
                for (; *cp && *cp != ':'; cp++);        // find end of token
                BREAK_IF (sp == cp);
                if (*cp) cp++;
                interfaces++;
        }

        THROW_UNLESS(interfaces, error);

        TRACE_MSG1(GENERIC, "interfaces: %d", interfaces);

        THROW_UNLESS((interface_list = (char **) CKMALLOC (sizeof (char *) * (interfaces + 1), GFP_KERNEL)), error);

        for (cp = sp = config->interface_names, interfaces = 0; cp && *cp; interfaces++) {
                for (; *cp && *cp == ':'; cp++);        // skip white space
                sp = cp;                                // save start of token
                for (; *cp && *cp != ':'; cp++);        // find end of token
                BREAK_IF (sp == cp);
                lp = cp;
                if (*cp) cp++;
                *lp = '\0';
                lp = CKMALLOC(strlen(sp), GFP_KERNEL);
                strcpy(lp, sp);
                interface_list[interfaces] = lp;

                TRACE_MSG3(GENERIC, "INTERFACE[%2d] %x \"%s\"", 
                                interfaces, interface_list[interfaces], interface_list[interfaces]);
        }

        config->composite_driver.device_description = &config->device_description;
        config->composite_driver.configuration_description = &config->configuration_description;
        config->composite_driver.driver.fops = &generic_function_ops;
        config->interface_list = interface_list;

        THROW_IF (usbd_register_composite_function (
                                &config->composite_driver,
                                config->composite_driver.driver.name,
                                config->class_name,
                                config->interface_list, NULL), error);

        config->registered++;

	TRACE_MSG0(GENERIC, "REGISTER FINISHED");

        CATCH(error) {
                otg_trace_invalidate_tag(GENERIC);
        }

}
Exemplo n.º 30
0
// Calculates the probability density of finding the particle at location r at 
// time t.
Real
GreensFunction1DAbsAbs::prob_r (Real r, Real t) const
{
    THROW_UNLESS( std::invalid_argument, 0.0 <= (r-sigma) && r <= a );
    THROW_UNLESS( std::invalid_argument, t >= 0.0 );

    const Real a(this->geta());
    const Real sigma(this->getsigma());
    const Real L(this->geta() - this->getsigma());
    const Real r0(this->getr0());
    const Real D(this->getD());
    const Real v(this->getv());

    // if there was no time change or no 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;
	}
    }
    else if ( fabs(r-sigma) < L*EPSILON || fabs(a-r) < L*EPSILON || L < 0.0 )
    {
	return 0.0;
    }

    // Set values that are constant in this calculation
    const Real expo(-D*t/(L*L));
    const Real rs_L((r-sigma)/L);
    const Real r0s_L((r0-sigma)/L);
    const Real vexpo(-v*v*t/4.0/D + v*(r-r0)/2.0/D);	// exponent of the drift-prefactor

    // Initialize summation
    Real nPI;
    Real sum = 0, term = 0, prev_term = 0;

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

	prev_term = term;

	nPI = n*M_PI;
	term = exp(nPI*nPI*expo) * sin(nPI*r0s_L) * sin(nPI*rs_L);
	sum += term;
	n++;
    }
    while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
	fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
	n <= MIN_TERMS);

    return 2.0/L * exp(vexpo) * sum;
}