[petsc-users] Nullspaces

Marco Cisternino marco.cisternino at optimad.it
Wed Jan 12 08:54:19 CST 2022


Hello Barry,
To answer your question, both the eigenvectors contain only two values: the eigenvectors entries are different in the two eigenvectors but coherent with the belonging of the entry to the sub-domains.

However, I was able to get the same behavior of the MatTestNullSpace using the two ways of creating the null space.

To summarize the issue, I did:

- MatNullSpaceCreate(getCommunicator(), PETSC_TRUE, 0, nullptr, &nullspace) (CASE 1)

- Vec* nsp;
  VecDuplicateVecs(m_rhs, 1, &nsp);
  VecSet(nsp[0],1.0);
  VecNormalize(nsp[0], nullptr);
  MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, 1, nsp, &nullspace); (CASE 2)

and then I tested with MatNullSpaceTest(nullspace, m_A, &isNullSpaceValid).
CASE 1 gave isNullSpaceValid=true but CASE 2 gave isNullSpaceValid=false.
I found the problem is the normalization of the Vec nsp[0].

Modifying CASE 2 like this:

        Vec* nsp;
        VecDuplicateVecs(m_rhs, 1, &nsp);
        PetscInt N;
        VecGetSize(nsp[0],&N);
        VecSet(nsp[0],1.0 / N);
        MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, 1, nsp, &nullspace);

I can get isNullSpaceValid= true even for CASE 2.

But most importantly, I can get isNullSpaceValid=true even creating the true 2-dimensional null space with explicit normalization (using the number of non-zero entries sub-domain per sub-domain) and not VecNormalize:

MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, nConstants, constants, &nullspace);
where nConstants=2 and constants[0] (constants[1]) has been set with 1/N0 (1/N1) in entries relative to sub-domain 0 (1).
I going to check which is the impact on CFD solution.

Any comment on this would be really appreciated.

Thank you all.

Marco Cisternino 

-----Original Message-----
From: Barry Smith <bsmith at petsc.dev> 
Sent: mercoledì 5 gennaio 2022 23:17
To: Marco Cisternino <marco.cisternino at optimad.it>
Cc: Jose E. Roman <jroman at dsic.upv.es>; petsc-users <petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] Nullspaces


  What do you get for the two eigenvectors ?



> On Jan 5, 2022, at 11:21 AM, Marco Cisternino <marco.cisternino at optimad.it> wrote:
> 
> Hello Jose and Stefano.
> Thank you, Jose for your hints.
> I computed the two smallest eigenvalues of my operator and they are tiny but not zero.
> The smallest 0 eigenvalue is = (4.71506e-08, 0) with abs error = 
> 3.95575e-07 The smallest 1 eigenvalue is = (1.95628e-07, 0) with abs 
> error = 4.048e-07 As Stefano remarked, I would have expected much tinier values, closer to zero.
> Probably something is wrong in what I do:
>    EPS eps;
>    EPSCreate(PETSC_COMM_WORLD, &eps);
>    EPSSetOperators( eps, matrix, NULL );
>    EPSSetWhichEigenpairs(eps, EPS_SMALLEST_MAGNITUDE);
>    EPSSetProblemType( eps, EPS_NHEP );
>    EPSSetConvergenceTest(eps,EPS_CONV_ABS);
>    EPSSetTolerances(eps, 1.0e-10, 1000);
>    EPSSetDimensions(eps,2,PETSC_DEFAULT,PETSC_DEFAULT);
>    EPSSetFromOptions( eps );
>    EPSSolve( eps );
> 
> Even commenting " EPSSetTolerances(eps, 1.0e-10, 1000);" and use default values, the results are exactly the same.
> 
> Am I correctly computing the 2 smallest eigenvalues?
> 
> They should be zeros but they are not. Any suggestions about how understanding why? 
> 
> In a previous email Mark remarked: "Also you say you divide by the cell volume. Maybe I am not understanding this but that is basically diagonal scaling and that will change the null space (ie, not a constant anymore)", therefore why does the null space built with MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0, nullptr, &nullspace); passes the MatNullSpaceTest??
> 
> Thank you all!
> 
> Marco Cisternino
> 
> -----Original Message-----
> From: Jose E. Roman <jroman at dsic.upv.es>
> Sent: martedì 4 gennaio 2022 19:30
> To: Marco Cisternino <marco.cisternino at optimad.it>
> Cc: Stefano Zampini <stefano.zampini at gmail.com>; petsc-users 
> <petsc-users at mcs.anl.gov>
> Subject: Re: [petsc-users] Nullspaces
> 
> To compute more than one eigenpair, call EPSSetDimensions(eps,nev,PETSC_DEFAULT,PETSC_DEFAULT).
> 
> To compute zero eigenvalues you may want to use an absolute convergence criterion, with EPSSetConvergenceTest(eps,EPS_CONV_ABS), but then a tolerance of 1e-12 is probably too small. You can try without this, anyway.
> 
> Jose
> 
> 
>> El 4 ene 2022, a las 18:44, Marco Cisternino <marco.cisternino at optimad.it> escribió:
>> 
>> Hello Stefano and thank you for your support.
>> I never used SLEPc before but I did this:
>> right after the matrix loading from file I added the following lines to my shared tiny code
>>    MatLoad(matrix, v);
>> 
>>    EPS eps;
>>    EPSCreate(PETSC_COMM_WORLD, &eps);
>>    EPSSetOperators( eps, matrix, NULL );
>>    EPSSetWhichEigenpairs(eps, EPS_SMALLEST_MAGNITUDE);
>>    EPSSetProblemType( eps, EPS_NHEP );
>>    EPSSetTolerances(eps, 1.0e-12, 1000);
>>    EPSSetFromOptions( eps );
>>    EPSSolve( eps );
>> 
>>    Vec xr, xi; /* eigenvector, x */
>>    PetscScalar kr, ki; /* eigenvalue, k */
>>    PetscInt j, nconv;
>>    PetscReal error;
>>    EPSGetConverged( eps, &nconv );
>>    for (j=0; j<nconv; j++) {
>>        EPSGetEigenpair( eps, j, &kr, &ki, xr, xi );
>>        EPSComputeError( eps, j, EPS_ERROR_ABSOLUTE, &error );
>>        std::cout << "The smallest eigenvalue is = (" << kr << ", " << ki << ") with error = " << error << std::endl;
>>    }
>> 
>> I launched using
>> mpirun -n 1 ./testnullspace -eps_monitor
>> 
>> and the output is
>> 
>>  1 EPS nconv=0 first unconverged value (error) -1499.29 
>> (6.57994794e+01)
>>  2 EPS nconv=0 first unconverged value (error) -647.468 
>> (5.39939262e+01)
>>  3 EPS nconv=0 first unconverged value (error) -177.157 
>> (9.49337698e+01)
>>  4 EPS nconv=0 first unconverged value (error) 59.6771 
>> (1.62531943e+02)
>>  5 EPS nconv=0 first unconverged value (error) 41.755 
>> (1.41965990e+02)
>>  6 EPS nconv=0 first unconverged value (error) -11.5462 
>> (3.60453662e+02)
>>  7 EPS nconv=0 first unconverged value (error) -6.04493 
>> (4.60890030e+02)
>>  8 EPS nconv=0 first unconverged value (error) -22.7362 
>> (8.67630086e+01)
>>  9 EPS nconv=0 first unconverged value (error) -12.9637
>> (1.08507821e+02)
>> 10 EPS nconv=0 first unconverged value (error) 7.7234 
>> (1.53561979e+02) …
>> 111 EPS nconv=0 first unconverged value (error) -2.27e-08
>> (6.84762319e+00)
>> 112 EPS nconv=0 first unconverged value (error) -2.60619e-08
>> (4.45245528e+00)
>> 113 EPS nconv=0 first unconverged value (error) -5.49592e-09
>> (1.87798984e+01)
>> 114 EPS nconv=0 first unconverged value (error) -9.9456e-09
>> (7.96711076e+00)
>> 115 EPS nconv=0 first unconverged value (error) -1.89779e-08
>> (4.15471472e+00)
>> 116 EPS nconv=0 first unconverged value (error) -2.05288e-08
>> (2.52953194e+00)
>> 117 EPS nconv=0 first unconverged value (error) -2.02919e-08
>> (2.90090711e+00)
>> 118 EPS nconv=0 first unconverged value (error) -3.8706e-08
>> (8.03595736e-01)
>> 119 EPS nconv=1 first unconverged value (error) -61751.8
>> (9.58036571e-07) Computed 1 pairs The smallest eigenvalue is = 
>> (-3.8706e-08, 0) with error = 4.9707e-07
>> 
>> Am I using SLEPc in the right way at least for the first smallest eigenvalue? If I’m on the right way I can find out how to compute the second one.
>> 
>> Thanks a lot
>> 
>> Marco Cisternino
> 



More information about the petsc-users mailing list