-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDaspkJac.cpp
61 lines (54 loc) · 1.76 KB
/
DaspkJac.cpp
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
#include "DaspkJac.h"
namespace Daetk
{
Jacobian* DaspkJacobian::theJac = 0;
Preconditioner* DaspkJacobian::thePrec = 0;
DaeDefinition* DaspkJacobian::theDae = 0;
void DaspkJacobian::jac_direct(real& t, real* y, real* yprime,
real* pd, real& cj, real* rpar, int* ipar)
{
//won't work with difference jacobian until I do something about the pd matrix
int Neq = theDae->getY0().dim();
const Vec yVec(Vec::REF,y,Neq,0,1);
const Vec ypVec(Vec::REF,yprime,Neq,0,1);
theDae->tDaeDef = t;
theDae->alphaDaeDef = cj;
#ifndef USE_BLAS
theDae->yDaeDef = yVec;
theDae->ypDaeDef = ypVec;
theDae->betaDaeDef = ypVec - theDae->alphaDaeDef*yVec;
#else
copy(yVec,theDae->yDaeDef);
copy(ypVec,theDae->ypDaeDef);
copy(ypVec,theDae->betaDaeDef);
axpy(-theDae->alphaDaeDef,yVec,theDae->betaDaeDef);
#endif
theDae->resetFunction();
theJac->evaluate(yVec,yVec);
}
void DaspkJacobian::jac_krylov(GlobDaspkRes res,int* ires,int* neq, real& t, real* y, real* yprime,
real* weight, real* residual,real& work,
real& h, real& cj,
real* wp, int* iwp, int& ier, real* rpar,int* ipar)
{
int Neq = theDae->getY0().dim();
const Vec yVec(Vec::REF,y,Neq,0,1);
const Vec ypVec(Vec::REF,yprime,Neq,0,1);
const Vec rVec(Vec::REF,residual,Neq,0,1);
theDae->tDaeDef = t;
theDae->alphaDaeDef = cj;
#ifndef USE_BLAS
theDae->yDaeDef = yVec;
theDae->ypDaeDef = ypVec;
theDae->betaDaeDef = ypVec - theDae->alphaDaeDef*yVec;
#else
copy(yVec,theDae->yDaeDef);
copy(ypVec,theDae->ypDaeDef);
copy(ypVec,theDae->betaDaeDef);
axpy(-theDae->alphaDaeDef,yVec,theDae->betaDaeDef);
#endif
theDae->resetFunction();
theJac->evaluate(yVec,rVec);
thePrec->prepare();
}
}//Daetk