PLaSK library

Loading...
Searching...
No Matches
hyman.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__MESH_HYMAN_H
15#define PLASK__MESH_HYMAN_H
16
17#include "../math.hpp"
18#include "rectangular2d.hpp"
19#include "rectilinear3d.hpp"
20#include "rectangular3d.hpp"
21#include "equilateral3d.hpp"
22#include "interpolation.hpp"
23
24 namespace plask {
25
26 template <typename T> struct Hyman {
27 static void filter(T& data, const T& a, const T& b) {
28 T lim = 3 * min(abs(a), abs(b));
29 if (data > lim) data = lim;
30 else if (data < -lim) data = -lim;
31 }
32};
33
34 template <> struct Hyman<dcomplex> {
35 static void filter(dcomplex& data, const dcomplex& a, const dcomplex& b) {
36 double re = data.real(), im = data.imag();
37 Hyman<double>::filter(re, real(a), real(b));
38 Hyman<double>::filter(im, imag(a), imag(b));
39 data = dcomplex(re,im);
40 }
41};
42
43 template <typename T> struct Hyman<Vec<2,T>> {
44 static void filter(Vec<2,T>& data, const Vec<2,T>& a, const Vec<2,T>& b) {
45 Hyman<T>::filter(data.c0, a.c0, b.c0);
46 Hyman<T>::filter(data.c1, a.c1, b.c1);
47 }
48};
49
50 template <typename T> struct Hyman<Vec<3,T>> {
51 static void filter(Vec<3,T>& data, const Vec<3,T>& a, const Vec<3,T>& b) {
52 Hyman<T>::filter(data.c0, a.c0, b.c0);
53 Hyman<T>::filter(data.c1, a.c1, b.c1);
54 Hyman<T>::filter(data.c2, a.c2, b.c2);
55 }
56};
57
58 template <typename T> struct Hyman<Tensor2<T>> {
59 static void filter(Tensor2<T>& data, const Tensor2<T>& a, const Tensor2<T>& b) {
60 Hyman<T>::filter(data.c00, a.c00, b.c00);
61 Hyman<T>::filter(data.c11, a.c11, b.c11);
62 }
63};
64
65 template <typename T> struct Hyman<Tensor3<T>> {
66 static void filter(Tensor3<T>& data, const Tensor3<T>& a, const Tensor3<T>& b) {
67 Hyman<T>::filter(data.c00, a.c00, b.c00);
68 Hyman<T>::filter(data.c11, a.c11, b.c11);
69 Hyman<T>::filter(data.c22, a.c22, b.c22);
70 Hyman<T>::filter(data.c01, a.c01, b.c01);
71 }
72};
73
74
75} // namespace plask
76
77#endif // PLASK__MESH_HYMAN_H