Commit 900ddee8 authored by GILLES Sebastien's avatar GILLES Sebastien

#1532 MatrixIO: replace the vector by a matrix in the code. To fill it, we...

#1532 MatrixIO: replace the vector by a matrix in the code. To fill it, we assemble a mass operator into the global matrix.
parent 702437a4
......@@ -17,6 +17,8 @@
#include "ThirdParty/Wrappers/Petsc/Vector/AccessVectorContent.hpp"
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "OperatorInstances/VariationalOperator/BilinearForm/Mass.hpp"
#include "Model/Internal/InitializeHelper.hpp"
#include "Model/Internal/CreateMeshDataDirectory.hpp"
......@@ -103,54 +105,56 @@ namespace MoReFEM::TestNS::PetscNS::MatrixIONS
Internal::ModelNS::CreateMeshDataDirectory(GetOutputDirectory()));
decltype(auto) god_of_dof_manager = GodOfDofManager::GetInstance(__FILE__, __LINE__);
decltype(auto) god_of_dof = god_of_dof_manager.GetGodOfDof(1);
decltype(auto) god_of_dof = god_of_dof_manager.GetGodOfDof(sole);
decltype(auto) numbering_subset = god_of_dof.GetNumberingSubset(1);
decltype(auto) row_numbering_subset = god_of_dof.GetNumberingSubset(row_index);
decltype(auto) col_numbering_subset = god_of_dof.GetNumberingSubset(column_index);
vector_ = std::make_unique<GlobalVector>(numbering_subset);
auto& vector = *vector_;
matrix_ = std::make_unique<GlobalMatrix>(row_numbering_subset, col_numbering_subset);
auto& matrix = *matrix_;
AllocateGlobalVector(god_of_dof, vector);
AllocateGlobalMatrix(god_of_dof, matrix);
{
Wrappers::Petsc::AccessVectorContent<Utilities::Access::read_and_write> content(vector,
__FILE__, __LINE__);
decltype(auto) unknown_manager = UnknownManager::GetInstance(__FILE__, __LINE__);
decltype(auto) unknown1 = unknown_manager.GetUnknownPtr(unknown1_index);
decltype(auto) unknown2 = unknown_manager.GetUnknownPtr(unknown2_index);
const auto size = content.GetSize(__FILE__, __LINE__);
const auto rank_plus_one = static_cast<double>(1 + mpi.GetRank<int>());
decltype(auto) felt_space = god_of_dof.GetFEltSpace(sole);
for (auto i = 0u; i < size; ++i)
content[i] = rank_plus_one * std::sqrt(i); // completely arbitrary value with no redundancy!
GlobalVariationalOperatorNS::Mass mass_op(felt_space,
unknown1,
unknown2);
}
{
const auto binary_file = GetProcessorWiseBinaryFile();
if (FilesystemNS::File::DoExist(binary_file))
FilesystemNS::File::Remove(binary_file, __FILE__, __LINE__);
}
{
const auto ascii_file = GetProcessorWiseAsciiFile();
if (FilesystemNS::File::DoExist(ascii_file))
FilesystemNS::File::Remove(ascii_file, __FILE__, __LINE__);
}
if (mpi.IsRootProcessor())
{
{
const auto binary_file = GetProgramWiseBinaryFile();
if (FilesystemNS::File::DoExist(binary_file))
FilesystemNS::File::Remove(binary_file, __FILE__, __LINE__);
}
{
const auto ascii_file = GetProgramWiseAsciiFile();
if (FilesystemNS::File::DoExist(ascii_file))
FilesystemNS::File::Remove(ascii_file, __FILE__, __LINE__);
}
}
// {
// const auto binary_file = GetProcessorWiseBinaryFile();
// if (FilesystemNS::File::DoExist(binary_file))
// FilesystemNS::File::Remove(binary_file, __FILE__, __LINE__);
// }
//
// {
// const auto ascii_file = GetProcessorWiseAsciiFile();
// if (FilesystemNS::File::DoExist(ascii_file))
// FilesystemNS::File::Remove(ascii_file, __FILE__, __LINE__);
// }
//
// if (mpi.IsRootProcessor())
// {
// {
// const auto binary_file = GetProgramWiseBinaryFile();
// if (FilesystemNS::File::DoExist(binary_file))
// FilesystemNS::File::Remove(binary_file, __FILE__, __LINE__);
// }
//
// {
// const auto ascii_file = GetProgramWiseAsciiFile();
// if (FilesystemNS::File::DoExist(ascii_file))
// FilesystemNS::File::Remove(ascii_file, __FILE__, __LINE__);
// }
// }
}
......
......@@ -15,7 +15,7 @@
# include <vector>
# include "Core/InputData/Instances/Result.hpp"
# include "Core/LinearAlgebra/GlobalVector.hpp"
# include "Core/LinearAlgebra/GlobalMatrix.hpp"
# include "Test/ThirdParty/PETSc/MatrixIO/InputData.hpp"
......@@ -82,8 +82,8 @@ namespace MoReFEM
//! Returns the path to result directory.
const FilesystemNS::Directory& GetOutputDirectory() const noexcept;
//! Accessor to the vector used for tests.
const GlobalVector& GetVector() const noexcept;
//! Accessor to the matrix used for tests.
const GlobalMatrix& GetMatrix() const noexcept;
//! Accessor to the path to the binary file for current rank.
const std::string& GetProcessorWiseBinaryFile() const noexcept;
......@@ -99,8 +99,8 @@ namespace MoReFEM
private:
//! Global vector which is used in the tests.
GlobalVector::unique_ptr vector_ = nullptr;
//! Global matrix which is used in the tests.
GlobalMatrix::unique_ptr matrix_ = nullptr;
//! Path to result directory.
const FilesystemNS::Directory output_directory_;
......
......@@ -20,10 +20,10 @@ namespace MoReFEM
{
inline const GlobalVector& ToyModel::GetVector() const noexcept
inline const GlobalMatrix& ToyModel::GetMatrix() const noexcept
{
assert(!(!vector_));
return *vector_;
assert(!(!matrix_));
return *matrix_;
}
......
......@@ -57,104 +57,6 @@ PRAGMA_DIAGNOSTIC(push)
#include "Utilities/Warnings/Internal/IgnoreWarning/disabled-macro-expansion.hpp"
BOOST_FIXTURE_TEST_SUITE(processor_wise, fixture_type)
BOOST_AUTO_TEST_CASE(creation)
{
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
decltype(auto) vector = model.GetVector();
std::string ascii_file = model.GetProcessorWiseAsciiFile();
std::string binary_file = model.GetProcessorWiseBinaryFile();
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == false);
vector.Print<MpiScale::processor_wise>(mpi, binary_file, __FILE__, __LINE__);
// As Lua file is set to ask binary file.
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
vector.Print<MpiScale::processor_wise>(mpi, ascii_file, __FILE__, __LINE__, binary_or_ascii::ascii);
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
}
BOOST_AUTO_TEST_CASE(load_ascii)
{
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
std::string ascii_file = model.GetProcessorWiseAsciiFile();
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true); // created in previous test!
decltype(auto) vector = model.GetVector();
std::vector<PetscInt> ghost_padding;
if (mpi.Nprocessor<int>() > 1)
ghost_padding = vector.GetGhostPadding();
Wrappers::Petsc::Vector from_file;
from_file.InitParallelFromProcessorWiseAsciiFile(mpi,
static_cast<unsigned int>(vector.GetProcessorWiseSize(__FILE__, __LINE__)),
static_cast<unsigned int>(vector.GetProgramWiseSize(__FILE__, __LINE__)),
ghost_padding,
ascii_file,
__FILE__, __LINE__);
mpi.Barrier();
std::string inequality_description;
Wrappers::Petsc::AreEqual(from_file,
vector,
NumericNS::DefaultEpsilon<double>(),
inequality_description,
__FILE__, __LINE__);
BOOST_CHECK_EQUAL(inequality_description, "");
}
BOOST_AUTO_TEST_CASE(load_binary)
{
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
std::string binary_file = model.GetProcessorWiseBinaryFile();
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true); // created in previous test!
decltype(auto) vector = model.GetVector();
std::vector<PetscInt> ghost_padding;
if (mpi.Nprocessor<int>() > 1)
ghost_padding = vector.GetGhostPadding();
Wrappers::Petsc::Vector from_file;
from_file.InitParallelFromProcessorWiseBinaryFile(mpi,
static_cast<unsigned int>(vector.GetProcessorWiseSize(__FILE__, __LINE__)),
static_cast<unsigned int>(vector.GetProgramWiseSize(__FILE__, __LINE__)),
ghost_padding,
binary_file,
__FILE__, __LINE__);
mpi.Barrier();
std::string inequality_description;
Wrappers::Petsc::AreEqual(from_file,
vector,
NumericNS::DefaultEpsilon<double>(),
inequality_description,
__FILE__, __LINE__);
BOOST_CHECK_EQUAL(inequality_description, "");
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_SUITE(program_wise, fixture_type)
......@@ -164,64 +66,64 @@ BOOST_FIXTURE_TEST_SUITE(program_wise, fixture_type)
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
decltype(auto) vector = model.GetVector();
std::string ascii_file = model.GetProgramWiseAsciiFile();
std::string binary_file = model.GetProgramWiseBinaryFile();
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == false);
vector.Print<MpiScale::program_wise>(mpi, binary_file, __FILE__, __LINE__);
// As Lua file is set to ask binary file.
if (mpi.IsRootProcessor())
{
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
}
vector.Print<MpiScale::program_wise>(mpi, ascii_file, __FILE__, __LINE__, binary_or_ascii::ascii);
if (mpi.IsRootProcessor())
{
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true);
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
}
// decltype(auto) vector = model.GetVector();
// std::string ascii_file = model.GetProgramWiseAsciiFile();
// std::string binary_file = model.GetProgramWiseBinaryFile();
//
// BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
// BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == false);
//
// vector.Print<MpiScale::program_wise>(mpi, binary_file, __FILE__, __LINE__);
//
// // As Lua file is set to ask binary file.
// if (mpi.IsRootProcessor())
// {
// BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == false);
// BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
// }
//
// vector.Print<MpiScale::program_wise>(mpi, ascii_file, __FILE__, __LINE__, binary_or_ascii::ascii);
//
// if (mpi.IsRootProcessor())
// {
// BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true);
// BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true);
// }
}
BOOST_AUTO_TEST_CASE(load_binary)
{
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
std::string binary_file = model.GetProgramWiseBinaryFile();
BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true); // created in previous test!
decltype(auto) vector = model.GetVector();
Wrappers::Petsc::Vector from_file;
std::vector<PetscInt> ghost_padding;
if (mpi.Nprocessor<int>() > 1)
ghost_padding = vector.GetGhostPadding();
from_file.InitFromProgramWiseBinaryFile(mpi,
static_cast<unsigned int>(vector.GetProcessorWiseSize(__FILE__, __LINE__)),
static_cast<unsigned int>(vector.GetProgramWiseSize(__FILE__, __LINE__)),
ghost_padding,
binary_file,
__FILE__, __LINE__);
std::string inequality_description;
Wrappers::Petsc::AreEqual(from_file,
vector,
NumericNS::DefaultEpsilon<double>(),
inequality_description,
__FILE__, __LINE__);
BOOST_CHECK_EQUAL(inequality_description, "");
}
// BOOST_AUTO_TEST_CASE(load_binary)
// {
// decltype(auto) model = GetModel();
// decltype(auto) mpi = model.GetMpi();
//
// std::string binary_file = model.GetProgramWiseBinaryFile();
// BOOST_CHECK(FilesystemNS::File::DoExist(binary_file) == true); // created in previous test!
// decltype(auto) vector = model.GetVector();
// Wrappers::Petsc::Vector from_file;
//
// std::vector<PetscInt> ghost_padding;
//
// if (mpi.Nprocessor<int>() > 1)
// ghost_padding = vector.GetGhostPadding();
//
// from_file.InitFromProgramWiseBinaryFile(mpi,
// static_cast<unsigned int>(vector.GetProcessorWiseSize(__FILE__, __LINE__)),
// static_cast<unsigned int>(vector.GetProgramWiseSize(__FILE__, __LINE__)),
// ghost_padding,
// binary_file,
// __FILE__, __LINE__);
//
// std::string inequality_description;
// Wrappers::Petsc::AreEqual(from_file,
// vector,
// NumericNS::DefaultEpsilon<double>(),
// inequality_description,
// __FILE__, __LINE__);
//
// BOOST_CHECK_EQUAL(inequality_description, "");
// }
// No load_ascii: not foreseen apparently in PETSc interface!
......@@ -229,46 +131,6 @@ BOOST_FIXTURE_TEST_SUITE(program_wise, fixture_type)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_SUITE(sequential_only, fixture_type)
BOOST_AUTO_TEST_CASE(load_ascii)
{
decltype(auto) model = GetModel();
decltype(auto) mpi = model.GetMpi();
if (mpi.Nprocessor<int>() == 1)
{
std::string ascii_file = model.GetProgramWiseAsciiFile();
BOOST_CHECK(FilesystemNS::File::DoExist(ascii_file) == true); // created in previous test!
decltype(auto) vector = model.GetVector();
Wrappers::Petsc::Vector from_file;
std::vector<PetscInt> ghost_padding;
BOOST_CHECK_EQUAL(vector.GetProcessorWiseSize(__FILE__, __LINE__),
vector.GetProgramWiseSize(__FILE__, __LINE__));
from_file.InitSequentialFromFile(mpi,
ascii_file,
__FILE__, __LINE__);
std::string inequality_description;
Wrappers::Petsc::AreEqual(from_file,
vector,
NumericNS::DefaultEpsilon<double>(),
inequality_description,
__FILE__, __LINE__);
BOOST_CHECK_EQUAL(inequality_description, "");
}
}
BOOST_AUTO_TEST_SUITE_END()
PRAGMA_DIAGNOSTIC(pop)
......
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