OGS
ProcessLib::Assembly::LocalMatrixOutput Struct Reference

Detailed Description

Writes local matrices to disk for debugging purposes.

Definition at line 42 of file MatrixOutput.h.

#include <MatrixOutput.h>

Public Member Functions

 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_b_data, std::vector< double > const *const local_Jac_data=nullptr)
 
 ~LocalMatrixOutput ()
 

Private Member Functions

bool isOutputRequested (std::size_t const element_id) const
 

Private Attributes

std::mutex mutex_
 
std::ofstream outputFile_
 
std::function< bool(std::size_t)> output_element_predicate_
 

Constructor & Destructor Documentation

◆ LocalMatrixOutput()

ProcessLib::Assembly::LocalMatrixOutput::LocalMatrixOutput ( )

Definition at line 234 of file MatrixOutput.cpp.

235{
236 auto const opt_prefix = getEnvironmentVariable("OGS_LOCAL_MAT_OUT_PREFIX");
237 auto const opt_elements =
238 getEnvironmentVariable("OGS_LOCAL_MAT_OUT_ELEMENTS");
239
240 if (!opt_prefix)
241 {
242 if (opt_elements)
243 {
244 WARN(
245 "Environment variable OGS_LOCAL_MAT_OUT_ELEMENTS is set, but "
246 "OGS_LOCAL_MAT_OUT_PREFIX is not. Local matrix debug output "
247 "will be disabled.");
248 }
249
250 return;
251 }
252 if (!opt_elements)
253 {
254 WARN(
255 "Environment variable OGS_LOCAL_MAT_OUT_PREFIX is set, but "
256 "OGS_LOCAL_MAT_OUT_ELEMENTS is not. Local matrix debug output "
257 "will be disabled.");
258 return;
259 }
260
263
265 {
266 WARN(
267 "Environment variable OGS_LOCAL_MAT_OUT_ELEMENTS not set "
268 "properly. Local matrix debug output will be disabled.");
269 return;
270 }
271
272 auto const outputFilename = localMatrixOutputFilename(*opt_prefix);
273 outputFile_.open(outputFilename);
274
275 if (!outputFile_)
276 {
277 OGS_FATAL(
278 "File `{}' for local matrix debug output could not be "
279 "opened.",
280 outputFilename);
281 }
282
283 DBUG("Successfully opened local matrix debug output file {}.",
284 outputFilename);
285}
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::function< bool(std::size_t)> createLocalMatrixOutputElementPredicate(std::string const &element_ids_str)
std::string localMatrixOutputFilename(std::string const &filenamePrefix)
static std::optional< std::string > getEnvironmentVariable(std::string const &env_var)
std::function< bool(std::size_t)> output_element_predicate_

References ProcessLib::Assembly::detail::createLocalMatrixOutputElementPredicate(), DBUG(), OGS_FATAL, output_element_predicate_, outputFile_, and WARN().

◆ ~LocalMatrixOutput()

ProcessLib::Assembly::LocalMatrixOutput::~LocalMatrixOutput ( )
default

Member Function Documentation

◆ isOutputRequested()

bool ProcessLib::Assembly::LocalMatrixOutput::isOutputRequested ( std::size_t const element_id) const
private

Definition at line 334 of file MatrixOutput.cpp.

335{
337}

References output_element_predicate_.

Referenced by operator()().

◆ operator()()

void ProcessLib::Assembly::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 = nullptr )

Definition at line 287 of file MatrixOutput.cpp.

293{
294 [[likely]] if (!isOutputRequested(element_id))
295 {
296 return;
297 }
298
299 std::lock_guard lock_guard{mutex_};
300
301 auto& fh = outputFile_;
302
303 DBUG("Writing to local matrix debug output file...");
304
305 fmt::print(fh, "## t = {:.15g}, process id = {}, element id = {}\n\n", t,
306 process_id, element_id);
307
308 if (!local_M_data.empty())
309 {
310 DBUG("... M");
311 fmt::print(fh, "# M\n{}\n\n", toSquareMatrixRowMajor(local_M_data));
312 }
313
314 if (!local_K_data.empty())
315 {
316 DBUG("... K");
317 fmt::print(fh, "# K\n{}\n\n", toSquareMatrixRowMajor(local_K_data));
318 }
319
320 if (!local_b_data.empty())
321 {
322 DBUG("... b");
323 fmt::print(fh, "# b\n{}\n\n", MathLib::toVector(local_b_data));
324 }
325
326 if (local_Jac_data && !local_Jac_data->empty())
327 {
328 DBUG("... Jac");
329 fmt::print(fh, "# Jac\n{}\n\n\n",
330 toSquareMatrixRowMajor(*local_Jac_data));
331 }
332}
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
Eigen::Map< const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > toSquareMatrixRowMajor(std::vector< double > entries)
bool isOutputRequested(std::size_t const element_id) const

References DBUG(), isOutputRequested(), mutex_, outputFile_, and MathLib::toVector().

Member Data Documentation

◆ mutex_

std::mutex ProcessLib::Assembly::LocalMatrixOutput::mutex_
private

Definition at line 58 of file MatrixOutput.h.

Referenced by operator()().

◆ output_element_predicate_

std::function<bool(std::size_t)> ProcessLib::Assembly::LocalMatrixOutput::output_element_predicate_
private

Definition at line 60 of file MatrixOutput.h.

Referenced by LocalMatrixOutput(), and isOutputRequested().

◆ outputFile_

std::ofstream ProcessLib::Assembly::LocalMatrixOutput::outputFile_
private

Definition at line 59 of file MatrixOutput.h.

Referenced by LocalMatrixOutput(), and operator()().


The documentation for this struct was generated from the following files: