Skip to content

Commit

Permalink
[PL] Separate matrix output for M,K,b and J,b
Browse files Browse the repository at this point in the history
A little code duplication in favor not to deal with pointers.
  • Loading branch information
endJunction committed Jul 17, 2024
1 parent b0cfd47 commit 3e9a70c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
49 changes: 37 additions & 12 deletions ProcessLib/Assembly/MatrixOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> const* local_M_data,
std::vector<double> const* local_K_data,
std::vector<double> const& local_b_data,
std::vector<double> const* const local_Jac_data)
void LocalMatrixOutput::operator()(double const t, int const process_id,
std::size_t const element_id,
std::vector<double> const& local_M_data,
std::vector<double> const& local_K_data,
std::vector<double> const& local_b_data)
{
[[likely]] if (!isOutputRequested(element_id))
{
Expand All @@ -307,29 +306,55 @@ 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())
{
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<double> const& local_b_data,
std::vector<double> 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));
}
}

Expand Down
10 changes: 7 additions & 3 deletions ProcessLib/Assembly/MatrixOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ struct LocalMatrixOutput

void operator()(double const t, int const process_id,
std::size_t const element_id,
std::vector<double> const* local_M_data,
std::vector<double> const* local_K_data,
std::vector<double> const& local_M_data,
std::vector<double> const& local_K_data,
std::vector<double> const& local_b_data);

void operator()(double const t, int const process_id,
std::size_t const element_id,
std::vector<double> const& local_b_data,
std::vector<double> const* const local_Jac_data = nullptr);
std::vector<double> const& local_Jac_data);

~LocalMatrixOutput();

Expand Down
8 changes: 4 additions & 4 deletions ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions ProcessLib/VectorMatrixAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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

0 comments on commit 3e9a70c

Please sign in to comment.