Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argupta
openfpm_numerics
Commits
64d29477
Commit
64d29477
authored
Dec 09, 2015
by
Pietro Incardona
Browse files
Staggered to normal for grid
parent
dfb8b8f7
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/FiniteDifference/Average.hpp
View file @
64d29477
...
...
@@ -65,24 +65,24 @@ class Avg<d,arg,Sys_eqs,CENTRAL>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
]
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
// if the system is staggered the CENTRAL derivative is equivalent to a forward derivative
if
(
is_grid_staggered
<
Sys_eqs
>::
value
())
{
Avg
<
d
,
arg
,
Sys_eqs
,
BACKWARD
>::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
Avg
<
d
,
arg
,
Sys_eqs
,
BACKWARD
>::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
);
return
;
}
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
}
...
...
@@ -135,16 +135,16 @@ class Avg<d,arg,Sys_eqs,FORWARD>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
]
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
// backward
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
}
...
...
@@ -177,15 +177,15 @@ class Avg<d,arg,Sys_eqs,BACKWARD>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
],
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
// forward
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
2
);
}
...
...
src/FiniteDifference/Derivative.hpp
View file @
64d29477
...
...
@@ -64,24 +64,24 @@ class D<d,arg,Sys_eqs,CENTRAL>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
]
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
// if the system is staggered the CENTRAL derivative is equivalent to a forward derivative
if
(
is_grid_staggered
<
Sys_eqs
>::
value
())
{
D
<
d
,
arg
,
Sys_eqs
,
BACKWARD
>::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
D
<
d
,
arg
,
Sys_eqs
,
BACKWARD
>::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
);
return
;
}
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
spacing
[
d
]
/
2.0
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
coeff
/
spacing
[
d
]
/
2.0
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
}
...
...
@@ -135,7 +135,7 @@ public:
*
*
*/
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
]
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
#ifdef SE_CLASS1
if
(
Sys_eqs
::
boundary
[
d
]
==
PERIODIC
)
...
...
@@ -146,42 +146,42 @@ public:
if
(
pos
.
get
(
d
)
==
(
long
int
)
gs
.
size
(
d
)
-
1
)
{
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
1.5
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
1.5
*
coeff
/
spacing
[
d
]
);
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
2.0
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
2.0
*
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
2
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
0.5
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
0.5
*
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
}
else
if
(
pos
.
get
(
d
)
==
0
)
{
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
1.5
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
1.5
*
coeff
/
spacing
[
d
]
);
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
2.0
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
2.0
*
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
2
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
0.5
*
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
0.5
*
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
}
else
{
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
}
}
...
...
@@ -231,16 +231,16 @@ class D<d,arg,Sys_eqs,FORWARD>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
]
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
+
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
// backward
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
coeff
/
spacing
[
d
]
);
}
...
...
@@ -273,16 +273,16 @@ class D<d,arg,Sys_eqs,BACKWARD>
*
*
*/
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
inline
static
void
value
(
const
typename
stub_or_real
<
Sys_eqs
,
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
typename
Sys_eqs
::
b_grid
::
decomposition
>::
type
&
g_map
,
grid_dist_key_dx
<
Sys_eqs
::
dims
>
&
kmap
,
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
,
typename
Sys_eqs
::
stype
(
&
spacing
)[
Sys_eqs
::
dims
],
std
::
unordered_map
<
long
int
,
typename
Sys_eqs
::
stype
>
&
cols
,
typename
Sys_eqs
::
stype
coeff
)
{
long
int
old_val
=
kmap
.
getKeyRef
().
get
(
d
);
kmap
.
getKeyRef
().
set_d
(
d
,
kmap
.
getKeyRef
().
get
(
d
)
-
1
);
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
-
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
-
coeff
/
spacing
[
d
]
);
kmap
.
getKeyRef
().
set_d
(
d
,
old_val
);
// forward
arg
::
value
(
g_map
,
kmap
,
gs
,
cols
,
coeff
);
arg
::
value
(
g_map
,
kmap
,
gs
,
spacing
,
cols
,
coeff
/
spacing
[
d
]
);
}
...
...
src/FiniteDifference/FDScheme.hpp
View file @
64d29477
...
...
@@ -13,6 +13,7 @@
#include "Grid/grid_dist_id_iterator_sub.hpp"
#include "eq.hpp"
#include "data_type/scalar.hpp"
#include "NN/CellList/CellDecomposer.hpp"
/*! \brief Finite Differences
*
...
...
@@ -73,6 +74,15 @@
template
<
typename
Sys_eqs
>
class
FDScheme
{
public:
// Distributed grid map
typedef
grid_dist_id
<
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
scalar
<
size_t
>
,
typename
Sys_eqs
::
b_grid
::
decomposition
>
g_map_type
;
typedef
Sys_eqs
Sys_eqs_typ
;
private:
// Padding
Padding
<
Sys_eqs
::
dims
>
pd
;
...
...
@@ -86,7 +96,8 @@ class FDScheme
// Domain Grid informations
const
grid_sm
<
Sys_eqs
::
dims
,
void
>
&
gs
;
typedef
grid_dist_id
<
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
,
scalar
<
size_t
>
,
typename
Sys_eqs
::
b_grid
::
decomposition
>
g_map_type
;
// Get the grid spacing
typename
Sys_eqs
::
stype
spacing
[
Sys_eqs
::
dims
];
// mapping grid
g_map_type
g_map
;
...
...
@@ -154,14 +165,14 @@ class FDScheme
for
(
size_t
i
=
0
;
i
<
nz_rows
.
size
()
;
i
++
)
{
if
(
nz_rows
.
get
(
i
)
==
false
)
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" Ill posed matrix
not all the rows are
filled
\n
"
;
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" Ill posed matrix
row "
<<
i
<<
" is not
filled
\n
"
;
}
// all the colums must have a non zero element
for
(
size_t
i
=
0
;
i
<
nz_cols
.
size
()
;
i
++
)
{
if
(
nz_cols
.
get
(
i
)
==
false
)
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" Ill posed matrix
not all the colums are
filled
\n
"
;
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" Ill posed matrix
colum "
<<
i
<<
" is not
filled
\n
"
;
}
}
...
...
@@ -177,6 +188,26 @@ class FDScheme
public:
/*! \brief Get the grid padding
*
* \return the grid padding
*
*/
const
Padding
<
Sys_eqs
::
dims
>
&
getPadding
()
{
return
pd
;
}
/*! \brief Return the map between the grid index position and the position in the distributed vector
*
* \return the map
*
*/
const
g_map_type
&
getMap
()
{
return
g_map
;
}
/*! \brief Constructor
*
* \param pd Padding
...
...
@@ -219,27 +250,69 @@ public:
// sync the ghost
g_map
.
template
ghost_get
<
0
>();
// Create a CellDecomposer and calculate the spacing
size_t
sz_g
[
Sys_eqs
::
dims
];
for
(
size_t
i
=
0
;
i
<
Sys_eqs
::
dims
;
i
++
)
sz_g
[
i
]
=
gs
.
getSize
()[
i
]
-
1
;
CellDecomposer_sm
<
Sys_eqs
::
dims
,
typename
Sys_eqs
::
stype
>
cd
(
domain
,
sz_g
,
0
);
for
(
size_t
i
=
0
;
i
<
Sys_eqs
::
dims
;
i
++
)
spacing
[
i
]
=
cd
.
getCellBox
().
getHigh
(
i
);
}
/*! \brief Impose an operator
*
* This function impose an operator on a box region to produce the system
*
* Ax = b
*
* ## Stokes equation, lid driven cavity with one splipping wall
*
* \param op Operator to impose (A term)
* \param num right hand side of the term (b term)
* \param id Equation id in the system that we are imposing
* \param start starting point of the box
* \param stop stop point of the box
*
*/
template
<
typename
T
>
void
impose
A
(
const
T
&
op
,
grid_dist_iterator_sub
<
Sys_eqs
::
dims
,
typename
Sys_eqs
::
b_grid
::
d_grid
>
it_d
,
bool
skip_first
=
false
)
template
<
typename
T
>
void
impose
(
const
T
&
op
,
typename
Sys_eqs
::
stype
num
,
long
int
id
,
const
long
int
(
&
start
)[
Sys_eqs
::
dims
],
const
long
int
(
&
stop
)[
Sys_eqs
::
dims
]
,
bool
skip_first
=
false
)
{
// key one
grid_key_dx
<
Sys_eqs
::
dims
>
gk_one
;
gk_one
.
one
();
// add padding to start and stop
grid_key_dx
<
Sys_eqs
::
dims
>
start
=
it_d
.
getS
tart
(
)
+
pd
.
getKP1
();
grid_key_dx
<
Sys_eqs
::
dims
>
stop
=
it_d
.
getS
top
(
)
+
pd
.
getKP1
();
grid_key_dx
<
Sys_eqs
::
dims
>
start
_k
=
grid_key_dx
<
Sys_eqs
::
dims
>
(
s
tart
)
+
pd
.
getKP1
();
grid_key_dx
<
Sys_eqs
::
dims
>
stop
_k
=
grid_key_dx
<
Sys_eqs
::
dims
>
(
s
top
)
+
pd
.
getKP1
();
auto
it
=
g_map
.
getSubDomainIterator
(
start
,
stop
);
auto
it
=
g_map
.
getSubDomainIterator
(
start_k
,
stop_k
);
impose
(
op
,
num
,
id
,
it
,
skip_first
);
}
/*! \brief Impose an operator
*
* This function impose an operator on a particular grid region to produce the system
*
* Ax = b
*
* ## Stokes equation, lid driven cavity with one splipping wall
*
* \param op Operator to impose (A term)
* \param num right hand side of the term (b term)
* \param id Equation id in the system that we are imposing
* \param it_d iterator that define where you want to impose
*
*/
template
<
typename
T
>
void
impose
(
const
T
&
op
,
typename
Sys_eqs
::
stype
num
,
long
int
id
,
grid_dist_iterator_sub
<
Sys_eqs
::
dims
,
typename
g_map_type
::
d_grid
>
it_d
,
bool
skip_first
=
false
)
{
auto
it
=
it_d
;
grid_sm
<
Sys_eqs
::
dims
,
void
>
gs
=
g_map
.
getGridInfoVoid
();
std
::
unordered_map
<
long
int
,
float
>
cols
;
// resize b if needed
b
.
resize
(
Sys_eqs
::
nvar
*
gs
.
size
());
bool
is_first
=
skip_first
;
// iterate all the grid points
...
...
@@ -254,68 +327,29 @@ public:
// get the position
auto
key
=
it
.
get
();
grid_key_dx
<
2
>
gkey
=
g_map
.
getGKey
(
key
);
// Calculate the non-zero colums
T
::
value
(
g_map
,
key
,
gs
,
cols
,
1.0
);
T
::
value
(
g_map
,
key
,
gs
,
spacing
,
cols
,
1.0
);
// create the triplet
for
(
auto
it
=
cols
.
begin
();
it
!=
cols
.
end
();
++
it
)
{
trpl
.
add
();
trpl
.
last
().
row
()
=
row
;
trpl
.
last
().
row
()
=
Sys_eqs
::
nvar
*
gs
.
LinId
(
gkey
)
+
id
;
trpl
.
last
().
col
()
=
it
->
first
;
trpl
.
last
().
value
()
=
it
->
second
;
std
::
cout
<<
"("
<<
trpl
.
last
().
row
()
<<
","
<<
trpl
.
last
().
col
()
<<
","
<<
trpl
.
last
().
value
()
<<
")"
<<
"
\n
"
;
}
b
.
get
(
Sys_eqs
::
nvar
*
gs
.
LinId
(
gkey
)
+
id
)
=
num
;
cols
.
clear
();
std
::
cout
<<
"
\n
"
;
++
row
;
++
it
;
}
}
/*! \brief Impose an operator
*
*
*
*/
void
imposeB
(
typename
Sys_eqs
::
stype
num
,
grid_dist_iterator_sub
<
Sys_eqs
::
dims
,
typename
Sys_eqs
::
b_grid
::
d_grid
>
it_d
,
bool
skip_first
=
false
)
{
// key one
grid_key_dx
<
Sys_eqs
::
dims
>
gk_one
;
gk_one
.
one
();
// add padding to start and stop
grid_key_dx
<
Sys_eqs
::
dims
>
start
=
it_d
.
getStart
()
+
pd
.
getKP1
();
grid_key_dx
<
Sys_eqs
::
dims
>
stop
=
it_d
.
getStop
()
+
pd
.
getKP1
();
auto
it
=
g_map
.
getSubDomainIterator
(
start
,
stop
);
std
::
unordered_map
<
long
int
,
float
>
cols
;
bool
is_first
=
skip_first
;
// iterate all the grid points
while
(
it
.
isNext
())
{
if
(
is_first
==
true
)
{
++
it
;
is_first
=
false
;
continue
;
}
// get the position
auto
key
=
it
.
get
();
b
.
add
(
num
);
cols
.
clear
();
++
row_b
;
++
it
;
}
...
...
src/FiniteDifference/FDScheme_unit_tests.hpp
View file @
64d29477
...
...
@@ -13,6 +13,7 @@
#include "Decomposition/CartDecomposition.hpp"
#include "util/grid_dist_testing.hpp"
#include "FiniteDifference/Average.hpp"
#include "FiniteDifference/sum.hpp"
constexpr
unsigned
int
x
=
0
;
constexpr
unsigned
int
y
=
1
;
...
...
@@ -128,6 +129,9 @@ BOOST_AUTO_TEST_CASE( der_central_non_periodic)
// grid_sm
grid_sm
<
2
,
void
>
ginfo
(
sz
);
// spacing
float
spacing
[
2
]
=
{
0.5
,
0.3
};
// Create several keys
grid_dist_key_dx
<
2
>
key11
(
0
,
grid_key_dx
<
2
>
(
1
,
1
));
grid_dist_key_dx
<
2
>
key00
(
0
,
grid_key_dx
<
2
>
(
0
,
0
));
...
...
@@ -138,17 +142,17 @@ BOOST_AUTO_TEST_CASE( der_central_non_periodic)
std
::
unordered_map
<
long
int
,
float
>
cols_x
;
std
::
unordered_map
<
long
int
,
float
>
cols_y
;
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key11
,
ginfo
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key11
,
ginfo
,
cols_y
,
1
);
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key11
,
ginfo
,
spacing
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key11
,
ginfo
,
spacing
,
cols_y
,
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
.
size
(),
2
);
BOOST_REQUIRE_EQUAL
(
cols_y
.
size
(),
2
);
BOOST_REQUIRE_EQUAL
(
cols_x
.
size
(),
2
ul
);
BOOST_REQUIRE_EQUAL
(
cols_y
.
size
(),
2
ul
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
+
1
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
-
1
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
+
1
],
1
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
-
1
],
-
1
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
+
16
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
-
16
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
+
16
],
1
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
-
16
],
-
1
/
spacing
[
1
]
);
// filled colums
...
...
@@ -159,88 +163,88 @@ BOOST_AUTO_TEST_CASE( der_central_non_periodic)
// Composed derivative
D
<
x
,
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
cols_xx
,
1
);
D
<
x
,
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
cols_xy
,
1
);
D
<
y
,
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
cols_yx
,
1
);
D
<
y
,
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
cols_yy
,
1
);
D
<
x
,
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
spacing
,
cols_xx
,
1
);
D
<
x
,
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
spacing
,
cols_xy
,
1
);
D
<
y
,
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
spacing
,
cols_yx
,
1
);
D
<
y
,
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
>
,
sys_nn
>::
value
(
g_map
,
key22
,
ginfo
,
spacing
,
cols_yy
,
1
);
BOOST_REQUIRE_EQUAL
(
cols_xx
.
size
(),
3
);
BOOST_REQUIRE_EQUAL
(
cols_xy
.
size
(),
4
);
BOOST_REQUIRE_EQUAL
(
cols_yx
.
size
(),
4
);
BOOST_REQUIRE_EQUAL
(
cols_yy
.
size
(),
3
);
BOOST_REQUIRE_EQUAL
(
cols_xx
.
size
(),
3
ul
);
BOOST_REQUIRE_EQUAL
(
cols_xy
.
size
(),
4
ul
);
BOOST_REQUIRE_EQUAL
(
cols_yx
.
size
(),
4
ul
);
BOOST_REQUIRE_EQUAL
(
cols_yy
.
size
(),
3
ul
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
32
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
34
],
-
2
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
36
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
32
],
1
/
spacing
[
0
]
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
34
],
-
2
/
spacing
[
0
]
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_xx
[
36
],
1
/
spacing
[
0
]
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
17
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
19
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
49
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
51
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
17
],
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
19
],
-
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
49
],
-
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
51
],
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
17
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
19
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
49
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
51
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
17
],
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
19
],
-
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yx
[
49
],
-
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_xy
[
51
],
1
/
spacing
[
0
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
2
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
34
],
-
2
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
66
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
2
],
1
/
spacing
[
1
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
34
],
-
2
/
spacing
[
1
]
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_yy
[
66
],
1
/
spacing
[
1
]
/
spacing
[
1
]
);
// Non periodic with one sided
cols_x
.
clear
();
cols_y
.
clear
();
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key11
,
ginfo
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key11
,
ginfo
,
cols_y
,
1
);
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key11
,
ginfo
,
spacing
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key11
,
ginfo
,
spacing
,
cols_y
,
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
.
size
(),
2
);
BOOST_REQUIRE_EQUAL
(
cols_y
.
size
(),
2
);
BOOST_REQUIRE_EQUAL
(
cols_x
.
size
(),
2
ul
);
BOOST_REQUIRE_EQUAL
(
cols_y
.
size
(),
2
ul
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
+
1
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
-
1
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
+
1
],
1
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_x
[
17
-
1
],
-
1
/
spacing
[
0
]
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
+
16
],
1
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
-
16
],
-
1
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
+
16
],
1
/
spacing
[
1
]
);
BOOST_REQUIRE_EQUAL
(
cols_y
[
17
-
16
],
-
1
/
spacing
[
1
]
);
// Border left
cols_x
.
clear
();
cols_y
.
clear
();
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key00
,
ginfo
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key00
,
ginfo
,
cols_y
,
1
);
D
<
x
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key00
,
ginfo
,
spacing
,
cols_x
,
1
);
D
<
y
,
Field
<
V
,
sys_nn
>
,
sys_nn
,
CENTRAL_B_ONE_SIDE
>::
value
(
g_map
,
key00
,
ginfo
,
spacing
,
cols_y
,
1
);
BOOST_REQUIRE_EQUAL
(
cols_x
.
size
(),
3
);
BOOST_REQUIRE_EQUAL
(