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

#902 Add safety whenever MatAXPY is called to check whether same non zero...

#902 Add safety whenever MatAXPY is called to check whether same non zero pattern might be used. The default value has been disabled: this parameter is way too important to be hidden.
parent bad953ff
......@@ -1125,6 +1125,11 @@ Petsc2 = {
-- Constraint: v > 0.
relativeTolerance = 1.e-4,
-- Step size tolerance
-- Expected format: {VALUE1, VALUE2, ...}
-- Constraint: v > 0.
stepSizeTolerance = 1e-8,
-- List of solver: { chebychev cg gmres preonly bicg python };
-- Expected format: {"VALUE1", "VALUE2", ...}
-- Constraint: ops_in(v, {'Mumps', 'Umfpack', 'Gmres'})
......
......@@ -105,6 +105,16 @@ namespace HappyHeart
ExceptionNS::PrintAndAbort(mpi, e.what());
}
}
void AssertSameNumberingSubset(const GlobalMatrix& matrix1,
const GlobalMatrix& matrix2)
{
assert(matrix1.GetRowNumberingSubset() == matrix2.GetRowNumberingSubset());
assert(matrix1.GetColNumberingSubset() == matrix2.GetColNumberingSubset());
}
#endif // NDEBUG
......
......@@ -132,6 +132,18 @@ namespace HappyHeart
const GlobalMatrix& matrix,
const Wrappers::Petsc::MatrixPattern& pattern,
const char* invoking_file, int invoking_line);
/*!
* \brief Assert two matrices share the same \a NumberingSubset.
*
* \param[in] matrix1 First matrix.
* \param[in] matrix2 Second matrix.
*/
void AssertSameNumberingSubset(const GlobalMatrix& matrix1,
const GlobalMatrix& matrix2);
# endif // NDEBUG
......
......@@ -148,7 +148,7 @@ namespace HappyHeart
//! Comparison use the underlying id.
bool operator<(const NumberingSubset& lhs, const NumberingSubset& rhs);
///@} // \addtogroup
......
......@@ -1120,12 +1120,12 @@ namespace HappyHeart
decltype(auto) pattern = god_of_dof.GetMatrixPattern(matrix.GetRowNumberingSubset(),
matrix.GetColNumberingSubset());
# ifndef NDEBUG
# ifndef NDEBUG
AssertMatrixRespectPattern(god_of_dof.MpiHappyHeart(),
matrix,
pattern,
invoking_file, invoking_line);
# endif // NDEBUG
# endif // NDEBUG
static_cast<void>(god_of_dof);
static_cast<void>(matrix);
......
......@@ -38,7 +38,6 @@ namespace HappyHeart
Wrappers::Petsc::AXPY(factor_, dof_source_, rhs, __FILE__, __LINE__);
}
} //namespace DofSourcePolicyNS
......
......@@ -142,7 +142,9 @@ namespace HappyHeart
unsigned int GeometricMeshRegion::Read(const std::string& mesh_file, Internal::MeshNS::FormatNS::Type format, const double space_unit)
unsigned int GeometricMeshRegion::Read(const std::string& mesh_file,
Internal::MeshNS::FormatNS::Type format,
const double space_unit)
{
GeometricElt::vector_shared_ptr unsort_element_list;
......
......@@ -215,7 +215,12 @@ namespace HappyHeart
system_matrix.Copy(mass_matrix, __FILE__, __LINE__);
const double theta = GetTheta();
Wrappers::Petsc::AXPY(theta, stiffness_matrix, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(stiffness_matrix, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, theta, stiffness_matrix, system_matrix, __FILE__, __LINE__);
}
......
......@@ -337,13 +337,18 @@ namespace HappyHeart
const auto& matrix_bidomain = GetMatrixBidomain();
const auto& matrix_capacity = GetMatrixCapacityPerTimeStep();
Wrappers::Petsc::AXPY(1., matrix_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(1., matrix_capacity, system_matrix, __FILE__, __LINE__);
// Test on the inversibility of the system matrix by adding a mass matrix on Ue.
auto& mass_matrix = GetMatrixExtracellularPotentialCapacity();
Wrappers::Petsc::AXPY(1.e-06, mass_matrix, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(system_matrix, matrix_bidomain);
AssertSameNumberingSubset(system_matrix, matrix_capacity);
AssertSameNumberingSubset(system_matrix, mass_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_capacity, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.e-06, mass_matrix, system_matrix, __FILE__, __LINE__);
}
......
......@@ -352,9 +352,14 @@ namespace HappyHeart
const auto& matrix_bidomain = GetMatrixBidomain();
const auto& matrix_capacity = GetMatrixCapacityPerTimeStep();
Wrappers::Petsc::AXPY(1., matrix_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(1., matrix_capacity, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(system_matrix, matrix_bidomain);
AssertSameNumberingSubset(system_matrix, matrix_capacity);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_capacity, system_matrix, __FILE__, __LINE__);
}
......@@ -390,7 +395,7 @@ namespace HappyHeart
rhs.ZeroEntries(__FILE__, __LINE__);
Wrappers::Petsc::AXPY(1., GetVectorTranscellularIonSource(), rhs, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., GetVectorTranscellularIonSource(), rhs, __FILE__, __LINE__);
}
......@@ -407,7 +412,7 @@ namespace HappyHeart
if (time > time_init && time < time_final)
{
Wrappers::Petsc::AXPY(1., GetVectorTranscellularCurrentAppliedOnLeftVentricle(), rhs, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., GetVectorTranscellularCurrentAppliedOnLeftVentricle(), rhs, __FILE__, __LINE__);
}
}
......@@ -421,7 +426,7 @@ namespace HappyHeart
if (time > time_init && time < time_final)
{
Wrappers::Petsc::AXPY(1., GetVectorTranscellularCurrentAppliedOnRightVentricle(), rhs, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., GetVectorTranscellularCurrentAppliedOnRightVentricle(), rhs, __FILE__, __LINE__);
}
}
}
......@@ -461,7 +466,7 @@ namespace HappyHeart
auto& vector_of_one = GetNonCstVectorOfOneOnExtracellularPotential();
Wrappers::Petsc::AXPY(-mean, vector_of_one, system_solution, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -mean, vector_of_one, system_solution, __FILE__, __LINE__);
}
......
......@@ -692,12 +692,17 @@ namespace HappyHeart
{
coefficient = 0.5;
Wrappers::Petsc::AXPY(1.,
#ifndef NDEBUG
AssertSameNumberingSubset(GetMatrixTangentStiffness(), system_matrix);
AssertSameNumberingSubset(GetMatrixMassPerSquareTimeStep(), system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.,
GetMatrixMassPerSquareTimeStep(),
system_matrix, __FILE__, __LINE__);
}
Wrappers::Petsc::AXPY(coefficient,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, coefficient,
GetMatrixTangentStiffness(),
system_matrix, __FILE__, __LINE__);
......@@ -705,7 +710,11 @@ namespace HappyHeart
if (run_case == StaticOrDynamic::static_)
{
Wrappers::Petsc::AXPY(coefficient,
#ifndef NDEBUG
AssertSameNumberingSubset(GetMatrixTangentFollowingPressure(), system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, coefficient,
GetMatrixTangentFollowingPressure(),
system_matrix, __FILE__, __LINE__);
}
......
......@@ -190,7 +190,11 @@ namespace HappyHeart
const auto coefficient =
2. * GetVolumicMass().GetConstantValue() / NumericNS::Square(parent::GetTimeManager().GetTimeStep());
Wrappers::Petsc::AXPY(coefficient,
#ifndef NDEBUG
AssertSameNumberingSubset(mass, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, coefficient,
mass,
system_matrix,
__FILE__, __LINE__);
......@@ -206,7 +210,11 @@ namespace HappyHeart
displacement_previous_time_iteration_matrix.Scale(coefficient, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(-.5,
#ifndef NDEBUG
AssertSameNumberingSubset(stiffness, displacement_previous_time_iteration_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -.5,
stiffness,
displacement_previous_time_iteration_matrix,
__FILE__, __LINE__);
......
......@@ -215,7 +215,11 @@ namespace HappyHeart
GetFluidDensity().GetConstantValue() / time_step);
GetMass().Assemble(std::make_tuple(std::ref(matrix)));
Wrappers::Petsc::AXPY(1., mass_fluid_velocity, residual_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(residual_matrix, mass_fluid_velocity);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., mass_fluid_velocity, residual_matrix, __FILE__, __LINE__);
}
......
......@@ -121,7 +121,11 @@ namespace HappyHeart
const auto coefficient =
2. * GetVolumicMass().GetConstantValue() / NumericNS::Square(parent::GetTimeManager().GetTimeStep());
Wrappers::Petsc::AXPY(coefficient,
#ifndef NDEBUG
AssertSameNumberingSubset(mass, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, coefficient,
mass,
system_matrix,
__FILE__, __LINE__);
......@@ -137,7 +141,11 @@ namespace HappyHeart
displacement_previous_time_iteration_matrix.Scale(coefficient, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(-.5,
#ifndef NDEBUG
AssertSameNumberingSubset(stiffness, displacement_previous_time_iteration_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -.5,
stiffness,
displacement_previous_time_iteration_matrix,
__FILE__, __LINE__);
......
......@@ -235,7 +235,10 @@ namespace HappyHeart
GetConductivityOperator().Assemble(std::make_tuple(std::ref(matrix)));
}
Wrappers::Petsc::AXPY(1., GetMatrixRobin(), system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(GetMatrixRobin(), system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., GetMatrixRobin(), system_matrix, __FILE__, __LINE__);
}
......@@ -319,8 +322,11 @@ namespace HappyHeart
const GlobalMatrix& capacity_matrix = GetMatrixCapacityPerTimeStep();
{
// System matrix.
Wrappers::Petsc::AXPY(1.,
#ifndef NDEBUG
AssertSameNumberingSubset(capacity_matrix, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.,
capacity_matrix,
system_matrix,
__FILE__, __LINE__);
......
......@@ -30,7 +30,6 @@ namespace HappyHeart
{
static_cast<void>(is_dynamic_iteration);
static_cast<void>(vm);
}
......@@ -62,11 +61,18 @@ namespace HappyHeart
void ComputeDynamicTimeSchemeTangentContribution(const VectorsAndMatrices<HyperelasticityNS::TimeScheme::half_sum>& vm,
GlobalMatrix& system_matrix)
{
Wrappers::Petsc::AXPY(0.5,
#ifndef NDEBUG
AssertSameNumberingSubset(system_matrix, vm.GetMatrixNewStiffness());
AssertSameNumberingSubset(system_matrix, vm.GetMatrixStiffnessPreviousTimeIteration());
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN,
0.5,
vm.GetMatrixNewStiffness(),
system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(0.5,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN,
0.5,
vm.GetMatrixStiffnessPreviousTimeIteration(),
system_matrix, __FILE__, __LINE__);
}
......
......@@ -65,9 +65,13 @@ namespace HappyHeart
void ComputeDynamicTimeSchemeTangentContribution(const VectorsAndMatrices<HyperelasticityNS::TimeScheme::midpoint>& vm,
GlobalMatrix& system_matrix)
GlobalMatrix& system_matrix)
{
Wrappers::Petsc::AXPY(0.5,
#ifndef NDEBUG
AssertSameNumberingSubset(vm.GetMatrixNewStiffness(), system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 0.5,
vm.GetMatrixNewStiffness(),
system_matrix, __FILE__, __LINE__);
}
......
......@@ -181,7 +181,10 @@ namespace HappyHeart
GetFluidDensity().GetConstantValue() / time_step);
GetMass().Assemble(std::make_tuple(std::ref(matrix)));
Wrappers::Petsc::AXPY(1., mass_fluid_velocity, residual_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(mass_fluid_velocity, residual_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., mass_fluid_velocity, residual_matrix, __FILE__, __LINE__);
}
......@@ -226,7 +229,7 @@ namespace HappyHeart
residual,
__FILE__, __LINE__);
Wrappers::Petsc::AXPY(-1., GetResidualRhs(), residual,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -1., GetResidualRhs(), residual,
__FILE__, __LINE__);
return residual;
......
......@@ -120,7 +120,12 @@ namespace HappyHeart
const auto coefficient =
2. * GetVolumicMass().GetConstantValue() / NumericNS::Square(parent::GetTimeManager().GetTimeStep());
Wrappers::Petsc::AXPY(coefficient,
#ifndef NDEBUG
AssertSameNumberingSubset(system_matrix, mass);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN,
coefficient,
mass,
system_matrix,
__FILE__, __LINE__);
......@@ -136,7 +141,12 @@ namespace HappyHeart
displacement_previous_time_iteration_matrix.Scale(coefficient, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(-.5,
#ifndef NDEBUG
AssertSameNumberingSubset(stiffness, displacement_previous_time_iteration_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN,
-.5,
stiffness,
displacement_previous_time_iteration_matrix,
__FILE__, __LINE__);
......@@ -201,12 +211,12 @@ namespace HappyHeart
const double factor = 2. / parent::GetTimeManager().GetTimeStep();
Wrappers::Petsc::AXPY(factor,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, factor,
newest_displacement,
velocity_prev_time_it,
__FILE__, __LINE__);
Wrappers::Petsc::AXPY(-factor,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -factor,
former_displacement,
velocity_prev_time_it,
__FILE__, __LINE__);
......
......@@ -259,7 +259,11 @@ namespace HappyHeart
auto& system_matrix = this->GetNonCstSystemMatrix(numbering_subset, numbering_subset);
const auto& capacity_matrix = GetMatrixCapacityPerTimeStep();
Wrappers::Petsc::AXPY(1., capacity_matrix, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(capacity_matrix, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., capacity_matrix, system_matrix, __FILE__, __LINE__);
}
......
......@@ -259,11 +259,16 @@ namespace HappyHeart
auto& system_matrix = GetNonCstSystemMatrix(numbering_subset, numbering_subset);
system_matrix.ZeroEntries(__FILE__, __LINE__);
Wrappers::Petsc::AXPY(1.,
#ifndef NDEBUG
AssertSameNumberingSubset(GetMatrixTangentStiffness(), system_matrix);
AssertSameNumberingSubset(GetMatrixTangentFollowingPressure(), system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.,
GetMatrixTangentStiffness(),
system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(1.,
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.,
GetMatrixTangentFollowingPressure(),
system_matrix, __FILE__, __LINE__);
......
......@@ -318,14 +318,20 @@ namespace HappyHeart
const auto& matrix_surfacic_bidomain = GetMatrixSurfacicBidomain();
const auto& matrix_capacity = GetMatrixCapacityPerTimeStep();
Wrappers::Petsc::AXPY(1., matrix_surfacic_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(1., matrix_capacity, system_matrix, __FILE__, __LINE__);
// Test on the inversibility of the system matrix by adding a mass matrix on Ue.
auto& mass_matrix = GetMatrixExtracellularPotentialCapacity();
Wrappers::Petsc::AXPY(1.e-06, mass_matrix, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(system_matrix, matrix_surfacic_bidomain);
AssertSameNumberingSubset(system_matrix, matrix_capacity);
AssertSameNumberingSubset(system_matrix, mass_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_surfacic_bidomain, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1., matrix_capacity, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, 1.e-06, mass_matrix, system_matrix, __FILE__, __LINE__);
}
......
......@@ -132,7 +132,12 @@ namespace HappyHeart
GetMassOperator().Assemble(std::make_tuple(std::ref(with_coeff_matrix)));
system_matrix.Copy(mass_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(-1., mass_matrix_prev, system_matrix, __FILE__, __LINE__);
#ifndef NDEBUG
AssertSameNumberingSubset(mass_matrix_prev, system_matrix);
#endif // NDEBUG
Wrappers::Petsc::AXPY(SAME_NONZERO_PATTERN, -1., mass_matrix_prev, system_matrix, __FILE__, __LINE__);
}
......@@ -152,6 +157,7 @@ namespace HappyHeart
modified_velocity_previous_iteration.Copy(velocity_previous_time_iteration, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(-1.,
solid_on_fluid_mesh.GetHalfSumVelocity(),
modified_velocity_previous_iteration,
......
......@@ -8,6 +8,8 @@
// Copyright © 2016 Inria. All rights reserved.
//
#include "ThirdParty/Wrappers/Petsc/Matrix/MatrixInfo.hpp"
#include "ModelInstances/UnderDevelopment/Poromechanics/ImplicitStepFluidVariationalFormulation.hpp"
#include "FiniteElement/FiniteElementSpace/GodOfDofManager.hpp" // \todo #820 For DEV only!
......@@ -151,6 +153,9 @@ namespace HappyHeart
__FILE__, __LINE__,
do_reuse_matrix);
Wrappers::Petsc::MatrixInfo("T11 in monolithic", t11_in_monolithic, __FILE__, __LINE__);
// Wrappers::Petsc::PtAP(fluid_mass_matrix_on_solid_mesh,
// GetInterpMassSolid2Fluid().GetInterpolationMatrix(),
// foo,
......@@ -172,8 +177,32 @@ namespace HappyHeart
parent::GetOutputDirectory(numbering_subset) + "/monolithic_T11_" + std::to_string(time_manager.NtimeModified()) + ".hhdata",
__FILE__, __LINE__);
t11_in_monolithic.Assembly(__FILE__, __LINE__);
// \todo #902 TMP!
system_matrix.ZeroEntries(__FILE__, __LINE__);
Wrappers::Petsc::MatrixInfo("System matrix", system_matrix, __FILE__, __LINE__);
// And now add t11 to system matrix.
Wrappers::Petsc::AXPY(1., t11_in_monolithic, system_matrix, __FILE__, __LINE__);
Wrappers::Petsc::AXPY(SUBSET_NONZERO_PATTERN,
1.,
t11_in_monolithic,
system_matrix, __FILE__,
__LINE__);
system_matrix.Assembly(__FILE__, __LINE__);
Wrappers::Petsc::MatrixInfo("System matrix after AXPY", system_matrix, __FILE__, __LINE__);
std::cout << "WRITE " << parent::GetOutputDirectory(numbering_subset) + "/system_matrix_after_T11_" + std::to_string(time_manager.NtimeModified()) + ".hhdata" << std::endl;
system_matrix.View(parent::MpiHappyHeart(),
parent::GetOutputDirectory(numbering_subset) + "/system_matrix_after_T11_" + std::to_string(time_manager.NtimeModified()) + ".hhdata",
__FILE__, __LINE__);
}
......