19 #ifndef __DOLFIN_N_VECTOR_H 20 #define __DOLFIN_N_VECTOR_H 27 #include <dolfin/common/types.h> 28 #include <sundials/sundials_nvector.h> 29 #include "DefaultFactory.h" 30 #include "GenericVector.h" 61 N_V = std::unique_ptr<_generic_N_Vector>(
new _generic_N_Vector);
63 N_V->content = (
void *)(
this);
76 N_V = std::unique_ptr<_generic_N_Vector>(
new _generic_N_Vector);
78 N_V->content = (
void *)(
this);
86 N_V = std::unique_ptr<_generic_N_Vector>(
new _generic_N_Vector);
88 N_V->content = (
void *)(
this);
97 N_V->content = (
void *)(
this);
104 std::shared_ptr<GenericVector>
vec()
const 111 { *vector = *x.vector;
return *
this; }
118 static N_Vector_ID N_VGetVectorID(N_Vector nv)
120 dolfin_debug(
"N_VGetVectorID");
121 return SUNDIALS_NVEC_CUSTOM;
126 static void N_VAbs(N_Vector x, N_Vector z)
128 dolfin_debug(
"N_VAbs");
137 static void N_VConst(
double c, N_Vector z)
139 dolfin_debug(
"N_VConst");
147 static N_Vector N_VClone(N_Vector z)
149 dolfin_debug(
"N_VClone");
154 _generic_N_Vector *V =
new _generic_N_Vector;
156 V->content = (
void *)(new_vector);
163 static N_Vector N_VCloneEmpty(N_Vector x)
165 dolfin_debug(
"N_VCloneEmpty");
166 dolfin_not_implemented();
172 static void N_VDestroy(N_Vector z)
174 dolfin_debug(
"N_VDestroy");
181 static void N_VSpace(N_Vector x,
long int *y,
long int *z)
183 dolfin_debug(
"N_VSpace");
184 dolfin_not_implemented();
188 static double* N_VGetArrayPointer(N_Vector x)
190 dolfin_debug(
"N_VGetArrayPointer");
191 dolfin_not_implemented();
196 static void N_VSetArrayPointer(
double* c,N_Vector x)
198 dolfin_debug(
"N_VSetArrayPointer");
199 dolfin_not_implemented();
204 static void N_VProd(N_Vector x, N_Vector y, N_Vector z)
206 dolfin_debug(
"N_VProd");
219 static void N_VDiv(N_Vector x, N_Vector y, N_Vector z)
221 dolfin_debug(
"N_VDiv");
227 std::vector<double> xdata;
228 vx->get_local(xdata);
229 std::vector<double> ydata;
230 vy->get_local(ydata);
231 for (
unsigned int i = 0; i != xdata.size(); ++i)
232 xdata[i] /= ydata[i];
234 vz->set_local(xdata);
240 static void N_VScale(
double c, N_Vector x, N_Vector z)
242 dolfin_debug(
"N_VScale");
253 static void N_VInv(N_Vector x, N_Vector z)
255 dolfin_debug(
"N_VInv");
260 std::vector<double> xvals;
261 vx->get_local(xvals);
262 for (
auto &val : xvals)
264 vz->set_local(xvals);
270 static void N_VAddConst(N_Vector x,
double c, N_Vector z)
272 dolfin_debug(
"N_VAddConst");
281 static double N_VDotProd(N_Vector x, N_Vector z)
283 dolfin_debug(
"N_VDotProd");
287 return vx->inner(*vz);
291 static double N_VMaxNorm(N_Vector x)
293 dolfin_debug(
"N_VMaxNorm");
295 auto vy = vx->copy();
301 static double N_VMin(N_Vector x)
303 dolfin_debug(
"N_VMin");
304 return (static_cast<const SUNDIALSNVector *>(x->content)->vec())->min();
309 static void N_VLinearSum(
double a, N_Vector x,
double b, N_Vector y, N_Vector z)
311 dolfin_debug(
"N_VLinearSum");
316 std::vector<double> xdata;
317 vx->get_local(xdata);
318 std::vector<double> ydata;
319 vy->get_local(ydata);
321 for (
unsigned int i = 0; i != xdata.size(); ++i)
322 xdata[i] = a*xdata[i] + b*ydata[i];
324 vz->set_local(xdata);
330 static double N_VWrmsNorm(N_Vector x, N_Vector z)
332 dolfin_debug(
"N_VWrmsNorm");
338 return y->norm(
"l2")/std::sqrt(y->size());
344 static double N_VWrmsNormMask(N_Vector x, N_Vector y, N_Vector z)
346 dolfin_debug(
"N_VWrmsNormMask");
347 dolfin_not_implemented();
353 static double N_VWl2Norm(N_Vector x, N_Vector z )
355 dolfin_debug(
"N_VWl2Norm");
356 dolfin_not_implemented();
361 static double N_VL1Norm(N_Vector x )
363 dolfin_debug(
"N_VL1Norm");
364 dolfin_not_implemented();
370 static void N_VCompare(
double c, N_Vector x, N_Vector z)
372 dolfin_debug(
"N_VCompare");
375 std::vector<double> xvals;
376 vx->get_local(xvals);
377 for (
auto &val : xvals)
378 val = (std::abs(val) >= c) ? 1.0 : 0.0;
379 vz->set_local(xvals);
385 static int N_VInvTest(N_Vector x, N_Vector z)
387 dolfin_debug(
"N_VInvTest");
388 int no_zero_found =
true;
392 std::vector<double> xvals;
393 vx->get_local(xvals);
394 for (
auto &val : xvals)
398 no_zero_found =
false;
399 vz->set_local(xvals);
403 return no_zero_found;
409 static double N_VMinQuotient(N_Vector x, N_Vector z )
411 dolfin_debug(
"N_VConstrMask");
412 dolfin_not_implemented();
417 static int N_VConstrMask(N_Vector x, N_Vector y, N_Vector z )
419 dolfin_debug(
"N_VConstrMask");
420 dolfin_not_implemented();
425 std::shared_ptr<GenericVector> vector;
428 std::unique_ptr<_generic_N_Vector> N_V;
431 struct _generic_N_Vector_Ops ops = {N_VGetVectorID,
const SUNDIALSNVector & operator=(const SUNDIALSNVector &x)
Assignment operator.
Definition: SUNDIALSNVector.h:110
SUNDIALSNVector(const SUNDIALSNVector &x)
Definition: SUNDIALSNVector.h:69
SUNDIALSNVector(MPI_Comm comm=MPI_COMM_WORLD)
Definition: SUNDIALSNVector.h:45
std::shared_ptr< GenericVector > vec() const
Definition: SUNDIALSNVector.h:104
virtual std::shared_ptr< GenericVector > create_vector(MPI_Comm comm) const
Create empty vector.
Definition: DefaultFactory.cpp:37
Definition: SUNDIALSNVector.h:38
SUNDIALSNVector(std::shared_ptr< GenericVector > x)
Definition: SUNDIALSNVector.h:84
N_Vector nvector() const
Definition: SUNDIALSNVector.h:95
SUNDIALSNVector(MPI_Comm comm, std::size_t N)
Definition: SUNDIALSNVector.h:56
This class defines a common interface for vectors.
Definition: GenericVector.h:47
Default linear algebra factory based on global parameter "linear_algebra_backend".
Definition: DefaultFactory.h:35
SUNDIALSNVector(const GenericVector &x)
Definition: SUNDIALSNVector.h:74