Actual source code: loaded_string.c
slepc-3.11.2 2019-07-30
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2019, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
10: /*
11: This example implements one of the problems found at
12: NLEVP: A Collection of Nonlinear Eigenvalue Problems,
13: The University of Manchester.
14: The details of the collection can be found at:
15: [1] T. Betcke et al., "NLEVP: A Collection of Nonlinear Eigenvalue
16: Problems", ACM Trans. Math. Software 39(2), Article 7, 2013.
18: The loaded_string problem is a rational eigenvalue problem for the
19: finite element model of a loaded vibrating string.
20: */
22: static char help[] = "Finite element model of a loaded vibrating string.\n\n"
23: "The command line options are:\n"
24: " -n <n>, dimension of the matrices.\n"
25: " -kappa <kappa>, stiffness of elastic spring.\n"
26: " -mass <m>, mass of the attached load.\n\n";
28: #include <slepcnep.h>
30: #define NMAT 3
32: int main(int argc,char **argv)
33: {
34: Mat A[NMAT]; /* problem matrices */
35: FN f[NMAT]; /* functions to define the nonlinear operator */
36: NEP nep; /* nonlinear eigensolver context */
37: PetscInt n=100,Istart,Iend,i;
38: PetscReal kappa=1.0,m=1.0;
39: PetscScalar sigma,numer[2],denom[2];
40: PetscBool terse;
43: SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
45: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
46: PetscOptionsGetReal(NULL,NULL,"-kappa",&kappa,NULL);
47: PetscOptionsGetReal(NULL,NULL,"-mass",&m,NULL);
48: sigma = kappa/m;
49: PetscPrintf(PETSC_COMM_WORLD,"Loaded vibrating string, n=%D kappa=%g m=%g\n\n",n,(double)kappa,(double)m);
51: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52: Build the problem matrices
53: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
55: /* initialize matrices */
56: for (i=0;i<NMAT;i++) {
57: MatCreate(PETSC_COMM_WORLD,&A[i]);
58: MatSetSizes(A[i],PETSC_DECIDE,PETSC_DECIDE,n,n);
59: MatSetFromOptions(A[i]);
60: MatSetUp(A[i]);
61: }
62: MatGetOwnershipRange(A[0],&Istart,&Iend);
64: /* A0 */
65: for (i=Istart;i<Iend;i++) {
66: MatSetValue(A[0],i,i,(i==n-1)?1.0*n:2.0*n,INSERT_VALUES);
67: if (i>0) { MatSetValue(A[0],i,i-1,-1.0*n,INSERT_VALUES); }
68: if (i<n-1) { MatSetValue(A[0],i,i+1,-1.0*n,INSERT_VALUES); }
69: }
71: /* A1 */
72: for (i=Istart;i<Iend;i++) {
73: MatSetValue(A[1],i,i,(i==n-1)?2.0/(6.0*n):4.0/(6.0*n),INSERT_VALUES);
74: if (i>0) { MatSetValue(A[1],i,i-1,1.0/(6.0*n),INSERT_VALUES); }
75: if (i<n-1) { MatSetValue(A[1],i,i+1,1.0/(6.0*n),INSERT_VALUES); }
76: }
78: /* A2 */
79: if (Istart<=n-1 && n-1<Iend) {
80: MatSetValue(A[2],n-1,n-1,kappa,INSERT_VALUES);
81: }
83: /* assemble matrices */
84: for (i=0;i<NMAT;i++) {
85: MatAssemblyBegin(A[i],MAT_FINAL_ASSEMBLY);
86: }
87: for (i=0;i<NMAT;i++) {
88: MatAssemblyEnd(A[i],MAT_FINAL_ASSEMBLY);
89: }
91: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92: Create the problem functions
93: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
95: /* f1=1 */
96: FNCreate(PETSC_COMM_WORLD,&f[0]);
97: FNSetType(f[0],FNRATIONAL);
98: numer[0] = 1.0;
99: FNRationalSetNumerator(f[0],1,numer);
101: /* f2=-lambda */
102: FNCreate(PETSC_COMM_WORLD,&f[1]);
103: FNSetType(f[1],FNRATIONAL);
104: numer[0] = -1.0; numer[1] = 0.0;
105: FNRationalSetNumerator(f[1],2,numer);
107: /* f3=lambda/(lambda-sigma) */
108: FNCreate(PETSC_COMM_WORLD,&f[2]);
109: FNSetType(f[2],FNRATIONAL);
110: numer[0] = 1.0; numer[1] = 0.0;
111: denom[0] = 1.0; denom[1] = -sigma;
112: FNRationalSetNumerator(f[2],2,numer);
113: FNRationalSetDenominator(f[2],2,denom);
115: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116: Create the eigensolver and solve the problem
117: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
119: NEPCreate(PETSC_COMM_WORLD,&nep);
120: NEPSetSplitOperator(nep,3,A,f,SUBSET_NONZERO_PATTERN);
121: NEPSetProblemType(nep,NEP_RATIONAL);
122: NEPSetFromOptions(nep);
123: NEPSolve(nep);
125: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126: Display solution and clean up
127: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
129: /* show detailed info unless -terse option is given by user */
130: PetscOptionsHasName(NULL,NULL,"-terse",&terse);
131: if (terse) {
132: NEPErrorView(nep,NEP_ERROR_RELATIVE,NULL);
133: } else {
134: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
135: NEPReasonView(nep,PETSC_VIEWER_STDOUT_WORLD);
136: NEPErrorView(nep,NEP_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
137: PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
138: }
139: NEPDestroy(&nep);
140: for (i=0;i<NMAT;i++) {
141: MatDestroy(&A[i]);
142: FNDestroy(&f[i]);
143: }
144: SlepcFinalize();
145: return ierr;
146: }
148: /*TEST
150: test:
151: suffix: 1
152: args: -nep_type rii -nep_target 4 -terse
153: requires: !single
155: testset:
156: args: -nep_type interpol -rg_type interval -rg_interval_endpoints 5,700,-.1,.1 -nep_nev 7 -nep_target 5 -nep_interpol_interpolation_degree 12 -nep_refine simple -terse
157: requires: !single
158: output_file: output/loaded_string_2.out
159: test:
160: suffix: 2
161: args: -nep_refine_scheme {{schur explicit}}
162: test:
163: suffix: 2_mbe
164: args: -nep_refine_scheme mbe -nep_refine_ksp_type preonly -nep_refine_pc_type lu
166: testset:
167: nsize: 2
168: args: -nep_type interpol -rg_type interval -rg_interval_endpoints 5,700,-.1,.1 -nep_nev 7 -nep_target 5 -nep_interpol_interpolation_degree 12 -nep_refine simple -nep_refine_partitions 2 -nep_interpol_st_ksp_type bcgs -nep_interpol_st_pc_type bjacobi -terse
169: requires: !single
170: output_file: output/loaded_string_2.out
171: test:
172: suffix: 3_explicit
173: args: -nep_refine_scheme explicit
174: test:
175: suffix: 3_mbe
176: args: -nep_refine_scheme mbe -nep_refine_ksp_type preonly -nep_refine_pc_type cholesky
178: test:
179: suffix: 4
180: nsize: 4
181: args: -nep_type interpol -rg_type interval -rg_interval_endpoints 5,700,-.1,.1 -nep_nev 7 -nep_target 5 -nep_interpol_interpolation_degree 10 -nep_refine simple -nep_refine_partitions 2 -nep_refine_scheme explicit -nep_interpol_st_ksp_type bcgs -nep_interpol_st_pc_type bjacobi -terse -info_exclude nep,pep,fn -log_exclude nep,pep,fn
182: requires: !single
183: output_file: output/loaded_string_2.out
184: timeoutfactor: 2
186: test:
187: suffix: 5
188: args: -nep_type nleigs -rg_type interval -rg_interval_endpoints 4,700,-.1,.1 -nep_nev 8 -nep_target 5 -terse
189: requires: !single
191: test:
192: suffix: 6
193: args: -nep_type nleigs -rg_type interval -rg_interval_endpoints 100,700 -nep_nev 5 -nep_tol 1e-9 -nep_target 140 -nep_nleigs_interpolation_degree 15 -nep_general -terse
194: requires: !complex !single
196: test:
197: suffix: 6_complex
198: args: -nep_type nleigs -rg_type interval -rg_interval_endpoints 100,700,-.1,.1 -nep_nev 5 -nep_tol 1e-9 -nep_target 140 -nep_nleigs_interpolation_degree 15 -nep_general -terse
199: requires: complex !single
200: output_file: output/loaded_string_6.out
202: test:
203: suffix: 7
204: args: -nep_type interpol -rg_type interval -rg_interval_endpoints 5,700 -nep_nev 5 -nep_target 100 -nep_interpol_interpolation_degree 20 -nep_ncv 20 -n 20 -nep_refine simple -nep_refine_its 1 -terse
205: requires: !complex double
207: test:
208: suffix: 7_complex
209: args: -nep_type interpol -rg_type interval -rg_interval_endpoints 5,700,-.1,.1 -nep_nev 5 -nep_target 100 -nep_interpol_interpolation_degree 20 -nep_ncv 20 -n 20 -nep_refine simple -nep_refine_its 1 -terse
210: requires: complex double
211: output_file: output/loaded_string_7.out
213: test:
214: suffix: 8
215: args: -nep_target 10 -nep_nev 3 -nep_tol 5e-10 -nep_type {{rii slp narnoldi}} -terse
216: requires: !single
218: TEST*/