FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
idefix/src/dataBlock/stateContainer.cpp at master · idefix-code/idefix · GitHub
idefix-code
idefix
Repository navigation
Code
Issues
3
(3)
Pull requests
9
(9)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
idefix
/
src
/
dataBlock
/
stateContainer.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (100 loc) · 3.79 KB
Breadcrumbs
idefix
/
src
/
dataBlock
/
stateContainer.cpp
Copy path
File metadata and controls
112 lines (100 loc) · 3.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
***********************************************************************************
//
Idefix MHD astrophysical code
//
//
Source file src/dataBlock/stateContainer.cpp
//
//
Last modified : 11/2022
//
//
Copyright(C) by :
//
- Geoffroy Lesur <geoffroy.lesur@univ-grenoble-alpes.fr> (IPAG/UGA/CNRS - 2022)
//
- Clément Robert <clement.robert@univ-grenoble-alpes.fr> (IPAG/UGA/CNRS - 2022)
//
and other code contributors
//
//
Licensed under CeCILL 2.1 License, see COPYING for more information
//
***********************************************************************************
#
include
"
stateContainer.hpp
"
#
include
<
vector
>
#
include
<
string
>
#
include
<
algorithm
>
#
include
"
idefix.hpp
"
StateContainer::StateContainer
() {
//
do nothing
}
void
StateContainer::CopyFrom
(StateContainer &in) {
idfx::pushRegion
(
"
StateContainer::CopyFrom
"
);
//
Make a deep copy from in
if
(in.
stateVector
.
size
() !=
this
->
stateVector
.
size
()) {
IDEFIX_ERROR
(
"
You cannot copy two state containers of different sizes.
"
);
}
for
(
int
s =
0
; s <
this
->
stateVector
.
size
() ; s++) {
if
(
this
->
stateVector
[s].
type
!= in.
stateVector
[s].
type
) {
IDEFIX_ERROR
(
"
Cannot copy from a stateContainer with different types
"
);
}
if
(
this
->
stateVector
[s].
type
== State::idefixArray4D) {
Kokkos::deep_copy
(
this
->
stateVector
[s].
array
, in.
stateVector
[s].
array
);
}
else
{
IDEFIX_ERROR
(
"
Cannot copy states which are undefined
"
);
}
}
idfx::popRegion
();
}
void
StateContainer::AllocateAs
(StateContainer &in) {
idfx::pushRegion
(
"
StateContainer::AllocateAs
"
);
//
Allocate arrays of current StateContainer with the same shape as in
for
(State stateIn : in.
stateVector
) {
//
We first do a shallow copy
State stateOut = stateIn;
if
(stateIn.
type
== State::idefixArray4D) {
//
But then reinit the array
stateOut.
array
= IdefixArray4D<real>(stateIn.
name
, stateIn.
array
.
extent
(
0
),
stateIn.
array
.
extent
(
1
),
stateIn.
array
.
extent
(
2
),
stateIn.
array
.
extent
(
3
));
}
else
{
IDEFIX_ERROR
(
"
Cannot allocate a state with type none
"
);
}
//
And add the new state to our stateVector
this
->
stateVector
.
push_back
(stateOut);
}
idfx::popRegion
();
}
void
StateContainer::PushArray
(IdefixArray4D<real>& in,
State::TypeLocation loc,
std::string name) {
idfx::pushRegion
(
"
StateContainer::PushArray
"
);
State state;
state.
array
= in;
state.
type
= State::idefixArray4D;
state.
name
= name;
state.
location
= loc;
this
->
stateVector
.
push_back
(state);
idfx::popRegion
();
}
void
StateContainer::AddAndStore
(
const
real wl,
const
real wr, StateContainer & in) {
idfx::pushRegion
(
"
StateContainer::AddAndStore
"
);
if
(in.
stateVector
.
size
() !=
this
->
stateVector
.
size
()) {
IDEFIX_ERROR
(
"
You cannot add two state containers of different sizes.
"
);
}
for
(
int
s =
0
; s <
this
->
stateVector
.
size
() ; s++) {
State stateIn = in.
stateVector
[s];
State stateOut =
this
->
stateVector
[s];
if
(stateIn.
type
!= stateOut.
type
) {
IDEFIX_ERROR
(
"
Cannot add and store states of different type
"
);
}
if
(stateIn.
type
== State::idefixArray4D) {
auto
Vin = stateIn.
array
;
auto
Vout = stateOut.
array
;
idefix_for
(
"
StateContainer::AddAndStore
"
,
0
, Vin.
extent
(
0
),
0
, Vin.
extent
(
1
),
0
, Vin.
extent
(
2
),
0
, Vin.
extent
(
3
),
KOKKOS_LAMBDA
(
int
n,
int
k,
int
j,
int
i) {
Vout
(n,k,j,i) = wl *
Vout
(n,k,j,i) + wr *
Vin
(n,k,j,i);
} );
}
else
{
IDEFIX_ERROR
(
"
Cannot Add and store from state of unknown type
"
);
}
}
idfx::popRegion
();
}
Back
|
FazBrowse Home
|
New Git URL