Commit a1cdd637 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1533 - #1532 Add a test about AreStrictlyEqual for PETSc matrix - and...

#1533 - #1532 Add a test about AreStrictlyEqual for PETSc matrix - and refactor the tests so that the same toy model may be used for different tests regarding PETSc matrices.
parent 3d5f3eb0
......@@ -4088,7 +4088,6 @@
BE8B5FA62077D65F00DC005E /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
BE8B5FA72077D67400DC005E /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
BE8B5FA82077D68E00DC005E /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
BE8B5FBB20793C7800DC005E /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CMakeLists.txt; path = ../../Core/CMakeLists.txt; sourceTree = "<group>"; };
BE8B5FC0207BC43F00DC005E /* test_results.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_results.cpp; sourceTree = "<group>"; };
BE8B67311CC0E2E100312399 /* Core.doxygen */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = Core.doxygen; sourceTree = "<group>"; };
BE8B67341CC0EA3800312399 /* NumberingSubset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NumberingSubset.cpp; sourceTree = "<group>"; };
......@@ -4326,6 +4325,10 @@
BE9E2E72249E316800AA6678 /* ToyModel.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ToyModel.hxx; sourceTree = "<group>"; };
BE9E2E73249E316800AA6678 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
BE9E2E74249E316800AA6678 /* ToyModel.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ToyModel.cpp; sourceTree = "<group>"; };
BE9E2E7724A0CB3700AA6678 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
BE9E2E7824A0CC4700AA6678 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = CMakeLists.txt; path = Sources/Test/ThirdParty/PETSc/Matrix/MatEqual/CMakeLists.txt; sourceTree = SOURCE_ROOT; };
BE9E2E7924A0CC8B00AA6678 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = Sources/Test/ThirdParty/PETSc/Matrix/MatEqual/main.cpp; sourceTree = SOURCE_ROOT; };
BE9E2E7A24A0CCA500AA6678 /* demo.lua */ = {isa = PBXFileReference; lastKnownFileType = file; name = demo.lua; path = Sources/Test/ThirdParty/PETSc/Matrix/MatEqual/demo.lua; sourceTree = SOURCE_ROOT; };
BE9EA61A1C89F50900836E0E /* ParameterAtDof.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ParameterAtDof.hpp; sourceTree = "<group>"; };
BE9FE80918CE0A6900177F79 /* Libmesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Libmesh.cpp; sourceTree = "<group>"; };
BE9FE80A18CE0A6900177F79 /* Libmesh.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Libmesh.hpp; sourceTree = "<group>"; };
......@@ -9358,18 +9361,38 @@
path = InputData;
sourceTree = "<group>";
};
BE9E2E6D249E316800AA6678 /* MatrixIO */ = {
BE9E2E6D249E316800AA6678 /* IO */ = {
isa = PBXGroup;
children = (
BE9E2E6E249E316800AA6678 /* CMakeLists.txt */,
BE9E2E70249E316800AA6678 /* demo.lua */,
BE9E2E73249E316800AA6678 /* main.cpp */,
BE9E2E70249E316800AA6678 /* demo.lua */,
);
path = IO;
sourceTree = "<group>";
};
BE9E2E7524A0CAF100AA6678 /* Matrix */ = {
isa = PBXGroup;
children = (
BE9E2E7724A0CB3700AA6678 /* CMakeLists.txt */,
BE9E2E71249E316800AA6678 /* InputData.hpp */,
BE9E2E74249E316800AA6678 /* ToyModel.cpp */,
BE9E2E6F249E316800AA6678 /* ToyModel.hpp */,
BE9E2E72249E316800AA6678 /* ToyModel.hxx */,
BE9E2E7624A0CB1200AA6678 /* MatEqual */,
BE9E2E6D249E316800AA6678 /* IO */,
);
path = Matrix;
sourceTree = "<group>";
};
BE9E2E7624A0CB1200AA6678 /* MatEqual */ = {
isa = PBXGroup;
children = (
BE9E2E7824A0CC4700AA6678 /* CMakeLists.txt */,
BE9E2E7924A0CC8B00AA6678 /* main.cpp */,
BE9E2E7A24A0CCA500AA6678 /* demo.lua */,
);
path = MatrixIO;
path = MatEqual;
sourceTree = "<group>";
};
BE9ECC091F5857B900D92CD7 /* Boost */ = {
......@@ -10660,9 +10683,8 @@
isa = PBXGroup;
children = (
BEF795D322DDBDB20054B192 /* CMakeLists.txt */,
BE8B5FBB20793C7800DC005E /* CMakeLists.txt */,
BE9E2E7524A0CAF100AA6678 /* Matrix */,
0209EA702326A612009F7D2F /* MatrixOperations */,
BE9E2E6D249E316800AA6678 /* MatrixIO */,
BEF795CF22DDBD7A0054B192 /* VectorIO */,
);
path = PETSc;
include(${CMAKE_CURRENT_LIST_DIR}/VectorIO/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/MatrixIO/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/Matrix/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/MatrixOperations/CMakeLists.txt)
add_library(MoReFEMTestPetscMatrix_lib
${CMAKE_CURRENT_LIST_DIR}/InputData.hpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.cpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.hpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.hxx
)
target_link_libraries(MoReFEMTestPetscMatrix_lib
${MOREFEM_TEST_TOOLS})
include(${CMAKE_CURRENT_LIST_DIR}/IO/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/MatEqual/CMakeLists.txt)
add_executable(MoReFEMTestPetscMatrixIO
${CMAKE_CURRENT_LIST_DIR}/main.cpp
${CMAKE_CURRENT_LIST_DIR}/InputData.hpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.cpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.hpp
${CMAKE_CURRENT_LIST_DIR}/ToyModel.hxx
)
${CMAKE_CURRENT_LIST_DIR}/main.cpp)
target_link_libraries(MoReFEMTestPetscMatrixIO
${MOREFEM_TEST_TOOLS}
)
MoReFEMTestPetscMatrix_lib)
add_test(PetscMatrixIO
MoReFEMTestPetscMatrixIO
......
......@@ -21,7 +21,7 @@
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "Test/Tools/Fixture/Model.hpp"
#include "Test/ThirdParty/PETSc/MatrixIO/ToyModel.hpp"
#include "Test/ThirdParty/PETSc/Matrix/ToyModel.hpp"
using namespace MoReFEM;
......@@ -78,12 +78,20 @@ BOOST_FIXTURE_TEST_CASE(load_ascii, fixture_type)
matrix.View(mpi,
ascii_file,
__FILE__, __LINE__);
__FILE__, __LINE__,
PETSC_VIEWER_BINARY_MATLAB,
FILE_MODE_WRITE);
if (mpi.IsRootProcessor())
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true);
GlobalMatrix loaded_matrix(matrix);
loaded_matrix.ZeroEntries(__FILE__, __LINE__);
loaded_matrix.Load(mpi,
ascii_file,
__FILE__, __LINE__,
PETSC_VIEWER_BINARY_MATLAB);
......@@ -163,7 +171,7 @@ namespace // anonymous
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
return
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/ThirdParty/PETSc/MatrixIO/demo.lua");
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/ThirdParty/PETSc/Matrix/IO/demo.lua");
}
......
add_executable(MoReFEMTestPetscMatrixEqual
${CMAKE_CURRENT_LIST_DIR}/main.cpp)
target_link_libraries(MoReFEMTestPetscMatrixEqual
MoReFEMTestPetscMatrix_lib)
add_test(PetscMatrixEqual
MoReFEMTestPetscMatrixEqual
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR}/Seq)
set_tests_properties(PetscMatrixEqual PROPERTIES TIMEOUT 20)
add_test(PetscMatrixEqual-mpi
${OPEN_MPI_INCL_DIR}/../bin/mpirun
--oversubscribe
-np 4
MoReFEMTestPetscMatrixEqual
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR}/Mpi4)
set_tests_properties(PetscMatrixEqual-mpi PROPERTIES TIMEOUT 20)
-- Comment lines are introduced by "--".
-- In a section (i.e. within braces), all entries must be separated by a comma.
Mesh1 = {
-- Path of the mesh file to use.
-- Expected format: "VALUE"
mesh = "${MOREFEM_ROOT}/Data/Mesh/elasticity_Nx50_Ny20_force_label.mesh",
-- Format of the input mesh.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'Ensight', 'Medit'})
format = "Medit",
-- Highest dimension of the input mesh. This dimension might be lower than the one effectively read in the
-- mesh file; in which case Coords will be reduced provided all the dropped values are 0. If not, an
-- exception is thrown.
-- Expected format: VALUE
-- Constraint: v <= 3 and v > 0
dimension = 2,
-- Space unit of the mesh.
-- Expected format: VALUE
space_unit = 1.
} -- Mesh1
Domain1 = {
-- Index of the geometric mesh upon which the domain is defined (as defined in the present file). Might be
-- left empty if domain not limited to one mesh; at most one value is expected here.
-- Expected format: {VALUE1, VALUE2, ...}
mesh_index = { 1 },
-- List of dimensions encompassed by the domain. Might be left empty if no restriction at all upon
-- dimensions.
-- Expected format: {VALUE1, VALUE2, ...}
-- Constraint: value_in(v, {0, 1, 2, 3})
dimension_list = { 2 },
-- List of mesh labels encompassed by the domain. Might be left empty if no restriction at all upon mesh
-- labels. This parameter does not make sense if no mesh is defined for the domain.
-- Expected format: {VALUE1, VALUE2, ...}
mesh_label_list = {},
-- List of geometric element types considered in the domain. Might be left empty if no restriction upon
-- these. No constraint is applied at LuaOptionFile level, as some geometric element types could be added after
-- generation of current input data file. Current list is below; if an incorrect value is put there it
-- will be detected a bit later when the domain object is built.
-- The known types when this file was generated are:
-- . Point1
-- . Segment2, Segment3
-- . Triangle3, Triangle6
-- . Quadrangle4, Quadrangle8, Quadrangle9
-- . Tetrahedron4, Tetrahedron10
-- . Hexahedron8, Hexahedron20, Hexahedron27.
-- Expected format: {"VALUE1", "VALUE2", ...}
geometric_element_type_list = {}
} -- Domain1
Unknown1 = {
-- Name of the unknown (used for displays in output).
-- Expected format: "VALUE"
name = "unknown1",
-- Index of the god of dof into which the finite element space is defined.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'scalar', 'vectorial'})
nature = "scalar"
} -- Unknown1
Unknown2 = {
-- Name of the unknown (used for displays in output).
-- Expected format: "VALUE"
name = "unknown2",
-- Index of the god of dof into which the finite element space is defined.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'scalar', 'vectorial'})
nature = "scalar"
} -- Unknown2
NumberingSubset1 = {
-- Name of the numbering subset (not really used; at the moment I just need one input parameter to ground
-- the possible values to choose elsewhere).
-- Expected format: "VALUE"
name = "row",
-- Whether a vector defined on this numbering subset might be used to compute a movemesh. If true, a
-- FEltSpace featuring this numbering subset will compute additional quantities to enable fast computation.
-- This should be false for most numbering subsets, and when it's true the sole unknown involved should be a
-- displacement.
-- Expected format: 'true' or 'false' (without the quote)
do_move_mesh = false
} -- NumberingSubset1
NumberingSubset2 = {
-- Name of the numbering subset (not really used; at the moment I just need one input parameter to ground
-- the possible values to choose elsewhere).
-- Expected format: "VALUE"
name = "column",
-- Whether a vector defined on this numbering subset might be used to compute a movemesh. If true, a
-- FEltSpace featuring this numbering subset will compute additional quantities to enable fast computation.
-- This should be false for most numbering subsets, and when it's true the sole unknown involved should be a
-- displacement.
-- Expected format: 'true' or 'false' (without the quote)
do_move_mesh = false
} -- NumberingSubset2
FiniteElementSpace1 = {
-- Index of the god of dof into which the finite element space is defined.
-- Expected format: VALUE
god_of_dof_index = 1,
-- Index of the domain onto which the finite element space is defined. This domain must be unidimensional.
-- Expected format: VALUE
domain_index = 1,
-- List of all unknowns defined in the finite element space. Unknowns here must be defined in this file as
-- an 'Unknown' block; expected name/identifier is the name given there.
-- Expected format: {"VALUE1", "VALUE2", ...}
unknown_list = { "unknown1", "unknown2" },
-- List of the shape function to use for each unknown;
-- Expected format: {"VALUE1", "VALUE2", ...}
shape_function_list = { "P1", "P1b" },
-- List of the numbering subset to use for each unknown;
-- Expected format: { VALUE1, VALUE2, ...}
numbering_subset_list = { 1, 2 }
} -- FiniteElementSpace1
Result = {
-- Directory in which all the results will be written. This path may use the environment variable
-- MOREFEM_RESULT_DIR, which is either provided in user's environment or automatically set to
-- '/Volumes/Data/${USER}/MoReFEM/Results' in MoReFEM initialization step. Please do not read this value
-- directly: it might have been extended in MoReFEMData class! Rather call the GetResultDirectory() from
-- this class.
-- Expected format: "VALUE"
output_directory = "${MOREFEM_TEST_OUTPUT_DIR}/Test/ThirdParty/Petsc/MatrixEqual",
-- Enables to skip some printing in the console. Can be used to WriteSolution every n time.
-- Expected format: VALUE
-- Constraint: v > 0
display_value = 1,
-- Defines the solutions output format. Set to false for ascii or true for binary.
-- Expected format: VALUE
binary_output = true
} -- Result
/*!
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 26 Apr 2013 12:18:22 +0200
// Copyright (c) Inria. All rights reserved.
//
*/
#include <cstdlib>
#define BOOST_TEST_MODULE petsc_matrix_io
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "ThirdParty/Wrappers/Tclap/StringPair.hpp"
#include "Utilities/Numeric/Numeric.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Utilities/Filesystem/File.hpp"
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "Test/Tools/Fixture/Model.hpp"
#include "Test/ThirdParty/PETSc/Matrix/ToyModel.hpp"
using namespace MoReFEM;
namespace // anonymous
{
struct LuaFile
{
static std::string GetPath();
};
using fixture_type =
TestNS::FixtureNS::Model
<
TestNS::PetscNS::MatrixIONS::ToyModel,
LuaFile,
TestNS::FixtureNS::call_run_method_at_first_call::no
>;
} // namespace anonymous
PRAGMA_DIAGNOSTIC(push)
#include "Utilities/Warnings/Internal/IgnoreWarning/disabled-macro-expansion.hpp"
BOOST_FIXTURE_TEST_CASE(creation, fixture_type)
{
decltype(auto) model = GetModel();
static_cast<void>(model);
}
BOOST_FIXTURE_TEST_CASE(equal_to_self, fixture_type)
{
decltype(auto) model = GetModel();
decltype(auto) matrix = model.GetMatrix();
BOOST_CHECK(Wrappers::Petsc::AreStrictlyEqual(matrix, matrix, __FILE__, __LINE__));
}
BOOST_FIXTURE_TEST_CASE(copy_is_equal, fixture_type)
{
decltype(auto) model = GetModel();
decltype(auto) matrix = model.GetMatrix();
GlobalMatrix copy(matrix);
BOOST_CHECK(Wrappers::Petsc::AreStrictlyEqual(matrix, copy, __FILE__, __LINE__));
}
BOOST_FIXTURE_TEST_CASE(not_equal, fixture_type)
{
decltype(auto) model = GetModel();
decltype(auto) matrix = model.GetMatrix();
GlobalMatrix zero(matrix);
zero.ZeroEntries(__FILE__, __LINE__);
BOOST_CHECK(!Wrappers::Petsc::AreStrictlyEqual(matrix, zero, __FILE__, __LINE__));
}
PRAGMA_DIAGNOSTIC(pop)
namespace // anonymous
{
std::string LuaFile::GetPath()
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
return
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/ThirdParty/PETSc/Matrix/MatEqual/demo.lua");
}
} // namespace anonymous
......@@ -22,7 +22,7 @@
#include "Model/Internal/InitializeHelper.hpp"
#include "Model/Internal/CreateMeshDataDirectory.hpp"
#include "Test/ThirdParty/PETSc/MatrixIO/ToyModel.hpp"
#include "Test/ThirdParty/PETSc/Matrix/ToyModel.hpp"
namespace MoReFEM::TestNS::PetscNS::MatrixIONS
......
......@@ -17,7 +17,7 @@
# include "Core/InputData/Instances/Result.hpp"
# include "Core/LinearAlgebra/GlobalMatrix.hpp"
# include "Test/ThirdParty/PETSc/MatrixIO/InputData.hpp"
# include "Test/ThirdParty/PETSc/Matrix/InputData.hpp"
namespace MoReFEM
......@@ -29,12 +29,9 @@ namespace MoReFEM
/*!
* \brief Toy model used to perform tests about I/O operations related to \a GlobalVector.
* \brief Toy model used to perform tests related to PETSc matrices
*
* This toy model role is to:
* - Initialize the data (including partitioning among the different ranks in the case of parallel run)
* - Create and store a \a GlobalVector onto which different I/O operations will be performed.
* - Set filenames for output files and ensure these files don't exist at first - they will be created by the tests themselves.
* Its role is mostly to fill a \a GlobalMatrix in a realistic case (mas operator over a mesh).
*/
class ToyModel : public Crtp::CrtpMpi<ToyModel>
{
......@@ -108,7 +105,7 @@ namespace MoReFEM
} // namespace MoReFEM
#include "Test/ThirdParty/PETSc/MatrixIO/ToyModel.hxx"
#include "Test/ThirdParty/PETSc/Matrix/ToyModel.hxx"
#endif // MOREFEM_x_TEST_x_THIRD_PARTY_x_P_E_T_SC_x_MATRIX_I_O_x_TOY_MODEL_HPP_
......@@ -87,7 +87,7 @@ namespace MoReFEM::TestNS::PetscNS::MatrixOperationsNS
for (auto i = 0u; i < size; ++i)
content[i] = rank_plus_one * std::sqrt(i); // completely arbitrary value with no redundancy!
// First all wrappers that do not use a DeReuseMatrix policy
// First all wrappers that do not use a DoReuseMatrix policy
Wrappers::Petsc::MatCreateTranspose(matrix_init_1,
matrix_4,
__FILE__, __LINE__);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment