-
Notifications
You must be signed in to change notification settings - Fork 62
/
equations_matrices_routines.f90
4874 lines (4247 loc) · 259 KB
/
equations_matrices_routines.f90
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
!> \file
!> \author Chris Bradley
!> \brief This module handles all equations matrix and rhs routines.
!>
!> \section LICENSE
!>
!> Version: MPL 1.1/GPL 2.0/LGPL 2.1
!>
!> The contents of this file are subject to the Mozilla Public License
!> Version 1.1 (the "License"); you may not use this file except in
!> compliance with the License. You may obtain a copy of the License at
!> http://www.mozilla.org/MPL/
!>
!> Software distributed under the License is distributed on an "AS IS"
!> basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
!> License for the specific language governing rights and limitations
!> under the License.
!>
!> The Original Code is OpenCMISS
!>
!> The Initial Developer of the Original Code is University of Auckland,
!> Auckland, New Zealand, the University of Oxford, Oxford, United
!> Kingdom and King's College, London, United Kingdom. Portions created
!> by the University of Auckland, the University of Oxford and King's
!> College, London are Copyright (C) 2007-2010 by the University of
!> Auckland, the University of Oxford and King's College, London.
!> All Rights Reserved.
!>
!> Contributor(s): David Ladd
!>
!> Alternatively, the contents of this file may be used under the terms of
!> either the GNU General Public License Version 2 or later (the "GPL"), or
!> the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
!> in which case the provisions of the GPL or the LGPL are applicable instead
!> of those above. If you wish to allow use of your version of this file only
!> under the terms of either the GPL or the LGPL, and not to allow others to
!> use your version of this file under the terms of the MPL, indicate your
!> decision by deleting the provisions above and replace them with the notice
!> and other provisions required by the GPL or the LGPL. If you do not delete
!> the provisions above, a recipient may use your version of this file under
!> the terms of any one of the MPL, the GPL or the LGPL.
!>
!> This module handles all equations matrix and rhs routines.
MODULE EquationsMatricesRoutines
USE BaseRoutines
USE DistributedMatrixVector
USE EquationsAccessRoutines
USE EquationsMappingAccessRoutines
USE EquationsMatricesAccessRoutines
USE EquationsSetAccessRoutines
USE EquationsSetConstants
USE FIELD_ROUTINES
USE ISO_VARYING_STRING
USE Kinds
USE Lists
USE MatrixVector
USE Strings
USE Types
USE LINKEDLIST_ROUTINES
#include "macros.h"
IMPLICIT NONE
PRIVATE
!Module parameters
!> \addtogroup EquationsMatricesRoutines_EquationsMatrixStructureTypes EquationsMatricesRoutines::EquationsMatrixStructureTypes
!> \brief Equations matrices structure (sparsity) types
!> \see EquationsMatricesRoutines
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_NO_STRUCTURE=1 !<No matrix structure - all elements can contain a value. \see EquationsMatricesRoutines_EquationsMatrixStructureTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_FEM_STRUCTURE=2 !<Finite element matrix structure. \see EquationsMatricesRoutines_EquationsMatrixStructureTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_DIAGONAL_STRUCTURE=3 !<Diagonal matrix structure. \see EquationsMatricesRoutines_EquationsMatrixStructureTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_NODAL_STRUCTURE=4 !<Nodal matrix structure. \see EquationsMatricesRoutines_EquationsMatrixStructureTypes,EquationsMatricesRoutines
!>@}
!> \addtogroup EquationsMatricesRoutines_LumpingTypes EquationsMatricesRoutines::LumpingTypes
!> \brief Equations matrix lumping types
!> \see EquationsMatricesRoutines
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_UNLUMPED=1 !<The matrix is not lumped \see EquationsMatricesRoutines_LumpingTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRIX_LUMPED=2 !<The matrix is "mass" lumped \see EquationsMatricesRoutines_LumpingTypes,EquationsMatricesRoutines
!>@}
!> \addtogroup EquationsMatricesRoutines_EquationsMatricesSparsityTypes EquationsMatricesRoutines::EquationsMatricesSparsityTypes
!> \brief Equations matrices sparsity types
!> \see EquationsMatricesRoutines
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_SPARSE_MATRICES=1 !<Use sparse equations matrices \see EquationsMatricesRoutines_EquationsMatricesSparsityTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_FULL_MATRICES=2 !<Use fully populated equation matrices \see EquationsMatricesRoutines_EquationsMatricesSparsityTypes,EquationsMatricesRoutines
!>@}
!> \addtogroup EquationsMatricesRoutines_SelectMatricesTypes EquationsMatricesRoutines::SelectMatricesTypes
!> \brief The types of selection available for the equations matrices
!> \see SOLVER_ROUTINES
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_ALL=1 !<Select all the equations matrices and vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_DYNAMIC_ONLY=2 !<Select only the dynamic equations matrices and vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_LINEAR_ONLY=3 !<Select only the linear equations matrices and vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_NONLINEAR_ONLY=4 !<Select only the nonlinear equations matrices and vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_JACOBIAN_ONLY=5 !<Select only the Jacobian equations matrix \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_RESIDUAL_ONLY=6 !<Select only the residual equations vector \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_RHS_ONLY=7 !<Select only the RHS equations vector \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_SOURCE_ONLY=8 !<Select only the RHS equations vector \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_RHS_RESIDUAL_ONLY=9 !<Select only the RHS and residual equations vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_RHS_SOURCE_ONLY=10 !<Assemble only the RHS and source equations vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_RESIDUAL_SOURCE_ONLY=11 !<Assemble only the residual and source equations vectors\see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
INTEGER(INTG), PARAMETER :: EQUATIONS_MATRICES_VECTORS_ONLY=12 !<Assemble only the equations vectors \see EquationsMatricesRoutines::SelectMatricesTypes,EquationsMatricesRoutines
!>@}
!> \addtogroup EquationsMatricesRoutines_GradientCalculationTypes EquationsMatricesRoutines::GradientCalculationTypes
!> \brief Gradient calculation types
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_GRADIENT_FINITE_DIFFERENCE_CALCULATED=1 !<Use finite differencing to calculate the gradient
INTEGER(INTG), PARAMETER :: EQUATIONS_GRADIENT_ANALYTIC_CALCULATED=2 !<Use an analytic gradient evaluation
!>@}
!> \addtogroup EquationsMatricesRoutines_JacobianCalculationTypes EquationsMatricesRoutines::JacobianCalculationTypes
!> \brief Jacobian calculation types
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_JACOBIAN_FINITE_DIFFERENCE_CALCULATED=1 !<Use finite differencing to calculate the Jacobian
INTEGER(INTG), PARAMETER :: EQUATIONS_JACOBIAN_ANALYTIC_CALCULATED=2 !<Use an analytic Jacobian evaluation
!>@}
!> \addtogroup EquationsMatricesRoutines_HessianCalculationTypes EquationsMatricesRoutines::HessianCalculationTypes
!> \brief Hessian calculation types
!>@{
INTEGER(INTG), PARAMETER :: EQUATIONS_HESSIAN_FINITE_DIFFERENCE_CALCULATED=1 !<Use finite differencing to calculate the Hessian
INTEGER(INTG), PARAMETER :: EQUATIONS_HESSIAN_ANALYTIC_CALCULATED=2 !<Use an analytic Hessian evaluation
!>@}
!>@}
!Module types
!Module variables
!Interfaces
!>Sets the storage type (sparsity) of the nonlinear (Jacobian) equations matrices
INTERFACE EquationsMatrices_NonlinearStorageTypeSet
MODULE PROCEDURE EquationsMatrices_NonlinearStorageTypeSet0
MODULE PROCEDURE EquationsMatrices_NonlinearStorageTypeSet1
END INTERFACE EquationsMatrices_NonlinearStorageTypeSet
!>Sets the structure (sparsity) of the nonlinear (Jacobian) equations matrices
INTERFACE EquationsMatrices_NonlinearStructureTypeSet
MODULE PROCEDURE EquationsMatrices_NonlinearStructureTypeSet0
MODULE PROCEDURE EquationsMatrices_NonlinearStructureTypeSet1
END INTERFACE EquationsMatrices_NonlinearStructureTypeSet
PUBLIC EQUATIONS_MATRIX_NO_STRUCTURE,EQUATIONS_MATRIX_FEM_STRUCTURE,EQUATIONS_MATRIX_DIAGONAL_STRUCTURE, &
& EQUATIONS_MATRIX_NODAL_STRUCTURE
PUBLIC EQUATIONS_MATRIX_UNLUMPED,EQUATIONS_MATRIX_LUMPED
PUBLIC EQUATIONS_MATRICES_SPARSE_MATRICES,EQUATIONS_MATRICES_FULL_MATRICES
PUBLIC EQUATIONS_MATRICES_ALL,EQUATIONS_MATRICES_LINEAR_ONLY,EQUATIONS_MATRICES_NONLINEAR_ONLY,EQUATIONS_MATRICES_JACOBIAN_ONLY, &
& EQUATIONS_MATRICES_RESIDUAL_ONLY,EQUATIONS_MATRICES_RHS_ONLY,EQUATIONS_MATRICES_SOURCE_ONLY, &
& EQUATIONS_MATRICES_RHS_RESIDUAL_ONLY,EQUATIONS_MATRICES_RHS_SOURCE_ONLY,EQUATIONS_MATRICES_RESIDUAL_SOURCE_ONLY, &
& EQUATIONS_MATRICES_VECTORS_ONLY
PUBLIC EQUATIONS_GRADIENT_FINITE_DIFFERENCE_CALCULATED,EQUATIONS_GRADIENT_ANALYTIC_CALCULATED
PUBLIC EQUATIONS_JACOBIAN_FINITE_DIFFERENCE_CALCULATED,EQUATIONS_JACOBIAN_ANALYTIC_CALCULATED
PUBLIC EQUATIONS_HESSIAN_FINITE_DIFFERENCE_CALCULATED,EQUATIONS_HESSIAN_ANALYTIC_CALCULATED
PUBLIC EquationsMatrices_DynamicLumpingTypeSet
PUBLIC EquationsMatrices_DynamicStorageTypeSet
PUBLIC EquationsMatrices_DynamicStructureTypeSet
!!TODO check if the elements should be create/destroy rather than initialise/finalise
PUBLIC EquationsMatrices_ElementInitialise,EquationsMatrices_ElementFinalise
PUBLIC EquationsMatrices_ElementAdd
PUBLIC EquationsMatrices_JacobianElementAdd
PUBLIC EquationsMatrices_ElementCalculate
PUBLIC EquationsMatrices_ElementMatrixFinalise,EquationsMatrices_ElementMatrixInitialise
PUBLIC EquationsMatrices_ElementMatrixCalculate
PUBLIC EquationsMatrices_ElementMatrixSetup
PUBLIC EquationsMatrices_ElementVectorFinalise,EquationsMatrices_ElementVectorInitialise
PUBLIC EquationsMatrices_ElementVectorCalculate
PUBLIC EquationsMatrices_ElementVectorSetup
PUBLIC EquationsMatrices_HessianOutput
PUBLIC EquationsMatrices_JacobianNodeAdd
PUBLIC EquationsMatrices_JacobianOutput
PUBLIC EquationsMatrices_JacobianTypesSet
PUBLIC EquationsMatrices_JacobianFiniteDifferenceStepSizeSet
PUBLIC EquationsMatrices_LinearStorageTypeSet
PUBLIC EquationsMatrices_LinearStructureTypeSet
PUBLIC EquationsMatrices_NodalInitialise,EquationsMatrices_NodalFinalise
PUBLIC EquationsMatrices_NodeAdd
PUBLIC EquationsMatrices_NodalCalculate
PUBLIC EquationsMatrices_NodalMatrixFinalise,EquationsMatrices_NodalMatrixInitialise
PUBLIC EquationsMatrices_NodalMatrixCalculate
PUBLIC EquationsMatrices_NodalMatrixSetup
PUBLIC EquationsMatrices_NodalVectorFinalise,EquationsMatrices_NodalVectorInitialise
PUBLIC EquationsMatrices_NodalVectorCalculate
PUBLIC EquationsMatrices_NodalVectorSetup
PUBLIC EquationsMatrices_NonlinearStorageTypeSet
PUBLIC EquationsMatrices_NonlinearStructureTypeSet
PUBLIC EquationsMatrices_ScalarDestroy
PUBLIC EquationsMatrices_VectorCreateFinish,EquationsMatrices_VectorCreateStart
PUBLIC EquationsMatrices_VectorDestroy
PUBLIC EquationsMatrices_VectorOutput
PUBLIC EquationsMatrices_VectorValuesInitialise
CONTAINS
!
!================================================================================================================================
!
!>Finalise the equations Hessian and deallocate all memory
SUBROUTINE EquationsMatrices_HessianFinalise(hessian,err,error,*)
!Argument variables
TYPE(EquationsHessianType), POINTER :: hessian !<A pointer to the equations Hessian to finalise
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
ENTERS("EquationsMatrices_HessianFinalise",err,error,*999)
IF(.NOT.ASSOCIATED(hessian)) THEN
IF(ASSOCIATED(hessian%hessian)) CALL DistributedMatrix_Destroy(hessian%hessian,err,error,*999)
CALL EquationsMatrices_ElementMatrixFinalise(hessian%elementHessian,err,error,*999)
DEALLOCATE(hessian)
ENDIF
EXITS("EquationsMatrices_HessianFinalise")
RETURN
999 ERRORSEXITS("EquationsMatrices_HessianFinalise",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_HessianFinalise
!
!================================================================================================================================
!
!>Finalise the equations Jacobian and deallocate all memory
SUBROUTINE EquationsMatrices_JacobianFinalise(equationsJacobian,err,error,*)
!Argument variables
TYPE(EquationsJacobianType), POINTER :: equationsJacobian !<A pointer to the equations Jacobian to finalise
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
ENTERS("EquationsMatrices_JacobianFinalise",err,error,*999)
IF(ASSOCIATED(equationsJacobian)) THEN
IF(ASSOCIATED(equationsJacobian%jacobian)) CALL DistributedMatrix_Destroy(equationsJacobian%jacobian,err,error,*999)
CALL EquationsMatrices_ElementMatrixFinalise(equationsJacobian%elementJacobian,err,error,*999)
CALL EquationsMatrices_NodalMatrixFinalise(equationsJacobian%nodalJacobian,err,error,*999)
DEALLOCATE(equationsJacobian)
ENDIF
EXITS("EquationsMatrices_JacobianFinalise")
RETURN
999 ERRORSEXITS("EquationsMatrices_JacobianFinalise",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_JacobianFinalise
!
!================================================================================================================================
!
!>Initialise the equations Jacobian.
SUBROUTINE EquationsMatrices_JacobianInitialise(nonlinearMatrices,matrixNumber,err,error,*)
!Argument variables
TYPE(EquationsMatricesNonlinearType), POINTER :: nonlinearMatrices !<A pointer to the equations matrices nonlinear matrices to initialise the Jacobian for
INTEGER(INTG), INTENT(IN) :: matrixNumber !<The index of the Jacobian matrix to initialise for the nonlinear matrices
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: dummyErr
TYPE(EquationsMappingNonlinearType), POINTER :: nonlinearMapping
TYPE(VARYING_STRING) :: dummyError,localError
ENTERS("EquationsMatrices_JacobianInitialise",err,error,*998)
IF(.NOT.ASSOCIATED(nonlinearMatrices)) CALL FlagError("Nonlinear matrices is not associated.",err,error,*998)
IF(.NOT.ALLOCATED(nonlinearMatrices%jacobians)) CALL FlagError("Nonlinear matrices Jacobians is not allocated.",err,error,*999)
NULLIFY(nonlinearMapping)
CALL EquationsMatricesNonlinear_NonlinearMappingGet(nonlinearMatrices,nonlinearMapping,err,error,*999)
IF(matrixNumber<1.OR.matrixNumber>nonlinearMatrices%numberOfJacobians) THEN
localError="The matrix number of "//TRIM(NumberToVString(matrixNumber,"*",err,error))// &
& " is invalid. The number must be >= 1 and <= "// &
& TRIM(NumberToVString(nonlinearMatrices%numberOfJacobians,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
ENDIF
IF(ASSOCIATED(nonlinearMatrices%jacobians(matrixNumber)%ptr)) THEN
localError="Nonlinear matrices Jacobian is already associated for matrix number "// &
& TRIM(NumberToVString(matrixNumber,"*",err,error))//"."
CALL FlagError(localError,err,error,*998)
ENDIF
ALLOCATE(nonlinearMatrices%jacobians(matrixNumber)%ptr,STAT=err)
IF(err/=0) CALL FlagError("Could not allocate equations Jacobian.",err,error,*999)
nonlinearMatrices%jacobians(matrixNumber)%ptr%jacobianNumber=matrixNumber
nonlinearMatrices%jacobians(matrixNumber)%ptr%nonlinearMatrices=>nonlinearMatrices
nonlinearMatrices%jacobians(matrixNumber)%ptr%storageType=MATRIX_BLOCK_STORAGE_TYPE
nonlinearMatrices%jacobians(matrixNumber)%ptr%structureType=EQUATIONS_MATRIX_NO_STRUCTURE
nonlinearMatrices%jacobians(matrixNumber)%ptr%numberOfColumns= &
& nonlinearMapping%jacobianToVarMap(matrixNumber)%numberOfColumns
nonlinearMatrices%jacobians(matrixNumber)%ptr%updateJacobian=.TRUE.
nonlinearMatrices%jacobians(matrixNumber)%ptr%firstAssembly=.TRUE.
nonlinearMapping%jacobianToVarMap(matrixNumber)%jacobian=>nonlinearMatrices%jacobians(matrixNumber)%ptr
NULLIFY(nonlinearMatrices%jacobians(matrixNumber)%ptr%jacobian)
CALL EquationsMatrices_ElementMatrixInitialise(nonlinearMatrices%jacobians(matrixNumber)%ptr%elementJacobian,err,error,*999)
CALL EquationsMatrices_NodalMatrixInitialise(nonlinearMatrices%jacobians(matrixNumber)%ptr%nodalJacobian,err,error,*999)
nonlinearMatrices%jacobians(matrixNumber)%ptr%jacobianCalculationType=EQUATIONS_JACOBIAN_FINITE_DIFFERENCE_CALCULATED
nonlinearMatrices%jacobians(matrixNumber)%ptr%jacobianFiniteDifferenceStepSize=1.0E-6_DP
EXITS("EquationsMatrices_JacobianInitialise")
RETURN
999 CALL EquationsMatrices_JacobianFinalise(nonlinearMatrices%jacobians(matrixNumber)%ptr,dummyErr,dummyError,*998)
998 ERRORSEXITS("EquationsMatrices_JacobianInitialise",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_JacobianInitialise
!
!================================================================================================================================
!
!>Finishes the creation of the vector equations matrices and RHS for the vector equations
SUBROUTINE EquationsMatrices_VectorCreateFinish(vectorMatrices,err,error,*)
!Argument variables
TYPE(EquationsMatricesVectorType), POINTER :: vectorMatrices !<The pointer to the vector equations matrices
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: dummyErr,matrixIdx,numberOfNonZeros
INTEGER(INTG), POINTER :: rowIndices(:),columnIndices(:)
TYPE(DOMAIN_MAPPING_TYPE), POINTER :: rowDomainMap,columnDomainMap
TYPE(EquationsJacobianType), POINTER :: jacobianMatrix
TYPE(EquationsMappingDynamicType), POINTER :: dynamicMapping
TYPE(EquationsMappingLinearType), POINTER :: linearMapping
TYPE(EquationsMappingVectorType), POINTER :: vectorMapping
TYPE(EquationsMatricesDynamicType), POINTER :: dynamicMatrices
TYPE(EquationsMatricesLinearType), POINTER :: linearMatrices
TYPE(EquationsMatricesNonlinearType), POINTER :: nonlinearMatrices
TYPE(EquationsMatricesRHSType), POINTER :: rhsVector
TYPE(EquationsMatricesSourceType), POINTER :: sourceVector
TYPE(EquationsMatrixType), POINTER :: equationsMatrix
TYPE(EquationsMappingNonlinearType), POINTER :: nonlinearMapping
TYPE(VARYING_STRING) :: dummyError,localError
TYPE(LinkedList), POINTER :: list(:)
NULLIFY(rowIndices)
NULLIFY(columnIndices)
ENTERS("EquationsMatrices_VectorCreateFinish",err,error,*998)
IF(.NOT.ASSOCIATED(vectorMatrices)) CALL FlagError("Vector equations matrices is not associated.",err,error,*998)
IF(vectorMatrices%vectorMatricesFinished) CALL FlagError("Vector equations matrices have already been finished.",err,error,*998)
NULLIFY(vectorMapping)
CALL EquationsMatricesVector_VectorMappingGet(vectorMatrices,vectorMapping,err,error,*999)
rowDomainMap=>vectorMapping%rowDOFSMapping
IF(.NOT.ASSOCIATED(rowDomainMap)) CALL FlagError("Row domain map is not associated.",err,error,*999)
dynamicMatrices=>vectorMatrices%dynamicMatrices
IF(ASSOCIATED(dynamicMatrices)) THEN
!Dynamic matrices
NULLIFY(dynamicMapping)
CALL EquationsMappingVector_DynamicMappingGet(vectorMapping,dynamicMapping,err,error,*999)
!Now create the individual dynamic equations matrices
DO matrixIdx=1,dynamicMatrices%numberOfDynamicMatrices
NULLIFY(equationsMatrix)
CALL EquationsMatricesDynamic_EquationsMatrixGet(dynamicMatrices,matrixIdx,equationsMatrix,err,error,*999)
columnDomainMap=>dynamicMapping%equationsMatrixToVarMaps(matrixIdx)%columnDOFSMapping
IF(.NOT.ASSOCIATED(columnDomainMap)) THEN
localError="Column domain map for dynamic matrix number "//TRIM(NumberToVString(matrixIdx,"*",err,error))// &
& " is not associated."
CALL FlagError(localError,err,error,*999)
ENDIF
!Create the distributed equations matrix
CALL DistributedMatrix_CreateStart(rowDomainMap,columnDomainMap,vectorMatrices%dynamicMatrices%matrices(matrixIdx)% &
& ptr%matrix,err,error,*999)
CALL DistributedMatrix_DataTypeSet(equationsMatrix%matrix,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedMatrix_StorageTypeSet(equationsMatrix%matrix,equationsMatrix%storageType,err,error,*999)
!Calculate and set the matrix structure/sparsity pattern
IF(equationsMatrix%storageType/=DISTRIBUTED_MATRIX_BLOCK_STORAGE_TYPE.AND. &
& equationsMatrix%storageType/=DISTRIBUTED_MATRIX_DIAGONAL_STORAGE_TYPE) THEN
NULLIFY(list)
CALL EquationsMatrix_StructureCalculate(equationsMatrix,numberOfNonZeros,rowIndices,columnIndices,list,err,error,*999)
CALL DistributedMatrix_LinkListSet(equationsMatrix%matrix,list,err,error,*999)
CALL DistributedMatrix_NumberOfNonZerosSet(equationsMatrix%matrix,numberOfNonZeros,err,error,*999)
CALL DistributedMatrix_StorageLocationsSet(equationsMatrix%matrix,rowIndices,columnIndices,err,error,*999)
IF(ASSOCIATED(rowIndices)) DEALLOCATE(rowIndices)
IF(ASSOCIATED(columnIndices)) DEALLOCATE(columnIndices)
ENDIF
CALL DistributedMatrix_CreateFinish(equationsMatrix%matrix,err,error,*999)
ENDDO !matrixIdx
ENDIF
linearMatrices=>vectorMatrices%linearMatrices
IF(ASSOCIATED(linearMatrices)) THEN
!Linear matrices
NULLIFY(linearMapping)
CALL EquationsMappingVector_LinearMappingGet(vectorMapping,linearMapping,err,error,*999)
!Now create the individual linear equations matrices
DO matrixIdx=1,linearMatrices%numberOfLinearMatrices
NULLIFY(equationsMatrix)
CALL EquationsMatricesLinear_EquationsMatrixGet(linearMatrices,matrixIdx,equationsMatrix,err,error,*999)
columnDomainMap=>linearMapping%equationsMatrixToVarMaps(matrixIdx)%columnDOFSMapping
IF(.NOT.ASSOCIATED(columnDomainMap)) THEN
localError="Column domain map for linear matrix number "//TRIM(NumberToVString(matrixIdx,"*",err,error))// &
& " is not associated."
CALL FlagError(localError,err,error,*999)
ENDIF
!Create the distributed equations matrix
CALL DistributedMatrix_CreateStart(rowDomainMap,columnDomainMap,vectorMatrices%linearMatrices%matrices(matrixIdx)% &
& ptr%matrix,err,error,*999)
CALL DistributedMatrix_DataTypeSet(equationsMatrix%matrix,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedMatrix_StorageTypeSet(equationsMatrix%matrix,equationsMatrix%storageType,err,error,*999)
!Calculate and set the matrix structure/sparsity pattern
IF(equationsMatrix%storageType/=DISTRIBUTED_MATRIX_BLOCK_STORAGE_TYPE.AND. &
& equationsMatrix%storageType/=DISTRIBUTED_MATRIX_DIAGONAL_STORAGE_TYPE) THEN
NULLIFY(list)
CALL EquationsMatrix_StructureCalculate(equationsMatrix,numberOfNonZeros,rowIndices,columnIndices,list,err,error,*999)
CALL DistributedMatrix_LinkListSet(equationsMatrix%matrix,LIST,err,error,*999)
CALL DistributedMatrix_NumberOfNonZerosSet(equationsMatrix%matrix,numberOfNonZeros,err,error,*999)
CALL DistributedMatrix_StorageLocationsSet(equationsMatrix%matrix,rowIndices,columnIndices,err,error,*999)
IF(ASSOCIATED(rowIndices)) DEALLOCATE(rowIndices)
IF(ASSOCIATED(columnIndices)) DEALLOCATE(columnIndices)
ENDIF
CALL DistributedMatrix_CreateFinish(equationsMatrix%matrix,err,error,*999)
ENDDO !matrixIdx
ENDIF
nonlinearMatrices=>vectorMatrices%nonlinearMatrices
IF(ASSOCIATED(nonlinearMatrices)) THEN
!Nonlinear matrices
NULLIFY(nonlinearMapping)
CALL EquationsMappingVector_NonlinearMappingGet(vectorMapping,nonlinearMapping,err,error,*999)
!Set up the Jacobian matrices
DO matrixIdx=1,nonlinearMatrices%numberOfJacobians
NULLIFY(jacobianMatrix)
CALL EquationsMatricesNonlinear_JacobianMatrixGet(nonlinearMatrices,matrixIdx,jacobianMatrix,err,error,*999)
columnDomainMap=>nonlinearMapping%jacobianToVarMap(matrixIdx)%columnDOFSMapping
IF(.NOT.ASSOCIATED(columnDomainMap)) THEN
localError="Column domain map for Jacobian matrix number "//TRIM(NumberToVString(matrixIdx,"*",err,error))// &
& " is not associated."
CALL FlagError(localError,err,error,*999)
ENDIF
!!TODO: Set the distributed matrix not to allocate the data if the Jacobian is not calculated.
!Create the distributed Jacobian matrix
CALL DistributedMatrix_CreateStart(rowDomainMap,columnDomainMap,jacobianMatrix%jacobian,err,error,*999)
CALL DistributedMatrix_DataTypeSet(jacobianMatrix%jacobian,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedMatrix_StorageTypeSet(jacobianMatrix%jacobian,jacobianMatrix%storageType,err,error,*999)
!Calculate and set the matrix structure/sparsity pattern
IF(jacobianMatrix%storageType/=DISTRIBUTED_MATRIX_BLOCK_STORAGE_TYPE.AND. &
& jacobianMatrix%storageType/=DISTRIBUTED_MATRIX_DIAGONAL_STORAGE_TYPE) THEN
CALL JacobianMatrix_StructureCalculate(jacobianMatrix,numberOfNonZeros,rowIndices,columnIndices,err,error,*999)
CALL DistributedMatrix_NumberOfNonZerosSet(jacobianMatrix%jacobian,numberOfNonZeros,err,error,*999)
CALL DistributedMatrix_StorageLocationsSet(jacobianMatrix%jacobian,rowIndices,columnIndices,err,error,*999)
IF(ASSOCIATED(rowIndices)) DEALLOCATE(rowIndices)
IF(ASSOCIATED(columnIndices)) DEALLOCATE(columnIndices)
ENDIF
CALL DistributedMatrix_CreateFinish(jacobianMatrix%jacobian,err,error,*999)
ENDDO !matrixIdx
!Set up the residual vector
CALL DistributedVector_CreateStart(rowDomainMap,vectorMatrices%nonlinearMatrices%residual,err,error,*999)
CALL DistributedVector_DataTypeSet(nonlinearMatrices%residual,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedVector_CreateFinish(nonlinearMatrices%residual,err,error,*999)
!Initialise the residual vector to zero for time dependent problems so that the previous residual is set to zero
CALL DistributedVector_AllValuesSet(nonlinearMatrices%residual,0.0_DP,err,error,*999)
ENDIF
rhsVector=>vectorMatrices%rhsVector
IF(ASSOCIATED(rhsVector)) THEN
!Set up the equations RHS vector
CALL DistributedVector_CreateStart(rowDomainMap,vectorMatrices%rhsVector%vector,err,error,*999)
CALL DistributedVector_DataTypeSet(rhsVector%vector,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedVector_CreateFinish(rhsVector%vector,err,error,*999)
ENDIF
sourceVector=>vectorMatrices%sourceVector
IF(ASSOCIATED(sourceVector)) THEN
!Set up the equations source vector
CALL DistributedVector_CreateStart(rowDomainMap,vectorMatrices%sourceVector%vector,err,error,*999)
CALL DistributedVector_DataTypeSet(sourceVector%vector,MATRIX_VECTOR_DP_TYPE,err,error,*999)
CALL DistributedVector_CreateFinish(sourceVector%vector,err,error,*999)
ENDIF
!Finish up
vectorMatrices%vectorMatricesFinished=.TRUE.
EXITS("EquationsMatrices_VectorCreateFinish")
RETURN
999 IF(ASSOCIATED(rowIndices)) DEALLOCATE(rowIndices)
IF(ASSOCIATED(columnIndices)) DEALLOCATE(columnIndices)
CALL EquationsMatrices_VectorFinalise(vectorMatrices,dummyErr,dummyError,*998)
998 ERRORSEXITS("EquationsMatrices_VectorCreateFinish",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_VectorCreateFinish
!
!================================================================================================================================
!
!>Starts the creation of the vector equations matrices and rhs for the vector equations
SUBROUTINE EquationsMatrices_VectorCreateStart(vectorEquations,vectorMatrices,err,error,*)
!Argument variables
TYPE(EquationsVectorType), POINTER :: vectorEquations !<The pointer to the vector equations to create the vector equations matrices for
TYPE(EquationsMatricesVectorType), POINTER :: vectorMatrices !<On return, a pointer to the vector equations matrices being created.
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: dummyErr
TYPE(EquationsType), POINTER :: equations
TYPE(VARYING_STRING) :: dummyError
ENTERS("EquationsMatrices_VectorCreateStart",err,error,*998)
IF(ASSOCIATED(vectorMatrices)) CALL FlagError("Vector equations matrices is already associated.",err,error,*998)
IF(.NOT.ASSOCIATED(vectorEquations)) CALL FlagError("Vector equations is not associated.",err,error,*998)
NULLIFY(equations)
CALL EquationsVector_EquationsGet(vectorEquations,equations,err,error,*999)
IF(.NOT.equations%equationsFinished) CALL FlagError("Vector equations equations has not been finished.",err,error,*999)
NULLIFY(vectorMatrices)
!Initialise the equations matrices
CALL EquationsMatrices_VectorInitialise(vectorEquations,err,error,*999)
vectorMatrices=>vectorEquations%vectorMatrices
EXITS("EquationsMatrices_VectorCreateStart")
RETURN
999 CALL EquationsMatrices_VectorFinalise(vectorEquations%vectorMatrices,dummyErr,dummyError,*998)
998 ERRORSEXITS("EquationsMatrices_VectorCreateStart",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_VectorCreateStart
!
!================================================================================================================================
!
!>Destroy the vector equations matrices
SUBROUTINE EquationsMatrices_VectorDestroy(vectorMatrices,err,error,*)
!Argument variables
TYPE(EquationsMatricesVectorType), POINTER :: vectorMatrices !<A pointer the vector equations matrices to destroy
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
ENTERS("EquationsMatrices_VectorDestroy",err,error,*999)
IF(.NOT.ASSOCIATED(vectorMatrices)) CALL FlagError("Vector equations matrices is not associated",err,error,*999)
CALL EquationsMatrices_VectorFinalise(vectorMatrices,err,error,*999)
EXITS("EquationsMatrices_VectorDestroy")
RETURN
999 ERRORSEXITS("EquationsMatrices_VectorDestroy",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_VectorDestroy
!
!================================================================================================================================
!
!>Calculate the positions in the equations matrices of the element matrix. Old CMISS name MELGE.
SUBROUTINE EquationsMatrices_ElementMatrixCalculate(elementMatrix,updateMatrix,rowElementNumbers,columnElementNumbers, &
& rowsFieldVariable,colsFieldVariable,err,error,*)
!Argument variables
TYPE(ElementMatrixType) :: elementMatrix !<The element matrix to calculate
LOGICAL :: updateMatrix !<Is .TRUE. if the element matrix is to be updated, .FALSE. if not.
INTEGER(INTG), INTENT(IN) :: rowElementNumbers(:) !<The row element number to calculate
INTEGER(INTG), INTENT(IN) :: columnElementNumbers(:) !<The column element number to calculate
TYPE(FIELD_VARIABLE_TYPE), POINTER :: rowsFieldVariable !<A pointer to the field variable associated with the rows
TYPE(FIELD_VARIABLE_TYPE), POINTER :: colsFieldVariable !<A pointer to the field variable associated with the columns
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: componentIdx,dataPointIdx,derivative,derivativeIdx,globalDOFIdx,localDOFIdx,localNodeIdx,node, &
& version,localDataPointNumber,elementIdx,rowElementNumber,colElementNumber
TYPE(BASIS_TYPE), POINTER :: basis
TYPE(DOMAIN_ELEMENTS_TYPE), POINTER :: elementsTopology
TYPE(DecompositionDataPointsType), POINTER :: decompositionData
TYPE(VARYING_STRING) :: localError
ENTERS("EquationsMatrices_ElementMatrixCalculate",err,error,*999)
IF(.NOT.ASSOCIATED(rowsFieldVariable)) CALL FlagError("Rows field variable is not associated.",err,error,*999)
IF(.NOT.ASSOCIATED(colsFieldVariable)) CALL FlagError("Columns field variable is not associated.",err,error,*999)
elementMatrix%numberOfRows=0
elementMatrix%numberOfColumns=0
IF(updateMatrix) THEN
IF(ASSOCIATED(rowsFieldVariable,colsFieldVariable)) THEN
!Row and columns variable is the same.
DO componentIdx=1,rowsFieldVariable%NUMBER_OF_COMPONENTS
elementsTopology=>rowsFieldVariable%components(componentIdx)%domain%topology%elements
DO elementIdx=1,SIZE(rowElementNumbers)
rowElementNumber=rowElementNumbers(elementIdx)
IF(rowElementNumber<1.OR.rowElementNumber>elementsTopology%TOTAL_NUMBER_OF_ELEMENTS) THEN
localError="Element number "//TRIM(NumberToVString(rowElementNumber,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of rows field variable type "//TRIM(NumberToVString(rowsFieldVariable%VARIABLE_TYPE,"*",err,error))// &
& ". The element number must be between 1 and "// &
& TRIM(NumberToVString(elementsTopology%TOTAL_NUMBER_OF_ELEMENTS,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
ENDIF
SELECT CASE(rowsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE)
CASE(FIELD_CONSTANT_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%CONSTANT_PARAM2DOF_MAP
globalDOFIdx=rowsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
CASE(FIELD_ELEMENT_BASED_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%ELEMENT_PARAM2DOF_MAP% &
& elements(rowElementNumber)
globalDOFIdx=rowsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
CASE(FIELD_NODE_BASED_INTERPOLATION)
basis=>elementsTopology%elements(rowElementNumber)%basis
DO localNodeIdx=1,basis%NUMBER_OF_NODES
node=elementsTopology%elements(rowElementNumber)%ELEMENT_NODES(localNodeIdx)
DO derivativeIdx=1,basis%NUMBER_OF_DERIVATIVES(localNodeIdx)
derivative=elementsTopology%elements(rowElementNumber)%ELEMENT_DERIVATIVES(derivativeIdx,localNodeIdx)
version=elementsTopology%elements(rowElementNumber)%elementVersions(derivativeIdx,localNodeIdx)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%NODE_PARAM2DOF_MAP%NODES(node)% &
& derivatives(derivative)%versions(version)
globalDOFIdx=rowsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
ENDDO !derivativeIdx
ENDDO !localNodeIdx
CASE(FIELD_GRID_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_GAUSS_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_DATA_POINT_BASED_INTERPOLATION)
decompositionData=>rowsFieldVariable%components(componentIdx)%domain%decomposition%topology%dataPoints
DO dataPointIdx=1,decompositionData%elementDataPoint(rowElementNumber)%numberOfProjectedData
localDataPointNumber=decompositionData%elementDataPoint(rowElementNumber)%dataIndices(dataPointIdx)%localNumber
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%DATA_POINT_PARAM2DOF_MAP% &
& DATA_POINTS(localDataPointNumber)
globalDOFIdx=rowsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
ENDDO !dataPointIdx
CASE DEFAULT
localError="The interpolation type of "// &
& TRIM(NumberToVString(rowsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of rows field variable type "//TRIM(NumberToVString(rowsFieldVariable%VARIABLE_TYPE,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
END SELECT
ENDDO !elementIdx
ENDDO !componentIdx
ELSE
!Row and column variables are different
!Row mapping
DO componentIdx=1,rowsFieldVariable%NUMBER_OF_COMPONENTS
elementsTopology=>rowsFieldVariable%components(componentIdx)%domain%topology%elements
DO elementIdx=1,SIZE(rowElementNumbers)
rowElementNumber=rowElementNumbers(elementIdx)
IF(rowElementNumber<1.OR.rowElementNumber>elementsTopology%TOTAL_NUMBER_OF_ELEMENTS) THEN
localError="Row element number "//TRIM(NumberToVString(rowElementNumber,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of rows field variable type "//TRIM(NumberToVString(rowsFieldVariable%VARIABLE_TYPE,"*",err,error))// &
& ". The element number must be between 1 and "// &
& TRIM(NumberToVString(elementsTopology%TOTAL_NUMBER_OF_ELEMENTS,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
ENDIF
SELECT CASE(rowsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE)
CASE(FIELD_CONSTANT_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%CONSTANT_PARAM2DOF_MAP
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
CASE(FIELD_ELEMENT_BASED_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%ELEMENT_PARAM2DOF_MAP% &
& elements(rowElementNumber)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
CASE(FIELD_NODE_BASED_INTERPOLATION)
basis=>elementsTopology%elements(rowElementNumber)%basis
DO localNodeIdx=1,basis%NUMBER_OF_NODES
node=elementsTopology%elements(rowElementNumber)%ELEMENT_NODES(localNodeIdx)
DO derivativeIdx=1,basis%NUMBER_OF_DERIVATIVES(localNodeIdx)
derivative=elementsTopology%elements(rowElementNumber)%ELEMENT_DERIVATIVES(derivativeIdx,localNodeIdx)
version=elementsTopology%elements(rowElementNumber)%elementVersions(derivativeIdx,localNodeIdx)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%NODE_PARAM2DOF_MAP%nodes(node)% &
& derivatives(derivative)%versions(version)
elementMatrix%numberOfRows=elementMatrix%numberOfRows+1
elementMatrix%rowDOFS(elementMatrix%numberOfRows)=localDOFIdx
ENDDO !derivativeIdx
ENDDO !localNodeIdx
CASE(FIELD_GRID_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_GAUSS_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_DATA_POINT_BASED_INTERPOLATION)
decompositionData=>rowsFieldVariable%components(componentIdx)%domain%decomposition%topology%dataPoints
DO dataPointIdx=1,decompositionData%elementDataPoint(colElementNumber)%numberOfProjectedData
localDataPointNumber=decompositionData%elementDataPoint(colElementNumber)%dataIndices(dataPointIdx)%localNumber
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%DATA_POINT_PARAM2DOF_MAP% &
& DATA_POINTS(localDataPointNumber)
globalDOFIdx=rowsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
ENDDO !dataPointIdx
CASE DEFAULT
localError="The interpolation type of "// &
& TRIM(NumberToVString(rowsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of rows field variable type "//TRIM(NumberToVString(rowsFieldVariable%VARIABLE_TYPE,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
END SELECT
ENDDO !elementIdx
ENDDO !componentIdx
!Column mapping
DO componentIdx=1,colsFieldVariable%NUMBER_OF_COMPONENTS
elementsTopology=>colsFieldVariable%components(componentIdx)%domain%topology%elements
DO elementIdx=1,SIZE(columnElementNumbers)
colElementNumber=columnElementNumbers(elementIdx)
IF(colElementNumber<1.AND.colElementNumber>elementsTopology%TOTAL_NUMBER_OF_ELEMENTS) THEN
localError="Column element number "//TRIM(NumberToVString(colElementNumber,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of column field variable type "//TRIM(NumberToVString(colsFieldVariable%VARIABLE_TYPE,"*",err,error))// &
& ". The element number must be between 1 and "// &
& TRIM(NumberToVString(elementsTopology%TOTAL_NUMBER_OF_ELEMENTS,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
ENDIF
SELECT CASE(colsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE)
CASE(FIELD_CONSTANT_INTERPOLATION)
localDOFIdx=colsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%CONSTANT_PARAM2DOF_MAP
globalDOFIdx=colsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
CASE(FIELD_ELEMENT_BASED_INTERPOLATION)
localDOFIdx=colsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%ELEMENT_PARAM2DOF_MAP% &
& elements(colElementNumber)
globalDOFIdx=colsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
CASE(FIELD_NODE_BASED_INTERPOLATION)
basis=>elementsTopology%elements(colElementNumber)%basis
DO localNodeIdx=1,basis%NUMBER_OF_NODES
node=elementsTopology%elements(colElementNumber)%ELEMENT_NODES(localNodeIdx)
DO derivativeIdx=1,basis%NUMBER_OF_DERIVATIVES(localNodeIdx)
derivative=elementsTopology%elements(colElementNumber)%ELEMENT_DERIVATIVES(derivativeIdx,localNodeIdx)
version=elementsTopology%elements(colElementNumber)%elementVersions(derivativeIdx,localNodeIdx)
localDOFIdx=colsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%NODE_PARAM2DOF_MAP%NODES(node)% &
& derivatives(derivative)%versions(version)
globalDOFIdx=colsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
ENDDO !derivativeIdx
ENDDO !localNodeIdx
CASE(FIELD_GRID_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_GAUSS_POINT_BASED_INTERPOLATION)
CALL FlagError("Not implemented.",err,error,*999)
CASE(FIELD_DATA_POINT_BASED_INTERPOLATION)
decompositionData=>colsFieldVariable%components(componentIdx)%domain%decomposition%topology%dataPoints
DO dataPointIdx=1,decompositionData%elementDataPoint(colElementNumber)%numberOfProjectedData
localDataPointNumber=decompositionData%elementDataPoint(colElementNumber)%dataIndices(dataPointIdx)%localNumber
localDOFIdx=colsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%DATA_POINT_PARAM2DOF_MAP% &
& DATA_POINTS(localDataPointNumber)
globalDOFIdx=colsFieldVariable%DOMAIN_MAPPING%LOCAL_TO_GLOBAL_MAP(localDOFIdx)
elementMatrix%numberOfColumns=elementMatrix%numberOfColumns+1
elementMatrix%columnDOFS(elementMatrix%numberOfColumns)=globalDOFIdx
ENDDO !dataPointIdx
CASE DEFAULT
localError="The interpolation type of "// &
& TRIM(NumberToVString(colsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of column field variable type "//TRIM(NumberToVString(colsFieldVariable%VARIABLE_TYPE,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
END SELECT
ENDDO !elementIdx
ENDDO !componentIdx
ENDIF
elementMatrix%matrix=0.0_DP
ENDIF
EXITS("EquationsMatrices_ElementMatrixCalculate")
RETURN
999 ERRORSEXITS("EquationsMatrices_ElementMatrixCalculate",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_ElementMatrixCalculate
!
!================================================================================================================================
!
!>Finalise an element matrix and deallocate all memory
SUBROUTINE EquationsMatrices_ElementMatrixFinalise(elementMatrix,err,error,*)
!Argument variables
TYPE(ElementMatrixType):: elementMatrix!<The element matrix to finalise
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
ENTERS("EquationsMatrices_ElementMatrixFinalise",err,error,*999)
elementMatrix%maxNumberOfRows=0
elementMatrix%maxNumberOfColumns=0
IF(ALLOCATED(elementMatrix%rowDOFS)) DEALLOCATE(elementMatrix%rowDOFS)
IF(ALLOCATED(elementMatrix%columnDOFS)) DEALLOCATE(elementMatrix%columnDOFS)
IF(ALLOCATED(elementMatrix%matrix)) DEALLOCATE(elementMatrix%matrix)
EXITS("EquationsMatrices_ElementMatrixFinalise")
RETURN
999 ERRORSEXITS("EquationsMatrices_ElementMatrixFinalise",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_ElementMatrixFinalise
!
!================================================================================================================================
!
!>Initialise the element matrix.
SUBROUTINE EquationsMatrices_ElementMatrixInitialise(elementMatrix,err,error,*)
!Argument variables
TYPE(ElementMatrixType) :: elementMatrix !The element matrix to initialise
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
ENTERS("EquationsMatrices_ElementMatrixInitialise",err,error,*999)
elementMatrix%equationsMatrixNumber=0
elementMatrix%numberOfRows=0
elementMatrix%numberOfColumns=0
elementMatrix%maxNumberOfRows=0
elementMatrix%maxNumberOfColumns=0
EXITS("EquationsMatrices_ElementMatrixInitialise")
RETURN
999 ERRORSEXITS("EquationsMatrices_ElementMatrixInitialise",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_ElementMatrixInitialise
!
!================================================================================================================================
!
!>Sets up the element matrix for the row and column field variables.
SUBROUTINE EquationsMatrices_ElementMatrixSetup(elementMatrix,rowsFieldVariable,columnsFieldVariable,rowsNumberOfElements, &
& colsNumberOfElements,err,error,*)
!Argument variables
TYPE(ElementMatrixType) :: elementMatrix !<The element matrix to setup
TYPE(FIELD_VARIABLE_TYPE), POINTER :: rowsFieldVariable !<A pointer to the field variable associated with the rows
TYPE(FIELD_VARIABLE_TYPE), POINTER :: columnsFieldVariable !<A pointer to the field variable associated with the columns
INTEGER(INTG), INTENT(IN) :: rowsNumberOfElements !<Number of elements in the row variables whose dofs are present in this element matrix
INTEGER(INTG), INTENT(IN) :: colsNumberOfElements !<Number of elements in the col variables whose dofs are present in this element matrix
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: dummyErr, componentIdx
TYPE(VARYING_STRING) :: dummyError
ENTERS("EquationsMatrices_ElementMatrixSetup",err,error,*998)
IF(.NOT.ASSOCIATED(rowsFieldVariable)) CALL FlagError("Rows field variable is not associated.",err,error,*999)
IF(.NOT.ASSOCIATED(columnsFieldVariable)) CALL FlagError("Columns field variable is not associated.",err,error,*999)
IF(ALLOCATED(elementMatrix%rowDOFS)) CALL FlagError("Element matrix row dofs already allocated.",err,error,*999)
IF(ALLOCATED(elementMatrix%columnDOFS)) CALL FlagError("Element matrix column dofs already allocated.",err,error,*999)
IF(ALLOCATED(elementMatrix%matrix)) CALL FlagError("Element matrix already allocated.",err,error,*999)
elementMatrix%maxNumberOfRows=0
DO componentIdx=1,rowsFieldVariable%NUMBER_OF_COMPONENTS
elementMatrix%maxNumberOfRows=elementMatrix%maxNumberOfRows+ &
& rowsFieldVariable%components(componentIdx)%maxNumberElementInterpolationParameters
ENDDO !componentIdx
elementMatrix%maxNumberOfRows=elementMatrix%maxNumberOfRows*rowsNumberOfElements
elementMatrix%maxNumberOfColumns=0
DO componentIdx=1,columnsFieldVariable%NUMBER_OF_COMPONENTS
elementMatrix%maxNumberOfColumns=elementMatrix%maxNumberOfColumns+ &
& columnsFieldVariable%components(componentIdx)%maxNumberElementInterpolationParameters
ENDDO !componentIdx
elementMatrix%maxNumberOfColumns=elementMatrix%maxNumberOfColumns*colsNumberOfElements
ALLOCATE(elementMatrix%rowDOFS(elementMatrix%maxNumberOfRows),STAT=err)
IF(err/=0) CALL FlagError("Could not allocate element matrix row dofs.",err,error,*999)
ALLOCATE(elementMatrix%columnDOFS(elementMatrix%maxNumberOfColumns),STAT=err)
IF(err/=0) CALL FlagError("Could not allocate element matrix column dofs.",err,error,*999)
ALLOCATE(elementMatrix%matrix(elementMatrix%maxNumberOfRows,elementMatrix%maxNumberOfColumns),STAT=err)
IF(err/=0) CALL FlagError("Could not allocate element matrix.",err,error,*999)
EXITS("EquationsMatrices_ElementMatrixSetup")
RETURN
999 CALL EquationsMatrices_ElementMatrixFinalise(elementMatrix,dummyErr,dummyError,*998)
998 ERRORSEXITS("EquationsMatrices_ElementMatrixSetup",err,error)
RETURN 1
END SUBROUTINE EquationsMatrices_ElementMatrixSetup
!
!================================================================================================================================
!
!>Calculate the positions in the equations rhs of the element rhs vector. Old CMISS name MELGE.
SUBROUTINE EquationsMatrices_ElementVectorCalculate(elementVector,updateVector,elementNumber,rowsFieldVariable,err,error,*)
!Argument variables
TYPE(ElementVectorType) :: elementVector !<The element vector to calculate.
LOGICAL :: updateVector !<Is .TRUE. if the element vector is to be updated, .FALSE. if not.
INTEGER(INTG), INTENT(IN) :: elementNumber !<The element number to calculate
TYPE(FIELD_VARIABLE_TYPE), POINTER :: rowsFieldVariable !<A pointer to the field variable associated with the rows
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local Variables
INTEGER(INTG) :: componentIdx,derivative,derivativeIdx,localDOFIdx,node,localNodeIdx,version,dataPointIdx,localDataPointNumber
TYPE(BASIS_TYPE), POINTER :: basis
TYPE(DOMAIN_ELEMENTS_TYPE), POINTER :: elementsTopology
TYPE(DecompositionDataPointsType), POINTER :: decompositionData
TYPE(VARYING_STRING) :: localError
ENTERS("EquationsMatrices_ElementVectorCalculate",err,error,*999)
IF(.NOT.ASSOCIATED(rowsFieldVariable)) CALL FlagError("Rows field variable is not associated.",err,error,*999)
!Calculate the rows for the element vector
elementVector%numberOfRows=0
IF(updateVector) THEN
DO componentIdx=1,rowsFieldVariable%NUMBER_OF_COMPONENTS
elementsTopology=>rowsFieldVariable%components(componentIdx)%domain%topology%elements
IF(elementNumber<1.OR.elementNumber>elementsTopology%TOTAL_NUMBER_OF_ELEMENTS) THEN
localError="Element number "//TRIM(NumberToVString(elementNumber,"*",err,error))// &
& " is invalid for component number "//TRIM(NumberToVString(componentIdx,"*",err,error))// &
& " of rows field variable type "//TRIM(NumberToVString(rowsFieldVariable%VARIABLE_TYPE,"*",err,error))// &
& ". The element number must be between 1 and "// &
& TRIM(NumberToVString(elementsTopology%TOTAL_NUMBER_OF_ELEMENTS,"*",err,error))//"."
CALL FlagError(localError,err,error,*999)
ENDIF
SELECT CASE(rowsFieldVariable%components(componentIdx)%INTERPOLATION_TYPE)
CASE(FIELD_CONSTANT_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%CONSTANT_PARAM2DOF_MAP
elementVector%numberOfRows=elementVector%numberOfRows+1
elementVector%rowDOFS(elementVector%numberOfRows)=localDOFIdx
CASE(FIELD_ELEMENT_BASED_INTERPOLATION)
localDOFIdx=rowsFieldVariable%components(componentIdx)%PARAM_TO_DOF_MAP%ELEMENT_PARAM2DOF_MAP%elements(elementNumber)
elementVector%numberOfRows=elementVector%numberOfRows+1
elementVector%rowDOFS(elementVector%numberOfRows)=localDOFIdx
CASE(FIELD_NODE_BASED_INTERPOLATION)