Reference documentation for deal.II version 9.3.3
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
sundials_backport.h
Go to the documentation of this file.
1//-----------------------------------------------------------
2//
3// Copyright (C) 2020 - 2021 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14//-----------------------------------------------------------
15
16/*
17 * The functions in this file are based on an implementation distributed within
18 * the SUNDIALS package, see the license here:
19 * https://computing.llnl.gov/projects/sundials/license.
20 * -----------------------------------------------------------------
21 * Programmer(s): Daniel Reynolds @ SMU
22 * David J. Gardner, Carol S. Woodward, and
23 * Slaven Peles @ LLNL
24 * -----------------------------------------------------------------*/
25
26#ifndef dealii_sundials_backport_h
27#define dealii_sundials_backport_h
28
29#include <deal.II/base/config.h>
30
31#ifdef DEAL_II_WITH_SUNDIALS
32
33# include <sundials/sundials_nvector.h>
34
36namespace SUNDIALS
37{
38 namespace internal
39 {
40 N_Vector
42 {
43 N_Vector v = new _generic_N_Vector;
44 N_Vector_Ops ops = new _generic_N_Vector_Ops;
45
46 /* initialize operations to nullptr */
47
48 /* constructors, destructors, and utility operations */
49 ops->nvgetvectorid = nullptr;
50 ops->nvclone = nullptr;
51 ops->nvcloneempty = nullptr;
52 ops->nvdestroy = nullptr;
53 ops->nvspace = nullptr;
54 ops->nvgetarraypointer = nullptr;
55 ops->nvsetarraypointer = nullptr;
56# if DEAL_II_SUNDIALS_VERSION_GTE(5, 0, 0)
57 ops->nvgetcommunicator = nullptr;
58 ops->nvgetlength = nullptr;
59# endif
60
61 /* standard vector operations */
62 ops->nvlinearsum = nullptr;
63 ops->nvconst = nullptr;
64 ops->nvprod = nullptr;
65 ops->nvdiv = nullptr;
66 ops->nvscale = nullptr;
67 ops->nvabs = nullptr;
68 ops->nvinv = nullptr;
69 ops->nvaddconst = nullptr;
70 ops->nvdotprod = nullptr;
71 ops->nvmaxnorm = nullptr;
72 ops->nvwrmsnormmask = nullptr;
73 ops->nvwrmsnorm = nullptr;
74 ops->nvmin = nullptr;
75 ops->nvwl2norm = nullptr;
76 ops->nvl1norm = nullptr;
77 ops->nvcompare = nullptr;
78 ops->nvinvtest = nullptr;
79 ops->nvconstrmask = nullptr;
80 ops->nvminquotient = nullptr;
81
82# if DEAL_II_SUNDIALS_VERSION_GTE(5, 0, 0)
83 /* fused vector operations (optional) */
84 ops->nvlinearcombination = nullptr;
85 ops->nvscaleaddmulti = nullptr;
86 ops->nvdotprodmulti = nullptr;
87
88 /* vector array operations (optional) */
89 ops->nvlinearsumvectorarray = nullptr;
90 ops->nvscalevectorarray = nullptr;
91 ops->nvconstvectorarray = nullptr;
92 ops->nvwrmsnormvectorarray = nullptr;
93 ops->nvwrmsnormmaskvectorarray = nullptr;
94 ops->nvscaleaddmultivectorarray = nullptr;
95 ops->nvlinearcombinationvectorarray = nullptr;
96
97 /* local reduction operations (optional) */
98 ops->nvdotprodlocal = nullptr;
99 ops->nvmaxnormlocal = nullptr;
100 ops->nvminlocal = nullptr;
101 ops->nvl1normlocal = nullptr;
102 ops->nvinvtestlocal = nullptr;
103 ops->nvconstrmasklocal = nullptr;
104 ops->nvminquotientlocal = nullptr;
105 ops->nvwsqrsumlocal = nullptr;
106 ops->nvwsqrsummasklocal = nullptr;
107
108# if DEAL_II_SUNDIALS_VERSION_GTE(5, 4, 0)
109 /* XBraid interface operations */
110 ops->nvbufsize = nullptr;
111 ops->nvbufpack = nullptr;
112 ops->nvbufunpack = nullptr;
113# endif
114
115# if DEAL_II_SUNDIALS_VERSION_GTE(5, 3, 0)
116 /* debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined) */
117 ops->nvprint = nullptr;
118 ops->nvprintfile = nullptr;
119# endif
120# endif
121
122 /* attach ops and initialize content to nullptr */
123 v->ops = ops;
124 v->content = nullptr;
125
126 return v;
127 }
128
129
130
131 void
132 N_VFreeEmpty(N_Vector v)
133 {
134 if (v == nullptr)
135 return;
136
137 /* free non-nullptr ops structure */
138 if (v->ops)
139 delete v->ops;
140 v->ops = nullptr;
141
142 /* free overall N_Vector object and return */
143 delete v;
144 }
145
146
147
148 int
149 N_VCopyOps(N_Vector w, N_Vector v)
150 {
151 /* Check that ops structures exist */
152 if (w == nullptr || v == nullptr)
153 return (-1);
154 if (w->ops == nullptr || v->ops == nullptr)
155 return (-1);
156
157 /* Copy ops from w to v */
158
159 /* constructors, destructors, and utility operations */
160 v->ops->nvgetvectorid = w->ops->nvgetvectorid;
161 v->ops->nvclone = w->ops->nvclone;
162 v->ops->nvcloneempty = w->ops->nvcloneempty;
163 v->ops->nvdestroy = w->ops->nvdestroy;
164 v->ops->nvspace = w->ops->nvspace;
165 v->ops->nvgetarraypointer = w->ops->nvgetarraypointer;
166 v->ops->nvsetarraypointer = w->ops->nvsetarraypointer;
167# if DEAL_II_SUNDIALS_VERSION_GTE(5, 0, 0)
168 v->ops->nvgetcommunicator = w->ops->nvgetcommunicator;
169 v->ops->nvgetlength = w->ops->nvgetlength;
170# endif
171
172 /* standard vector operations */
173 v->ops->nvlinearsum = w->ops->nvlinearsum;
174 v->ops->nvconst = w->ops->nvconst;
175 v->ops->nvprod = w->ops->nvprod;
176 v->ops->nvdiv = w->ops->nvdiv;
177 v->ops->nvscale = w->ops->nvscale;
178 v->ops->nvabs = w->ops->nvabs;
179 v->ops->nvinv = w->ops->nvinv;
180 v->ops->nvaddconst = w->ops->nvaddconst;
181 v->ops->nvdotprod = w->ops->nvdotprod;
182 v->ops->nvmaxnorm = w->ops->nvmaxnorm;
183 v->ops->nvwrmsnormmask = w->ops->nvwrmsnormmask;
184 v->ops->nvwrmsnorm = w->ops->nvwrmsnorm;
185 v->ops->nvmin = w->ops->nvmin;
186 v->ops->nvwl2norm = w->ops->nvwl2norm;
187 v->ops->nvl1norm = w->ops->nvl1norm;
188 v->ops->nvcompare = w->ops->nvcompare;
189 v->ops->nvinvtest = w->ops->nvinvtest;
190 v->ops->nvconstrmask = w->ops->nvconstrmask;
191 v->ops->nvminquotient = w->ops->nvminquotient;
192
193# if DEAL_II_SUNDIALS_VERSION_GTE(5, 0, 0)
194 /* fused vector operations */
195 v->ops->nvlinearcombination = w->ops->nvlinearcombination;
196 v->ops->nvscaleaddmulti = w->ops->nvscaleaddmulti;
197 v->ops->nvdotprodmulti = w->ops->nvdotprodmulti;
198
199 /* vector array operations */
200 v->ops->nvlinearsumvectorarray = w->ops->nvlinearsumvectorarray;
201 v->ops->nvscalevectorarray = w->ops->nvscalevectorarray;
202 v->ops->nvconstvectorarray = w->ops->nvconstvectorarray;
203 v->ops->nvwrmsnormvectorarray = w->ops->nvwrmsnormvectorarray;
204 v->ops->nvwrmsnormmaskvectorarray = w->ops->nvwrmsnormmaskvectorarray;
205 v->ops->nvscaleaddmultivectorarray = w->ops->nvscaleaddmultivectorarray;
206 v->ops->nvlinearcombinationvectorarray =
207 w->ops->nvlinearcombinationvectorarray;
208
209 /* local reduction operations */
210 v->ops->nvdotprodlocal = w->ops->nvdotprodlocal;
211 v->ops->nvmaxnormlocal = w->ops->nvmaxnormlocal;
212 v->ops->nvminlocal = w->ops->nvminlocal;
213 v->ops->nvl1normlocal = w->ops->nvl1normlocal;
214 v->ops->nvinvtestlocal = w->ops->nvinvtestlocal;
215 v->ops->nvconstrmasklocal = w->ops->nvconstrmasklocal;
216 v->ops->nvminquotientlocal = w->ops->nvminquotientlocal;
217 v->ops->nvwsqrsumlocal = w->ops->nvwsqrsumlocal;
218 v->ops->nvwsqrsummasklocal = w->ops->nvwsqrsummasklocal;
219
220# if DEAL_II_SUNDIALS_VERSION_GTE(5, 4, 0)
221 /* XBraid interface operations */
222 v->ops->nvbufsize = w->ops->nvbufsize;
223 v->ops->nvbufpack = w->ops->nvbufpack;
224 v->ops->nvbufunpack = w->ops->nvbufunpack;
225# endif
226
227# if DEAL_II_SUNDIALS_VERSION_GTE(5, 3, 0)
228 /* debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined) */
229 v->ops->nvprint = w->ops->nvprint;
230 v->ops->nvprintfile = w->ops->nvprintfile;
231# endif
232# endif
233
234 return (0);
235 }
236 } // namespace internal
237} // namespace SUNDIALS
239
240#endif // DEAL_II_WITH_SUNDIALS
241#endif // dealii_sundials_sunlinsol_newempty_h
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
int N_VCopyOps(N_Vector w, N_Vector v)
void N_VFreeEmpty(N_Vector v)