KASKADE 7 development version
Loading...
Searching...
No Matches
bddcRestrictionCapture.hh
Go to the documentation of this file.
1#ifndef KASKADE_BDDC_RESTRICTION_CAPTURE_HH
2#define KASKADE_BDDC_RESTRICTION_CAPTURE_HH
3
4#include <cstdint>
5#include <cstdlib>
6#include <filesystem>
7#include <fstream>
8#include <iomanip>
9#include <stdexcept>
10#include <string>
11
12namespace Kaskade::BDDC {
19template<int components, class Values, class Excluded, class Interfaces>
20void captureRestrictionBuffer(int subdomain, std::uint64_t& invocation,
21 Values const& values, Excluded const& excluded,
22 Interfaces const& interfaces)
23{
24 char const* directory = std::getenv("KASKADE_RESTRICTION_CAPTURE");
25 if (!directory || !*directory) return;
26 ++invocation;
27 if (invocation > 32 && invocation != 50 && invocation != 100 &&
28 invocation != 200 && invocation != 300) return;
29 namespace fs = std::filesystem;
30 fs::path root(directory);
31 fs::create_directories(root);
32 auto openNew = [&](std::string const& suffix) {
33 fs::path path = root / ("sub" + std::to_string(subdomain) + suffix + ".csv");
34 if (fs::exists(path))
35 throw std::runtime_error("Restriction capture refuses to overwrite " + path.string());
36 std::ofstream out(path);
37 out.exceptions(std::ios::failbit | std::ios::badbit);
38 out << std::setprecision(17);
39 return out;
40 };
41 if (invocation == 1)
42 {
43 auto topology = openNew("-topology");
44 topology << "neighbor,index,excluded\n";
45 for (auto const& [neighbor, indices] : interfaces)
46 for (auto i : indices)
47 topology << neighbor << ',' << i << ','
48 << (!excluded.empty() && excluded[i] ? 1 : 0) << '\n';
49 }
50 auto out = openNew("-call" + std::to_string(invocation));
51 out << "index,component,excluded,value\n";
52 for (std::size_t i=0; i<values.size(); ++i)
53 for (int j=0; j<components; ++j)
54 out << i << ',' << j << ',' << (!excluded.empty() && excluded[i] ? 1 : 0)
55 << ',' << values[i][j] << '\n';
56}
57}
58#endif
std::vector< std::pair< int, std::vector< int > > > Interfaces
A data structure describing the interfaces of a subdomain.
void captureRestrictionBuffer(int subdomain, std::uint64_t &invocation, Values const &values, Excluded const &excluded, Interfaces const &interfaces)