MaMiCo
1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
coupling
filtering
filters
WriteToFile.h
1
// This file is part of the Mamico project. For conditions of distribution
2
// and use, please see the copyright notice in Mamico's main folder, or at
3
// www5.in.tum.de/mamico
4
5
#pragma once
6
#include "coupling/filtering/interfaces/FilterInterfaceReadOnly.h"
7
8
#include <fstream>
9
#include <string>
10
#include <vector>
11
12
// #define DEBUG_WRITE_TO_FILE
13
14
namespace
coupling
{
15
namespace
filtering
{
16
template
<
unsigned
int
dim>
class
WriteToFile
;
17
}
18
}
// namespace coupling
19
20
/*
21
* Read-only filter that writes cell data to a specified file in .csv format.
22
*
23
* Output format will be compliant to the usual MaMiCo CSV format (using ';' as
24
* separator). Output order will be:
25
* - current iteration
26
* - scalar cell properties
27
* - vector cell properties
28
*
29
* The output file will either contain data of all or just the final coupling
30
* iteration. Boolean parameter 'overwrite' is true in the latter case. If you
31
* wish to print out just one cell and not the entire input domain, pass to
32
* "oneCellOnly" in constructor the corresponding local, md2macro, noGhost
33
* index.
34
*
35
* @author Felix Maurer
36
*/
37
template
<
unsigned
int
dim>
class
coupling::filtering::WriteToFile
:
public
coupling::filtering::FilterInterfaceReadOnly
<dim> {
38
public
:
39
WriteToFile(
const
std::vector<
coupling::datastructures::CouplingCell<dim>
*>& inputCells,
40
const
std::vector<
coupling::datastructures::CouplingCell<dim>
*>& outputCells,
const
std::array<bool, 7> filteredValues,
41
std::string location,
// output file location
42
bool
overwrite =
false
,
int
oneCellOnly = -1)
43
:
44
45
coupling::filtering::FilterInterfaceReadOnly<dim>
(inputCells, outputCells, filteredValues,
"WTF"
), _location(location), _overwrite(overwrite),
46
_oneCellOnly(oneCellOnly), _iteration(1) {
47
if
(!_overwrite) {
48
_file.open(location);
49
_file.close();
50
}
51
52
#ifdef DEBUG_WRITE_TO_FILE
53
std::cout <<
" WTF: Write to file instance created. Will save to: "
<< _location << std::endl;
54
if
(_overwrite)
55
std::cout <<
" It will only print output of the last iteration."
<< std::endl;
56
if
(_oneCellOnly != -1)
57
std::cout <<
" It will only print data of cell with linear "
58
"sequence domain index "
59
<< _oneCellOnly << std::endl;
60
#endif
61
}
62
63
~WriteToFile() {
64
#ifdef DEBUG_WRITE_TO_FILE
65
std::cout <<
" WTF: Write to file instance deconstructed."
<< std::endl;
66
#endif
67
}
68
69
void
operator()();
70
71
private
:
72
std::string _location;
73
74
// true of only the last iteration should be in file output
75
bool
_overwrite;
76
77
//-1 if all cells should be in file output, holds index of the only cell to be
78
// outputted otherwise
79
int
_oneCellOnly;
// TODO: use CellIndex!
80
81
std::ofstream _file;
82
unsigned
int
_iteration;
83
};
84
85
// include implementation of header
86
#include "WriteToFile.cpph"
coupling::datastructures::CouplingCell
defines the cell type with cell-averaged quantities only (no linked cells).
Definition
CouplingCell.h:29
coupling::filtering::FilterInterfaceReadOnly
Definition
FilterInterfaceReadOnly.h:22
coupling::filtering::WriteToFile
Definition
WriteToFile.h:37
coupling::filtering
Definition
FilterPipeline.h:21
coupling
everything necessary for coupling operations, is defined in here
Definition
AdditiveMomentumInsertion.h:15
Generated by
1.17.0