-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent.h
129 lines (97 loc) · 3.34 KB
/
current.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef CURRENT_H_
#define CURRENT_H_
#include "zpic.h"
#include "vec3grid.h"
#include "moving_window.h"
#include "filter.h"
namespace current {
namespace bc {
enum type { none = 0, periodic, reflecting };
}
typedef bnd<bc::type> bc_type;
}
class Current {
private:
/// @brief Associated sycl queue
sycl::queue & q;
/// @brief Simulation box size
float2 box;
/// @brief cell size
float2 dx;
/// @brief time step
float dt;
/// @brief Moving window information
MovingWindow moving_window;
/// @brief Boundary condition
current::bc_type bc;
/// @brief Iteration number
int iter;
/**
* @brief Process boundary conditions
*
*/
void process_bc();
public:
/// @brief Current density
vec3grid<float3> * J;
/// @brief Filtering parameters
Filter::Digital *filter;
Current( uint2 const ntiles, uint2 const nx, float2 const box, float const dt, sycl::queue & q );
~Current() {
delete (J);
delete (filter);
}
current::bc_type get_bc( ) { return bc; }
void set_bc( current::bc_type new_bc ) {
// Validate parameters
if ( (new_bc.x.lower == current::bc::periodic) || (new_bc.x.upper == current::bc::periodic) ) {
if ( new_bc.x.lower != new_bc.x.upper ) {
std::cerr << "(*error*) Current boundary type mismatch along x.\n";
std::cerr << "(*error*) When choosing periodic boundaries both lower and upper types must be set to current::bc::periodic.\n";
exit(1);
}
}
if ( (new_bc.y.lower == current::bc::periodic) || (new_bc.y.upper == current::bc::periodic) ) {
if ( new_bc.y.lower != new_bc.y.upper ) {
std::cerr << "(*error*) Current boundary type mismatch along y.\n";
std::cerr << "(*error*) When choosing periodic boundaries both lower and upper types must be set to emf::bc::periodic.\n";
exit(1);
}
}
// Store new values
bc = new_bc;
std::string bc_name[] = {"none", "periodic", "reflecting"};
std::cout << "(*info*) Current boundary conditions\n";
std::cout << "(*info*) x : [ " << bc_name[ bc.x.lower ] << ", " << bc_name[ bc.x.upper ] << " ]\n";
std::cout << "(*info*) y : [ " << bc_name[ bc.y.lower ] << ", " << bc_name[ bc.y.upper ] << " ]\n";
// Set periodic flags on tile grids
J->periodic.x = ( bc.x.lower == current::bc::periodic );
J->periodic.y = ( bc.y.lower == current::bc::periodic );
}
/**
* @brief Sets moving window algorithm
*
* This method can only be called before the simulation has started (iter = 0)
*
* @return int 0 on success, -1 on error
*/
int set_moving_window() {
if ( iter == 0 ) {
moving_window.init( dx.x );
bc.x.lower = bc.x.upper = current::bc::none;
J->periodic.x = false;
return 0;
} else {
std::cerr << "(*error*) set_moving_window() called with iter != 0\n";
return -1;
}
}
void set_filter( Filter::Digital const & new_filter ) {
delete filter;
filter = new_filter.clone();
}
void advance();
void zero();
void save( fcomp::cart const jc );
};
#endif