Exemple #1
0
static PetscErrorCode IJacobian(TS ts,PetscReal t,Vec U,Vec Udot,PetscReal a,Mat A,Mat B,AppCtx *ctx)
{
  PetscErrorCode ierr;
  PetscInt       rowcol[] = {0,1,2,3};
  PetscScalar    *u,*udot,J[4][4];

  PetscFunctionBegin;
  ierr    = VecGetArray(U,&u);CHKERRQ(ierr);
  ierr    = VecGetArray(Udot,&udot);CHKERRQ(ierr);
  J[0][0] = a + ctx->k2;   J[0][1] = 0.0;                J[0][2] = -k1(ctx,t);       J[0][3] = 0.0;
  J[1][0] = 0.0;           J[1][1] = a + ctx->k3*u[3];   J[1][2] = -k1(ctx,t);       J[1][3] = ctx->k3*u[1];
  J[2][0] = 0.0;           J[2][1] = -ctx->k3*u[3];      J[2][2] = a + k1(ctx,t);    J[2][3] =  -ctx->k3*u[1];
  J[3][0] =  -ctx->k2;     J[3][1] = ctx->k3*u[3];       J[3][2] = 0.0;              J[3][3] = a + ctx->k3*u[1];
  ierr    = MatSetValues(B,4,rowcol,4,rowcol,&J[0][0],INSERT_VALUES);CHKERRQ(ierr);
  ierr    = VecRestoreArray(U,&u);CHKERRQ(ierr);
  ierr    = VecRestoreArray(Udot,&udot);CHKERRQ(ierr);

  ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  if (A != B) {
    ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
    ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}
Exemple #2
0
//-----------------------------------------------------------------------------
// github issue #388
BOOST_AUTO_TEST_CASE_TEMPLATE(
    waitForEventThatAlreadyFinishedShouldBeSkipped,
    TDevStream,
    TestStreams)
{
    using Fixture = alpaka::test::stream::StreamTestFixture<TDevStream>;
    using Stream = typename Fixture::Stream;
    using Dev = typename Fixture::Dev;

    if(!alpaka::test::stream::IsSyncStream<Stream>::value)
    {
        Fixture f1;
        Fixture f2;
        auto s1 = f1.m_stream;
        auto s2 = f2.m_stream;
        alpaka::test::event::EventHostManualTrigger<Dev> k1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k2(f2.m_dev);
        alpaka::event::Event<Stream> e1(f1.m_dev);

        // 1. kernel k1 is enqueued into stream s1
        // s1 = [k1]
        alpaka::stream::enqueue(s1, k1);
        // 2. kernel k2 is enqueued into stream s2
        // s2 = [k2]
        alpaka::stream::enqueue(s2, k2);

        // 3. event e1 is enqueued into stream s1
        // s1 = [k1, e1]
        alpaka::stream::enqueue(s1, e1);

        // 4. s2 waits for e1
        // s2 = [k2, ->e1]
        alpaka::wait::wait(s2, e1);

        // 5. kernel k1 finishes
        // s1 = [e1]
        k1.trigger();

        // 6. e1 is finished
        // s1 = []
        alpaka::wait::wait(e1);
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(e1));

        // 7. e1 is re-enqueued again but this time into s2
        // s2 = [k2, ->e1, e1]
        alpaka::stream::enqueue(s2, e1);

        // 8. kernel k2 finishes
        // s2 = [->e1, e1]
        k2.trigger();

        // 9. e1 had already been signaled so there should not be waited even though the event is now reused within s2 and its current state is 'unfinished' again.
        // s2 = [e1]

        // Both streams should successfully finish
        alpaka::wait::wait(s1);
        // s2 = []
        alpaka::wait::wait(s2);
    }
}
Exemple #3
0
void RK4_step(                          // replaces x(t) by x(t + dt)
    Matrix<double,1>& x,                // solution vector
    double dt,                          // fixed time step
    Matrix<double,1> flow(Matrix<double,1>&))   // derivative vector
{
    int n = x.size();
    Matrix<double,1> f(n), k1(n), k2(n), k3(n), k4(n), x_temp(n);
    f = flow(x);
    for (int i = 0; i < n; i++) {
        k1[i] = dt * f[i];
        x_temp[i] = x[i] + k1[i] / 2;
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++) {
        k2[i] = dt * f[i];
        x_temp[i] = x[i] + k2[i] / 2;
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++) {
        k3[i] = dt * f[i];
        x_temp[i] = x[i] + k3[i];
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++)
        k4[i] = dt * f[i];
    for (int i = 0; i < n; i++)
        x[i] += (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) / 6;
}
Exemple #4
0
 TEST(KeyBtreeTest, put_overwrite)
 {
   KeyBtree<KeyInfo, int> btr(sizeof(KeyInfo));
   KeyInfo k1(10, 1);
   KeyInfo k2(10, 2);
   KeyInfo key(1, 1);
   int value, old_value;
   EXPECT_EQ(btr.put(k1, 100), ERROR_CODE_OK);
   EXPECT_EQ(btr.put(k2, 101, true), ERROR_CODE_OK);
   {
     BtreeReadHandle handle;
     btr.get_read_handle(handle);
     btr.set_key_range(handle, btr.get_min_key(), 0, btr.get_max_key(), 0);
     EXPECT_EQ(btr.get_next(handle, key, value), ERROR_CODE_OK);
     EXPECT_EQ(value, 101);
     EXPECT_EQ(key.b_, 1);
   }
   // overwrite key
   EXPECT_EQ(btr.put(k2, 102, old_value, true, true), ERROR_CODE_OK);
   {
     BtreeReadHandle handle;
     btr.get_read_handle(handle);
     btr.set_key_range(handle, btr.get_min_key(), 0, btr.get_max_key(), 0);
     EXPECT_EQ(btr.get_next(handle, key, value), ERROR_CODE_OK);
     EXPECT_EQ(old_value, 101);
     EXPECT_EQ(value, 102);
     EXPECT_EQ(key.b_, 2);
   }
 }
Exemple #5
0
TPZCompMesh * ComputationalMesh(TPZGeoMesh * gmesh, int p)
{
    int matid = 1;
    int dim = 2;
    REAL wavespeed = 1.0;

    ///Computational Mesh
    TPZCompEl::SetgOrder(p);
    TPZCompMesh * cmesh = new TPZCompMesh(gmesh);
    cmesh->SetDimModel(dim);    
    cmesh->SetAllCreateFunctionsContinuous();
    
    TPZMaterial * Air = new TPZLinearWave(matid,dim);
    cmesh->InsertMaterialObject(Air);
    
    {
        //Boundary Conditions
        TPZFMatrix<STATE> k1(dim,dim,0.), k2(dim,dim,0.);
        TPZMaterial * BCD = Air->CreateBC(Air, 2, 0, k1, k2);
        cmesh->InsertMaterialObject(BCD);
        
        TPZMaterial * BCN = Air->CreateBC(Air, 3, 1, k1, k2);
        cmesh->InsertMaterialObject(BCN);
    }   
        
    cmesh->AutoBuild();
    cmesh->AdjustBoundaryElements();
    cmesh->CleanUpUnconnectedNodes();    
    
    return cmesh;
}
bool
GenericSchedulerThread::startTask(const ThreadStartArgsPtr& inArgs)
{
    {
        QMutexLocker quitLocker(&_imp->mustQuitMutex);
        if (!_imp->startingThreadAllowed || _imp->mustQuit) {
            return false;
        }
    }

    {
        QMutexLocker k1(&_imp->enqueuedTasksMutex);
        QMutexLocker k2(&_imp->abortRequestedMutex);
#ifdef TRACE_GENERIC_SCHEDULER_THREAD
        qDebug() << QThread::currentThread() << ": Requesting task on" <<  getThreadName().c_str() << ", is thread aborted?" << (bool)(_imp->abortRequested > 0);
#endif
        if (_imp->abortRequested > 0) {
            _imp->queuedTaskWhileProcessingAbort.push_back(inArgs);
        } else {
            _imp->enqueuedTasks.push_back(inArgs);
        }
    }

    if ( !isRunning() ) {
        start();
    } else {
        ///Wake up the thread with a start request
        QMutexLocker locker(&_imp->startRequestsMutex);
        ++_imp->startRequests;

        _imp->startRequestsCond.wakeOne();
    }

    return true;
}
Exemple #7
0
/**
 * returns the modified spherical Bessel function of the second kind needed
 * for bound states.
 \param l = order of the function (orbital angular momentum)
 \param rho = independent variable (rho = k * r)
 */
double sphericalB::k(int l, double rho)
{
  switch (l)
    {
    case 0:
      return k0(rho);
    case 1:
      return k1(rho);
    case 2: 
      return k2(rho);
    case 3: 
      return k3(rho);
    case 4:
      return k4(rho);
    case 5:
      return k5(rho);
    case 6:
      return k6(rho);
    case 7:
      return k7(rho);
    default:
      cout << "no l>6 programed in sphericalB" << endl;
      return 0.;
    }
}
Exemple #8
0
static bool ocl_integral( InputArray _src, OutputArray _sum, int sdepth )
{
    if ( _src.type() != CV_8UC1 || _src.step() % vlen != 0 || _src.offset() % vlen != 0  ||
         !(sdepth == CV_32S || sdepth == CV_32F) )
        return false;

    ocl::Kernel k1("integral_sum_cols", ocl::imgproc::integral_sum_oclsrc,
                   format("-D sdepth=%d", sdepth));
    if (k1.empty())
        return false;

    Size size = _src.size(), t_size = Size(((size.height + vlen - 1) / vlen) * vlen, size.width),
            ssize(size.width + 1, size.height + 1);
    _sum.create(ssize, sdepth);
    UMat src = _src.getUMat(), t_sum(t_size, sdepth), sum = _sum.getUMat();
    t_sum = t_sum(Range::all(), Range(0, size.height));

    int offset = (int)src.offset / vlen, pre_invalid = (int)src.offset % vlen;
    int vcols = (pre_invalid + src.cols + vlen - 1) / vlen;
    int sum_offset = (int)sum.offset / vlen;

    k1.args(ocl::KernelArg::PtrReadOnly(src), ocl::KernelArg::PtrWriteOnly(t_sum),
            offset, pre_invalid, src.rows, src.cols, (int)src.step, (int)t_sum.step);
    size_t gt = ((vcols + 1) / 2) * 256, lt = 256;
    if (!k1.run(1, &gt, &lt, false))
        return false;

    ocl::Kernel k2("integral_sum_rows", ocl::imgproc::integral_sum_oclsrc,
                   format("-D sdepth=%d", sdepth));
    k2.args(ocl::KernelArg::PtrReadWrite(t_sum), ocl::KernelArg::PtrWriteOnly(sum),
            t_sum.rows, t_sum.cols, (int)t_sum.step, (int)sum.step, sum_offset);

    size_t gt2 = t_sum.cols  * 32, lt2 = 256;
    return k2.run(1, &gt2, &lt2, false);
}
Exemple #9
0
void build_kernel(Binary<expr::op::Div, Call<B, I, J>, S> e,
                  Kernel<T>& k)
{
  Kernel<T> k1(k);
  Kernel_builder<Call<B, I, J>, T>::apply(e.arg1(), k1);
  k1 /= T(e.arg2());
  k += k1;
}
Exemple #10
0
void build_kernel(Binary<expr::op::Mult, Binary<O, L, R>, S> e,
                  Kernel<T>& k)
{
  Kernel<T> k1(k);
  Kernel_builder<Binary<O, L, R>, T>::apply(e.arg1(), k1);
  k1 *= T(e.arg2());
  k += k1;
}
TextStream& SVGFEComposite::externalRepresentation(TextStream& ts) const
{
    ts << "[type=COMPOSITE] ";
    SVGFilterEffect::externalRepresentation(ts);
    if (!in2().isEmpty())
        ts << " [in2=\"" << in2() << "\"]";
    ts << " [k1=" << k1() << " k2=" << k2() << " k3=" << k3() << " k4=" << k4() << "]";
    return ts;
}
const QString Rendering::CChapterDisplay::text(
        const BtConstModuleList &modules,
        const QString &keyName,
        const DisplayOptions &displayOptions,
        const FilterOptions &filterOptions)
{
    using CSBMI = CSwordBibleModuleInfo;

    BT_ASSERT(modules.count() >= 1);
    BT_ASSERT(!keyName.isEmpty());

    const CSwordModuleInfo *module = modules.first();

    if (modules.count() == 1)
        module->module().setSkipConsecutiveLinks( true ); //skip empty, linked verses

    CTextRendering::KeyTreeItem::Settings settings;
    settings.keyRenderingFace =
        displayOptions.verseNumbers
        ? CTextRendering::KeyTreeItem::Settings::SimpleKey
        : CTextRendering::KeyTreeItem::Settings::NoKey;

    QString startKey = keyName;
    QString endKey = startKey;

    //check whether there's an intro we have to include
    BT_ASSERT((module->type() == CSwordModuleInfo::Bible));

    if (module->type() == CSwordModuleInfo::Bible) {
        // HACK: enable headings for VerseKeys:
        static_cast<sword::VerseKey *>(module->module().getKey())
                ->setIntros(true);

        BT_ASSERT(dynamic_cast<CSBMI const *>(module));
        const CSBMI *bible = static_cast<const CSBMI*>(module);

        CSwordVerseKey k1(module);
        k1.setIntros(true);
        k1.setKey(keyName);

        if (k1.getChapter() == 1)
            k1.setChapter(0); // Chapter 1, start with 0:0, otherwise X:0

        k1.setVerse(0);

        startKey = k1.key();

        if (k1.getChapter() == 0)
            k1.setChapter(1);

        k1.setVerse(bible->verseCount(k1.book(), k1.getChapter()));
        endKey = k1.key();
    }

    CDisplayRendering render(displayOptions, filterOptions);
    return render.renderKeyRange( startKey, endKey, modules, keyName, settings );
}
Exemple #13
0
static PetscErrorCode IFunction(TS ts,PetscReal t,Vec U,Vec Udot,Vec F,AppCtx *ctx)
{
  PetscErrorCode ierr;
  PetscScalar    *u,*udot,*f;

  PetscFunctionBegin;
  ierr = VecGetArray(U,&u);CHKERRQ(ierr);
  ierr = VecGetArray(Udot,&udot);CHKERRQ(ierr);
  ierr = VecGetArray(F,&f);CHKERRQ(ierr);
  f[0] = udot[0] - k1(ctx,t)*u[2] + ctx->k2*u[0];
  f[1] = udot[1] - k1(ctx,t)*u[2] + ctx->k3*u[1]*u[3] - ctx->sigma2;
  f[2] = udot[2] - ctx->k3*u[1]*u[3] + k1(ctx,t)*u[2];
  f[3] = udot[3] - ctx->k2*u[0] + ctx->k3*u[1]*u[3];
  ierr = VecRestoreArray(U,&u);CHKERRQ(ierr);
  ierr = VecRestoreArray(Udot,&udot);CHKERRQ(ierr);
  ierr = VecRestoreArray(F,&f);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
int main(int argc, char* argv[])
{
  Hammer h;
  Knee k1(1);

  QObject::connect(&h, SIGNAL(hit(bool)), &k1, SLOT(reflex(bool)));
  h.setHardHit(true);
  h.setHardHit(false);
  return 0;
}
Exemple #15
0
static bool ocl_integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, int sdepth, int sqdepth )
{
    bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;

    if ( _src.type() != CV_8UC1 || _src.step() % vlen != 0 || _src.offset() % vlen != 0 ||
         (!doubleSupport && (sdepth == CV_64F || sqdepth == CV_64F)) )
        return false;

    char cvt[40];
    String opts = format("-D sdepth=%d -D sqdepth=%d -D TYPE=%s -D TYPE4=%s4 -D convert_TYPE4=%s%s",
                         sdepth, sqdepth, ocl::typeToStr(sqdepth), ocl::typeToStr(sqdepth),
                         ocl::convertTypeStr(sdepth, sqdepth, 4, cvt),
                         doubleSupport ? " -D DOUBLE_SUPPORT" : "");

    ocl::Kernel k1("integral_cols", ocl::imgproc::integral_sqrsum_oclsrc, opts);
    if (k1.empty())
        return false;

    Size size = _src.size(), dsize = Size(size.width + 1, size.height + 1),
            t_size = Size(((size.height + vlen - 1) / vlen) * vlen, size.width);
    UMat src = _src.getUMat(), t_sum(t_size, sdepth), t_sqsum(t_size, sqdepth);
    t_sum = t_sum(Range::all(), Range(0, size.height));
    t_sqsum = t_sqsum(Range::all(), Range(0, size.height));

    _sum.create(dsize, sdepth);
    _sqsum.create(dsize, sqdepth);
    UMat sum = _sum.getUMat(), sqsum = _sqsum.getUMat();

    int offset = src.offset / vlen;
    int pre_invalid = src.offset % vlen;
    int vcols = (pre_invalid + src.cols + vlen - 1) / vlen;
    int sum_offset = sum.offset / sum.elemSize();
    int sqsum_offset = sqsum.offset / sqsum.elemSize();
    CV_Assert(sqsum.offset % sqsum.elemSize() == 0);

    k1.args(ocl::KernelArg::PtrReadOnly(src), ocl::KernelArg::PtrWriteOnly(t_sum),
            ocl::KernelArg::PtrWriteOnly(t_sqsum), offset, pre_invalid, src.rows,
            src.cols, (int)src.step, (int)t_sum.step, (int)t_sqsum.step);

    size_t gt = ((vcols + 1) / 2) * 256, lt = 256;
    if (!k1.run(1, &gt, &lt, false))
        return false;

    ocl::Kernel k2("integral_rows", ocl::imgproc::integral_sqrsum_oclsrc, opts);
    if (k2.empty())
        return false;

    k2.args(ocl::KernelArg::PtrReadOnly(t_sum), ocl::KernelArg::PtrReadOnly(t_sqsum),
            ocl::KernelArg::PtrWriteOnly(sum), ocl::KernelArg::PtrWriteOnly(sqsum),
            t_sum.rows, t_sum.cols, (int)t_sum.step, (int)t_sqsum.step,
            (int)sum.step, (int)sqsum.step, sum_offset, sqsum_offset);

    size_t gt2 = t_sum.cols  * 32, lt2 = 256;
    return k2.run(1, &gt2, &lt2, false);
}
PassRefPtr<FilterEffect> SVGFECompositeElement::build(SVGFilterBuilder* filterBuilder)
{
    FilterEffect* input1 = filterBuilder->getEffectById(in1());
    FilterEffect* input2 = filterBuilder->getEffectById(in2());
    
    if (!input1 || !input2)
        return 0;
    
    return FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
                                        k1(), k2(), k3(), k4());
}
Exemple #17
0
        void uniqueIndexCompatibleTest() {
            ShardKeyPattern k1( BSON( "a" << 1 ) );
            verify( k1.isUniqueIndexCompatible( BSON( "_id" << 1 ) ) );
            verify( k1.isUniqueIndexCompatible( BSON( "a" << 1 << "b" << 1 ) ) );
            verify( k1.isUniqueIndexCompatible( BSON( "a" << -1 ) ) );
            verify( ! k1.isUniqueIndexCompatible( BSON( "b" << 1 ) ) );

            ShardKeyPattern k2( BSON( "a" <<  "hashed") );
            verify( k2.isUniqueIndexCompatible( BSON( "a" << 1 ) ) );
            verify( ! k2.isUniqueIndexCompatible( BSON( "b" << 1 ) ) );
        }
Exemple #18
0
int main()
{
  try
    {
      symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s");
      symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),p6("p6"),tp("tp"),v1("v1"),v2("v2"),l5("l5");
      symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4");
      symbol s12("s12"),s23("s23"),s34("s34"),s45("s45"),s51("s51"),s13("s13"),s15("s15"),s56("s56"),s16("s16"),s123("s123"),s234("s234"),s345("s345");
      lst inv_l;
      inv_l.append(p1*p1 == 0);
      inv_l.append( p2*p2 == 0);inv_l.append( p3*p3  ==  0);inv_l.append( p4*p4  ==  0);inv_l.append( p5*p5  ==  0);inv_l.append( p6*p6  ==  0);
      inv_l.append(p1* p2  ==  s12/2);inv_l.append( p2* p3  ==  s23/2);inv_l.append( p3* p4  ==  s34/2);inv_l.append( p4* p5  ==  s45/2);
      inv_l.append(p5* p6  ==  s56/2);inv_l.append( p1* p6  ==  s16/2);inv_l.append( p1* p3  ==  (-s12 + s123 - s23)/2);
      inv_l.append(p2* p4  ==  (-s23 + s234 - s34)/2);
      inv_l.append( p3* p5  ==  (-s34 + s345 - s45)/2);
      inv_l.append(p1* p4  ==  (-s123 + s23 - s234 + s56)/2);
      inv_l.append(p1* p5  ==  (-s16 + s234 - s56)/2);
      inv_l.append( p2* p5  ==  (s16 - s234 + s34 - s345)/2);
      inv_l.append( p2* p6  ==  (-s12 - s16 + s345)/2);
      inv_l.append( p3* p6  ==  (s12 - s123 - s345 + s45)/2);
      inv_l.append( p4* p6  ==  (s123 - s45 - s56)/2);
      
      
      RoMB_loop_by_loop hexag(lst(k1),
                              lst(-pow(p1 + k1,2),-pow(p1 + p2 + k1,2),
                                  -pow(p1 + p2 + p3 + k1,2),
                                  -pow(p1 + p2 + p3 + p4 + k1,2),
                                  -pow(p1+p2+p3+p4+p5+k1,2),-pow(k1,2)),
                              inv_l,
                              lst(1,1,1,1,1,1),true);
      hexag.integrate_map(lst(s12 == -1, s23 == -2, s34 == -3, s45 == -4, s56 == -5, s16 == -6, s123 == -7, s234 == -8, s345 == -9));
/*

 FRESULT for parameters: {s12==-1,s23==-2,s34==-3,s45==-4,s56==-5,s16==-6,s123==-7,s234==-8,s345==-9}
 
  FRESULT anl :           = -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+43/1008*eps^(-2)+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)-1/30240*(-1132.7960047725738361+576*log(8)-163*log(3)+264*log(9)+533*log(2)-479*log(6)-444*log(7)+271*log(4)-287*log(5))*eps^(-1)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9)
   FRESULT num:           = 1.9907333428263254975E-4+(0.032177795803854872908)*eps^(-1)+(0.04265873015873015873)*eps^(-2)
    eps^-2 term: 43/1008 +/- 0
     eps^-1 term: 0.03746018534300839405-2/105*log(8)+163/30240*log(3)-11/1260*log(9)-533/30240*log(2)+479/30240*log(6)+37/2520*log(7)-271/30240*log(4)+41/4320*log(5) +/- 9.022403780167233619E-6
      eps^0 term: -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) +/- 1.04620404922048185285E-4
      */

    }
  catch(std::exception &p)
    {
      std::cerr<<"******************************************************************"<<endl;
      std::cerr<<"   >>>ERROR:  "<<p.what()<<endl;
      std::cerr<<"******************************************************************"<<endl;
      return 1;
    }
  return 0;
}
Exemple #19
0
//-----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE_TEMPLATE(
    eventReEnqueueShouldBePossibleIfNobodyWaitsFor,
    TDevStream,
    TestStreams)
{
    using Fixture = alpaka::test::stream::StreamTestFixture<TDevStream>;
    using Stream = typename Fixture::Stream;
    using Dev = typename Fixture::Dev;

    if(!alpaka::test::stream::IsSyncStream<Stream>::value)
    {
        Fixture f1;
        auto s1 = f1.m_stream;
        alpaka::event::Event<Stream> e1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k2(f1.m_dev);

        // s1 = [k1]
        alpaka::stream::enqueue(s1, k1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));

        // s1 = [k1, e1]
        alpaka::stream::enqueue(s1, e1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [k1, e1, k2]
        alpaka::stream::enqueue(s1, k2);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));

        // re-enqueue should be possible
        // s1 = [k1, k2, e1]
        alpaka::stream::enqueue(s1, e1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [k2, e1]
        k1.trigger();
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [e1]
        k2.trigger();
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(k2));
        alpaka::wait::wait(e1);
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(e1));
    }
}
Exemple #20
0
void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    QPen oldPen = p->pen();
    p->setPen(scm.gridColor(option, d->view));

    const QPoint base = option.rect.topLeft();

    QPoint p2 = base + QPoint(-scm.indentation() - 1, 0);
    QPoint p3 = base + QPoint(-2 * scm.border() - 2 * scm.decorationMargin() - scm.decorationSize(), 0);
    QPoint p4 = base + QPoint(-1, 0);
    QPoint p5(iconsRect(option,
                           index).left() - 1, base.y());
    QPoint p6(option.rect.right(), base.y());

    QPoint v(0, option.rect.height());

    const bool paintForParent =
        index.parent().isValid() &&
        !index.row();

    if (paintForParent) {
        QPoint p1(-2 * scm.indentation() - 1, 0);
        p1 += base;
        p->drawLine(p1, p2);
    }


    QPoint k0(0, base.y());
    QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y());
    p->drawLine(k0, k1);
    p->drawLine(k0 + v, k1 + v);
    p->drawLine(k0, k0 + v);
    p->drawLine(k1, k1 + v);

    p->drawLine(p2, p6);
    p->drawLine(p2 + v, p6 + v);
    p->drawLine(p2, p2 + v);
    p->drawLine(p3, p3 + v);
    p->drawLine(p4, p4 + v);
    p->drawLine(p5, p5 + v);
    p->drawLine(p6, p6 + v);

    //// For debugging purposes only
    //p->setPen(Qt::blue);
    //KritaUtils::renderExactRect(p, iconsRect(option, index));
    //KritaUtils::renderExactRect(p, textRect(option, index));
    //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft()));

    p->setPen(oldPen);
}
Exemple #21
0
inline OutputIterator copy_if_impl(InputIterator first,
                                   InputIterator last,
                                   OutputIterator result,
                                   Predicate predicate,
                                   bool copyIndex,
                                   command_queue &queue)
{
    typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;

    size_t count = detail::iterator_range_size(first, last);
    if(count == 0){
        return result;
    }

    const context &context = queue.get_context();

    // storage for destination indices
    ::boost::compute::vector<cl_uint> indices(count, context);

    // write counts
    ::boost::compute::detail::meta_kernel k1("copy_if_write_counts");
    k1 << indices.begin()[k1.get_global_id(0)] << " = "
           << predicate(first[k1.get_global_id(0)]) << " ? 1 : 0;\n";
    k1.exec_1d(queue, 0, count);

    // count number of elements to be copied
    size_t copied_element_count =
        ::boost::compute::count(indices.begin(), indices.end(), 1, queue);

    // scan indices
    ::boost::compute::exclusive_scan(indices.begin(),
                                     indices.end(),
                                     indices.begin(),
                                     queue);

    // copy values
    ::boost::compute::detail::meta_kernel k2("copy_if_do_copy");
    k2 << "if(" << predicate(first[k2.get_global_id(0)]) << ")" <<
          "    " << result[indices.begin()[k2.get_global_id(0)]] << "=";

    if(copyIndex){
        k2 << k2.get_global_id(0) << ";\n";
    }
    else {
        k2 << first[k2.get_global_id(0)] << ";\n";
    }

    k2.exec_1d(queue, 0, count);

    return result + static_cast<difference_type>(copied_element_count);
}
bool SVGFECompositeElement::build(SVGResourceFilter* filterResource)
{
    FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
    FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
    
    if(!input1 || !input2)
        return false;
    
    RefPtr<FilterEffect> effect = FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
                                        k1(), k2(), k3(), k4());
    filterResource->addFilterEffect(this, effect.release());

    return true;
}
bool SVGFECompositeElement::build(FilterBuilder* builder)
{
    FilterEffect* input1 = builder->getEffectById(in1());
    FilterEffect* input2 = builder->getEffectById(in2());
    
    if(!input1 || !input2)
        return false;
    
    RefPtr<FilterEffect> addedEffect = FEComposite::create(input1, input2, static_cast<CompositeOperationType> (_operator()),
                                        k1(), k2(), k3(), k4());
    builder->add(result(), addedEffect.release());

    return true;
}
Exemple #24
0
void RK4::integrate(std::valarray<double> &X, std::valarray<double> &V, double dt, SolarSystem mysystem, double G, double eps)
{
    std::valarray<double> k1(1,6*mysystem.numberOfBodies());
    std::valarray<double> k2(1,6*mysystem.numberOfBodies());
    std::valarray<double> k3(1,6*mysystem.numberOfBodies());
    std::valarray<double> k4(1,6*mysystem.numberOfBodies());

    // RK4 integration using vector X from solarysystem class.
    k1 = mysystem.calculateRK4(X, V, G, eps) * dt;
    k2 = mysystem.calculateRK4(X + 0.5 * k1, V, G, eps) * dt;
    k3 = mysystem.calculateRK4(X + 0.5 * k2, V, G, eps) * dt;
    k4 = mysystem.calculateRK4(X + k3, V, G, eps) * dt;
    X += (1.0/6) * (k1 + 2 * (k2 + k3) + k4);

}
Exemple #25
0
void lengthcalc(Mat_DP origins, Segment *segchain[]) {

	Vec_DP k0(3), k1(3), k2(3), k3(3);

	for (int i=0; i<3; i++) {
		k0[i]=origins[0][i];
		k1[i]=origins[1][i];
		k2[i]=origins[2][i];
		k3[i]=origins[3][i];
	}

	segchain[0]->length=KINEMATICS::distpnts(k0,k1);
	segchain[1]->length=KINEMATICS::distpnts(k1,k2);
	segchain[2]->length=KINEMATICS::distpnts(k2,k3);

	return;
}
Exemple #26
0
void DynamicalSystem::integrateStepRungeKutta(double dt, const Ref<const VectorXd> x, Ref<VectorXd> x_updated, Ref<VectorXd> xd_updated) const
{
  // 4th order Runge-Kutta for a 1st order system
  // http://en.wikipedia.org/wiki/Runge-Kutta_method#The_Runge.E2.80.93Kutta_method

  int l = x.size();
  VectorXd k1(l), k2(l), k3(l), k4(l);
  differentialEquation(x,k1);
  VectorXd input_k2 = x + dt*0.5*k1;
  differentialEquation(input_k2,k2);
  VectorXd input_k3 = x + dt*0.5*k2;
  differentialEquation(input_k3,k3);
  VectorXd input_k4 = x + dt*k3;
  differentialEquation(input_k4,k4);

  x_updated = x + dt*(k1 + 2.0*(k2+k3) + k4)/6.0;
  differentialEquation(x_updated,xd_updated);
}
Exemple #27
0
void Euler_solve(cube &data_vector,double step_size,int time_steps, int n_planets,vec masses,double G,double epsilon){

    //Define all the different variables used for the method
    vec k1(6);
    mat accel(n_planets,3);

    k1.fill(0);
    accel.fill(0);

    //Evolve through time
    for(int t=0;t< time_steps-1;t++){

        //Calculate inital acceleration
        accel_calculate(data_vector,masses,n_planets,accel,t,G,epsilon);

        for(int i=0;i< n_planets;i++){

            //Calculate k1 for each dim
            k1(3)= step_size*accel(i,0);
            k1(4)= step_size*accel(i,1);
            k1(5)= step_size*accel(i,2);
            for(int j=3;j<6;j++){
                data_vector(i,j,t+1) = data_vector(i,j,t) + k1(j);
            }

            k1(0)= step_size*data_vector(i,3,t+1);
            k1(1)= step_size*data_vector(i,4,t+1);
            k1(2)= step_size*data_vector(i,5,t+1);

            //Update new position
            for(int j=0;j<3;j++){
                data_vector(i,j,t+1) = data_vector(i,j,t) + k1(j);
            }
        }
    }
}
Exemple #28
0
int main(){
   Btree<Key,Value> index;
   index.recover("test.index");
   Key k1("12134");
   Key k2("11111");
   Value v1(1,1);
   Value v2(3,2);
   Value v3(4,5);
   index.insert_kv(k1,v1);
   index.insert_kv(k1,v2);
   index.insert_kv(k2,v3);
   list<Value> vs;
   list<Value>::iterator it;
   index.find_values(k1,vs);
   for(it=vs.begin();it!=vs.end();it++){
       cout<<(*it).s_id<<" "<<(*it).d_id<<endl;
   }
     
}
Exemple #29
0
void ctBdG::RK_Propagator(int i, int eta){
	VectorXcd wvVec(4), k1(4), k2(4), k3(4), k4(4);
	double normwv;
	wvVec(0) = _bdg_u(i,eta);
	wvVec(1) = _bdg_a(i,eta);
	wvVec(2) = _bdg_b(i,eta);
	wvVec(3) = _bdg_v(i,eta);
	k1 = -myI * (_bdg *  wvVec);
	k2 = -myI * (_bdg * (wvVec+_dt*k1*0.5));
	k3 = -myI * (_bdg * (wvVec+_dt*k2*0.5));
	k4 = -myI * (_bdg * (wvVec+_dt*k3));
	wvVec += _dt*(k1+2.0*k2+2.0*k3+k4)/6.0;
	normwv = wvVec.norm();
	wvVec /= normwv;
	//		cout << normwv << endl;
	_bdg_u(i,eta) = wvVec(0);
	_bdg_a(i,eta) = wvVec(1);
	_bdg_b(i,eta) = wvVec(2);
	_bdg_v(i,eta) = wvVec(3);
}
Exemple #30
0
void PlaneMetricRep::drawRectangleForPlane(Vector3D p0_r, Vector3D n_r, double size)
{
	if (!mRect)
		return;
	// draw a rectangle showing the plane:
	Vector3D e_z = n_r;
	Vector3D k1(1,0,0);
	Vector3D k2(0,1,0);
	Vector3D e_x;
	if (cross(k2,e_z).length() > cross(k1,e_z).length())
		e_x = cross(k2,e_z)/cross(k2,e_z).length();
	else
		e_x = cross(k1,e_z)/cross(k1,e_z).length();

	Vector3D e_y = cross(e_z,e_x);
	Transform3D rMb = createTransformIJC(e_x, e_y, p0_r);
	double bb_size = 0.10/size;
	DoubleBoundingBox3D bb(-bb_size,bb_size,-bb_size,bb_size,0,0);

	mRect->updatePosition(bb, rMb);
}