[petsc-users] Nullspace
Mark Adams
mfadams at lbl.gov
Tue Nov 20 22:08:00 CST 2018
Yes, that's right.
Also, it is best to send this to the list, like petsc-users, for a few
reasons.
It is useful for the core developers, as well as any lurkers really, to
casually see what people are doing. And the threads are archived and are a
good source of deep documentation. eg, one could search for these methods
to see any discussion on them if you want to go beyond the documentation.
Your question is a good question. Could be a FAQ (even if not that
frequent).
Mark
On Tue, Nov 20, 2018 at 10:32 PM Sanjay Govindjee <s_g at berkeley.edu> wrote:
> Thanks. I will give this a try and see what makes best sense. In the
> Thermo-Elastic case I think it should be easy.
> The vectors are the 3 translations, the 3 rotations (all on the first 3
> dofs), then a 'translation' on the 4th dof.
>
> I'll let you know if it works or not.
>
> -sanjay
>
> -------------------------------------------------------------------
> Sanjay Govindjee, PhD, PE
> Horace, Dorothy, and Katherine Johnson Professor in Engineering
>
> 779 Davis Hall
> University of California
> Berkeley, CA 94720-1710
>
> Voice: +1 510 642 6060
> FAX: +1 510 643 5264s_g at berkeley.eduhttp://faculty.ce.berkeley.edu/sanjay
> -------------------------------------------------------------------
>
> Books:
>
> Engineering Mechanics of Deformable Solidshttp://amzn.com/0199651647
>
> Engineering Mechanics 3 (Dynamics) 2nd Editionhttp://amzn.com/3642537111
>
> Engineering Mechanics 3, Supplementary Problems: Dynamics http://www.amzn.com/B00SOXN8JU
>
> NSF NHERI SimCenterhttps://simcenter.designsafe-ci.org/
> -------------------------------------------------------------------
>
>
> On 11/20/18 10:39 AM, Mark Adams wrote:
>
> PCSetCoordinates is essentially deprecated for this reason. Fragile.
>
> The recommended way is to use MatSetNearNullSpace. There is a helper
> function MatNullSpaceCreateRigidBody that takes coordinates that is a
> reroll of PCSetCoordinates basically, but you can not use that.
>
> 1) You can create the null space yourself and give it to the matrix. Here
> is a sample code:
>
> if (nearnulldim) {
> MatNullSpace nullsp;
> Vec *nullvecs;
> PetscInt i;
> ierr = PetscMalloc1(nearnulldim,&nullvecs);CHKERRQ(ierr);
> for (i=0; i<nearnulldim; i++) {
> ierr = VecCreate(PETSC_COMM_WORLD,&nullvecs[i]);CHKERRQ(ierr);
> ierr = VecLoad(nullvecs[i],viewer);CHKERRQ(ierr);
> }
> ierr = MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_FALSE,nearnulldim,nullvecs,&nullsp);CHKERRQ(ierr);
> ierr = MatSetNearNullSpace(A,nullsp);CHKERRQ(ierr);
> for (i=0; i<nearnulldim; i++) {ierr = VecDestroy(&nullvecs[i]);CHKERRQ(ierr);}
> ierr = PetscFree(nullvecs);CHKERRQ(ierr);
> ierr = MatNullSpaceDestroy(&nullsp);CHKERRQ(ierr);
> }
>
> You have nearnulldim = 2*D + 1. You need to replace VecLoad here with
> code that sets the null space explicitly.
> 2) Here is another way that would use PETSc's RBM constructor. Here is the
> recommended way to set the null space now with PETSc's RBMs:
> if (use_nearnullspace) { MatNullSpace matnull; Vec vec_coords; PetscScalar
> *c; ierr = VecCreate(MPI_COMM_WORLD,&vec_coords);CHKERRQ(ierr); ierr =
> VecSetBlockSize(vec_coords,3);CHKERRQ(ierr); ierr =
> VecSetSizes(vec_coords,m,PETSC_DECIDE);CHKERRQ(ierr); ierr =
> VecSetUp(vec_coords);CHKERRQ(ierr); ierr =
> VecGetArray(vec_coords,&c);CHKERRQ(ierr); for (i=0; i<m; i++) c[i] =
> coords[i]; /* Copy since Scalar type might be Complex */ ierr =
> VecRestoreArray(vec_coords,&c);CHKERRQ(ierr); ierr =
> MatNullSpaceCreateRigidBody(vec_coords,&matnull);CHKERRQ(ierr); ierr =
> MatSetNearNullSpace(Amat,matnull);CHKERRQ(ierr); ierr =
> MatNullSpaceDestroy(&matnull);CHKERRQ(ierr); ierr =
> VecDestroy(&vec_coords);CHKERRQ(ierr); } else {
> Now there is a method to get the vectors out of the null space:
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatNullSpaceGetVecs.html
>
> Now you can create the RBMs (6) with thus second code and the get the
> vectors with MatNullSpaceGetVecs -- giving MatNullSpaceGetVecs a vector
> array of size 7. This will give you the 6 RBMs. Now you just need to
> manually create and set the 7th vector with a basis vector for your thermal
> dof. I assume that this is the correct null space mathematically. Then use
> that in MatNullSpaceCreate.
>
> You could use either approach.
>
> Note, I don't know if all this has been tested well with > 6 null
> vectors, so we may need to fix bug(s).
>
> Mark
>
>
>
>
>
> On Tue, Nov 20, 2018 at 1:03 PM Sanjay Govindjee <s_g at berkeley.edu> wrote:
>
>> Mark,
>> In parFEAP we have been using GAMG together with PCSetCoordinates.
>> This works fine for mechanical problems, but
>> one of our users wants to solve thermo-elastic problems (4 - dofs per
>> node). The matrix now has a block size of 4
>> and GAMG is complaining:
>>
>> [0]PETSC ERROR: Petsc has generated inconsistent data
>> [0]PETSC ERROR: Don't know how to create null space for ndm=3, ndf=4. Use MatSetNearNullSpace.
>> [0]PETSC ERROR: #1 PCSetCoordinates_AGG() line 196 in /home/user/Software/petsc-3.9.2/src/ksp/pc/impls/gamg/agg.c
>> [0]PETSC ERROR: #2 PCSetCoordinates() line 1876 in /home/user/Software/petsc-3.9.2/src/ksp/pc/interface/precon.c
>>
>> I looked at the docs for how to try to set the null space but it was not fully clear to me what is the best way
>> to do this. Can you give me some hints here?
>>
>> -sanjay
>>
>> --
>> -------------------------------------------------------------------
>> Sanjay Govindjee, PhD, PE
>> Horace, Dorothy, and Katherine Johnson Professor in Engineering
>>
>> 779 Davis Hall
>> University of California
>> Berkeley, CA 94720-1710
>>
>> Voice: +1 510 642 6060
>> FAX: +1 510 643 5264s_g at berkeley.eduhttp://faculty.ce.berkeley.edu/sanjay
>> -------------------------------------------------------------------
>>
>> Books:
>>
>> Engineering Mechanics of Deformable Solidshttp://amzn.com/0199651647
>>
>> Engineering Mechanics 3 (Dynamics) 2nd Editionhttp://amzn.com/3642537111
>>
>> Engineering Mechanics 3, Supplementary Problems: Dynamics http://www.amzn.com/B00SOXN8JU
>>
>> NSF NHERI SimCenterhttps://simcenter.designsafe-ci.org/
>> -------------------------------------------------------------------
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181120/c6da0565/attachment.html>
More information about the petsc-users
mailing list