IFPACK Development
Loading...
Searching...
No Matches
az_ifpack_prec_create.c
1
2/*@HEADER
3// ***********************************************************************
4//
5// Ifpack: Object-Oriented Algebraic Preconditioner Package
6// Copyright (2002) Sandia Corporation
7//
8// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9// license for use of this work by or on behalf of the U.S. Government.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39//
40// ***********************************************************************
41//@HEADER
42*/
43
44/*******************************************************************************
45 * MATRIX FREE matrix vector multiplication
46 ******************************************************************************/
47
48#include <stdio.h>
49#include <stdlib.h>
50#include <math.h>
51#include "az_aztec.h"
52#include "az_ifpack.h"
53void AZ_ifpack_prec_create(double *x, double *b,
54 int *options, double *params,
55 int *proc_config,
56 AZ_MATRIX *Amat, AZ_PRECOND **Prec)
57{
58 AZ_IFPACK *Prec_pass_data;
59 void *precon, *bmat ;
60 int nr, nc, *data_org;
61 double rthresh, athresh;
62
63 Prec_pass_data = (AZ_IFPACK *) AZ_allocate(sizeof(AZ_IFPACK));
64 az2ifp_blockmatrix(&bmat, Amat); /* Create IFPACK encapsulation of Amat */
65
66 /* set the preconditioning structure 'Prec'. */
67
68 if (options[AZ_precond] == AZ_none)
69 ifp_preconditioner(&precon, bmat, IFP_NONE,
70 (double) options[AZ_graph_fill], 0.0,
71 IFP_INVERSE, 0.0, 0.0);
72
73 else if (options[AZ_precond] == AZ_Jacobi)
74 {
75 rthresh = params[AZ_rthresh];
76 athresh = params[AZ_athresh];
77 ifp_preconditioner(&precon, bmat, IFP_BJACOBI, 0.0, 0.0,
78 IFP_SVD, rthresh, athresh);
79 /*IFP_INVERSE, 0.0, 0.0); */
80 }
81
82 else if (options[AZ_precond] == AZ_dom_decomp &&
83 options[AZ_subdomain_solve] == AZ_bilu_ifp)
84 {
85 rthresh = params[AZ_rthresh];
86 athresh = params[AZ_athresh];
87 ifp_preconditioner(&precon, bmat,
88 IFP_BILUK, (double) options[AZ_graph_fill], 0.0,
89 IFP_SVD, rthresh, athresh);
90 /*IFP_INVERSE, 0.0, 0.0); */
91
92 }
93 else
94 {
95 printf("Not a supported preconditioner in az_ifpack_prec_create\n");
96 abort();
97 }
98
99 (*Prec) = AZ_precond_create(Amat,AZ_ifpack_precon,NULL);
100
101
102 /* Store pointers to preconditioner and IFPACK encapsulation of Amat */
103 Prec_pass_data->precon = precon;
104 Prec_pass_data->bmat = bmat;
105
106 /* Construct auxiliary vector for use with apply function.
107 NOTE: We are assuming only one RHS at this time !!! */
108
109 data_org = Amat->data_org;
110 nr = data_org[AZ_N_internal] + data_org[AZ_N_border];
111 nc = 1;
112 /*input_vector = (double *) malloc (nr * sizeof(double));
113 Prec_pass_data.input_vector = input_vector; */
114 Prec_pass_data->nr = nr;
115 Prec_pass_data->nc = nc;
116 (*Prec)->Pmat = Amat;
117 Prec_pass_data->user_aux_ptr = (*Prec)->Pmat->aux_ptr; /* Save this to be able to restore*/
118 (*Prec)->Pmat->aux_ptr = (void *) Prec_pass_data;
119 (*Prec)->prec_function = AZ_ifpack_precon;
120 Prec_pass_data->user_precon = options[AZ_precond]; /* Save this to be able to restore*/
121 options[AZ_precond] = AZ_user_precond;
122}