-
Notifications
You must be signed in to change notification settings - Fork 0
/
poisson.hh
189 lines (130 loc) · 4.83 KB
/
poisson.hh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
poisson.cc - This file is part of MUSIC -
a code to generate multi-scale initial conditions
for cosmological simulations
Copyright (C) 2010 Oliver Hahn
*/
#ifndef __POISSON_HH
#define __POISSON_HH
#include <string>
#include <map>
#include "general.hh"
#include "mesh.hh"
//! abstract base class for Poisson solvers and gradient calculations
class poisson_plugin
{
protected:
//! reference to the config_file object that holds all configuration options
config_file& cf_;
public:
//! constructor
explicit poisson_plugin( config_file& cf )
: cf_(cf)
{ }
//! destructor
virtual ~poisson_plugin()
{ }
//! solve Poisson's equation Du=f
virtual double solve( grid_hierarchy& f, grid_hierarchy& u ) = 0;
//! compute the gradient of u
virtual double gradient( int dir, grid_hierarchy& u, grid_hierarchy& Du ) = 0;
//! compute the gradient and add
virtual double gradient_add( int dir, grid_hierarchy& u, grid_hierarchy& Du ) = 0;
};
#pragma mark -
/*!
* @brief implements abstract factory design pattern for poisson solver plug-ins
*/
struct poisson_plugin_creator
{
//! create an instance of a plug-in
virtual poisson_plugin * create( config_file& cf ) const = 0;
//! destroy an instance of a plug-in
virtual ~poisson_plugin_creator() { }
};
//! maps the name of a plug-in to a pointer of the factory pattern
std::map< std::string, poisson_plugin_creator *>& get_poisson_plugin_map();
//! print a list of all registered output plug-ins
void print_poisson_plugins();
/*!
* @brief concrete factory pattern for output plug-ins
*/
template< class Derived >
struct poisson_plugin_creator_concrete : public poisson_plugin_creator
{
//! register the plug-in by its name
poisson_plugin_creator_concrete( const std::string& plugin_name )
{
get_poisson_plugin_map()[ plugin_name ] = this;
}
//! create an instance of the plug-in
poisson_plugin * create( config_file& cf ) const
{
return new Derived( cf );
}
};
/**************************************************************************************/
/**************************************************************************************/
#pragma mark -
//! adaptive FAS multigrid implementation of abstract base class poisson_plugin
class multigrid_poisson_plugin : public poisson_plugin
{
public:
//! constructor
explicit multigrid_poisson_plugin( config_file& cf )
: poisson_plugin( cf )
{ }
//! solve Poisson's equation Du=f
double solve( grid_hierarchy& f, grid_hierarchy& u );
//! compute the gradient of u
double gradient( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute the gradient and add
double gradient_add( int dir, grid_hierarchy& u, grid_hierarchy& Du );
protected:
//! various FD approximation implementations
struct implementation
{
//! solve 2nd order FD approximation to Poisson's equation
double solve_O2( grid_hierarchy& f, grid_hierarchy& u );
//! solve 4th order FD approximation to Poisson's equation
double solve_O4( grid_hierarchy& f, grid_hierarchy& u );
//! solve 6th order FD approximation to Poisson's equation
double solve_O6( grid_hierarchy& f, grid_hierarchy& u );
//! compute 2nd order FD gradient
void gradient_O2( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute and add 2nd order FD gradient
void gradient_add_O2( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute 4th order FD gradient
void gradient_O4( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute and add 4th order FD gradient
void gradient_add_O4( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute 6th order FD gradient
void gradient_O6( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute and add 6th order FD gradient
void gradient_add_O6( int dir, grid_hierarchy& u, grid_hierarchy& Du );
};
};
/**************************************************************************************/
/**************************************************************************************/
#pragma mark -
//! FFT based implementation of abstract base class poisson_plugin
class fft_poisson_plugin : public poisson_plugin
{
public:
//! constructor
explicit fft_poisson_plugin( config_file& cf )
: poisson_plugin( cf )
{ }
//! solve Poisson's equation Du=f
double solve( grid_hierarchy& f, grid_hierarchy& u );
//! compute the gradient of u
double gradient( int dir, grid_hierarchy& u, grid_hierarchy& Du );
//! compute the gradient and add
double gradient_add( int dir, grid_hierarchy& u, grid_hierarchy& Du ){ return 0.0; }
};
/**************************************************************************************/
/**************************************************************************************/
#pragma mark -
template< typename T >
void poisson_hybrid( T& f, int idir, int order, bool periodic, bool deconvolve_cic );
#endif // __POISSON_HH