From 3e9a70cd397af307a97011096814bcc3e4deae2a Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Wed, 17 Jul 2024 23:20:13 +0200 Subject: [PATCH] [PL] Separate matrix output for M,K,b and J,b A little code duplication in favor not to deal with pointers. --- ProcessLib/Assembly/MatrixOutput.cpp | 49 ++++++++++++++----- ProcessLib/Assembly/MatrixOutput.h | 10 ++-- .../ParallelVectorMatrixAssembler.cpp | 8 +-- ProcessLib/VectorMatrixAssembler.cpp | 5 +- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/ProcessLib/Assembly/MatrixOutput.cpp b/ProcessLib/Assembly/MatrixOutput.cpp index 6e01624cd83..56ed505c69f 100644 --- a/ProcessLib/Assembly/MatrixOutput.cpp +++ b/ProcessLib/Assembly/MatrixOutput.cpp @@ -286,12 +286,11 @@ LocalMatrixOutput::LocalMatrixOutput() outputFilename); } -void LocalMatrixOutput::operator()( - double const t, int const process_id, std::size_t const element_id, - std::vector const* local_M_data, - std::vector const* local_K_data, - std::vector const& local_b_data, - std::vector const* const local_Jac_data) +void LocalMatrixOutput::operator()(double const t, int const process_id, + std::size_t const element_id, + std::vector const& local_M_data, + std::vector const& local_K_data, + std::vector const& local_b_data) { [[likely]] if (!isOutputRequested(element_id)) { @@ -307,16 +306,16 @@ void LocalMatrixOutput::operator()( fmt::print(fh, "## t = {:.15g}, process id = {}, element id = {}\n\n", t, process_id, element_id); - if (local_M_data && !local_M_data->empty()) + if (!local_M_data.empty()) { DBUG("... M"); - fmt::print(fh, "# M\n{}\n\n", toSquareMatrixRowMajor(*local_M_data)); + fmt::print(fh, "# M\n{}\n\n", toSquareMatrixRowMajor(local_M_data)); } - if (local_K_data && !local_K_data->empty()) + if (!local_K_data.empty()) { DBUG("... K"); - fmt::print(fh, "# K\n{}\n\n", toSquareMatrixRowMajor(*local_K_data)); + fmt::print(fh, "# K\n{}\n\n", toSquareMatrixRowMajor(local_K_data)); } if (!local_b_data.empty()) @@ -324,12 +323,38 @@ void LocalMatrixOutput::operator()( DBUG("... b"); fmt::print(fh, "# b\n{}\n\n", MathLib::toVector(local_b_data)); } +} + +void LocalMatrixOutput::operator()(double const t, int const process_id, + std::size_t const element_id, + std::vector const& local_b_data, + std::vector const& local_Jac_data) +{ + [[likely]] if (!isOutputRequested(element_id)) + { + return; + } + + std::lock_guard lock_guard{mutex_}; + + auto& fh = outputFile_; + + DBUG("Writing to local matrix debug output file..."); + + fmt::print(fh, "## t = {:.15g}, process id = {}, element id = {}\n\n", t, + process_id, element_id); + + if (!local_b_data.empty()) + { + DBUG("... b"); + fmt::print(fh, "# b\n{}\n\n", MathLib::toVector(local_b_data)); + } - if (local_Jac_data && !local_Jac_data->empty()) + if (!local_Jac_data.empty()) { DBUG("... Jac"); fmt::print(fh, "# Jac\n{}\n\n\n", - toSquareMatrixRowMajor(*local_Jac_data)); + toSquareMatrixRowMajor(local_Jac_data)); } } diff --git a/ProcessLib/Assembly/MatrixOutput.h b/ProcessLib/Assembly/MatrixOutput.h index aee4e411932..2b3d285f7b1 100644 --- a/ProcessLib/Assembly/MatrixOutput.h +++ b/ProcessLib/Assembly/MatrixOutput.h @@ -45,10 +45,14 @@ struct LocalMatrixOutput void operator()(double const t, int const process_id, std::size_t const element_id, - std::vector const* local_M_data, - std::vector const* local_K_data, + std::vector const& local_M_data, + std::vector const& local_K_data, + std::vector const& local_b_data); + + void operator()(double const t, int const process_id, + std::size_t const element_id, std::vector const& local_b_data, - std::vector const* const local_Jac_data = nullptr); + std::vector const& local_Jac_data); ~LocalMatrixOutput(); diff --git a/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp b/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp index ee4d4f94b8f..e799f5153ce 100644 --- a/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp +++ b/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp @@ -205,8 +205,8 @@ void ParallelVectorMatrixAssembler::assembleWithJacobian( continue; } - local_matrix_output_(t, process_id, element_id, nullptr, - nullptr, local_b_data, &local_Jac_data); + local_matrix_output_(t, process_id, element_id, local_b_data, + local_Jac_data); } } else @@ -241,8 +241,8 @@ void ParallelVectorMatrixAssembler::assembleWithJacobian( continue; } - local_matrix_output_(t, process_id, element_id, nullptr, - nullptr, local_b_data, &local_Jac_data); + local_matrix_output_(t, process_id, element_id, local_b_data, + local_Jac_data); } } } // OpenMP parallel section diff --git a/ProcessLib/VectorMatrixAssembler.cpp b/ProcessLib/VectorMatrixAssembler.cpp index 35e00a85b33..815a32159b2 100644 --- a/ProcessLib/VectorMatrixAssembler.cpp +++ b/ProcessLib/VectorMatrixAssembler.cpp @@ -99,7 +99,7 @@ void VectorMatrixAssembler::assemble( b->add(indices, _local_b_data); } - _local_output(t, process_id, mesh_item_id, &_local_M_data, &_local_K_data, + _local_output(t, process_id, mesh_item_id, _local_M_data, _local_K_data, _local_b_data); } @@ -169,8 +169,7 @@ void VectorMatrixAssembler::assembleWithJacobian( "errors in the local assembler of the current process."); } - _local_output(t, process_id, mesh_item_id, nullptr, nullptr, _local_b_data, - &_local_Jac_data); + _local_output(t, process_id, mesh_item_id, _local_b_data, _local_Jac_data); } } // namespace ProcessLib