Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
la
linsys_PETSC.hh
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4
*
5
* Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6
* especially for academic research:
7
* Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8
*
9
* This program is free software; you can redistribute it and/or modify it under the terms
10
* of the GNU General Public License version 3 as published by the Free Software Foundation.
11
*
12
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
* See the GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along with this program; if not,
17
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18
*
19
*
20
* $Id: la_linsys.hh 1299 2011-08-23 21:42:50Z jakub.sistek $
21
* $Revision: 1299 $
22
* $LastChangedBy: jakub.sistek $
23
* $LastChangedDate: 2011-08-23 23:42:50 +0200 (Tue, 23 Aug 2011) $
24
*
25
* @file
26
* @brief Solver based on the original PETSc solver using MPIAIJ matrix and succesive Schur complement construction
27
* @author Jakub Sistek
28
*
29
*
30
*/
31
32
#ifndef LA_LINSYS_PETSC_HH_
33
#define LA_LINSYS_PETSC_HH_
34
35
// derived from base linsys
36
#include "
la/linsys.hh
"
37
38
#include "
la/distribution.hh
"
39
#include "
input/input_type.hh
"
40
#include "
input/accessors.hh
"
41
42
class
LinSys_PETSC
:
public
LinSys
43
{
44
45
public
:
46
static
Input::Type::Record
input_type
;
47
48
LinSys_PETSC
(
const
Distribution
* rows_ds);
49
50
/**
51
* Copy constructor.
52
*/
53
LinSys_PETSC
(
LinSys_PETSC
&other );
54
55
/**
56
* Returns whole Distribution class for distribution of the solution.
57
*/
58
inline
const
Distribution
*
get_ds
( )
59
{
60
return
rows_ds_
;
61
}
62
63
const
Mat &
get_matrix
()
64
{
65
return
matrix_
;
66
}
67
68
const
Vec &
get_rhs
()
69
{
70
return
rhs_
;
71
}
72
73
PetscErrorCode
set_matrix
(Mat &
matrix
, MatStructure str)
74
{
75
matrix_changed_
=
true
;
76
return
MatCopy(matrix,
matrix_
, str);
77
}
78
79
PetscErrorCode
set_rhs
(Vec &
rhs
)
80
{
81
rhs_changed_
=
true
;
82
return
VecCopy(rhs,
rhs_
);
83
}
84
85
PetscErrorCode
mat_zero_entries
()
86
{
87
matrix_changed_
=
true
;
88
return
MatZeroEntries(
matrix_
);
89
}
90
91
PetscErrorCode
rhs_zero_entries
()
92
{
93
rhs_changed_
=
true
;
94
return
VecSet(
rhs_
, 0);
95
}
96
97
void
start_allocation
();
98
99
void
start_add_assembly
();
100
101
void
start_insert_assembly
();
102
103
void
mat_set_values
(
int
nrow,
int
*rows,
int
ncol,
int
*cols,
double
*vals );
104
105
void
rhs_set_values
(
int
nrow,
int
*rows,
double
*vals );
106
107
void
preallocate_values
(
int
nrow,
int
*rows,
int
ncol,
int
*cols);
108
109
void
preallocate_matrix
();
110
111
void
finish_assembly
();
112
113
void
finish_assembly
( MatAssemblyType assembly_type );
114
115
void
apply_constrains
(
double
scalar = 1. );
116
117
void
set_initial_guess_nonzero
(
bool
set_nonzero =
true
);
118
119
int
solve
();
120
121
/**
122
* Returns information on absolute solver accuracy
123
*/
124
inline
double
get_absolute_accuracy
(){
125
return
a_tol_
;
126
};
127
128
void
get_whole_solution
(
std::vector<double>
& globalSolution );
129
130
void
view
( );
131
132
/**
133
* Sets specific parameters of LinSys_PETSC defined by user in input file and used to calculate
134
*/
135
void
set_from_input
(
const
Input::Record
in_rec);
136
137
double
get_solution_precision
();
138
139
~LinSys_PETSC
( );
140
141
private
:
142
// make a pointer to the data array out of a std::vector
143
template
<
typename
T>
144
T *
makePetscPointer_
(
std::vector<T>
& array )
145
{
146
if
( array.size() )
return
&(array[0]);
147
return
PETSC_NULL;
148
}
149
150
// PetscScalar to double casting functor
151
struct
PetscScalar2Double_
:
public
std::unary_function< PetscScalar, double >
152
{
153
double
operator()
( PetscScalar arg )
154
{
155
return
static_cast<
double
>
( arg );
156
}
157
};
158
159
void
gatherSolution_
( );
160
161
protected
:
162
163
std::string
params_
;
//!< command-line-like options for the PETSc solver
164
165
bool
init_guess_nonzero
;
//!< flag for starting from nonzero guess
166
167
Mat
matrix_
;
//!< Petsc matrix of the problem.
168
Vec
rhs_
;
//!< PETSc vector constructed with vx array.
169
170
double
*
v_rhs_
;
//!< local RHS array pointing to Vec rhs_
171
172
Vec
on_vec_
;
//!< Vectors for counting non-zero entries in diagonal block.
173
Vec
off_vec_
;
//!< Vectors for counting non-zero entries in off-diagonal block.
174
175
double
solution_precision_
;
// precision of KSP system solver
176
177
178
};
179
180
#endif
/* LA_LINSYS_PETSC_HH_ */
Generated on Thu May 29 2014 23:14:48 for Flow123d by
1.8.4