Skip to content

Commit

Permalink
unitest for the allocation of the rhs vector
Browse files Browse the repository at this point in the history
  • Loading branch information
happyKitesurfer committed Feb 16, 2025
1 parent f1547b0 commit 2a6951d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/matrixPetsc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function(neofoam_unit_test_petsc TEST)
NeoFOAM
cpptrace::cpptrace
${PETSc_LIBRARIES}
${PETSc_LIBRARY_DIRS}/libkokkoscore.so.4.4)
${PETSc_LIBRARY_DIRS}/libkokkoscore.so.4.4
mpi)
target_include_directories(${TEST} PRIVATE ${PETSc_INCLUDE_DIRS})
target_link_directories(${TEST} PRIVATE ${PETSc_LIBRARY_DIRS})
link_directories(${PETSc_LIBRARY_DIRS})
Expand Down
44 changes: 44 additions & 0 deletions test/matrixPetsc/matrixAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,48 @@ TEST_CASE("matrix assembly")
REQUIRE(v[8] == 9.);
REQUIRE(v[9] == 10.);
}

SECTION("rhs assembly" + execName)
{

NeoFOAM::size_t size = 10;
NeoFOAM::Field<NeoFOAM::scalar> values(
exec, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}
);
PetscInt rowIdx[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
PetscScalar v[10];

Vec b;

PetscInitialize(NULL, NULL, NULL, NULL);

VecCreate(PETSC_COMM_SELF, &b);
VecSetSizes(b, PETSC_DECIDE, size);

std::cout << execName << "\n";
if (execName == "GPUExecutor")
{
VecSetType(b, VECKOKKOS);
}
else
{
VecSetType(b, VECSEQ);
}

VecSetPreallocationCOO(b, size, rowIdx);
VecSetValuesCOO(b, values.data(), ADD_VALUES);

VecGetValues(b, size, rowIdx, v);

REQUIRE(v[0] == 1.);
REQUIRE(v[1] == 2.);
REQUIRE(v[2] == 3.);
REQUIRE(v[3] == 4.);
REQUIRE(v[4] == 5.);
REQUIRE(v[5] == 6.);
REQUIRE(v[6] == 7.);
REQUIRE(v[7] == 8.);
REQUIRE(v[8] == 9.);
REQUIRE(v[9] == 10.);
}
}

0 comments on commit 2a6951d

Please sign in to comment.