Actual source code: dvd_schm.c
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2012, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7:
8: SLEPc is free software: you can redistribute it and/or modify it under the
9: terms of version 3 of the GNU Lesser General Public License as published by
10: the Free Software Foundation.
12: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15: more details.
17: You should have received a copy of the GNU Lesser General Public License
18: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20: */
22: #include davidson.h
24: #define DVD_CHECKSUM(b) \
25: ( (b)->max_size_V + (b)->max_size_auxV + (b)->max_size_auxS + \
26: (b)->own_vecs + (b)->own_scalars + (b)->max_size_oldX )
30: PetscErrorCode dvd_schm_basic_preconf(dvdDashboard *d, dvdBlackboard *b,
31: PetscInt mpd, PetscInt min_size_V, PetscInt bs,
32: PetscInt ini_size_V, PetscInt size_initV, PetscInt plusk,
33: HarmType_t harmMode, KSP ksp, InitType_t init, PetscBool allResiduals,
34: EPSOrthType orth, PetscInt cX_proj, PetscInt cX_impr, Method_t method)
35: {
37: PetscInt check_sum0, check_sum1;
41: PetscMemzero(b, sizeof(dvdBlackboard));
42: b->state = DVD_STATE_PRECONF;
44: for(check_sum0=-1,check_sum1=DVD_CHECKSUM(b); check_sum0 != check_sum1;
45: check_sum0 = check_sum1, check_sum1 = DVD_CHECKSUM(b)) {
46: b->own_vecs = b->own_scalars = 0;
48: /* Setup basic management of V */
49: dvd_managementV_basic(d, b, bs, mpd, min_size_V, plusk,
50: harmMode==DVD_HARM_NONE?PETSC_FALSE:PETSC_TRUE,
51: allResiduals);
52:
53:
54: /* Setup the initial subspace for V */
55: dvd_initV(d, b, ini_size_V, size_initV,
56: init==DVD_INITV_KRYLOV?PETSC_TRUE:PETSC_FALSE);
57:
58: /* Setup the convergence in order to use the SLEPc convergence test */
59: dvd_testconv_slepc(d, b);
60:
61: /* Setup Raileigh-Ritz for selecting the best eigenpairs in V */
62: dvd_calcpairs_qz(d, b, orth, PETSC_NULL, cX_proj,
63: harmMode==DVD_HARM_NONE?PETSC_FALSE:PETSC_TRUE);
64: if (harmMode != DVD_HARM_NONE) {
65: dvd_harm_conf(d, b, harmMode, PETSC_FALSE, 0.0);
66: }
67:
68: /* Setup the method for improving the eigenvectors */
69: switch(method) {
70: case DVD_METH_GD:
71: case DVD_METH_JD:
72: dvd_improvex_jd(d, b, ksp, bs, cX_impr, PETSC_FALSE);
73: dvd_improvex_jd_proj_uv(d, b, DVD_PROJ_KZX);
74: dvd_improvex_jd_lit_const(d, b, 0, 0.0, 0.0);
75: break;
76: case DVD_METH_GD2:
77: dvd_improvex_gd2(d, b, ksp, bs);
78: break;
79: }
80: }
82: return(0);
83: }
88: PetscErrorCode dvd_schm_basic_conf(dvdDashboard *d, dvdBlackboard *b,
89: PetscInt mpd, PetscInt min_size_V, PetscInt bs,
90: PetscInt ini_size_V, PetscInt size_initV, PetscInt plusk,
91: IP ip, HarmType_t harmMode, PetscBool fixedTarget, PetscScalar t, KSP ksp,
92: PetscReal fix, InitType_t init, PetscBool allResiduals, EPSOrthType orth,
93: PetscInt cX_proj, PetscInt cX_impr, PetscBool dynamic, Method_t method)
94: {
95: PetscInt check_sum0, check_sum1, maxits;
96: Vec *fv;
97: PetscScalar *fs;
98: PetscReal tol;
99: PetscErrorCode ierr;
103: b->state = DVD_STATE_CONF;
104: check_sum0 = DVD_CHECKSUM(b);
105: b->own_vecs = 0; b->own_scalars = 0;
106: fv = b->free_vecs; fs = b->free_scalars;
108: /* Setup basic management of V */
109: dvd_managementV_basic(d, b, bs, mpd, min_size_V, plusk,
110: harmMode==DVD_HARM_NONE?PETSC_FALSE:PETSC_TRUE,
111: allResiduals);
112:
114: /* Setup the initial subspace for V */
115: dvd_initV(d, b, ini_size_V, size_initV,
116: init==DVD_INITV_KRYLOV?PETSC_TRUE:PETSC_FALSE);
118: /* Setup the convergence in order to use the SLEPc convergence test */
119: dvd_testconv_slepc(d, b);
121: /* Setup Raileigh-Ritz for selecting the best eigenpairs in V */
122: dvd_calcpairs_qz(d, b, orth, ip, cX_proj,
123: harmMode==DVD_HARM_NONE?PETSC_FALSE:PETSC_TRUE);
124: if (harmMode != DVD_HARM_NONE) {
125: dvd_harm_conf(d, b, harmMode, fixedTarget, t);
126: }
128: /* Setup the method for improving the eigenvectors */
129: switch(method) {
130: case DVD_METH_GD:
131: case DVD_METH_JD:
132: dvd_improvex_jd(d, b, ksp, bs, cX_impr, dynamic);
133: dvd_improvex_jd_proj_uv(d, b, DVD_PROJ_KZX);
134:
135: KSPGetTolerances(ksp, &tol, PETSC_NULL, PETSC_NULL, &maxits);
136:
137: dvd_improvex_jd_lit_const(d, b, maxits, tol, fix);
138: break;
139: case DVD_METH_GD2:
140: dvd_improvex_gd2(d, b, ksp, bs);
141: break;
142: }
144: check_sum1 = DVD_CHECKSUM(b);
145: if ((check_sum0 != check_sum1) ||
146: (b->free_vecs - fv > b->own_vecs) ||
147: (b->free_scalars - fs > b->own_scalars))
148: SETERRQ(PETSC_COMM_SELF,1, "Something awful happened");
149:
150: return(0);
151: }