OGS
ProcessLib::Assembly::LocalMatrixOutput Struct Reference

Detailed Description

Writes local matrices to disk for debugging purposes.

Definition at line 44 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)
 
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 &local_Jac_data)
 
 ~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 261 of file MatrixOutput.cpp.

262{
263 auto const opt_prefix = getEnvironmentVariable("OGS_LOCAL_MAT_OUT_PREFIX");
264 auto const opt_elements =
265 getEnvironmentVariable("OGS_LOCAL_MAT_OUT_ELEMENTS");
266
267 if (!opt_prefix)
268 {
269 if (opt_elements)
270 {
271 WARN(
272 "Environment variable OGS_LOCAL_MAT_OUT_ELEMENTS is set, but "
273 "OGS_LOCAL_MAT_OUT_PREFIX is not. Local matrix debug output "
274 "will be disabled.");
275 }
276
277 return;
278 }
279 if (!opt_elements)
280 {
281 WARN(
282 "Environment variable OGS_LOCAL_MAT_OUT_PREFIX is set, but "
283 "OGS_LOCAL_MAT_OUT_ELEMENTS is not. Local matrix debug output "
284 "will be disabled.");
285 return;
286 }
287
290
292 {
293 WARN(
294 "Environment variable OGS_LOCAL_MAT_OUT_ELEMENTS not set "
295 "properly. Local matrix debug output will be disabled.");
296 return;
297 }
298
299 auto const outputFilename = localMatrixOutputFilename(*opt_prefix);
300 outputFile_.open(outputFilename);
301
302 if (!outputFile_)
303 {
304 OGS_FATAL(
305 "File `{}' for local matrix debug output could not be "
306 "opened.",
307 outputFilename);
308 }
309
310 DBUG("Successfully opened local matrix debug output file {}.",
311 outputFilename);
312}
#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 388 of file MatrixOutput.cpp.

389{
391}

References output_element_predicate_.

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

◆ operator()() [1/2]

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

Definition at line 354 of file MatrixOutput.cpp.

358{
359 [[likely]] if (!isOutputRequested(element_id))
360 {
361 return;
362 }
363
364 std::lock_guard lock_guard{mutex_};
365
366 auto& fh = outputFile_;
367
368 DBUG("Writing to local matrix debug output file...");
369
370 fmt::print(fh, "## t = {:.{}g}, process id = {}, element id = {}\n\n", t,
371 std::numeric_limits<double>::max_digits10, process_id,
372 element_id);
373
374 if (!local_b_data.empty())
375 {
376 DBUG("... b");
377 fmt::print(fh, "# b\n{}\n\n", MathLib::toVector(local_b_data));
378 }
379
380 if (!local_Jac_data.empty())
381 {
382 DBUG("... Jac");
383 fmt::print(fh, "# Jac\n{}\n\n\n",
384 toSquareMatrixRowMajor(local_Jac_data));
385 }
386}
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().

◆ operator()() [2/2]

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 )

Definition at line 314 of file MatrixOutput.cpp.

319{
320 [[likely]] if (!isOutputRequested(element_id))
321 {
322 return;
323 }
324
325 std::lock_guard lock_guard{mutex_};
326
327 auto& fh = outputFile_;
328
329 DBUG("Writing to local matrix debug output file...");
330
331 fmt::print(fh, "## t = {:.{}g}, process id = {}, element id = {}\n\n", t,
332 std::numeric_limits<double>::max_digits10, process_id,
333 element_id);
334
335 if (!local_M_data.empty())
336 {
337 DBUG("... M");
338 fmt::print(fh, "# M\n{}\n\n", toSquareMatrixRowMajor(local_M_data));
339 }
340
341 if (!local_K_data.empty())
342 {
343 DBUG("... K");
344 fmt::print(fh, "# K\n{}\n\n", toSquareMatrixRowMajor(local_K_data));
345 }
346
347 if (!local_b_data.empty())
348 {
349 DBUG("... b");
350 fmt::print(fh, "# b\n{}\n\n", MathLib::toVector(local_b_data));
351 }
352}

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

Member Data Documentation

◆ mutex_

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

Definition at line 64 of file MatrixOutput.h.

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

◆ output_element_predicate_

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

Definition at line 66 of file MatrixOutput.h.

Referenced by LocalMatrixOutput(), and isOutputRequested().

◆ outputFile_

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

Definition at line 65 of file MatrixOutput.h.

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


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