Example #1
0
    void TestPetscExceptions()
    {
        /*
         * Note we could test with TS_ASSERT_THROWS_THIS() but PetscException
         * includes line numbers so it isn't very robust.
         */
        int err = 0;
        TS_ASSERT_THROWS_NOTHING(PETSCEXCEPT(err));

        Vec v;
        err = VecCreateMPI(PETSC_COMM_WORLD, 2, 1, &v);
        PetscTools::Destroy(v);
        //#define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong */
        //#define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
        TS_ASSERT_EQUALS(err, PETSC_ERR_ARG_INCOMP);
        TS_ASSERT_THROWS(PETSCEXCEPT(err), Exception);

        err=PETSC_ERR_FILE_OPEN;
        //#define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
        TS_ASSERT_EQUALS(err, PETSC_ERR_FILE_OPEN);
        TS_ASSERT_THROWS(PETSCEXCEPT(err), Exception);

        // See if we can do it without a temporary
        TS_ASSERT_THROWS(
            PETSCEXCEPT(VecCreateMPI(PETSC_COMM_WORLD, 2, 1, &v)), Exception);
        PetscTools::Destroy(v);

        // This test give back an "unknown error" message
        TS_ASSERT_THROWS( PETSCEXCEPT(-3), Exception);
    }
Example #2
0
void PetscVecTools::WAXPY(Vec w, double a, Vec x, Vec y)
{
#if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
    PETSCEXCEPT( VecWAXPY(&a, x, y, w) );
#else
    PETSCEXCEPT( VecWAXPY(w, a, x, y) );
#endif
}
Example #3
0
void PetscVecTools::Scale(Vec vector, double scaleFactor)
{
#if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
    PETSCEXCEPT( VecScale(&scaleFactor, vector) );
#else
    PETSCEXCEPT( VecScale(vector, scaleFactor) );
#endif
}
Example #4
0
void PetscSetupUtils::InitialisePetsc()
{
    // The CommandLineArguments instance is filled in by the cxxtest test suite runner.
    CommandLineArguments* p_args = CommandLineArguments::Instance();
    PETSCEXCEPT(PetscInitialize(p_args->p_argc, p_args->p_argv, PETSC_NULL, PETSC_NULL));
}