hxt_linear_system.c 3.22 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
2
/*
 * Marblesbag - Copyright (C) <2010-2018>
3
4
 * <Universite catholique de Louvain (UCL), Belgium
 *  Universite de Montpellier, France>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
5
 * 	
6
 * List of the contributors to the development of Marblesbag: see AUTHORS file.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
7
8
9
 * Description and complete License: see LICENSE file.
 * 	
 * This program (Marblesbag) is free software: 
10
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
11
12
13
14
15
16
 * Public License as published by the Free Software Foundation, either version
 * 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Lesser General Public License for more details.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
18
 * 
19
20
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program (see COPYING and COPYING.LESSER files).  If not, 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
21
22
23
 * see <http://www.gnu.org/licenses/>.
 */

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
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
#include "hxt_linear_system.h"
#include "hxt_class_macro.h"
#include "hxt_message.h"

#define HXTLinearSystem_MEMBERS(operation, opdata) \
  operation(opdata,AddToMatrix,int,int,const double*,);\
  operation(opdata,AddMatrixEntry,int,int,int,int, double,);\
  operation(opdata,AddToRhs,double*,int,const double*,);\
  operation(opdata,ZeroMatrix,);\
  operation(opdata,Size,int*,);\
  operation(opdata,Solve,double*,double*,);\
  operation(opdata,SetMatrixRowIdentity,int,int,);\
  operation(opdata,SetMatrixRowFieldCombinaison,int,int,double*,);\
  operation(opdata,SetRhsEntry,double*,int,int,double,);\
  operation(opdata,AddRhsEntry,double*,int,int,double,);\
  operation(opdata,HasConverged,int*,);\
  operation(opdata,GetRhsNorm,double*,double*,);

HXT_DECLARE_INTERFACE(LinearSystem)

#include "hxt_linear_system_lu.h"
HXT_DECLARE_DERIVED_CLASS(LinearSystem, LinearSystemLU)

#ifdef HXT_HAVE_PETSC
#include "hxt_linear_system_petsc.h"
HXT_DECLARE_DERIVED_CLASS(LinearSystem, LinearSystemPETSc)
#endif

HXTStatus hxtInitializeLinearSystems(int *argc, char ***argv) {
  HXT_CHECK(hxtLinearSystemLURegister());
#ifdef HXT_HAVE_PETSC
  HXT_CHECK(hxtInitializePETSc(argc, argv));
  HXT_CHECK(hxtLinearSystemPETScRegister());
#endif
  return HXT_STATUS_OK;
}

HXTStatus hxtLinearSystemCreateLU(HXTLinearSystem **sys, int nElement, int nNodesByElement, int nFields, uint32_t *elements) {
  if(hxtLinearSystemLUClass==NULL)
    HXT_ERROR_MSG(HXT_STATUS_FAILED,"linear system lu class not registred");
  HXTLinearSystemLU *syslu;
  HXT_CHECK(hxtLinearSystemLUCreate(&syslu, nElement, nNodesByElement, nFields, elements));
  HXT_CHECK(hxtLinearSystemCreate(sys, hxtLinearSystemLUClass, syslu));
  return HXT_STATUS_OK;
};

#ifdef HXT_HAVE_PETSC
71
HXTStatus hxtLinearSystemCreatePETSc(HXTLinearSystem **sys, int nElement, int nNodesByElement, int nFields, uint32_t *elements, const char *petscOptionsPrefix) {
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
72
73
74
  if(hxtLinearSystemPETScClass==NULL)
    HXT_ERROR_MSG(HXT_STATUS_FAILED,"linear system petsc class not registred");
  HXTLinearSystemPETSc *syspetsc;
75
  HXT_CHECK(hxtLinearSystemPETScCreate(&syspetsc, nElement, nNodesByElement, nFields, elements, petscOptionsPrefix));
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
76
77
78
79
80
81
82
  HXT_CHECK(hxtLinearSystemCreate(sys, hxtLinearSystemPETScClass, syspetsc));
  return HXT_STATUS_OK;
};

#endif