-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhale_backend-1.6.0.patch
2206 lines (2144 loc) · 65.7 KB
/
whale_backend-1.6.0.patch
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f14a3bb..6f3ef42 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -115,6 +115,7 @@ list(APPEND OPTIONAL_PACKAGES "Sphinx")
list(APPEND OPTIONAL_PACKAGES "HDF5")
list(APPEND OPTIONAL_PACKAGES "VTK")
list(APPEND OPTIONAL_PACKAGES "QT")
+list(APPEND OPTIONAL_PACKAGES "whale")
# Add options
foreach (OPTIONAL_PACKAGE ${OPTIONAL_PACKAGES})
@@ -597,6 +598,18 @@ if (DOLFIN_ENABLE_QT)
find_package(Qt4)
endif()
+# Check for Whale
+if (DOLFIN_ENABLE_WHALE)
+ #find_package(whale)
+ find_path(WHALE_INCLUDE_DIR whale/whale.h)
+ find_library(WHALE_LIBRARY whale /opt/Work/FEniCS/lib)
+ set(WHALE_INCLUDE_DIRS ${WHALE_INCLUDE_DIR})
+ set(WHALE_LIBRARIES ${WHALE_LIBRARY})
+ set(WHALE_DEFINITIONS "-DHAS_WHALE")
+ find_package_handle_standard_args(whale DEFAULT_MSG WHALE_INCLUDE_DIR WHALE_LIBRARY)
+ mark_as_advanced(WHALE_INCLUDE_DIR WHALE_LIBRARY)
+endif()
+
# Check for VTK
if (DOLFIN_ENABLE_VTK)
find_package(VTK HINTS ${VTK_DIR} $ENV{VTK_DIR} NO_MODULE)
diff --git a/dolfin/CMakeLists.txt b/dolfin/CMakeLists.txt
index 9c6dd65..5f566d2 100644
--- a/dolfin/CMakeLists.txt
+++ b/dolfin/CMakeLists.txt
@@ -247,6 +247,13 @@ if (DOLFIN_ENABLE_VTK AND VTK_FOUND)
list(APPEND DOLFIN_EXTRA_TARGET_LINK_LIBRARIES ${DOLFIN_VTK_LIBRARIES})
endif()
+# Whale
+if (DOLFIN_ENABLE_WHALE AND WHALE_FOUND)
+ list(APPEND DOLFIN_CXX_DEFINITIONS ${WHALE_DEFINITIONS})
+ list(APPEND DOLFIN_DEP_SYSTEM_INCLUDE_DIRECTORIES ${WHALE_INCLUDE_DIRS})
+ list(APPEND DOLFIN_TARGET_LINK_LIBRARIES ${WHALE_LIBRARIES})
+endif()
+
#------------------------------------------------------------------------------
# Set compiler flags, include directories and library dependencies
diff --git a/dolfin/common/SubSystemsManager.cpp b/dolfin/common/SubSystemsManager.cpp
index bb1a819..85e3671 100644
--- a/dolfin/common/SubSystemsManager.cpp
+++ b/dolfin/common/SubSystemsManager.cpp
@@ -34,6 +34,10 @@
#include <slepc.h>
#endif
+#ifdef HAS_WHALE
+#include <whale/whale.h>
+#endif
+
#include <dolfin/common/constants.h>
#include <dolfin/common/Timer.h>
#include <dolfin/parameter/GlobalParameters.h>
@@ -54,7 +58,8 @@ SubSystemsManager& SubSystemsManager::singleton()
}
//-----------------------------------------------------------------------------
SubSystemsManager::SubSystemsManager() : petsc_initialized(false),
- control_mpi(false)
+ control_mpi(false),
+ whale_initialized(false)
{
// Do nothing
}
@@ -319,3 +324,49 @@ bool SubSystemsManager::mpi_finalized()
#endif
}
//-----------------------------------------------------------------------------
+
+void SubSystemsManager::init_whale(int argc, char *argv[])
+{
+#ifdef HAS_WHALE
+ if (singleton().whale_initialized )
+ return;
+
+ const bool use_whale = parameters["use_whale_backend"];
+ if (use_whale) {
+ log(TRACE,"whale is enabled");
+ whale::WhaleInit(argc, argv);
+ }
+ else
+ log(TRACE,"whale is disabled");
+
+ singleton().whale_initialized = true;
+#else
+ dolfin_error("SubSystemsManager.cpp",
+ "initialize Whale subsystem",
+ "DOLFIN has not been configured with Whale support");
+#endif
+}
+
+void SubSystemsManager::init_whale()
+{
+#ifdef HAS_WHALE
+ if (singleton().whale_initialized )
+ return;
+
+ const bool use_whale = parameters["use_whale_backend"];
+ if (use_whale) {
+ log(TRACE,"whale is enabled");
+ int argc = 0;
+ char** argv = NULL;
+ whale::WhaleInit(argc, argv);
+ }
+ else
+ log(TRACE,"whale is disabled");
+
+ singleton().whale_initialized = true;
+#else
+ dolfin_error("SubSystemsManager.cpp",
+ "initialize Whale subsystem",
+ "DOLFIN has not been configured with Whale support");
+#endif
+}
diff --git a/dolfin/common/SubSystemsManager.h b/dolfin/common/SubSystemsManager.h
index ffc9fcd..c190f3f 100644
--- a/dolfin/common/SubSystemsManager.h
+++ b/dolfin/common/SubSystemsManager.h
@@ -65,6 +65,9 @@ namespace dolfin
/// finalised)
static bool mpi_finalized();
+ static void init_whale();
+ static void init_whale(int argc, char *argv[]);
+
private:
// Constructor (private)
@@ -88,6 +91,7 @@ namespace dolfin
// State variables
bool petsc_initialized;
bool control_mpi;
+ bool whale_initialized;
};
diff --git a/dolfin/common/defines.cpp b/dolfin/common/defines.cpp
index 3680bd5..4009a14 100644
--- a/dolfin/common/defines.cpp
+++ b/dolfin/common/defines.cpp
@@ -80,6 +80,15 @@ bool dolfin::has_petsc()
#endif
}
//-------------------------------------------------------------------------
+bool dolfin::has_whale()
+{
+#ifdef HAS_WHALE
+ return true;
+#else
+ return false;
+#endif
+}
+//-------------------------------------------------------------------------
bool dolfin::has_slepc()
{
#ifdef HAS_SLEPC
diff --git a/dolfin/common/defines.h b/dolfin/common/defines.h
index a949943..112efa1 100644
--- a/dolfin/common/defines.h
+++ b/dolfin/common/defines.h
@@ -73,6 +73,9 @@ namespace dolfin
/// Return true if DOLFIN is compiled with HDF5
bool has_hdf5();
+ /// Return true if DOLFIN is compiled with Whale
+ bool has_whale();
+
}
#endif
diff --git a/dolfin/common/init.cpp b/dolfin/common/init.cpp
index f62e6e4..31cff5d 100644
--- a/dolfin/common/init.cpp
+++ b/dolfin/common/init.cpp
@@ -31,5 +31,9 @@ void dolfin::init(int argc, char* argv[])
#ifdef HAS_PETSC
SubSystemsManager::init_petsc(argc, argv);
#endif
+
+ #ifdef HAS_WHALE
+ SubSystemsManager::init_whale(argc, argv);
+ #endif
}
//-----------------------------------------------------------------------------
diff --git a/dolfin/la/DefaultFactory.cpp b/dolfin/la/DefaultFactory.cpp
index b8cbe1b..cca5743 100644
--- a/dolfin/la/DefaultFactory.cpp
+++ b/dolfin/la/DefaultFactory.cpp
@@ -25,6 +25,7 @@
#include "PETScFactory.h"
#include "STLFactory.h"
#include "TpetraFactory.h"
+#include "WhaleFactory.h"
#include "DefaultFactory.h"
using namespace dolfin;
@@ -84,6 +85,19 @@ DefaultFactory::krylov_solver_preconditioners() const
//-----------------------------------------------------------------------------
GenericLinearAlgebraFactory& DefaultFactory::factory()
{
+#ifdef HAS_WHALE
+ const bool use_whale = dolfin::parameters["use_whale_backend"];
+ if (use_whale)
+ {
+ return WhaleFactory::instance();
+ }
+#endif
+
+ factory_internal();
+}
+//-----------------------------------------------------------------------------
+GenericLinearAlgebraFactory& DefaultFactory::factory_internal()
+{
// Fallback
const std::string default_backend = "Eigen";
diff --git a/dolfin/la/DefaultFactory.h b/dolfin/la/DefaultFactory.h
index 9ff0869..dc541c0 100644
--- a/dolfin/la/DefaultFactory.h
+++ b/dolfin/la/DefaultFactory.h
@@ -74,6 +74,7 @@ namespace dolfin
/// Return instance of default backend
static GenericLinearAlgebraFactory& factory();
+ static GenericLinearAlgebraFactory& factory_internal();
};
diff --git a/dolfin/la/GenericLUSolver.h b/dolfin/la/GenericLUSolver.h
index 464dc95..dc82ed8 100644
--- a/dolfin/la/GenericLUSolver.h
+++ b/dolfin/la/GenericLUSolver.h
@@ -27,6 +27,10 @@
#include <dolfin/common/Variable.h>
#include "GenericLinearSolver.h"
+#ifdef HAS_WHALE
+#include "WhaleExtensions.h"
+#endif
+
namespace dolfin
{
@@ -37,6 +41,9 @@ namespace dolfin
/// This a base class for LU solvers
class GenericLUSolver : public GenericLinearSolver
+#ifdef HAS_WHALE
+ ,public GenericWhaleLUSolver
+#endif
{
public:
diff --git a/dolfin/la/GenericLinearOperator.h b/dolfin/la/GenericLinearOperator.h
index edb1910..c19588a 100644
--- a/dolfin/la/GenericLinearOperator.h
+++ b/dolfin/la/GenericLinearOperator.h
@@ -23,6 +23,10 @@
#include "LinearAlgebraObject.h"
+#ifdef HAS_WHALE
+#include "WhaleExtensions.h"
+#endif
+
namespace dolfin
{
@@ -40,6 +44,9 @@ namespace dolfin
/// use the _LinearOperator_ class.
class GenericLinearOperator : public virtual LinearAlgebraObject
+#ifdef HAS_WHALE
+ ,virtual public GenericWhaleLinearOperator
+#endif
{
public:
@@ -58,6 +65,7 @@ namespace dolfin
protected:
friend class LinearOperator;
+ friend class WhaleLinearOperator;
// Initialize linear operator to match parallel layout of vectors
// x and y for product y = Ax. Needs to be implemented by backend.
diff --git a/dolfin/la/GenericLinearSolver.h b/dolfin/la/GenericLinearSolver.h
index 3e72bc1..328b9e5 100644
--- a/dolfin/la/GenericLinearSolver.h
+++ b/dolfin/la/GenericLinearSolver.h
@@ -28,6 +28,10 @@
#include <dolfin/common/Variable.h>
#include <dolfin/log/log.h>
+#ifdef HAS_WHALE
+#include "WhaleExtensions.h"
+#endif
+
namespace dolfin
{
@@ -40,6 +44,10 @@ namespace dolfin
/// This class provides a general solver for linear systems Ax = b.
class GenericLinearSolver : public Variable
+#ifdef HAS_WHALE
+ ,virtual public GenericWhaleLinearSolver
+ ,public GenericWhaleKrylovSolver
+#endif
{
public:
diff --git a/dolfin/la/GenericMatrix.h b/dolfin/la/GenericMatrix.h
index 144513a..6938bdf 100644
--- a/dolfin/la/GenericMatrix.h
+++ b/dolfin/la/GenericMatrix.h
@@ -33,6 +33,10 @@
#include "GenericTensor.h"
#include "GenericLinearOperator.h"
+#ifdef HAS_WHALE
+#include "WhaleExtensions.h"
+#endif
+
namespace dolfin
{
@@ -42,6 +46,9 @@ namespace dolfin
/// This class defines a common interface for matrices.
class GenericMatrix : public GenericTensor, public GenericLinearOperator
+#ifdef HAS_WHALE
+ ,public GenericWhaleMatrix
+#endif
{
public:
diff --git a/dolfin/la/GenericVector.h b/dolfin/la/GenericVector.h
index bec570f..b613b0f 100644
--- a/dolfin/la/GenericVector.h
+++ b/dolfin/la/GenericVector.h
@@ -36,6 +36,10 @@
#include "TensorLayout.h"
#include "GenericTensor.h"
+#ifdef HAS_WHALE
+#include "WhaleExtensions.h"
+#endif
+
namespace dolfin
{
template<typename T> class Array;
@@ -43,6 +47,9 @@ namespace dolfin
/// This class defines a common interface for vectors.
class GenericVector : public GenericTensor
+#ifdef HAS_WHALE
+ ,public GenericWhaleVector
+#endif
{
public:
diff --git a/dolfin/la/KrylovSolver.h b/dolfin/la/KrylovSolver.h
index 24e456b..42af060 100644
--- a/dolfin/la/KrylovSolver.h
+++ b/dolfin/la/KrylovSolver.h
@@ -83,6 +83,11 @@ namespace dolfin
this->parameters.update(parameters);
solver->parameters.update(parameters);
}
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestKrylovSolver();
+#endif
+
// FIXME: This should not be needed. Need to cleanup linear solver
// name jungle: default, lu, iterative, direct, krylov, etc
diff --git a/dolfin/la/LUSolver.h b/dolfin/la/LUSolver.h
index 2eb68ab..ee4f4bf 100644
--- a/dolfin/la/LUSolver.h
+++ b/dolfin/la/LUSolver.h
@@ -89,6 +89,12 @@ namespace dolfin
this->parameters.update(parameters);
solver->parameters.update(parameters);
}
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestLUSolver();
+ virtual void TestLinearSolver();
+#endif
+
// FIXME: This should not be needed. Need to cleanup linear solver
// name jungle: default, lu, iterative, direct, krylov, etc /
diff --git a/dolfin/la/LinearOperator.h b/dolfin/la/LinearOperator.h
index 68904aa..d771c34 100644
--- a/dolfin/la/LinearOperator.h
+++ b/dolfin/la/LinearOperator.h
@@ -73,6 +73,11 @@ namespace dolfin
/// Return concrete instance / unwrap (shared pointer version)
virtual std::shared_ptr<LinearAlgebraObject> shared_instance();
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestLinearOperator();
+#endif
+
private:
// Pointer to concrete implementation
diff --git a/dolfin/la/LinearSolver.h b/dolfin/la/LinearSolver.h
index 3eb97ea..f6cde12 100644
--- a/dolfin/la/LinearSolver.h
+++ b/dolfin/la/LinearSolver.h
@@ -80,6 +80,11 @@ namespace dolfin
this->parameters.update(parameters);
solver->update_parameters(parameters);
}
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestLinearSolver();
+#endif
+
// FIXME: This should not be needed. Need to cleanup linear solver
// name jungle: default, lu, iterative, direct, krylov, etc
@@ -94,6 +99,8 @@ namespace dolfin
friend class KrylovSolver;
friend class LinearVariationalSolver;
friend class NewtonSolver;
+ friend class WhaleKrylovSolver;
+ friend class WhaleLUSolver;
// Check whether string is contained in list
static bool in_list(const std::string& method,
diff --git a/dolfin/la/Matrix.h b/dolfin/la/Matrix.h
index 36f40c5..3d46eec 100644
--- a/dolfin/la/Matrix.h
+++ b/dolfin/la/Matrix.h
@@ -239,6 +239,12 @@ namespace dolfin
const Matrix& operator= (const Matrix& A)
{ *matrix = *A.matrix; return *this; }
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestMatrix();
+ virtual void TestLinearOperator();
+#endif
+
private:
// Pointer to concrete implementation
diff --git a/dolfin/la/PETScVector.cpp b/dolfin/la/PETScVector.cpp
index 7805bcc..a1ca576 100644
--- a/dolfin/la/PETScVector.cpp
+++ b/dolfin/la/PETScVector.cpp
@@ -77,6 +77,10 @@ PETScVector::PETScVector(const PETScVector& v) : _x(NULL)
{
PetscErrorCode ierr;
+ // avoid crashing if the vector is uninitialized
+ if (!v._x)
+ return;
+
// Create new vector
ierr = VecDuplicate(v._x, &_x);
if (ierr != 0) petsc_error(ierr, __FILE__, "VecDuplicate");
diff --git a/dolfin/la/Vector.h b/dolfin/la/Vector.h
index 21aed8d..d7d459d 100644
--- a/dolfin/la/Vector.h
+++ b/dolfin/la/Vector.h
@@ -285,6 +285,11 @@ namespace dolfin
const Vector& operator= (const Vector& x)
{ *vector = *x.vector; return *this; }
+#ifdef HAS_WHALE
+ /// Whale Extensions Interface
+ virtual void TestVector();
+#endif
+
private:
// Pointer to concrete implementation
diff --git a/dolfin/la/WhaleExtensions.cpp b/dolfin/la/WhaleExtensions.cpp
new file mode 100644
index 0000000..3ca374d
--- /dev/null
+++ b/dolfin/la/WhaleExtensions.cpp
@@ -0,0 +1,108 @@
+#ifdef HAS_WHALE
+
+#include <iostream>
+
+#include "WhaleExtensions.h"
+#include "WhaleVector.h"
+#include "WhaleMatrix.h"
+#include "WhaleLinearOperator.h"
+#include "WhaleLUSolver.h"
+#include "WhaleKrylovSolver.h"
+
+#include "Vector.h"
+#include "Matrix.h"
+#include "LinearOperator.h"
+#include "LinearSolver.h"
+#include "LUSolver.h"
+#include "KrylovSolver.h"
+
+namespace dolfin
+{
+
+void Vector::TestVector()
+{
+ GenericWhaleVector& Base = this->down_cast<GenericWhaleVector>();
+ Base.TestVector();
+}
+
+void Matrix::TestMatrix()
+{
+ GenericWhaleMatrix& Base = this->down_cast<GenericWhaleMatrix>();
+ Base.TestMatrix();
+}
+
+void Matrix::TestLinearOperator()
+{
+ GenericWhaleLinearOperator& Base = this->down_cast<GenericWhaleLinearOperator>();
+ Base.TestLinearOperator();
+}
+
+void LinearOperator::TestLinearOperator()
+{
+ GenericWhaleLinearOperator& _matABase = _matA->down_cast<GenericWhaleLinearOperator>();
+ _matABase.TestLinearOperator();
+}
+
+void LUSolver::TestLinearSolver()
+{
+ GenericWhaleLinearSolver& Base = dynamic_cast<GenericWhaleLinearSolver&>(*solver.get());
+ Base.TestLinearSolver();
+}
+
+void LUSolver::TestLUSolver()
+{
+ GenericLUSolver& LBase = dynamic_cast<GenericLUSolver&>(*solver.get());
+ GenericWhaleLUSolver& Base = dynamic_cast<GenericWhaleLUSolver&>(LBase);
+ Base.TestLUSolver();
+}
+
+void KrylovSolver::TestKrylovSolver()
+{
+ GenericWhaleKrylovSolver& Base = dynamic_cast<GenericWhaleKrylovSolver&>(*solver.get());
+ Base.TestKrylovSolver();
+}
+
+void LinearSolver::TestLinearSolver()
+{
+ GenericWhaleLinearSolver& Base = dynamic_cast<GenericWhaleLinearSolver&>(*solver.get());
+ Base.TestLinearSolver();
+}
+
+void WhaleVector::TestVector()
+{
+ std::cout << "WhaleVector test\n";
+}
+
+void WhaleMatrix::TestMatrix()
+{
+ std::cout << "WhaleMatrix test\n";
+}
+
+void WhaleMatrix::TestLinearOperator()
+{
+ std::cout << "WhaleMatrix TestLinearOperator\n";
+}
+
+void WhaleLinearOperator::TestLinearOperator()
+{
+ std::cout << "WhaleLinearOperator TestLinearOperator\n";
+}
+
+void WhaleLUSolver::TestLUSolver()
+{
+ std::cout << "WhaleLUSolver TestLUSolver\n";
+}
+
+void WhaleLUSolver::TestLinearSolver()
+{
+ std::cout << "WhaleLUSolver TestLinearSolver\n";
+}
+
+void WhaleKrylovSolver::TestKrylovSolver()
+{
+ std::cout << "WhaleKrylovSolver TestKrylovSolver\n";
+}
+
+}
+
+#endif
diff --git a/dolfin/la/WhaleExtensions.h b/dolfin/la/WhaleExtensions.h
new file mode 100644
index 0000000..9d57f44
--- /dev/null
+++ b/dolfin/la/WhaleExtensions.h
@@ -0,0 +1,62 @@
+/*
+ * WhaleExtensions.h
+ *
+ * Created on: Feb 25, 2014
+ * Author: emmmarou
+ */
+
+#ifndef WHALEEXTENSIONS_H_
+#define WHALEEXTENSIONS_H_
+
+#ifdef HAS_WHALE
+
+namespace dolfin
+{
+
+class GenericWhaleVector
+{
+public:
+ virtual ~GenericWhaleVector() {}
+ virtual void TestVector() {};
+};
+
+class GenericWhaleLinearOperator
+{
+public:
+ virtual ~GenericWhaleLinearOperator() {}
+ virtual void TestLinearOperator() {};
+};
+
+class GenericWhaleMatrix : virtual public GenericWhaleLinearOperator
+{
+public:
+ virtual ~GenericWhaleMatrix() {}
+ virtual void TestMatrix() {};
+};
+
+class GenericWhaleLinearSolver
+{
+public:
+ virtual ~GenericWhaleLinearSolver() {}
+ virtual void TestLinearSolver() {};
+};
+
+class GenericWhaleLUSolver : virtual public GenericWhaleLinearSolver
+{
+public:
+ virtual ~GenericWhaleLUSolver() {}
+ virtual void TestLUSolver() {};
+};
+
+class GenericWhaleKrylovSolver
+{
+public:
+ virtual ~GenericWhaleKrylovSolver() {}
+ virtual void TestKrylovSolver() {};
+};
+
+}
+
+#endif
+
+#endif /* WHALEEXTENSIONS_H_ */
diff --git a/dolfin/la/WhaleFactory.cpp b/dolfin/la/WhaleFactory.cpp
new file mode 100644
index 0000000..8d3e2bd
--- /dev/null
+++ b/dolfin/la/WhaleFactory.cpp
@@ -0,0 +1,87 @@
+#ifdef HAS_WHALE
+
+#include <dolfin/parameter/GlobalParameters.h>
+#include "WhaleFactory.h"
+#include "DefaultFactory.h"
+#include "WhaleVector.h"
+#include "WhaleMatrix.h"
+#include "WhaleLinearOperator.h"
+#include "WhaleLUSolver.h"
+#include "WhaleKrylovSolver.h"
+
+using namespace dolfin;
+
+WhaleFactory WhaleFactory::factory;
+
+//-----------------------------------------------------------------------------
+std::shared_ptr<GenericMatrix> WhaleFactory::create_matrix() const
+{
+ log(PROGRESS,"whale create_matrix\n");
+ std::shared_ptr<GenericMatrix> M(df().create_matrix());
+ std::shared_ptr<GenericMatrix> W(new WhaleMatrix(*M.get()));
+ return W;
+}
+//-----------------------------------------------------------------------------
+std::shared_ptr<GenericVector> WhaleFactory::create_vector() const
+{
+ log(PROGRESS,"whale create_vector\n");
+ std::shared_ptr<GenericVector> V(df().create_vector());
+ std::shared_ptr<GenericVector> W(new WhaleVector(*V.get()));
+ return W;
+}
+//-----------------------------------------------------------------------------
+std::shared_ptr<TensorLayout> WhaleFactory::create_layout(std::size_t rank) const
+{
+ return df().create_layout(rank);
+}
+//-----------------------------------------------------------------------------
+std::shared_ptr<GenericLinearOperator> WhaleFactory::create_linear_operator() const
+{
+ log(PROGRESS,"whale create_linear_operator\n");
+ std::shared_ptr<GenericLinearOperator> L(df().create_linear_operator());
+ std::shared_ptr<GenericLinearOperator> W(new WhaleLinearOperator(L.get()));
+ return W;
+}
+//-----------------------------------------------------------------------------
+std::shared_ptr<GenericLUSolver>
+ WhaleFactory::create_lu_solver(std::string method) const
+{
+ log(PROGRESS,"whale create_lu_solver\n");
+ std::shared_ptr<GenericLUSolver> W(new WhaleLUSolver(method));
+ return W;
+}
+//-----------------------------------------------------------------------------
+std::shared_ptr<GenericLinearSolver>
+ WhaleFactory::create_krylov_solver(std::string method,
+ std::string preconditioner) const
+{
+ log(PROGRESS,"whale create_krylov_solver\n");
+ std::shared_ptr<GenericLinearSolver> W(new WhaleKrylovSolver(method,preconditioner));
+ return W;
+}
+//-----------------------------------------------------------------------------
+std::map<std::string, std::string>
+ WhaleFactory::lu_solver_methods() const
+{
+ return df().lu_solver_methods();
+}
+ //-----------------------------------------------------------------------------
+std::map<std::string, std::string>
+ WhaleFactory::krylov_solver_methods() const
+{
+ return df().krylov_solver_methods();
+}
+//-----------------------------------------------------------------------------
+std::map<std::string, std::string>
+ WhaleFactory::krylov_solver_preconditioners() const
+{
+ return df().krylov_solver_preconditioners();
+}
+//-----------------------------------------------------------------------------
+GenericLinearAlgebraFactory& WhaleFactory::df() const
+{
+ DefaultFactory::factory_internal();
+}
+//-----------------------------------------------------------------------------
+
+#endif
diff --git a/dolfin/la/WhaleFactory.h b/dolfin/la/WhaleFactory.h
new file mode 100644
index 0000000..d09d5ae
--- /dev/null
+++ b/dolfin/la/WhaleFactory.h
@@ -0,0 +1,68 @@
+#ifndef __WHALE_FACTORY_H
+#define __WHALE_FACTORY_H
+
+#ifdef HAS_WHALE
+
+#include "GenericLinearAlgebraFactory.h"
+
+namespace dolfin
+{
+
+ class WhaleFactory : public GenericLinearAlgebraFactory
+ {
+ public:
+
+ /// Destructor
+ virtual ~WhaleFactory() {}
+
+ /// Create empty matrix
+ virtual std::shared_ptr<GenericMatrix> create_matrix() const;
+
+ /// Create empty vector (global)
+ virtual std::shared_ptr<GenericVector> create_vector() const;
+
+ /// Create empty tensor layout
+ virtual std::shared_ptr<TensorLayout> create_layout(std::size_t rank) const;
+
+ /// Create empty linear operator
+ virtual std::shared_ptr<GenericLinearOperator> create_linear_operator() const;
+
+ /// Create LU solver
+ virtual std::shared_ptr<dolfin::GenericLUSolver>
+ create_lu_solver(std::string method) const;
+
+ /// Create Krylov solver
+ virtual std::shared_ptr<dolfin::GenericLinearSolver>
+ create_krylov_solver(std::string method, std::string preconditioner) const;
+
+ /// Return a list of available LU solver methods
+ std::map<std::string, std::string>
+ lu_solver_methods() const;
+
+ /// Return a list of available Krylov solver methods
+ std::map<std::string, std::string>
+ krylov_solver_methods() const;
+
+ /// Return a list of available preconditioners
+ std::map<std::string, std::string>
+ krylov_solver_preconditioners() const;
+
+ /// Return singleton instance
+ static WhaleFactory& instance()
+ { return factory; }
+
+ private:
+
+ GenericLinearAlgebraFactory& df() const;
+
+ /// Private constructor
+ WhaleFactory() {}
+ static WhaleFactory factory;
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/dolfin/la/WhaleKrylovSolver.cpp b/dolfin/la/WhaleKrylovSolver.cpp
new file mode 100644
index 0000000..0ec455b
--- /dev/null
+++ b/dolfin/la/WhaleKrylovSolver.cpp
@@ -0,0 +1,112 @@
+#ifdef HAS_WHALE
+
+#include <dolfin/parameter/GlobalParameters.h>
+#include "WhaleKrylovSolver.h"
+#include "DefaultFactory.h"
+#include "KrylovSolver.h"
+#include "LinearSolver.h"
+
+using namespace dolfin;
+
+//-----------------------------------------------------------------------------
+Parameters WhaleKrylovSolver::default_parameters()
+{
+ return KrylovSolver::default_parameters();
+}
+//-----------------------------------------------------------------------------
+WhaleKrylovSolver::WhaleKrylovSolver(std::string method, std::string preconditioner)
+{
+ init(method, preconditioner);
+}
+//-----------------------------------------------------------------------------
+WhaleKrylovSolver::WhaleKrylovSolver(std::shared_ptr<const GenericLinearOperator> A,
+ std::string method, std::string preconditioner)
+{
+ init(method, preconditioner);
+ set_operator(A);
+}
+//-----------------------------------------------------------------------------
+WhaleKrylovSolver::~WhaleKrylovSolver()
+{
+ // Do nothing
+}
+//-----------------------------------------------------------------------------
+void WhaleKrylovSolver::set_operator(const std::shared_ptr<const GenericLinearOperator> A)
+{
+ dolfin_assert(nested);
+ nested->parameters.update(parameters);
+ nested->set_operator(A);
+}
+//-----------------------------------------------------------------------------
+void WhaleKrylovSolver::set_operators(const std::shared_ptr<const GenericLinearOperator> A,
+ const std::shared_ptr<const GenericLinearOperator> P)
+{
+ dolfin_assert(nested);
+ nested->parameters.update(parameters);
+ nested->set_operators(A,P);
+}
+//-----------------------------------------------------------------------------
+void WhaleKrylovSolver::set_nullspace(const VectorSpaceBasis& nullspace)
+{
+ nested->set_nullspace(nullspace);
+}
+//-----------------------------------------------------------------------------
+std::size_t WhaleKrylovSolver::solve(GenericVector& x, const GenericVector& b)
+{
+ dolfin_assert(nested);
+ //check_dimensions(solver->get_operator(), x, b);
+
+ nested->parameters.update(parameters);
+ return nested->solve(x, b);
+}
+//-----------------------------------------------------------------------------
+std::size_t WhaleKrylovSolver::solve(const GenericLinearOperator& A,
+ GenericVector& x,
+ const GenericVector& b)
+{
+ dolfin_assert(nested);
+ //check_dimensions(A, x, b);
+
+ nested->parameters.update(parameters);
+ return nested->solve(A, x, b);
+}
+//-----------------------------------------------------------------------------
+void WhaleKrylovSolver::init(std::string method, std::string preconditioner)
+{
+ // Get default linear algebra factory
+ GenericLinearAlgebraFactory& factory = DefaultFactory::factory_internal();
+
+ // Get list of available methods and preconditioners
+ std::map<std::string, std::string>
+ methods = factory.krylov_solver_methods();
+ std::map<std::string, std::string>
+ preconditioners = factory.krylov_solver_preconditioners();
+
+ // Check that method is available
+ if (!LinearSolver::in_list(method, methods))
+ {
+ dolfin_error("WhaleKrylovSolver.cpp",
+ "solve linear system using Krylov iteration",
+ "Unknown Krylov method \"%s\". "
+ "Use list_krylov_solver_methods() to list available Krylov methods",
+ method.c_str());
+ }
+
+ // Check that preconditioner is available
+ if (!LinearSolver::in_list(preconditioner, preconditioners))
+ {
+ dolfin_error("WhaleKrylovSolver.cpp",
+ "solve linear system using Krylov iteration",
+ "Unknown preconditioner \"%s\". "
+ "Use list_krylov_solver_preconditioners() to list available preconditioners()",
+ preconditioner.c_str());
+ }
+
+ // Set default parameters
+ parameters = dolfin::parameters("krylov_solver");
+
+ // Initialize solver
+ nested = factory.create_krylov_solver(method, preconditioner);
+ nested->parameters.update(parameters);
+}
+#endif
diff --git a/dolfin/la/WhaleKrylovSolver.h b/dolfin/la/WhaleKrylovSolver.h
new file mode 100644
index 0000000..3b8dd86
--- /dev/null
+++ b/dolfin/la/WhaleKrylovSolver.h
@@ -0,0 +1,87 @@
+#ifndef __WHALE_KRYLOV_SOLVER_H
+#define __WHALE_KRYLOV_SOLVER_H
+
+#ifdef HAS_WHALE
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <boost/scoped_ptr.hpp>
+#include "GenericLinearSolver.h"
+#include "WhaleObject.h"
+#include "WhaleExtensions.h"
+
+namespace dolfin
+{
+
+ class GenericLinearOperator;
+ class GenericVector;
+ class VectorSpaceBasis;
+
+ /// This class defines an interface for a Krylov solver. The
+ /// approproiate solver is chosen on the basis of the matrix/vector
+ /// type.
+
+ class WhaleKrylovSolver : public GenericLinearSolver, public WhaleObject
+ {
+ public:
+
+ /// Constructor
+ WhaleKrylovSolver(std::string method="default",
+ std::string preconditioner="default");
+
+ /// Constructor