MaMiCo 1.2
Loading...
Searching...
No Matches
NLM.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
3
4#pragma once
5
6#include "coupling/filtering/filters/Datastructures.h"
7#include "coupling/filtering/interfaces/JunctorInterface.h"
8#include <array>
9
10namespace coupling {
11namespace filtering {
12template <unsigned int dim, coupling::indexing::IndexTrait... scope> class NLM;
13}
14} // namespace coupling
15
24template <unsigned int dim, coupling::indexing::IndexTrait... scope> class coupling::filtering::NLM : public coupling::filtering::JunctorInterface<dim, 2, 1> {
25public:
26 using CellIndex_T = coupling::indexing::CellIndex<dim, coupling::indexing::IndexTrait::vector, scope..., coupling::indexing::IndexTrait::md2macro,
27 coupling::indexing::IndexTrait::noGhost>;
28
29 NLM(const std::vector<coupling::datastructures::CouplingCell<dim>*> inputCellVector_unfiltered,
30 const std::vector<coupling::datastructures::CouplingCell<dim>*> inputCellVector_prefiltered,
31 const std::vector<coupling::datastructures::CouplingCell<dim>*> outputCellVector, const std::array<bool, 7> filteredValues, int tws, double sigsq,
32 double sigsq_rel, double hsq, double hsq_rel, int M = 2, int d = 1)
33 : coupling::filtering::JunctorInterface<dim, 2, 1>({inputCellVector_unfiltered, inputCellVector_prefiltered}, {outputCellVector}, filteredValues, "NLM"),
34 _timeWindowSize(tws), _M(M), _d(d), _sigsq(sigsq), _sigsq_rel(sigsq_rel), _hsq(hsq), _hsq_rel(hsq_rel), _cycleCounter(0), _t(0),
35 _flowfield(CellIndex_T::numberCellsInDomain, tws), _flowfield_prefiltered(CellIndex_T::numberCellsInDomain, tws),
36 _patchfield(CellIndex_T::numberCellsInDomain - tarch::la::Vector<dim, unsigned int>(2), tws), _innerCellIndices() {
37 // Initialize flowfield
38 for (int t = 0; t < tws; ++t)
39 for (auto idx : CellIndex_T()) {
41 coupling::filtering::Quantities<dim>& q = _flowfield(idxv, t);
42 q[0] = 1;
43 for (unsigned int d = 1; d <= dim; ++d)
44 q[d] = 0;
45 coupling::filtering::Quantities<dim>& qp = _flowfield_prefiltered(idxv, t);
46 qp[0] = 1;
47 for (unsigned int d = 1; d <= dim; ++d)
48 qp[d] = 0;
49 }
50
51 // Initialize innerCellIndices
52 auto domainSize = CellIndex_T::numberCellsInDomain;
53 for (auto idx : CellIndex_T()) {
55 for (unsigned int d = 0; d < dim; d++)
56 if (idxv[d] == 0 || idxv[d] == domainSize[d] - 1)
57 goto continue_loop;
58 _innerCellIndices.push_back(idx);
59 continue_loop:;
60 }
61
62#ifdef NLM_DEBUG
63 std::cout << " NLM: Created NLM instance." << std::endl;
64 std::cout << " WARNING: Regardless of configuration, NLM always filters "
65 "macroscopic mass and momentum."
66 << std::endl;
67#endif
68 }
69
70 virtual ~NLM() {
71#ifdef NLM_DEBUG
72 std::cout << " NLM: Destroyed NLM instance." << std::endl;
73#endif
74 }
75
76 void operator()();
77
78private:
83 void save_data();
84
90
95 void denoise();
96
104 std::vector<tarch::la::Vector<dim, int>> compute_boundary_neighbors(const tarch::la::Vector<dim, unsigned int>&);
105
111
112 const unsigned int _timeWindowSize; // number of snapshots / coupling cycles taken into
113 // consideration for noise reduction
114 // unsigned int _timeModulo; // e.g. 2,4,8 ....
115 const unsigned int _M; // search volume has size (2M+1)^3
116 const unsigned int _d; // patches have size (2d+1)^4; this makes at least _d
117 // ghost layer necessary
118 double _sigsq, _sigsq_rel;
119 double _hsq, _hsq_rel;
120
121 unsigned int _cycleCounter; // coupling cycle counter, indicates how many data
122 // snapshots are available already
123 unsigned int _t; // active temporal index, iterates cyclic between zero and
124 // _timeWindowSize
125 coupling::filtering::Flowfield<dim> _flowfield;
126 coupling::filtering::Flowfield<dim> _flowfield_prefiltered;
127 coupling::filtering::Patchfield<dim> _patchfield;
128 std::vector<CellIndex_T> _innerCellIndices;
129
130 inline unsigned int posmod(int i, int n) const { return (i % n + n) % n; }
131};
132
133// include implementation of header
134#include "NLM.cpph"
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
Definition JunctorInterface.h:29
Definition NLM.h:24
std::vector< tarch::la::Vector< dim, int > > compute_boundary_neighbors(const tarch::la::Vector< dim, unsigned int > &)
Definition CellIndex.h:85
Definition Vector.h:24
Definition FilterPipeline.h:21
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15