From dontbugthedevs at proton.me Tue May 5 08:06:09 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Tue, 05 May 2026 13:06:09 +0000 Subject: [petsc-users] Additiional DoF per cell Message-ID: Hello, I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... Looking at example 77 (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 Then add the new field: PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ DMAddField(dm, ..., p_FE) The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form [K_uu, K_up | K_pu, K_pp] { u | p } = RHS the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. "point X has a number of DoF not divisible by 2 field components" Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? Thank you, Noam. -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Tue May 5 08:57:46 2026 From: knepley at gmail.com (Matthew Knepley) Date: Tue, 5 May 2026 09:57:46 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < petsc-users at mcs.anl.gov> wrote: > Hello, > > I am trying to work with a "mixed" FE discretization, where besides the > usual displacements DoF in nodes, there is an additional field (e.g. > pressure) that is also part of the system. This additional field has a > certain number of additional dof : p0, p1, p2... > > Looking at example 77 ( > https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!d2oAkBYY7K4cid5hk6pHYh2SJmG3IV32CRLu9ioTzh_Fod3pljEWEAFr55I2vDgRnMxVpuyJvyvod7ZOJWk1$ > ) > this seems to be handled with an additional field, added to the DM. I've > tried so, but then I am getting from the DM arrays whose size/contents are > not what I expected. > > For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss > rule for quadrature), with just one field, a call to DMPlexGetVecClosure() > gives me an array with 8 entries (say, the coordinates of the initial > mesh): x = x0, y0, .... x3, y3 > > Then add the new field: > > PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value > of nc here */ > DMAddField(dm, ..., p_FE) > > The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). > This results in a closure of size 22. > That is wrong. Are you sure about 22? > However, what I am looking for is a closure of size 8 + 3 i.e. the > original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) > p0, p1, p2, so that in a system with "block" matrices of the form > > [K_uu, K_up | K_pu, K_pp] { u | p } = RHS > > the unknowns {p} has size 3 per cell. Is this possible? I tried some > combinations of dim / nc for the new PetscFE, but when creating the DM > section I get errors e.g. > This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!d2oAkBYY7K4cid5hk6pHYh2SJmG3IV32CRLu9ioTzh_Fod3pljEWEAFr55I2vDgRnMxVpuyJvyvod2tCkJS0$ Thanks, Matt > "point X has a number of DoF not divisible by 2 field components" > > Is this a hint that I should have 3 x dim new DoF, and simply not deal > with entries that I don't need? Or I am not setting up the section properly > (works with just one field)? > > Thank you, > Noam. > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d2oAkBYY7K4cid5hk6pHYh2SJmG3IV32CRLu9ioTzh_Fod3pljEWEAFr55I2vDgRnMxVpuyJvyvodxncmM78$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Wed May 6 05:56:05 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Wed, 06 May 2026 10:56:05 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: Hello, > That is wrong. Are you sure about 22? That's what I get, from the argument "csize" in DMPlexGetVecClosure(). Here's the output of PetscDSView: Discrete System with 2 fields cell total dim 11 total comp 5 Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet PetscFE Object: u (mech_) 1 MPI process type: vector Vector Finite Element in 2 dimensions with 2 components PetscSpace Object: Q1 (mech_) 1 MPI process type: sum Space in 2 variables with 2 components, size 8 Sum space of 2 concatenated subspaces (all identical) PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process type: tensor Space in 2 variables with 1 components, size 4 Tensor space of 2 subspaces (all identical) PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process type: poly Space in 1 variables with 1 components, size 2 Polynomial space of degree 1 PetscDualSpace Object: Q1 (mech_) 1 MPI process type: sum Dual space with 2 components, size 8 Sum dual space of 2 concatenated subspaces (all identical) PetscDualSpace Object: Q1 1 MPI process type: lagrange Dual space with 1 components, size 4 Continuous tensor Lagrange dual space Quadrature on a quadrilateral of order 3 on 4 points (dim 2) Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet PetscFE Object: p (pres_) 1 MPI process type: vector Vector Finite Element in 2 dimensions with 3 components PetscSpace Object: Q0 (pres_) 1 MPI process type: sum Space in 2 variables with 3 components, size 3 Sum space of 3 concatenated subspaces (all identical) PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process type: tensor Space in 2 variables with 1 components, size 1 Tensor space of 2 subspaces (all identical) PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process type: poly Space in 1 variables with 1 components, size 1 Polynomial space of degree 0 PetscDualSpace Object: Q0 (pres_) 1 MPI process type: sum Dual space with 3 components, size 3 Sum dual space of 3 concatenated subspaces (all identical) PetscDualSpace Object: Q0 1 MPI process type: lagrange Dual space with 1 components, size 1 Discontinuous tensor Lagrange dual space Quadrature on a quadrilateral of order 3 on 4 points (dim 2) Weak Form System with 2 fields using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) However, the closure of a Vec is still 22. On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: > On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: > >> Hello, >> >> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >> >> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!e56d5TY3E06BjaC77FED7jTCooWx_yV4rzNMykCHBix2ArsRqkepXOSXKwSsWnQUWVeiX4KtVgIMFD4ie8w-ZTbGcPkTPPXu$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >> >> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >> >> Then add the new field: >> >> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >> DMAddField(dm, ..., p_FE) >> >> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. > > That is wrong. Are you sure about 22? > >> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >> >> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >> >> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. > > This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes > > https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!e56d5TY3E06BjaC77FED7jTCooWx_yV4rzNMykCHBix2ArsRqkepXOSXKwSsWnQUWVeiX4KtVgIMFD4ie8w-ZTbGcNvtZhBB$ > > Thanks, > > Matt > >> "point X has a number of DoF not divisible by 2 field components" >> >> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >> >> Thank you, >> Noam. > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!e56d5TY3E06BjaC77FED7jTCooWx_yV4rzNMykCHBix2ArsRqkepXOSXKwSsWnQUWVeiX4KtVgIMFD4ie8w-ZTbGcKCEU3eo$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Wed May 6 08:32:05 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Wed, 06 May 2026 13:32:05 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: >> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet > > 1. Why does pressure have 3 components in 2D? I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. With nc = 1 the closure size is 18 instead. > 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. > 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. > > Thanks, For reference, -ds_view with only one (displacements) fields shows: --- Discrete System with 1 fields cell total dim 8 total comp 2 Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet PetscFE Object: u (disp_) 1 MPI process type: vector Vector Finite Element in 2 dimensions with 2 components PetscSpace Object: Q1 (disp_) 1 MPI process type: sum Space in 2 variables with 2 components, size 8 Sum space of 2 concatenated subspaces (all identical) PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process type: tensor Space in 2 variables with 1 components, size 4 Tensor space of 2 subspaces (all identical) PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process type: poly Space in 1 variables with 1 components, size 2 Polynomial space of degree 1 PetscDualSpace Object: Q1 (disp_) 1 MPI process type: sum Dual space with 2 components, size 8 Sum dual space of 2 concatenated subspaces (all identical) PetscDualSpace Object: Q1 1 MPI process type: lagrange Dual space with 1 components, size 4 Continuous tensor Lagrange dual space Quadrature on a quadrilateral of order 3 on 4 points (dim 2) Weak Form System with 1 fields--- and -dm_view --- DM Object: 1 MPI process type: plex DM_0x55c117db1b00_2 in 2 dimensions: Number of 0-cells per rank: 4 Number of 1-cells per rank: 4 Number of 2-cells per rank: 1 Labels: celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) Cell Sets: 1 strata with value/size (1 (1)) surf: 1 strata with value/size (1 (1)) Face Sets: 2 strata with value/size (2 (1), 3 (1)) edge_right: 1 strata with value/size (3 (1)) edge_left: 1 strata with value/size (2 (1)) Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) P1: 1 strata with value/size (4 (1)) P2: 1 strata with value/size (5 (1)) P3: 1 strata with value/size (6 (1)) P4: 1 strata with value/size (7 (1)) Field u: adjacency FEM /// With the second field, the two lines below are added Field p: adjacency FEM --- DM set up DM :: dm_mesh PetscFE :: u_FE, p_FE PetscInt :: dim, dim_u_FE, tdim PetscDS :: dm_ds DMCreate(PETSC_COMM_WORLD, dm_mesh) DMSetType(dm_mesh, DMPLEX) DMGetDimension(dm_mesh, dim) // dim = 2 DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see -- using flags -dm_plex_filename QUAD1.msh -dm_plex_interpolate 1 -dm_plex_gmsh_use_generic -dm_plex_gmsh_use_regions -dm_plex_gmsh_multiple_tags -dm_plex_gmsh_mark_vertices -- some operations with labels // u field PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 DMAddField(dm_mesh, NULL, (PetscObject)u_FE) // p field PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 DMAddField(dm_mesh, NULL, (PetscObject)p_FE) DMCreateDS(dm_mesh) DMGetDS(dm_mesh, dm_DS) PetscDSGetTotalDimension(dm_DS, tdim) // tdim with flags -disp_petscdualspace_lagrange_node_type equispaced -disp_petscdualspace_lagrange_node_endpoints 1 I believe these are all the DM related calls. Thanks, Noam On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: > On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: > >> Hello, >> >>> That is wrong. Are you sure about 22? >> >> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >> >> Here's the output of PetscDSView: >> >> Discrete System with 2 fields >> cell total dim 11 total comp 5 >> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: u (mech_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 2 components >> PetscSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Space in 2 variables with 2 components, size 8 >> Sum space of 2 concatenated subspaces (all identical) >> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 4 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 2 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Dual space with 2 components, size 8 >> Sum dual space of 2 concatenated subspaces (all identical) >> PetscDualSpace Object: Q1 1 MPI process >> type: lagrange >> Dual space with 1 components, size 4 >> Continuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet > > 1. Why does pressure have 3 components in 2D? > >> PetscFE Object: p (pres_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 3 components >> PetscSpace Object: Q0 (pres_) 1 MPI process >> type: sum >> Space in 2 variables with 3 components, size 3 >> Sum space of 3 concatenated subspaces (all identical) >> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 1 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 1 >> Polynomial space of degree 0 >> PetscDualSpace Object: Q0 (pres_) 1 MPI process >> type: sum >> Dual space with 3 components, size 3 >> Sum dual space of 3 concatenated subspaces (all identical) >> PetscDualSpace Object: Q0 1 MPI process >> type: lagrange >> Dual space with 1 components, size 1 >> Discontinuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Weak Form System with 2 fields >> >> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >> >> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >> >> However, the closure of a Vec is still 22. > > 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. > > 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. > > Thanks, > > Matt > >> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >> >>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>> >>>> Hello, >>>> >>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>> >>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!cn6JRmJG7QhdyZz0lvZaYRtKqRQvyvTdVQ3gxFv0ygegKzmT7TIhIGJY1-3Lqsx-WYQr8TFguDTc80rdQ59W2YsgwLc6X6ro$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>> >>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>> >>>> Then add the new field: >>>> >>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>> DMAddField(dm, ..., p_FE) >>>> >>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>> >>> That is wrong. Are you sure about 22? >>> >>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>> >>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>> >>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>> >>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>> >>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!cn6JRmJG7QhdyZz0lvZaYRtKqRQvyvTdVQ3gxFv0ygegKzmT7TIhIGJY1-3Lqsx-WYQr8TFguDTc80rdQ59W2YsgwMAHwbRI$ >>> >>> Thanks, >>> >>> Matt >>> >>>> "point X has a number of DoF not divisible by 2 field components" >>>> >>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>> >>>> Thank you, >>>> Noam. >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!cn6JRmJG7QhdyZz0lvZaYRtKqRQvyvTdVQ3gxFv0ygegKzmT7TIhIGJY1-3Lqsx-WYQr8TFguDTc80rdQ59W2YsgwP9eqEp3$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!cn6JRmJG7QhdyZz0lvZaYRtKqRQvyvTdVQ3gxFv0ygegKzmT7TIhIGJY1-3Lqsx-WYQr8TFguDTc80rdQ59W2YsgwP9eqEp3$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Wed May 6 09:06:05 2026 From: knepley at gmail.com (Matthew Knepley) Date: Wed, 6 May 2026 10:06:05 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. Here is what I get Discrete System with 2 fields cell total dim 11 total comp 3 Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet PetscFE Object: Q1 (mech_) 1 MPI process type: vector Vector Finite Element in 2 dimensions with 2 components PetscSpace Object: Q1 (mech_) 1 MPI process type: sum Space in 2 variables with 2 components, size 8 Sum space of 2 concatenated subspaces (all identical) PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process type: tensor Space in 2 variables with 1 components, size 4 Tensor space of 2 subspaces (all identical) PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process type: poly Space in 1 variables with 1 components, size 2 Polynomial space of degree 1 PetscDualSpace Object: Q1 (mech_) 1 MPI process type: sum Dual space with 2 components, size 8 Sum dual space of 2 concatenated subspaces (all identical) PetscDualSpace Object: Q1 1 MPI process type: lagrange Dual space with 1 components, size 4 Continuous tensor Lagrange dual space Quadrature on a quadrilateral of order 3 on 4 points (dim 2) Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet PetscFE Object: Q1 (pres_) 1 MPI process type: basic Basic Finite Element in 2 dimensions with 1 components PetscSpace Object: Q1 (pres_) 1 MPI process type: poly Space in 2 variables with 1 components, size 3 Polynomial space of degree 1 PetscDualSpace Object: Q1 (pres_) 1 MPI process type: lagrange Dual space with 1 components, size 3 Discontinuous Lagrange dual space Quadrature on a quadrilateral of order 3 on 4 points (dim 2) Weak Form System with 2 fields I have attached the code I used. Thanks, Matt On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: > > Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet > > > 1. Why does pressure have 3 components in 2D? > > > I used nc = 3 when calling PetscFECreateDefault() for the pressure field. > Confusion between wanting 3 addditional DoF and components. > > With nc = 1 the closure size is 18 instead. > > 2. Did you look at the incompressible example SNES ex69? It sets up this > exact element. > > > I changed some of my code following the example and got rid of some > errors. But I'll have a more thorough look again. > > 3. Please send me that code that sets up your DM. It sounds like somehow > you have a copy of your fields. > > Thanks, > > > For reference, -ds_view with only one (displacements) fields shows: > > --- > Discrete System with 1 fields > cell total dim 8 total comp 2 > Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: u (disp_) 1 MPI process > type: vector > Vector Finite Element in 2 dimensions with 2 components > PetscSpace Object: Q1 (disp_) 1 MPI process > type: sum > Space in 2 variables with 2 components, size 8 > Sum space of 2 concatenated subspaces (all identical) > PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process > type: tensor > Space in 2 variables with 1 components, size 4 > Tensor space of 2 subspaces (all identical) > PetscSpace Object: sum component tensor component > (disp_sumcomp_tensorcomp_) 1 MPI process > type: poly > Space in 1 variables with 1 components, size 2 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (disp_) 1 MPI process > type: sum > Dual space with 2 components, size 8 > Sum dual space of 2 concatenated subspaces (all identical) > PetscDualSpace Object: Q1 1 MPI process > type: lagrange > Dual space with 1 components, size 4 > Continuous tensor Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Weak Form System with 1 fields > --- > > and -dm_view > > --- > DM Object: 1 MPI process > type: plex > DM_0x55c117db1b00_2 in 2 dimensions: > Number of 0-cells per rank: 4 > Number of 1-cells per rank: 4 > Number of 2-cells per rank: 1 > Labels: > celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) > depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) > Cell Sets: 1 strata with value/size (1 (1)) > surf: 1 strata with value/size (1 (1)) > Face Sets: 2 strata with value/size (2 (1), 3 (1)) > edge_right: 1 strata with value/size (3 (1)) > edge_left: 1 strata with value/size (2 (1)) > Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) > P1: 1 strata with value/size (4 (1)) > P2: 1 strata with value/size (5 (1)) > P3: 1 strata with value/size (6 (1)) > P4: 1 strata with value/size (7 (1)) > Field u: > adjacency FEM > /// With the second field, the two lines below are added > Field p: > adjacency FEM > --- > > DM set up > > DM :: dm_mesh > PetscFE :: u_FE, p_FE > PetscInt :: dim, dim_u_FE, tdim > PetscDS :: dm_ds > > > DMCreate(PETSC_COMM_WORLD, dm_mesh) > DMSetType(dm_mesh, DMPLEX) > DMGetDimension(dm_mesh, dim) // dim = 2 > DMSetFromOptions(dm_mesh) // this was called twice by mistake, now > removed; no changes that I can see > > -- using flags > > -dm_plex_filename QUAD1.msh > -dm_plex_interpolate 1 > -dm_plex_gmsh_use_generic > -dm_plex_gmsh_use_regions > -dm_plex_gmsh_multiple_tags > -dm_plex_gmsh_mark_vertices > > -- some operations with labels > > // u field > PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", > PETSC_DETERMINE, u_FE) > PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 > DMAddField(dm_mesh, NULL, (PetscObject)u_FE) > > // p field > PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", > PETSC_DETERMINE, p_FE) > PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 > DMAddField(dm_mesh, NULL, (PetscObject)p_FE) > > DMCreateDS(dm_mesh) > DMGetDS(dm_mesh, dm_DS) > PetscDSGetTotalDimension(dm_DS, tdim) // tdim > > with flags > > -disp_petscdualspace_lagrange_node_type equispaced > -disp_petscdualspace_lagrange_node_endpoints 1 > > > I believe these are all the DM related calls. > > Thanks, > Noam > > On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < > knepley at gmail.com> wrote: > > On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: > >> Hello, >> >> That is wrong. Are you sure about 22? >> >> >> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >> >> Here's the output of PetscDSView: >> >> Discrete System with 2 fields >> cell total dim 11 total comp 5 >> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: u (mech_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 2 components >> PetscSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Space in 2 variables with 2 components, size 8 >> Sum space of 2 concatenated subspaces (all identical) >> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 4 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component >> (mech_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 2 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Dual space with 2 components, size 8 >> Sum dual space of 2 concatenated subspaces (all identical) >> PetscDualSpace Object: Q1 1 MPI process >> type: lagrange >> Dual space with 1 components, size 4 >> Continuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >> > > 1. Why does pressure have 3 components in 2D? > >> PetscFE Object: p (pres_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 3 components >> PetscSpace Object: Q0 (pres_) 1 MPI process >> type: sum >> Space in 2 variables with 3 components, size 3 >> Sum space of 3 concatenated subspaces (all identical) >> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 1 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component >> (pres_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 1 >> Polynomial space of degree 0 >> PetscDualSpace Object: Q0 (pres_) 1 MPI process >> type: sum >> Dual space with 3 components, size 3 >> Sum dual space of 3 concatenated subspaces (all identical) >> PetscDualSpace Object: Q0 1 MPI process >> type: lagrange >> Dual space with 1 components, size 1 >> Discontinuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Weak Form System with 2 fields >> >> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting >> the FE object name to "p". >> >> The entry "cell total dim 10" agrees with the output of >> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >> >> However, the closure of a Vec is still 22. >> > > 2. Did you look at the incompressible example SNES ex69? It sets up this > exact element. > > 3. Please send me that code that sets up your DM. It sounds like somehow > you have a copy of your fields. > > Thanks, > > Matt > >> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley >> wrote: >> >> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >> petsc-users at mcs.anl.gov> wrote: >> >>> Hello, >>> >>> I am trying to work with a "mixed" FE discretization, where besides the >>> usual displacements DoF in nodes, there is an additional field (e.g. >>> pressure) that is also part of the system. This additional field has a >>> certain number of additional dof : p0, p1, p2... >>> >>> Looking at example 77 ( >>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!cTGCzVKs6o_ZRihhznX93v3GQiChyo6en4Q9X0s7_oXupwu9NuNR1rte2V1LNFwYnm57xjj2xq4ScOVT8s3N$ >>> ) >>> this seems to be handled with an additional field, added to the DM. I've >>> tried so, but then I am getting from the DM arrays whose size/contents are >>> not what I expected. >>> >>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss >>> rule for quadrature), with just one field, a call to DMPlexGetVecClosure() >>> gives me an array with 8 entries (say, the coordinates of the initial >>> mesh): x = x0, y0, .... x3, y3 >>> >>> Then add the new field: >>> >>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value >>> of nc here */ >>> DMAddField(dm, ..., p_FE) >>> >>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + >>> 3). This results in a closure of size 22. >>> >> >> That is wrong. Are you sure about 22? >> >>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>> p0, p1, p2, so that in a system with "block" matrices of the form >>> >>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>> >>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>> combinations of dim / nc for the new PetscFE, but when creating the DM >>> section I get errors e.g. >>> >> >> This is what you should get. I definitely have examples that do this. For >> example, here is Q1-P0 (I think that is what you are suggesting) for >> incompressible Stokes >> >> >> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!cTGCzVKs6o_ZRihhznX93v3GQiChyo6en4Q9X0s7_oXupwu9NuNR1rte2V1LNFwYnm57xjj2xq4ScAQm-Ely$ >> >> Thanks, >> >> Matt >> >>> "point X has a number of DoF not divisible by 2 field components" >>> >>> Is this a hint that I should have 3 x dim new DoF, and simply not deal >>> with entries that I don't need? Or I am not setting up the section properly >>> (works with just one field)? >>> >>> Thank you, >>> Noam. >>> >> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cTGCzVKs6o_ZRihhznX93v3GQiChyo6en4Q9X0s7_oXupwu9NuNR1rte2V1LNFwYnm57xjj2xq4ScB-eeU3l$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cTGCzVKs6o_ZRihhznX93v3GQiChyo6en4Q9X0s7_oXupwu9NuNR1rte2V1LNFwYnm57xjj2xq4ScB-eeU3l$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cTGCzVKs6o_ZRihhznX93v3GQiChyo6en4Q9X0s7_oXupwu9NuNR1rte2V1LNFwYnm57xjj2xq4ScB-eeU3l$ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ex94.c Type: application/octet-stream Size: 1527 bytes Desc: not available URL: From knepley at gmail.com Wed May 6 06:39:37 2026 From: knepley at gmail.com (Matthew Knepley) Date: Wed, 6 May 2026 07:39:37 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: > Hello, > > That is wrong. Are you sure about 22? > > > That's what I get, from the argument "csize" in DMPlexGetVecClosure(). > > Here's the output of PetscDSView: > > Discrete System with 2 fields > cell total dim 11 total comp 5 > Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: u (mech_) 1 MPI process > type: vector > Vector Finite Element in 2 dimensions with 2 components > PetscSpace Object: Q1 (mech_) 1 MPI process > type: sum > Space in 2 variables with 2 components, size 8 > Sum space of 2 concatenated subspaces (all identical) > PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process > type: tensor > Space in 2 variables with 1 components, size 4 > Tensor space of 2 subspaces (all identical) > PetscSpace Object: sum component tensor component > (mech_sumcomp_tensorcomp_) 1 MPI process > type: poly > Space in 1 variables with 1 components, size 2 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (mech_) 1 MPI process > type: sum > Dual space with 2 components, size 8 > Sum dual space of 2 concatenated subspaces (all identical) > PetscDualSpace Object: Q1 1 MPI process > type: lagrange > Dual space with 1 components, size 4 > Continuous tensor Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet > 1. Why does pressure have 3 components in 2D? > PetscFE Object: p (pres_) 1 MPI process > type: vector > Vector Finite Element in 2 dimensions with 3 components > PetscSpace Object: Q0 (pres_) 1 MPI process > type: sum > Space in 2 variables with 3 components, size 3 > Sum space of 3 concatenated subspaces (all identical) > PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process > type: tensor > Space in 2 variables with 1 components, size 1 > Tensor space of 2 subspaces (all identical) > PetscSpace Object: sum component tensor component > (pres_sumcomp_tensorcomp_) 1 MPI process > type: poly > Space in 1 variables with 1 components, size 1 > Polynomial space of degree 0 > PetscDualSpace Object: Q0 (pres_) 1 MPI process > type: sum > Dual space with 3 components, size 3 > Sum dual space of 3 concatenated subspaces (all identical) > PetscDualSpace Object: Q0 1 MPI process > type: lagrange > Dual space with 1 components, size 1 > Discontinuous tensor Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Weak Form System with 2 fields > > using as the second field (dim = 2, nc = 3, prefix = "pres") and setting > the FE object name to "p". > > The entry "cell total dim 10" agrees with the output of > PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) > > However, the closure of a Vec is still 22. > 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. Thanks, Matt > On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley > wrote: > > On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < > petsc-users at mcs.anl.gov> wrote: > >> Hello, >> >> I am trying to work with a "mixed" FE discretization, where besides the >> usual displacements DoF in nodes, there is an additional field (e.g. >> pressure) that is also part of the system. This additional field has a >> certain number of additional dof : p0, p1, p2... >> >> Looking at example 77 ( >> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!dgCGMDKX0lQYHlCGpF8h1ZTP6zOmpezZRQiG5zqOHKm8pCFYv_yUAKaXAsHTEuxUZNlUWgy026NskhiSy0Mt$ >> ) >> this seems to be handled with an additional field, added to the DM. I've >> tried so, but then I am getting from the DM arrays whose size/contents are >> not what I expected. >> >> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss >> rule for quadrature), with just one field, a call to DMPlexGetVecClosure() >> gives me an array with 8 entries (say, the coordinates of the initial >> mesh): x = x0, y0, .... x3, y3 >> >> Then add the new field: >> >> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value >> of nc here */ >> DMAddField(dm, ..., p_FE) >> >> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). >> This results in a closure of size 22. >> > > That is wrong. Are you sure about 22? > >> However, what I am looking for is a closure of size 8 + 3 i.e. the >> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >> p0, p1, p2, so that in a system with "block" matrices of the form >> >> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >> >> the unknowns {p} has size 3 per cell. Is this possible? I tried some >> combinations of dim / nc for the new PetscFE, but when creating the DM >> section I get errors e.g. >> > > This is what you should get. I definitely have examples that do this. For > example, here is Q1-P0 (I think that is what you are suggesting) for > incompressible Stokes > > > https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!dgCGMDKX0lQYHlCGpF8h1ZTP6zOmpezZRQiG5zqOHKm8pCFYv_yUAKaXAsHTEuxUZNlUWgy026NskqJzzOX5$ > > Thanks, > > Matt > >> "point X has a number of DoF not divisible by 2 field components" >> >> Is this a hint that I should have 3 x dim new DoF, and simply not deal >> with entries that I don't need? Or I am not setting up the section properly >> (works with just one field)? >> >> Thank you, >> Noam. >> > > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dgCGMDKX0lQYHlCGpF8h1ZTP6zOmpezZRQiG5zqOHKm8pCFYv_yUAKaXAsHTEuxUZNlUWgy026NskuDOEF3q$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dgCGMDKX0lQYHlCGpF8h1ZTP6zOmpezZRQiG5zqOHKm8pCFYv_yUAKaXAsHTEuxUZNlUWgy026NskuDOEF3q$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_g at berkeley.edu Thu May 7 17:25:55 2026 From: s_g at berkeley.edu (Sanjay Govindjee) Date: Thu, 7 May 2026 15:25:55 -0700 Subject: [petsc-users] Compile issue Message-ID: I am trying to update our code to petsc 3.25.1. We were previously on 3.22.4. I am running into a compile error that I can not understand. I went through the release notes but can not see what is wrong. Any suggestions will be appreciated. -sanjay /Users/sg/petsc/gnu/bin/mpif90 -o parstop.o -c -fPIC -Wall -ffree-line-length-none -ffree-line-length-0 -Wno-lto-type-mismatch -Wno-unused-dummy-argument -g -O -I/Users/sg/petsc/include -I/Users/sg/petsc/gnu/include -I/opt/X11/include -I/Users/sg/Feap/ver87/include -I/Users/sg/Feap/ver87/modules -I/usr/local/include -J/Users/sg/Feap/ver87/modules parstop.F parstop.F:64:72: 64 | if(.not.PetscObjectIsNull(Mdiag)) then | 1 Warning: Line truncated at (1) [-Wline-truncation] parstop.F:64:70: 64 | if(.not.PetscObjectIsNull(Mdiag)) then | 1 Error: Syntax error in IF-clause after (1) parstop.F:66:9: 66 | endif | 1 Error: Expecting END SUBROUTINE statement at (1) parstop.F:68:72: 68 | if(.not.PetscObjectIsNull(Msqrt)) then | 1 Warning: Line truncated at (1) [-Wline-truncation] parstop.F:68:70: 68 | if(.not.PetscObjectIsNull(Msqrt)) then | 1 Error: Syntax error in IF-clause after (1) parstop.F:70:9: 70 | endif | 1 Error: Expecting END SUBROUTINE statement at (1) The subroutine is super simple: # include use petscksp use pfeapc implicit none # include "pfeapb.h" PetscErrorCode ierr logical :: eflag save ! Close out PETSc matrices if(.not.PetscObjectIsNull(Kmat)) then call MatDestroy(Kmat, ierr) endif if(.not.PetscObjectIsNull(Pmat)) then call MatDestroy(Pmat, ierr) endif if(.not.PetscObjectIsNull(Mmat)) then call MatDestroy(Mmat, ierr) endif if(pfeap_dstr) then call KSPDestroy(kspsol, ierr) endif ! Close out PETSc vectors if(.not.PetscObjectIsNull(Mdiag)) then call VecDestroy(Mdiag, ierr) endif if(.not.PetscObjectIsNull(Msqrt)) then call VecDestroy(Msqrt, ierr) endif The custom module pfeapc contains the objects: module pfeapc # include use petscksp implicit none Vec :: rhs, sol, xvec Vec :: yvec, zvec Vec :: Mdiag, Msqrt Mat :: Kmat, Mmat, Pmat KSP :: kspsol end module pfeapc ------ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Fri May 8 04:08:40 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Fri, 08 May 2026 09:08:40 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On the plus side, using the flags you provided in the previous email -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 the output of -ds_view is identical to yours, so setting up the fields should be correct. Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. However, the closure size was still wrong. But, I figured out the reason: the manual set up of the section. For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). So as you previously suggested > [...] It sounds like somehow you have a copy of your fields. the number of DoF per field were indeed "doubled" with the sum of both fields. Thanks, Noam On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: > Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. > > Here is what I get > > Discrete System with 2 fields > cell total dim 11 total comp 3 > Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: Q1 (mech_) 1 MPI process > type: vector > Vector Finite Element in 2 dimensions with 2 components > PetscSpace Object: Q1 (mech_) 1 MPI process > type: sum > Space in 2 variables with 2 components, size 8 > Sum space of 2 concatenated subspaces (all identical) > PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process > type: tensor > Space in 2 variables with 1 components, size 4 > Tensor space of 2 subspaces (all identical) > PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process > type: poly > Space in 1 variables with 1 components, size 2 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (mech_) 1 MPI process > type: sum > Dual space with 2 components, size 8 > Sum dual space of 2 concatenated subspaces (all identical) > PetscDualSpace Object: Q1 1 MPI process > type: lagrange > Dual space with 1 components, size 4 > Continuous tensor Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: Q1 (pres_) 1 MPI process > type: basic > Basic Finite Element in 2 dimensions with 1 components > PetscSpace Object: Q1 (pres_) 1 MPI process > type: poly > Space in 2 variables with 1 components, size 3 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (pres_) 1 MPI process > type: lagrange > Dual space with 1 components, size 3 > Discontinuous Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Weak Form System with 2 fields > > I have attached the code I used. > > Thanks, > > Matt > > On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: > >>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>> >>> 1. Why does pressure have 3 components in 2D? >> >> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >> >> With nc = 1 the closure size is 18 instead. >> >>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >> >> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >> >>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>> >>> Thanks, >> >> For reference, -ds_view with only one (displacements) fields shows: >> >> --- >> Discrete System with 1 fields >> cell total dim 8 total comp 2 >> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: u (disp_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 2 components >> PetscSpace Object: Q1 (disp_) 1 MPI process >> type: sum >> Space in 2 variables with 2 components, size 8 >> Sum space of 2 concatenated subspaces (all identical) >> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 4 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 2 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (disp_) 1 MPI process >> type: sum >> Dual space with 2 components, size 8 >> Sum dual space of 2 concatenated subspaces (all identical) >> PetscDualSpace Object: Q1 1 MPI process >> type: lagrange >> Dual space with 1 components, size 4 >> Continuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Weak Form System with 1 fields--- >> >> and -dm_view >> >> --- >> DM Object: 1 MPI process >> type: plex >> DM_0x55c117db1b00_2 in 2 dimensions: >> Number of 0-cells per rank: 4 >> Number of 1-cells per rank: 4 >> Number of 2-cells per rank: 1 >> Labels: >> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >> Cell Sets: 1 strata with value/size (1 (1)) >> surf: 1 strata with value/size (1 (1)) >> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >> edge_right: 1 strata with value/size (3 (1)) >> edge_left: 1 strata with value/size (2 (1)) >> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >> P1: 1 strata with value/size (4 (1)) >> P2: 1 strata with value/size (5 (1)) >> P3: 1 strata with value/size (6 (1)) >> P4: 1 strata with value/size (7 (1)) >> Field u: >> adjacency FEM >> /// With the second field, the two lines below are added >> Field p: >> adjacency FEM >> --- >> >> DM set up >> >> DM :: dm_mesh >> PetscFE :: u_FE, p_FE >> PetscInt :: dim, dim_u_FE, tdim >> PetscDS :: dm_ds >> >> DMCreate(PETSC_COMM_WORLD, dm_mesh) >> DMSetType(dm_mesh, DMPLEX) >> DMGetDimension(dm_mesh, dim) // dim = 2 >> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >> >> -- using flags >> >> -dm_plex_filename QUAD1.msh >> -dm_plex_interpolate 1 >> -dm_plex_gmsh_use_generic >> -dm_plex_gmsh_use_regions >> -dm_plex_gmsh_multiple_tags >> -dm_plex_gmsh_mark_vertices >> >> -- some operations with labels >> >> // u field >> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >> >> // p field >> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >> >> DMCreateDS(dm_mesh) >> DMGetDS(dm_mesh, dm_DS) >> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >> >> with flags >> >> -disp_petscdualspace_lagrange_node_type equispaced >> -disp_petscdualspace_lagrange_node_endpoints 1 >> >> I believe these are all the DM related calls. >> >> Thanks, >> Noam >> >> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >> >>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>> >>>> Hello, >>>> >>>>> That is wrong. Are you sure about 22? >>>> >>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>> >>>> Here's the output of PetscDSView: >>>> >>>> Discrete System with 2 fields >>>> cell total dim 11 total comp 5 >>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: u (mech_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>> >>> 1. Why does pressure have 3 components in 2D? >>> >>>> PetscFE Object: p (pres_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 3 components >>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 3 components, size 3 >>>> Sum space of 3 concatenated subspaces (all identical) >>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 1 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 1 >>>> Polynomial space of degree 0 >>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>> type: sum >>>> Dual space with 3 components, size 3 >>>> Sum dual space of 3 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q0 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 1 >>>> Discontinuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 2 fields >>>> >>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>> >>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>> >>>> However, the closure of a Vec is still 22. >>> >>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>> >>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>> >>> Thanks, >>> >>> Matt >>> >>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>> >>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>> >>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!coaEY5gLR5T_HZTbCB5LQ1_YdCo5TIY7difWJI7pNqUH9KO-YkgY51Bt_zimYz1oJJE6ri7CqRCfudTctaK7aEfiphUlkAUc$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>> >>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>> >>>>>> Then add the new field: >>>>>> >>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>> DMAddField(dm, ..., p_FE) >>>>>> >>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>> >>>>> That is wrong. Are you sure about 22? >>>>> >>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>> >>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>> >>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>> >>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>> >>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!coaEY5gLR5T_HZTbCB5LQ1_YdCo5TIY7difWJI7pNqUH9KO-YkgY51Bt_zimYz1oJJE6ri7CqRCfudTctaK7aEfippxKIxkx$ >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>> >>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>> >>>>>> Thank you, >>>>>> Noam. >>>>> >>>>> -- >>>>> >>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!coaEY5gLR5T_HZTbCB5LQ1_YdCo5TIY7difWJI7pNqUH9KO-YkgY51Bt_zimYz1oJJE6ri7CqRCfudTctaK7aEfipo1f9jek$ >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!coaEY5gLR5T_HZTbCB5LQ1_YdCo5TIY7difWJI7pNqUH9KO-YkgY51Bt_zimYz1oJJE6ri7CqRCfudTctaK7aEfipo1f9jek$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!coaEY5gLR5T_HZTbCB5LQ1_YdCo5TIY7difWJI7pNqUH9KO-YkgY51Bt_zimYz1oJJE6ri7CqRCfudTctaK7aEfipo1f9jek$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Fri May 8 06:05:45 2026 From: knepley at gmail.com (Matthew Knepley) Date: Fri, 8 May 2026 07:05:45 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: > On the plus side, using the flags you provided in the previous email > > -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 > -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 > > the output of -ds_view is identical to yours, so setting up the fields > should be correct. > Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" > so as to have a discontinuous field. > > However, the closure size was still wrong. > > But, I figured out the reason: the manual set up of the section. > For the argument "numDof" in DMPlexCreateSection(), I was computing the > number of DoF with PetscSectionGetDof() (which was fine until now, since > there was a single field), instead of PetscSectionGetFieldDof(). > So as you previously suggested > > [...] It sounds like somehow you have a copy of your fields. > > > the number of DoF per field were indeed "doubled" with the sum of both > fields. > Excellent. Let me know if you have any more issues. Thanks, Matt > Thanks, > Noam > > On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley > wrote: > > Okay, this is a problem with specifying the space I believe. You want a > discontinuous space for pressure. > > Here is what I get > > Discrete System with 2 fields > cell total dim 11 total comp 3 > Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: Q1 (mech_) 1 MPI process > type: vector > Vector Finite Element in 2 dimensions with 2 components > PetscSpace Object: Q1 (mech_) 1 MPI process > type: sum > Space in 2 variables with 2 components, size 8 > Sum space of 2 concatenated subspaces (all identical) > PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process > type: tensor > Space in 2 variables with 1 components, size 4 > Tensor space of 2 subspaces (all identical) > PetscSpace Object: sum component tensor component > (mech_sumcomp_tensorcomp_) 1 MPI process > type: poly > Space in 1 variables with 1 components, size 2 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (mech_) 1 MPI process > type: sum > Dual space with 2 components, size 8 > Sum dual space of 2 concatenated subspaces (all identical) > PetscDualSpace Object: Q1 1 MPI process > type: lagrange > Dual space with 1 components, size 4 > Continuous tensor Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet > PetscFE Object: Q1 (pres_) 1 MPI process > type: basic > Basic Finite Element in 2 dimensions with 1 components > PetscSpace Object: Q1 (pres_) 1 MPI process > type: poly > Space in 2 variables with 1 components, size 3 > Polynomial space of degree 1 > PetscDualSpace Object: Q1 (pres_) 1 MPI process > type: lagrange > Dual space with 1 components, size 3 > Discontinuous Lagrange dual space > Quadrature on a quadrilateral of order 3 on 4 points (dim 2) > Weak Form System with 2 fields > > I have attached the code I used. > > Thanks, > > Matt > > On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: > >> >> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >> >> >> 1. Why does pressure have 3 components in 2D? >> >> >> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. >> Confusion between wanting 3 addditional DoF and components. >> >> With nc = 1 the closure size is 18 instead. >> >> 2. Did you look at the incompressible example SNES ex69? It sets up this >> exact element. >> >> >> I changed some of my code following the example and got rid of some >> errors. But I'll have a more thorough look again. >> >> 3. Please send me that code that sets up your DM. It sounds like somehow >> you have a copy of your fields. >> >> Thanks, >> >> >> For reference, -ds_view with only one (displacements) fields shows: >> >> --- >> Discrete System with 1 fields >> cell total dim 8 total comp 2 >> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: u (disp_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 2 components >> PetscSpace Object: Q1 (disp_) 1 MPI process >> type: sum >> Space in 2 variables with 2 components, size 8 >> Sum space of 2 concatenated subspaces (all identical) >> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 4 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component >> (disp_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 2 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (disp_) 1 MPI process >> type: sum >> Dual space with 2 components, size 8 >> Sum dual space of 2 concatenated subspaces (all identical) >> PetscDualSpace Object: Q1 1 MPI process >> type: lagrange >> Dual space with 1 components, size 4 >> Continuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Weak Form System with 1 fields >> --- >> >> and -dm_view >> >> --- >> DM Object: 1 MPI process >> type: plex >> DM_0x55c117db1b00_2 in 2 dimensions: >> Number of 0-cells per rank: 4 >> Number of 1-cells per rank: 4 >> Number of 2-cells per rank: 1 >> Labels: >> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >> Cell Sets: 1 strata with value/size (1 (1)) >> surf: 1 strata with value/size (1 (1)) >> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >> edge_right: 1 strata with value/size (3 (1)) >> edge_left: 1 strata with value/size (2 (1)) >> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >> P1: 1 strata with value/size (4 (1)) >> P2: 1 strata with value/size (5 (1)) >> P3: 1 strata with value/size (6 (1)) >> P4: 1 strata with value/size (7 (1)) >> Field u: >> adjacency FEM >> /// With the second field, the two lines below are added >> Field p: >> adjacency FEM >> --- >> >> DM set up >> >> DM :: dm_mesh >> PetscFE :: u_FE, p_FE >> PetscInt :: dim, dim_u_FE, tdim >> PetscDS :: dm_ds >> >> >> DMCreate(PETSC_COMM_WORLD, dm_mesh) >> DMSetType(dm_mesh, DMPLEX) >> DMGetDimension(dm_mesh, dim) // dim = 2 >> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >> removed; no changes that I can see >> >> -- using flags >> >> -dm_plex_filename QUAD1.msh >> -dm_plex_interpolate 1 >> -dm_plex_gmsh_use_generic >> -dm_plex_gmsh_use_regions >> -dm_plex_gmsh_multiple_tags >> -dm_plex_gmsh_mark_vertices >> >> -- some operations with labels >> >> // u field >> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >> PETSC_DETERMINE, u_FE) >> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >> >> // p field >> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >> PETSC_DETERMINE, p_FE) >> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >> >> DMCreateDS(dm_mesh) >> DMGetDS(dm_mesh, dm_DS) >> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >> >> with flags >> >> -disp_petscdualspace_lagrange_node_type equispaced >> -disp_petscdualspace_lagrange_node_endpoints 1 >> >> >> I believe these are all the DM related calls. >> >> Thanks, >> Noam >> >> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >> knepley at gmail.com> wrote: >> >> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >> >>> Hello, >>> >>> That is wrong. Are you sure about 22? >>> >>> >>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>> >>> Here's the output of PetscDSView: >>> >>> Discrete System with 2 fields >>> cell total dim 11 total comp 5 >>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: u (mech_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 2 components >>> PetscSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Space in 2 variables with 2 components, size 8 >>> Sum space of 2 concatenated subspaces (all identical) >>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 4 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component >>> (mech_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 2 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Dual space with 2 components, size 8 >>> Sum dual space of 2 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q1 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 4 >>> Continuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>> >> >> 1. Why does pressure have 3 components in 2D? >> >>> PetscFE Object: p (pres_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 3 components >>> PetscSpace Object: Q0 (pres_) 1 MPI process >>> type: sum >>> Space in 2 variables with 3 components, size 3 >>> Sum space of 3 concatenated subspaces (all identical) >>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 1 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component >>> (pres_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 1 >>> Polynomial space of degree 0 >>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>> type: sum >>> Dual space with 3 components, size 3 >>> Sum dual space of 3 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q0 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 1 >>> Discontinuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Weak Form System with 2 fields >>> >>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting >>> the FE object name to "p". >>> >>> The entry "cell total dim 10" agrees with the output of >>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>> >>> However, the closure of a Vec is still 22. >>> >> >> 2. Did you look at the incompressible example SNES ex69? It sets up this >> exact element. >> >> 3. Please send me that code that sets up your DM. It sounds like somehow >> you have a copy of your fields. >> >> Thanks, >> >> Matt >> >>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley >>> wrote: >>> >>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>> petsc-users at mcs.anl.gov> wrote: >>> >>>> Hello, >>>> >>>> I am trying to work with a "mixed" FE discretization, where besides the >>>> usual displacements DoF in nodes, there is an additional field (e.g. >>>> pressure) that is also part of the system. This additional field has a >>>> certain number of additional dof : p0, p1, p2... >>>> >>>> Looking at example 77 ( >>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJDWQyy5f$ >>>> ) >>>> this seems to be handled with an additional field, added to the DM. I've >>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>> not what I expected. >>>> >>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss >>>> rule for quadrature), with just one field, a call to DMPlexGetVecClosure() >>>> gives me an array with 8 entries (say, the coordinates of the initial >>>> mesh): x = x0, y0, .... x3, y3 >>>> >>>> Then add the new field: >>>> >>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>> value of nc here */ >>>> DMAddField(dm, ..., p_FE) >>>> >>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + >>>> 3). This results in a closure of size 22. >>>> >>> >>> That is wrong. Are you sure about 22? >>> >>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>> >>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>> >>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>>> combinations of dim / nc for the new PetscFE, but when creating the DM >>>> section I get errors e.g. >>>> >>> >>> This is what you should get. I definitely have examples that do this. >>> For example, here is Q1-P0 (I think that is what you are suggesting) for >>> incompressible Stokes >>> >>> >>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJOYF2hni$ >>> >>> Thanks, >>> >>> Matt >>> >>>> "point X has a number of DoF not divisible by 2 field components" >>>> >>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal >>>> with entries that I don't need? Or I am not setting up the section properly >>>> (works with just one field)? >>>> >>>> Thank you, >>>> Noam. >>>> >>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJISojy8A$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJISojy8A$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJISojy8A$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d7n2bBRse7a9tBVL6RV7XqGopPgMbm6YlXOKdBzOEHT8exs7pN-id9yJDURq8w5KZpeKwclBsFSWJISojy8A$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mfadams at lbl.gov Fri May 8 06:52:33 2026 From: mfadams at lbl.gov (Mark Adams) Date: Fri, 8 May 2026 07:52:33 -0400 Subject: [petsc-users] Compile issue In-Reply-To: References: Message-ID: Result from (cut and paste into) Claude: ## Diagnosis The compile error is caused by **fixed-form Fortran line truncation at column 72**. Your file `parstop.F` uses the `.F` extension, which tells `gfortran` to use **fixed-form** parsing (72-column limit by default). In PETSc 3.25, the [`PetscObjectIsNull`](include/petsc/finclude/petscsysbase.h:132) macro expanded significantly. It is now defined as: ```fortran #define PetscObjectIsNull(obj) (obj%v == 0 .or. obj%v == PETSC_FORTRAN_TYPE_INITIALIZE .or. obj%v == -3) ``` When the preprocessor expands `PetscObjectIsNull(Mdiag)`, the resulting line is far longer than 72 characters and gets truncated mid-expression, producing the syntax error. The compiler warnings confirm this: ``` parstop.F:64:72: Warning: Line truncated at (1) [-Wline-truncation] ``` ## Solution: Rename `.F` to `.F90` **Rename `parstop.F` ? `parstop.F90`** (and do the same for any other `.F` files that use `PetscObjectIsNull`). Your code is already written in free-form Fortran style (`!` comments, `::` declarations, `implicit none`), so the `.F` extension is misleading. The `.F90` extension will: 1. Invoke the C preprocessor (uppercase `F` is preserved) 2. Use **free-form** parsing (132-column default limit) 3. Work with your existing `-ffree-line-length-none` flag, which removes the line length limit entirely This is the cleanest fix and requires no code changes ? only a file rename. ### Alternative: Keep `.F` and add a compiler flag If renaming is not feasible, add `-ffixed-line-length-none` to your `mpif90` flags to remove the 72-column truncation for fixed-form files. On Thu, May 7, 2026 at 6:26?PM Sanjay Govindjee via petsc-users < petsc-users at mcs.anl.gov> wrote: > I am trying to update our code to petsc 3.25.1. We were previously on > 3.22.4. I am running into a compile error that I can not understand. I > went through the release notes but can not see what is wrong. Any > suggestions will be appreciated. > > -sanjay > > /Users/sg/petsc/gnu/bin/mpif90 -o parstop.o -c -fPIC -Wall > -ffree-line-length-none -ffree-line-length-0 -Wno-lto-type-mismatch > -Wno-unused-dummy-argument -g -O -I/Users/sg/petsc/include > -I/Users/sg/petsc/gnu/include -I/opt/X11/include > -I/Users/sg/Feap/ver87/include -I/Users/sg/Feap/ver87/modules > -I/usr/local/include -J/Users/sg/Feap/ver87/modules parstop.F > parstop.F:64:72: > > 64 | if(.not.PetscObjectIsNull(Mdiag)) then > | > 1 > Warning: Line truncated at (1) [-Wline-truncation] > parstop.F:64:70: > > 64 | if(.not.PetscObjectIsNull(Mdiag)) then > | > 1 > Error: Syntax error in IF-clause after (1) > parstop.F:66:9: > > 66 | endif > | 1 > Error: Expecting END SUBROUTINE statement at (1) > parstop.F:68:72: > > 68 | if(.not.PetscObjectIsNull(Msqrt)) then > | > 1 > Warning: Line truncated at (1) [-Wline-truncation] > parstop.F:68:70: > > 68 | if(.not.PetscObjectIsNull(Msqrt)) then > | > 1 > Error: Syntax error in IF-clause after (1) > parstop.F:70:9: > > 70 | endif > | 1 > Error: Expecting END SUBROUTINE statement at (1) > > The subroutine is super simple: > > # include > use petscksp > use pfeapc > implicit none > > # include "pfeapb.h" > > PetscErrorCode ierr > > logical :: eflag > > save > > ! Close out PETSc matrices > if(.not.PetscObjectIsNull(Kmat)) then > call MatDestroy(Kmat, ierr) > endif > > if(.not.PetscObjectIsNull(Pmat)) then > call MatDestroy(Pmat, ierr) > endif > > if(.not.PetscObjectIsNull(Mmat)) then > call MatDestroy(Mmat, ierr) > endif > > if(pfeap_dstr) then > call KSPDestroy(kspsol, ierr) > endif > > ! Close out PETSc vectors > if(.not.PetscObjectIsNull(Mdiag)) then > call VecDestroy(Mdiag, ierr) > endif > > if(.not.PetscObjectIsNull(Msqrt)) then > call VecDestroy(Msqrt, ierr) > endif > > The custom module pfeapc contains the objects: > > module pfeapc > # include > use petscksp > implicit none > > Vec :: rhs, sol, xvec > Vec :: yvec, zvec > Vec :: Mdiag, Msqrt > Mat :: Kmat, Mmat, Pmat > KSP :: kspsol > end module pfeapc > > > > ------ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Fri May 8 07:01:43 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Fri, 08 May 2026 12:01:43 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: Moving on to the values of the closure. Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: -- nc = 1 closure = y0 x1 y1 x2 y2 x3 y3 0 x0 -- nc = 3 closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 -- nc = 7 closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 Looking at that output: - The first value is always a y coordinate (second component of u field). - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIvmj8bxC$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. Thanks, Noam On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: > On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: > >> On the plus side, using the flags you provided in the previous email >> >> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >> >> the output of -ds_view is identical to yours, so setting up the fields should be correct. >> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >> >> However, the closure size was still wrong. >> >> But, I figured out the reason: the manual set up of the section. >> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >> So as you previously suggested >> >>> [...] It sounds like somehow you have a copy of your fields. >> >> the number of DoF per field were indeed "doubled" with the sum of both fields. > > Excellent. Let me know if you have any more issues. > > Thanks, > > Matt > >> Thanks, >> Noam >> >> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >> >>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>> >>> Here is what I get >>> >>> Discrete System with 2 fields >>> cell total dim 11 total comp 3 >>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (mech_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 2 components >>> PetscSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Space in 2 variables with 2 components, size 8 >>> Sum space of 2 concatenated subspaces (all identical) >>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 4 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 2 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Dual space with 2 components, size 8 >>> Sum dual space of 2 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q1 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 4 >>> Continuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (pres_) 1 MPI process >>> type: basic >>> Basic Finite Element in 2 dimensions with 1 components >>> PetscSpace Object: Q1 (pres_) 1 MPI process >>> type: poly >>> Space in 2 variables with 1 components, size 3 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 3 >>> Discontinuous Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Weak Form System with 2 fields >>> >>> I have attached the code I used. >>> >>> Thanks, >>> >>> Matt >>> >>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>> >>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> >>>>> 1. Why does pressure have 3 components in 2D? >>>> >>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>> >>>> With nc = 1 the closure size is 18 instead. >>>> >>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>> >>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>> >>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>> >>>>> Thanks, >>>> >>>> For reference, -ds_view with only one (displacements) fields shows: >>>> >>>> --- >>>> Discrete System with 1 fields >>>> cell total dim 8 total comp 2 >>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: u (disp_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 1 fields--- >>>> >>>> and -dm_view >>>> >>>> --- >>>> DM Object: 1 MPI process >>>> type: plex >>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>> Number of 0-cells per rank: 4 >>>> Number of 1-cells per rank: 4 >>>> Number of 2-cells per rank: 1 >>>> Labels: >>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>> Cell Sets: 1 strata with value/size (1 (1)) >>>> surf: 1 strata with value/size (1 (1)) >>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>> edge_right: 1 strata with value/size (3 (1)) >>>> edge_left: 1 strata with value/size (2 (1)) >>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>> P1: 1 strata with value/size (4 (1)) >>>> P2: 1 strata with value/size (5 (1)) >>>> P3: 1 strata with value/size (6 (1)) >>>> P4: 1 strata with value/size (7 (1)) >>>> Field u: >>>> adjacency FEM >>>> /// With the second field, the two lines below are added >>>> Field p: >>>> adjacency FEM >>>> --- >>>> >>>> DM set up >>>> >>>> DM :: dm_mesh >>>> PetscFE :: u_FE, p_FE >>>> PetscInt :: dim, dim_u_FE, tdim >>>> PetscDS :: dm_ds >>>> >>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>> DMSetType(dm_mesh, DMPLEX) >>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>> >>>> -- using flags >>>> >>>> -dm_plex_filename QUAD1.msh >>>> -dm_plex_interpolate 1 >>>> -dm_plex_gmsh_use_generic >>>> -dm_plex_gmsh_use_regions >>>> -dm_plex_gmsh_multiple_tags >>>> -dm_plex_gmsh_mark_vertices >>>> >>>> -- some operations with labels >>>> >>>> // u field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>> >>>> // p field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>> >>>> DMCreateDS(dm_mesh) >>>> DMGetDS(dm_mesh, dm_DS) >>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>> >>>> with flags >>>> >>>> -disp_petscdualspace_lagrange_node_type equispaced >>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>> >>>> I believe these are all the DM related calls. >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>> >>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>>> That is wrong. Are you sure about 22? >>>>>> >>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>> >>>>>> Here's the output of PetscDSView: >>>>>> >>>>>> Discrete System with 2 fields >>>>>> cell total dim 11 total comp 5 >>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> >>>>> 1. Why does pressure have 3 components in 2D? >>>>> >>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 3 components, size 3 >>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 1 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 1 >>>>>> Polynomial space of degree 0 >>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 3 components, size 3 >>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 1 >>>>>> Discontinuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 2 fields >>>>>> >>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>> >>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>> >>>>>> However, the closure of a Vec is still 22. >>>>> >>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>> >>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>> >>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>> >>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIqGUiP8y$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>> >>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>> >>>>>>>> Then add the new field: >>>>>>>> >>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>> >>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>> >>>>>>> That is wrong. Are you sure about 22? >>>>>>> >>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>> >>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>> >>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>> >>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>> >>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIg7lpe7Y$ >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Matt >>>>>>> >>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>> >>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>> >>>>>>>> Thank you, >>>>>>>> Noam. >>>>>>> >>>>>>> -- >>>>>>> >>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>> -- Norbert Wiener >>>>>>> >>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIofCHV1h$ >>>>> >>>>> -- >>>>> >>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIofCHV1h$ >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIofCHV1h$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ZJz_pZR7M_mMi6gIDNMkNQy_6DO0K3sPQyCW-lCG3GWkYxEDauwvsaPpgiykvB00ywn3uvdURZsfZd4cNU2ZdMtLIofCHV1h$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Fri May 8 08:25:04 2026 From: knepley at gmail.com (Matthew Knepley) Date: Fri, 8 May 2026 09:25:04 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: > Moving on to the values of the closure. > > Initially I create a vector for the DM with DMCreateLocal/GlobalVector, > which is used for e.g. the solution. Following the example before, it will > have size 8 (coordinates) + nc (for the p field). > > I am getting a seemingly random order when I test with different values of > nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, > y_i . The rest nc components are set to zero. The closure returns: > > -- nc = 1 > closure = y0 x1 y1 x2 y2 x3 y3 0 x0 > > -- nc = 3 > closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 > > -- nc = 7 > closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 > > Looking at that output: > - The first value is always a y coordinate (second component of u field). > - The position of the nc = 0 components change (starting with nc = 8, all > zero values come first, followed by the coordinates). > > Looking again at ex77.c ( > https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLbfKOReb$ ), it says the > closure stacks up the fields, which aligns with the output above (all u > values, then all p values), but which is the starting point seems arbitrary. > This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? Thanks, Matt > The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not > be correct to start with. > > I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, > ...) so that I only get the u field DoF. But I will need to deal with the p > field values as well at some point. > > Thanks, > Noam > > On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley > wrote: > > On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: > >> On the plus side, using the flags you provided in the previous email >> >> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 >> -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >> >> the output of -ds_view is identical to yours, so setting up the fields >> should be correct. >> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity >> 0" so as to have a discontinuous field. >> >> However, the closure size was still wrong. >> >> But, I figured out the reason: the manual set up of the section. >> For the argument "numDof" in DMPlexCreateSection(), I was computing the >> number of DoF with PetscSectionGetDof() (which was fine until now, since >> there was a single field), instead of PetscSectionGetFieldDof(). >> So as you previously suggested >> >> [...] It sounds like somehow you have a copy of your fields. >> >> >> the number of DoF per field were indeed "doubled" with the sum of both >> fields. >> > > Excellent. Let me know if you have any more issues. > > Thanks, > > Matt > >> Thanks, >> Noam >> >> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >> knepley at gmail.com> wrote: >> >> Okay, this is a problem with specifying the space I believe. You want a >> discontinuous space for pressure. >> >> Here is what I get >> >> Discrete System with 2 fields >> cell total dim 11 total comp 3 >> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: Q1 (mech_) 1 MPI process >> type: vector >> Vector Finite Element in 2 dimensions with 2 components >> PetscSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Space in 2 variables with 2 components, size 8 >> Sum space of 2 concatenated subspaces (all identical) >> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >> type: tensor >> Space in 2 variables with 1 components, size 4 >> Tensor space of 2 subspaces (all identical) >> PetscSpace Object: sum component tensor component >> (mech_sumcomp_tensorcomp_) 1 MPI process >> type: poly >> Space in 1 variables with 1 components, size 2 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (mech_) 1 MPI process >> type: sum >> Dual space with 2 components, size 8 >> Sum dual space of 2 concatenated subspaces (all identical) >> PetscDualSpace Object: Q1 1 MPI process >> type: lagrange >> Dual space with 1 components, size 4 >> Continuous tensor Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >> PetscFE Object: Q1 (pres_) 1 MPI process >> type: basic >> Basic Finite Element in 2 dimensions with 1 components >> PetscSpace Object: Q1 (pres_) 1 MPI process >> type: poly >> Space in 2 variables with 1 components, size 3 >> Polynomial space of degree 1 >> PetscDualSpace Object: Q1 (pres_) 1 MPI process >> type: lagrange >> Dual space with 1 components, size 3 >> Discontinuous Lagrange dual space >> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >> Weak Form System with 2 fields >> >> I have attached the code I used. >> >> Thanks, >> >> Matt >> >> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >> >>> >>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>> >>> >>> 1. Why does pressure have 3 components in 2D? >>> >>> >>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>> field. Confusion between wanting 3 addditional DoF and components. >>> >>> With nc = 1 the closure size is 18 instead. >>> >>> 2. Did you look at the incompressible example SNES ex69? It sets up this >>> exact element. >>> >>> >>> I changed some of my code following the example and got rid of some >>> errors. But I'll have a more thorough look again. >>> >>> 3. Please send me that code that sets up your DM. It sounds like somehow >>> you have a copy of your fields. >>> >>> Thanks, >>> >>> >>> For reference, -ds_view with only one (displacements) fields shows: >>> >>> --- >>> Discrete System with 1 fields >>> cell total dim 8 total comp 2 >>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: u (disp_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 2 components >>> PetscSpace Object: Q1 (disp_) 1 MPI process >>> type: sum >>> Space in 2 variables with 2 components, size 8 >>> Sum space of 2 concatenated subspaces (all identical) >>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 4 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component >>> (disp_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 2 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>> type: sum >>> Dual space with 2 components, size 8 >>> Sum dual space of 2 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q1 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 4 >>> Continuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Weak Form System with 1 fields >>> --- >>> >>> and -dm_view >>> >>> --- >>> DM Object: 1 MPI process >>> type: plex >>> DM_0x55c117db1b00_2 in 2 dimensions: >>> Number of 0-cells per rank: 4 >>> Number of 1-cells per rank: 4 >>> Number of 2-cells per rank: 1 >>> Labels: >>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>> Cell Sets: 1 strata with value/size (1 (1)) >>> surf: 1 strata with value/size (1 (1)) >>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>> edge_right: 1 strata with value/size (3 (1)) >>> edge_left: 1 strata with value/size (2 (1)) >>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>> P1: 1 strata with value/size (4 (1)) >>> P2: 1 strata with value/size (5 (1)) >>> P3: 1 strata with value/size (6 (1)) >>> P4: 1 strata with value/size (7 (1)) >>> Field u: >>> adjacency FEM >>> /// With the second field, the two lines below are added >>> Field p: >>> adjacency FEM >>> --- >>> >>> DM set up >>> >>> DM :: dm_mesh >>> PetscFE :: u_FE, p_FE >>> PetscInt :: dim, dim_u_FE, tdim >>> PetscDS :: dm_ds >>> >>> >>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>> DMSetType(dm_mesh, DMPLEX) >>> DMGetDimension(dm_mesh, dim) // dim = 2 >>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>> removed; no changes that I can see >>> >>> -- using flags >>> >>> -dm_plex_filename QUAD1.msh >>> -dm_plex_interpolate 1 >>> -dm_plex_gmsh_use_generic >>> -dm_plex_gmsh_use_regions >>> -dm_plex_gmsh_multiple_tags >>> -dm_plex_gmsh_mark_vertices >>> >>> -- some operations with labels >>> >>> // u field >>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >>> PETSC_DETERMINE, u_FE) >>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>> >>> // p field >>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>> PETSC_DETERMINE, p_FE) >>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>> >>> DMCreateDS(dm_mesh) >>> DMGetDS(dm_mesh, dm_DS) >>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>> >>> with flags >>> >>> -disp_petscdualspace_lagrange_node_type equispaced >>> -disp_petscdualspace_lagrange_node_endpoints 1 >>> >>> >>> I believe these are all the DM related calls. >>> >>> Thanks, >>> Noam >>> >>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>> knepley at gmail.com> wrote: >>> >>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>> >>>> Hello, >>>> >>>> That is wrong. Are you sure about 22? >>>> >>>> >>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>> >>>> Here's the output of PetscDSView: >>>> >>>> Discrete System with 2 fields >>>> cell total dim 11 total comp 5 >>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: u (mech_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component >>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> >>> >>> 1. Why does pressure have 3 components in 2D? >>> >>>> PetscFE Object: p (pres_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 3 components >>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 3 components, size 3 >>>> Sum space of 3 concatenated subspaces (all identical) >>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 1 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component >>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 1 >>>> Polynomial space of degree 0 >>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>> type: sum >>>> Dual space with 3 components, size 3 >>>> Sum dual space of 3 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q0 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 1 >>>> Discontinuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 2 fields >>>> >>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>> setting the FE object name to "p". >>>> >>>> The entry "cell total dim 10" agrees with the output of >>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>> >>>> However, the closure of a Vec is still 22. >>>> >>> >>> 2. Did you look at the incompressible example SNES ex69? It sets up this >>> exact element. >>> >>> 3. Please send me that code that sets up your DM. It sounds like somehow >>> you have a copy of your fields. >>> >>> Thanks, >>> >>> Matt >>> >>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>> knepley at gmail.com> wrote: >>>> >>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>> petsc-users at mcs.anl.gov> wrote: >>>> >>>>> Hello, >>>>> >>>>> I am trying to work with a "mixed" FE discretization, where besides >>>>> the usual displacements DoF in nodes, there is an additional field (e.g. >>>>> pressure) that is also part of the system. This additional field has a >>>>> certain number of additional dof : p0, p1, p2... >>>>> >>>>> Looking at example 77 ( >>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLbfKOReb$ >>>>> ) >>>>> this seems to be handled with an additional field, added to the DM. I've >>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>> not what I expected. >>>>> >>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss >>>>> rule for quadrature), with just one field, a call to DMPlexGetVecClosure() >>>>> gives me an array with 8 entries (say, the coordinates of the initial >>>>> mesh): x = x0, y0, .... x3, y3 >>>>> >>>>> Then add the new field: >>>>> >>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>> value of nc here */ >>>>> DMAddField(dm, ..., p_FE) >>>>> >>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + >>>>> 3). This results in a closure of size 22. >>>>> >>>> >>>> That is wrong. Are you sure about 22? >>>> >>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>> >>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>> >>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>>>> combinations of dim / nc for the new PetscFE, but when creating the DM >>>>> section I get errors e.g. >>>>> >>>> >>>> This is what you should get. I definitely have examples that do this. >>>> For example, here is Q1-P0 (I think that is what you are suggesting) for >>>> incompressible Stokes >>>> >>>> >>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLVhejtNH$ >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> "point X has a number of DoF not divisible by 2 field components" >>>>> >>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal >>>>> with entries that I don't need? Or I am not setting up the section properly >>>>> (works with just one field)? >>>>> >>>>> Thank you, >>>>> Noam. >>>>> >>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLX2UM_XW$ >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLX2UM_XW$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLX2UM_XW$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLX2UM_XW$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZYVvIZ23hgIUw1csU5wjCmuKc2ME0bKW_hMQOOxG61n7EzW1LrohDd6nwgeCInKDjUr65-CfGFEXLX2UM_XW$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_g at berkeley.edu Fri May 8 08:45:13 2026 From: s_g at berkeley.edu (Sanjay Govindjee) Date: Fri, 8 May 2026 06:45:13 -0700 Subject: [petsc-users] Compile issue In-Reply-To: References: Message-ID: <4A1C0FDA-7A6D-48F3-94B1-761709C5E18F@berkeley.edu> An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Fri May 8 10:58:30 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Fri, 08 May 2026 15:58:30 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: > This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? If I use the exact same arrays/values for constructing the section, I get the same closure arrangement in the code you provided. Not surprising I guess? A seemingly random number of coordinates / zeroes / more coordinates. I checked example 14 (https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py3G8GO-1$ ) for constructing the section. These are the values I used: - n_fields = 2 - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] The u field is defined in the nodes, with 2 components (u, v), hence the first "2". Then no components for edges/faces. For the p field, what I am trying to simulate is having nc (independent) DoF, sort of like having nc scalar fields, if that makes sense? Hence using: - N = nc - Also using the flag "-pres_petscspace_degree 0" But I'm not sure about those values. Then for simplicity numBC = 0 and all other arguments are NULL (will deal with boundary conditions later). With these arguments, I get the same as before e.g. -- nc = 3 (total dimension = 11) closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 Thanks, Noam On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley wrote: > On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: > >> Moving on to the values of the closure. >> >> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). >> >> I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: >> >> -- nc = 1 >> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >> >> -- nc = 3 >> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >> >> -- nc = 7 >> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >> >> Looking at that output: >> - The first value is always a y coordinate (second component of u field). >> - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). >> >> Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6PywznNWCV$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. > > This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? > > Thanks, > > Matt > >> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. >> >> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: >> >>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>> >>>> On the plus side, using the flags you provided in the previous email >>>> >>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>> >>>> the output of -ds_view is identical to yours, so setting up the fields should be correct. >>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >>>> >>>> However, the closure size was still wrong. >>>> >>>> But, I figured out the reason: the manual set up of the section. >>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >>>> So as you previously suggested >>>> >>>>> [...] It sounds like somehow you have a copy of your fields. >>>> >>>> the number of DoF per field were indeed "doubled" with the sum of both fields. >>> >>> Excellent. Let me know if you have any more issues. >>> >>> Thanks, >>> >>> Matt >>> >>>> Thanks, >>>> Noam >>>> >>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >>>> >>>>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>>>> >>>>> Here is what I get >>>>> >>>>> Discrete System with 2 fields >>>>> cell total dim 11 total comp 3 >>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 2 components >>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 2 components, size 8 >>>>> Sum space of 2 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 4 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 2 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Dual space with 2 components, size 8 >>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q1 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 4 >>>>> Continuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>> type: basic >>>>> Basic Finite Element in 2 dimensions with 1 components >>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>> type: poly >>>>> Space in 2 variables with 1 components, size 3 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 3 >>>>> Discontinuous Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Weak Form System with 2 fields >>>>> >>>>> I have attached the code I used. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>>>> >>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> >>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>> >>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>>>> >>>>>> With nc = 1 the closure size is 18 instead. >>>>>> >>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>> >>>>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>>>> >>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>> >>>>>>> Thanks, >>>>>> >>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>> >>>>>> --- >>>>>> Discrete System with 1 fields >>>>>> cell total dim 8 total comp 2 >>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 1 fields--- >>>>>> >>>>>> and -dm_view >>>>>> >>>>>> --- >>>>>> DM Object: 1 MPI process >>>>>> type: plex >>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>> Number of 0-cells per rank: 4 >>>>>> Number of 1-cells per rank: 4 >>>>>> Number of 2-cells per rank: 1 >>>>>> Labels: >>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>> surf: 1 strata with value/size (1 (1)) >>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>> P1: 1 strata with value/size (4 (1)) >>>>>> P2: 1 strata with value/size (5 (1)) >>>>>> P3: 1 strata with value/size (6 (1)) >>>>>> P4: 1 strata with value/size (7 (1)) >>>>>> Field u: >>>>>> adjacency FEM >>>>>> /// With the second field, the two lines below are added >>>>>> Field p: >>>>>> adjacency FEM >>>>>> --- >>>>>> >>>>>> DM set up >>>>>> >>>>>> DM :: dm_mesh >>>>>> PetscFE :: u_FE, p_FE >>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>> PetscDS :: dm_ds >>>>>> >>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>>>> >>>>>> -- using flags >>>>>> >>>>>> -dm_plex_filename QUAD1.msh >>>>>> -dm_plex_interpolate 1 >>>>>> -dm_plex_gmsh_use_generic >>>>>> -dm_plex_gmsh_use_regions >>>>>> -dm_plex_gmsh_multiple_tags >>>>>> -dm_plex_gmsh_mark_vertices >>>>>> >>>>>> -- some operations with labels >>>>>> >>>>>> // u field >>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>> >>>>>> // p field >>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>> >>>>>> DMCreateDS(dm_mesh) >>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>> >>>>>> with flags >>>>>> >>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>> >>>>>> I believe these are all the DM related calls. >>>>>> >>>>>> Thanks, >>>>>> Noam >>>>>> >>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>>>> >>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>> >>>>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>>>> >>>>>>>> Here's the output of PetscDSView: >>>>>>>> >>>>>>>> Discrete System with 2 fields >>>>>>>> cell total dim 11 total comp 5 >>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>> type: vector >>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>> type: tensor >>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>> Polynomial space of degree 1 >>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Dual space with 2 components, size 8 >>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 4 >>>>>>>> Continuous tensor Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> >>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>> >>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>> type: vector >>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>> type: tensor >>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>> Polynomial space of degree 0 >>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Dual space with 3 components, size 3 >>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 1 >>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Weak Form System with 2 fields >>>>>>>> >>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>>>> >>>>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>> >>>>>>>> However, the closure of a Vec is still 22. >>>>>>> >>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>> >>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Matt >>>>>>> >>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>>>> >>>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>>>> >>>>>>>>>> Hello, >>>>>>>>>> >>>>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>>>> >>>>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py97AKIcR$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>>>> >>>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>>> >>>>>>>>>> Then add the new field: >>>>>>>>>> >>>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>>> >>>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>>>> >>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>> >>>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>>> >>>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>>> >>>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>>>> >>>>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>>>> >>>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py73Sp5rw$ >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> >>>>>>>>> Matt >>>>>>>>> >>>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>>> >>>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>>>> >>>>>>>>>> Thank you, >>>>>>>>>> Noam. >>>>>>>>> >>>>>>>>> -- >>>>>>>>> >>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>> -- Norbert Wiener >>>>>>>>> >>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py2Cs1gOX$ >>>>>>> >>>>>>> -- >>>>>>> >>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>> -- Norbert Wiener >>>>>>> >>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py2Cs1gOX$ >>>>> >>>>> -- >>>>> >>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py2Cs1gOX$ >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py2Cs1gOX$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!d2JFxZGkjTcatHxdKx4pPfY6siKmIrA14IHy1Hiz4-p_so34WqYSq1CesOsjWMyyLBw3JsNJ8uWWKK6uAjNb7j6Py2Cs1gOX$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Fri May 8 12:11:03 2026 From: knepley at gmail.com (Matthew Knepley) Date: Fri, 8 May 2026 13:11:03 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Fri, May 8, 2026 at 11:58?AM Noam T. wrote: > This is likely to be a Section construction problem again. The Section > fields are separated by DMPlexVecGetClosure(), sp you must not have defined > the fields in the Section. If you put these calls into the code that I sent > you, what do you get? > > > If I use the exact same arrays/values for constructing the section, I get > the same closure arrangement in the code you provided. Not surprising I > guess? A seemingly random number of coordinates / zeroes / more coordinates. > Can you send the code for this? The are _many_ examples using multiple fields like this, so I assure you it does not return things in random order. Thanks, Matt > I checked example 14 ( > https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6Dcg86580H$ ) for > constructing the section. These are the values I used: > > - n_fields = 2 > > - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] > > The u field is defined in the nodes, with 2 components (u, v), hence the > first "2". Then no components for edges/faces. > For the p field, what I am trying to simulate is having nc (independent) > DoF, sort of like having nc scalar fields, if that makes sense? Hence using: > > - N = nc > - Also using the flag "-pres_petscspace_degree 0" > > But I'm not sure about those values. > > Then for simplicity numBC = 0 and all other arguments are NULL (will deal > with boundary conditions later). > > With these arguments, I get the same as before e.g. > > -- nc = 3 (total dimension = 11) > closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 > > Thanks, > Noam > > > On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley > wrote: > > On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: > >> Moving on to the values of the closure. >> >> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, >> which is used for e.g. the solution. Following the example before, it will >> have size 8 (coordinates) + nc (for the p field). >> >> I am getting a seemingly random order when I test with different values >> of nc. Say, I initialize the vector (VecSetValues) with the coordinates >> x_i, y_i . The rest nc components are set to zero. The closure returns: >> >> -- nc = 1 >> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >> >> -- nc = 3 >> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >> >> -- nc = 7 >> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >> >> Looking at that output: >> - The first value is always a y coordinate (second component of u field). >> - The position of the nc = 0 components change (starting with nc = 8, all >> zero values come first, followed by the coordinates). >> >> Looking again at ex77.c ( >> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6Dcswltmb_$ ), it says the >> closure stacks up the fields, which aligns with the output above (all u >> values, then all p values), but which is the starting point seems arbitrary. >> > > This is likely to be a Section construction problem again. The Section > fields are separated by DMPlexVecGetClosure(), sp you must not have defined > the fields in the Section. If you put these calls into the code that I sent > you, what do you get? > > Thanks, > > Matt > >> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not >> be correct to start with. >> >> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, >> ...) so that I only get the u field DoF. But I will need to deal with the p >> field values as well at some point. >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley >> wrote: >> >> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >> >>> On the plus side, using the flags you provided in the previous email >>> >>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 >>> -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>> >>> the output of -ds_view is identical to yours, so setting up the fields >>> should be correct. >>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity >>> 0" so as to have a discontinuous field. >>> >>> However, the closure size was still wrong. >>> >>> But, I figured out the reason: the manual set up of the section. >>> For the argument "numDof" in DMPlexCreateSection(), I was computing the >>> number of DoF with PetscSectionGetDof() (which was fine until now, since >>> there was a single field), instead of PetscSectionGetFieldDof(). >>> So as you previously suggested >>> >>> [...] It sounds like somehow you have a copy of your fields. >>> >>> >>> the number of DoF per field were indeed "doubled" with the sum of both >>> fields. >>> >> >> Excellent. Let me know if you have any more issues. >> >> Thanks, >> >> Matt >> >>> Thanks, >>> Noam >>> >>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >>> knepley at gmail.com> wrote: >>> >>> Okay, this is a problem with specifying the space I believe. You want a >>> discontinuous space for pressure. >>> >>> Here is what I get >>> >>> Discrete System with 2 fields >>> cell total dim 11 total comp 3 >>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (mech_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 2 components >>> PetscSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Space in 2 variables with 2 components, size 8 >>> Sum space of 2 concatenated subspaces (all identical) >>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 4 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component >>> (mech_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 2 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Dual space with 2 components, size 8 >>> Sum dual space of 2 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q1 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 4 >>> Continuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (pres_) 1 MPI process >>> type: basic >>> Basic Finite Element in 2 dimensions with 1 components >>> PetscSpace Object: Q1 (pres_) 1 MPI process >>> type: poly >>> Space in 2 variables with 1 components, size 3 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 3 >>> Discontinuous Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Weak Form System with 2 fields >>> >>> I have attached the code I used. >>> >>> Thanks, >>> >>> Matt >>> >>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>> >>>> >>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> >>>> >>>> 1. Why does pressure have 3 components in 2D? >>>> >>>> >>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>>> field. Confusion between wanting 3 addditional DoF and components. >>>> >>>> With nc = 1 the closure size is 18 instead. >>>> >>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>> this exact element. >>>> >>>> >>>> I changed some of my code following the example and got rid of some >>>> errors. But I'll have a more thorough look again. >>>> >>>> 3. Please send me that code that sets up your DM. It sounds like >>>> somehow you have a copy of your fields. >>>> >>>> Thanks, >>>> >>>> >>>> For reference, -ds_view with only one (displacements) fields shows: >>>> >>>> --- >>>> Discrete System with 1 fields >>>> cell total dim 8 total comp 2 >>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: u (disp_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component >>>> (disp_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 1 fields >>>> --- >>>> >>>> and -dm_view >>>> >>>> --- >>>> DM Object: 1 MPI process >>>> type: plex >>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>> Number of 0-cells per rank: 4 >>>> Number of 1-cells per rank: 4 >>>> Number of 2-cells per rank: 1 >>>> Labels: >>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>> Cell Sets: 1 strata with value/size (1 (1)) >>>> surf: 1 strata with value/size (1 (1)) >>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>> edge_right: 1 strata with value/size (3 (1)) >>>> edge_left: 1 strata with value/size (2 (1)) >>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>> P1: 1 strata with value/size (4 (1)) >>>> P2: 1 strata with value/size (5 (1)) >>>> P3: 1 strata with value/size (6 (1)) >>>> P4: 1 strata with value/size (7 (1)) >>>> Field u: >>>> adjacency FEM >>>> /// With the second field, the two lines below are added >>>> Field p: >>>> adjacency FEM >>>> --- >>>> >>>> DM set up >>>> >>>> DM :: dm_mesh >>>> PetscFE :: u_FE, p_FE >>>> PetscInt :: dim, dim_u_FE, tdim >>>> PetscDS :: dm_ds >>>> >>>> >>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>> DMSetType(dm_mesh, DMPLEX) >>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>>> removed; no changes that I can see >>>> >>>> -- using flags >>>> >>>> -dm_plex_filename QUAD1.msh >>>> -dm_plex_interpolate 1 >>>> -dm_plex_gmsh_use_generic >>>> -dm_plex_gmsh_use_regions >>>> -dm_plex_gmsh_multiple_tags >>>> -dm_plex_gmsh_mark_vertices >>>> >>>> -- some operations with labels >>>> >>>> // u field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >>>> PETSC_DETERMINE, u_FE) >>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>> >>>> // p field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>>> PETSC_DETERMINE, p_FE) >>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>> >>>> DMCreateDS(dm_mesh) >>>> DMGetDS(dm_mesh, dm_DS) >>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>> >>>> with flags >>>> >>>> -disp_petscdualspace_lagrange_node_type equispaced >>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>> >>>> >>>> I believe these are all the DM related calls. >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>>> knepley at gmail.com> wrote: >>>> >>>> On Wed, May 6, 2026 at 6:56?AM Noam T. >>>> wrote: >>>> >>>>> Hello, >>>>> >>>>> That is wrong. Are you sure about 22? >>>>> >>>>> >>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>> >>>>> Here's the output of PetscDSView: >>>>> >>>>> Discrete System with 2 fields >>>>> cell total dim 11 total comp 5 >>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: u (mech_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 2 components >>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 2 components, size 8 >>>>> Sum space of 2 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 4 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 2 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Dual space with 2 components, size 8 >>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q1 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 4 >>>>> Continuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> >>>> >>>> 1. Why does pressure have 3 components in 2D? >>>> >>>>> PetscFE Object: p (pres_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 3 components >>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 3 components, size 3 >>>>> Sum space of 3 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 1 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 1 >>>>> Polynomial space of degree 0 >>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>> type: sum >>>>> Dual space with 3 components, size 3 >>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q0 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 1 >>>>> Discontinuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Weak Form System with 2 fields >>>>> >>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>>> setting the FE object name to "p". >>>>> >>>>> The entry "cell total dim 10" agrees with the output of >>>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>> >>>>> However, the closure of a Vec is still 22. >>>>> >>>> >>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>> this exact element. >>>> >>>> 3. Please send me that code that sets up your DM. It sounds like >>>> somehow you have a copy of your fields. >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>>> knepley at gmail.com> wrote: >>>>> >>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>>> petsc-users at mcs.anl.gov> wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> I am trying to work with a "mixed" FE discretization, where besides >>>>>> the usual displacements DoF in nodes, there is an additional field (e.g. >>>>>> pressure) that is also part of the system. This additional field has a >>>>>> certain number of additional dof : p0, p1, p2... >>>>>> >>>>>> Looking at example 77 ( >>>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6Dcswltmb_$ >>>>>> ) >>>>>> this seems to be handled with an additional field, added to the DM. I've >>>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>>> not what I expected. >>>>>> >>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 >>>>>> Gauss rule for quadrature), with just one field, a call to >>>>>> DMPlexGetVecClosure() gives me an array with 8 entries (say, the >>>>>> coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>> >>>>>> Then add the new field: >>>>>> >>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>>> value of nc here */ >>>>>> DMAddField(dm, ..., p_FE) >>>>>> >>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + >>>>>> 3). This results in a closure of size 22. >>>>>> >>>>> >>>>> That is wrong. Are you sure about 22? >>>>> >>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>>> >>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>> >>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>>>>> combinations of dim / nc for the new PetscFE, but when creating the DM >>>>>> section I get errors e.g. >>>>>> >>>>> >>>>> This is what you should get. I definitely have examples that do this. >>>>> For example, here is Q1-P0 (I think that is what you are suggesting) for >>>>> incompressible Stokes >>>>> >>>>> >>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcoVy_yQo$ >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>> >>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not >>>>>> deal with entries that I don't need? Or I am not setting up the section >>>>>> properly (works with just one field)? >>>>>> >>>>>> Thank you, >>>>>> Noam. >>>>>> >>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ >>>>> >>>>> >>>>> >>>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!edUnVT0riBfGlM-PBLoL5Upf_LZpAgjIEYIWs6z6IsKOoCkXDpg8MP4NGMnSpotKjG-0ROFHOp6DcnKlheDW$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Fri May 8 13:54:38 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Fri, 08 May 2026 18:54:38 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: Code attached. Noticed from PetscSectionView: PetscSectionSym Object: 1 MPI process type: label Label 'depth' Symmetry for stratum value 0 (0 dofs per point): no symmetries Symmetry for stratum value 1 (0 dofs per point): no symmetries Symmetry for stratum value 2 (12 dofs per point): <---------------------- 12 DoF ? Orientation range: [-4, 4) Symmetry for stratum value -1 (0 dofs per point): no symmetries Thanks, Noam On Friday, May 8th, 2026 at 3:58 PM, Noam T. wrote: >> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? > > If I use the exact same arrays/values for constructing the section, I get the same closure arrangement in the code you provided. Not surprising I guess? A seemingly random number of coordinates / zeroes / more coordinates. > > I checked example 14 (https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-Ryuk3MR$ ) for constructing the section. These are the values I used: > > - n_fields = 2 > > - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] > > The u field is defined in the nodes, with 2 components (u, v), hence the first "2". Then no components for edges/faces. > For the p field, what I am trying to simulate is having nc (independent) DoF, sort of like having nc scalar fields, if that makes sense? Hence using: > > - N = nc > - Also using the flag "-pres_petscspace_degree 0" > > But I'm not sure about those values. > > Then for simplicity numBC = 0 and all other arguments are NULL (will deal with boundary conditions later). > > With these arguments, I get the same as before e.g. > > -- nc = 3 (total dimension = 11) > closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 > > Thanks, > Noam > > On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley wrote: > >> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >> >>> Moving on to the values of the closure. >>> >>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). >>> >>> I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: >>> >>> -- nc = 1 >>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>> >>> -- nc = 3 >>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>> >>> -- nc = 7 >>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>> >>> Looking at that output: >>> - The first value is always a y coordinate (second component of u field). >>> - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). >>> >>> Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-e8bSoMv$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. >> >> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >> >> Thanks, >> >> Matt >> >>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. >>> >>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. >>> >>> Thanks, >>> Noam >>> >>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: >>> >>>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>>> >>>>> On the plus side, using the flags you provided in the previous email >>>>> >>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>> >>>>> the output of -ds_view is identical to yours, so setting up the fields should be correct. >>>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >>>>> >>>>> However, the closure size was still wrong. >>>>> >>>>> But, I figured out the reason: the manual set up of the section. >>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >>>>> So as you previously suggested >>>>> >>>>>> [...] It sounds like somehow you have a copy of your fields. >>>>> >>>>> the number of DoF per field were indeed "doubled" with the sum of both fields. >>>> >>>> Excellent. Let me know if you have any more issues. >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >>>>> >>>>>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>>>>> >>>>>> Here is what I get >>>>>> >>>>>> Discrete System with 2 fields >>>>>> cell total dim 11 total comp 3 >>>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>>> type: basic >>>>>> Basic Finite Element in 2 dimensions with 1 components >>>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>>> type: poly >>>>>> Space in 2 variables with 1 components, size 3 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 3 >>>>>> Discontinuous Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 2 fields >>>>>> >>>>>> I have attached the code I used. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>>>>> >>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> >>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>> >>>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>>>>> >>>>>>> With nc = 1 the closure size is 18 instead. >>>>>>> >>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>> >>>>>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>>>>> >>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>> >>>>>>>> Thanks, >>>>>>> >>>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>>> >>>>>>> --- >>>>>>> Discrete System with 1 fields >>>>>>> cell total dim 8 total comp 2 >>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>>> type: vector >>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>>> type: sum >>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>>> type: tensor >>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>>> type: poly >>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>> Polynomial space of degree 1 >>>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>>> type: sum >>>>>>> Dual space with 2 components, size 8 >>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>> type: lagrange >>>>>>> Dual space with 1 components, size 4 >>>>>>> Continuous tensor Lagrange dual space >>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>> Weak Form System with 1 fields--- >>>>>>> >>>>>>> and -dm_view >>>>>>> >>>>>>> --- >>>>>>> DM Object: 1 MPI process >>>>>>> type: plex >>>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>>> Number of 0-cells per rank: 4 >>>>>>> Number of 1-cells per rank: 4 >>>>>>> Number of 2-cells per rank: 1 >>>>>>> Labels: >>>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>>> surf: 1 strata with value/size (1 (1)) >>>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>>> P1: 1 strata with value/size (4 (1)) >>>>>>> P2: 1 strata with value/size (5 (1)) >>>>>>> P3: 1 strata with value/size (6 (1)) >>>>>>> P4: 1 strata with value/size (7 (1)) >>>>>>> Field u: >>>>>>> adjacency FEM >>>>>>> /// With the second field, the two lines below are added >>>>>>> Field p: >>>>>>> adjacency FEM >>>>>>> --- >>>>>>> >>>>>>> DM set up >>>>>>> >>>>>>> DM :: dm_mesh >>>>>>> PetscFE :: u_FE, p_FE >>>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>>> PetscDS :: dm_ds >>>>>>> >>>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>>>>> >>>>>>> -- using flags >>>>>>> >>>>>>> -dm_plex_filename QUAD1.msh >>>>>>> -dm_plex_interpolate 1 >>>>>>> -dm_plex_gmsh_use_generic >>>>>>> -dm_plex_gmsh_use_regions >>>>>>> -dm_plex_gmsh_multiple_tags >>>>>>> -dm_plex_gmsh_mark_vertices >>>>>>> >>>>>>> -- some operations with labels >>>>>>> >>>>>>> // u field >>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>>> >>>>>>> // p field >>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>>> >>>>>>> DMCreateDS(dm_mesh) >>>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>>> >>>>>>> with flags >>>>>>> >>>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>>> >>>>>>> I believe these are all the DM related calls. >>>>>>> >>>>>>> Thanks, >>>>>>> Noam >>>>>>> >>>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>>>>> >>>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>>>>> >>>>>>>>> Hello, >>>>>>>>> >>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>> >>>>>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>>>>> >>>>>>>>> Here's the output of PetscDSView: >>>>>>>>> >>>>>>>>> Discrete System with 2 fields >>>>>>>>> cell total dim 11 total comp 5 >>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>>> type: vector >>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>> type: tensor >>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>> type: poly >>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>> Polynomial space of degree 1 >>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>> type: lagrange >>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> >>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>> >>>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>>> type: vector >>>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>>> type: tensor >>>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>> type: poly >>>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>>> Polynomial space of degree 0 >>>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Dual space with 3 components, size 3 >>>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>>> type: lagrange >>>>>>>>> Dual space with 1 components, size 1 >>>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>> Weak Form System with 2 fields >>>>>>>>> >>>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>>>>> >>>>>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>>> >>>>>>>>> However, the closure of a Vec is still 22. >>>>>>>> >>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>> >>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Matt >>>>>>>> >>>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>>>>> >>>>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>>>>> >>>>>>>>>>> Hello, >>>>>>>>>>> >>>>>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>>>>> >>>>>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-ZskdyIY$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>>>>> >>>>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>>>> >>>>>>>>>>> Then add the new field: >>>>>>>>>>> >>>>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>>>> >>>>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>>>>> >>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>> >>>>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>>>> >>>>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>>>> >>>>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>>>>> >>>>>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>>>>> >>>>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-SATvQri$ >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> Matt >>>>>>>>>> >>>>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>>>> >>>>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>>>>> >>>>>>>>>>> Thank you, >>>>>>>>>>> Noam. >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>> -- Norbert Wiener >>>>>>>>>> >>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-X_2BGka$ >>>>>>>> >>>>>>>> -- >>>>>>>> >>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>> -- Norbert Wiener >>>>>>>> >>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-X_2BGka$ >>>>>> >>>>>> -- >>>>>> >>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-X_2BGka$ >>>> >>>> -- >>>> >>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>> -- Norbert Wiener >>>> >>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-X_2BGka$ >> >> -- >> >> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >> -- Norbert Wiener >> >> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!dTW1geu9Hl8C02vJ60f8bAt7xMKE7PAyr-XtejSI5cwo5ksbHXjzI1_4KHUSIp6nJumkE6Z3myEbTEi6f6qo-N5z-X_2BGka$ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_u_p.c Type: text/x-csrc Size: 3631 bytes Desc: not available URL: From knepley at gmail.com Fri May 8 14:12:55 2026 From: knepley at gmail.com (Matthew Knepley) Date: Fri, 8 May 2026 15:12:55 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: > Code attached. > I think you misunderstand the definition of the element. I do not think you want 3 components for your pressure. You want 1 component. It is a scalar variable. In my original example, I had a single component. Components create tensor spaces. If you are using discontinuous P1, then it has 3 unknowns, which is what I think you are trying to specify. You should change the space you are using if you want to change the number of variables. Does that clear it up? Thanks, Matt > Noticed from PetscSectionView: > > PetscSectionSym Object: 1 MPI process > type: label > Label 'depth' > Symmetry for stratum value 0 (0 dofs per point): no symmetries > Symmetry for stratum value 1 (0 dofs per point): no symmetries > Symmetry for stratum value 2 (12 dofs per point): > <---------------------- 12 DoF ? > Orientation range: [-4, 4) > Symmetry for stratum value -1 (0 dofs per point): no symmetries > > Thanks, > Noam > > On Friday, May 8th, 2026 at 3:58 PM, Noam T. > wrote: > > This is likely to be a Section construction problem again. The Section > fields are separated by DMPlexVecGetClosure(), sp you must not have defined > the fields in the Section. If you put these calls into the code that I sent > you, what do you get? > > > If I use the exact same arrays/values for constructing the section, I get > the same closure arrangement in the code you provided. Not surprising I > guess? A seemingly random number of coordinates / zeroes / more coordinates. > > I checked example 14 ( > https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85WxiwA5OT$ ) for > constructing the section. These are the values I used: > > - n_fields = 2 > > - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] > > The u field is defined in the nodes, with 2 components (u, v), hence the > first "2". Then no components for edges/faces. > For the p field, what I am trying to simulate is having nc (independent) > DoF, sort of like having nc scalar fields, if that makes sense? Hence using: > > - N = nc > - Also using the flag "-pres_petscspace_degree 0" > > But I'm not sure about those values. > > Then for simplicity numBC = 0 and all other arguments are NULL (will deal > with boundary conditions later). > > With these arguments, I get the same as before e.g. > > -- nc = 3 (total dimension = 11) > closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 > > Thanks, > Noam > > > On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley > wrote: > > On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: > >> Moving on to the values of the closure. >> >> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, >> which is used for e.g. the solution. Following the example before, it will >> have size 8 (coordinates) + nc (for the p field). >> >> I am getting a seemingly random order when I test with different values >> of nc. Say, I initialize the vector (VecSetValues) with the coordinates >> x_i, y_i . The rest nc components are set to zero. The closure returns: >> >> -- nc = 1 >> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >> >> -- nc = 3 >> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >> >> -- nc = 7 >> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >> >> Looking at that output: >> - The first value is always a y coordinate (second component of u field). >> - The position of the nc = 0 components change (starting with nc = 8, all >> zero values come first, followed by the coordinates). >> >> Looking again at ex77.c ( >> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W1bcMCjb$ ), it says the >> closure stacks up the fields, which aligns with the output above (all u >> values, then all p values), but which is the starting point seems arbitrary. >> > > This is likely to be a Section construction problem again. The Section > fields are separated by DMPlexVecGetClosure(), sp you must not have defined > the fields in the Section. If you put these calls into the code that I sent > you, what do you get? > > Thanks, > > Matt > >> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not >> be correct to start with. >> >> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, >> ...) so that I only get the u field DoF. But I will need to deal with the p >> field values as well at some point. >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley >> wrote: >> >> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >> >>> On the plus side, using the flags you provided in the previous email >>> >>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 >>> -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>> >>> the output of -ds_view is identical to yours, so setting up the fields >>> should be correct. >>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity >>> 0" so as to have a discontinuous field. >>> >>> However, the closure size was still wrong. >>> >>> But, I figured out the reason: the manual set up of the section. >>> For the argument "numDof" in DMPlexCreateSection(), I was computing the >>> number of DoF with PetscSectionGetDof() (which was fine until now, since >>> there was a single field), instead of PetscSectionGetFieldDof(). >>> So as you previously suggested >>> >>> [...] It sounds like somehow you have a copy of your fields. >>> >>> >>> the number of DoF per field were indeed "doubled" with the sum of both >>> fields. >>> >> >> Excellent. Let me know if you have any more issues. >> >> Thanks, >> >> Matt >> >>> Thanks, >>> Noam >>> >>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >>> knepley at gmail.com> wrote: >>> >>> Okay, this is a problem with specifying the space I believe. You want a >>> discontinuous space for pressure. >>> >>> Here is what I get >>> >>> Discrete System with 2 fields >>> cell total dim 11 total comp 3 >>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (mech_) 1 MPI process >>> type: vector >>> Vector Finite Element in 2 dimensions with 2 components >>> PetscSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Space in 2 variables with 2 components, size 8 >>> Sum space of 2 concatenated subspaces (all identical) >>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>> type: tensor >>> Space in 2 variables with 1 components, size 4 >>> Tensor space of 2 subspaces (all identical) >>> PetscSpace Object: sum component tensor component >>> (mech_sumcomp_tensorcomp_) 1 MPI process >>> type: poly >>> Space in 1 variables with 1 components, size 2 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>> type: sum >>> Dual space with 2 components, size 8 >>> Sum dual space of 2 concatenated subspaces (all identical) >>> PetscDualSpace Object: Q1 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 4 >>> Continuous tensor Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>> PetscFE Object: Q1 (pres_) 1 MPI process >>> type: basic >>> Basic Finite Element in 2 dimensions with 1 components >>> PetscSpace Object: Q1 (pres_) 1 MPI process >>> type: poly >>> Space in 2 variables with 1 components, size 3 >>> Polynomial space of degree 1 >>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>> type: lagrange >>> Dual space with 1 components, size 3 >>> Discontinuous Lagrange dual space >>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>> Weak Form System with 2 fields >>> >>> I have attached the code I used. >>> >>> Thanks, >>> >>> Matt >>> >>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>> >>>> >>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> >>>> >>>> 1. Why does pressure have 3 components in 2D? >>>> >>>> >>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>>> field. Confusion between wanting 3 addditional DoF and components. >>>> >>>> With nc = 1 the closure size is 18 instead. >>>> >>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>> this exact element. >>>> >>>> >>>> I changed some of my code following the example and got rid of some >>>> errors. But I'll have a more thorough look again. >>>> >>>> 3. Please send me that code that sets up your DM. It sounds like >>>> somehow you have a copy of your fields. >>>> >>>> Thanks, >>>> >>>> >>>> For reference, -ds_view with only one (displacements) fields shows: >>>> >>>> --- >>>> Discrete System with 1 fields >>>> cell total dim 8 total comp 2 >>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: u (disp_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component >>>> (disp_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 1 fields >>>> --- >>>> >>>> and -dm_view >>>> >>>> --- >>>> DM Object: 1 MPI process >>>> type: plex >>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>> Number of 0-cells per rank: 4 >>>> Number of 1-cells per rank: 4 >>>> Number of 2-cells per rank: 1 >>>> Labels: >>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>> Cell Sets: 1 strata with value/size (1 (1)) >>>> surf: 1 strata with value/size (1 (1)) >>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>> edge_right: 1 strata with value/size (3 (1)) >>>> edge_left: 1 strata with value/size (2 (1)) >>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>> P1: 1 strata with value/size (4 (1)) >>>> P2: 1 strata with value/size (5 (1)) >>>> P3: 1 strata with value/size (6 (1)) >>>> P4: 1 strata with value/size (7 (1)) >>>> Field u: >>>> adjacency FEM >>>> /// With the second field, the two lines below are added >>>> Field p: >>>> adjacency FEM >>>> --- >>>> >>>> DM set up >>>> >>>> DM :: dm_mesh >>>> PetscFE :: u_FE, p_FE >>>> PetscInt :: dim, dim_u_FE, tdim >>>> PetscDS :: dm_ds >>>> >>>> >>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>> DMSetType(dm_mesh, DMPLEX) >>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>>> removed; no changes that I can see >>>> >>>> -- using flags >>>> >>>> -dm_plex_filename QUAD1.msh >>>> -dm_plex_interpolate 1 >>>> -dm_plex_gmsh_use_generic >>>> -dm_plex_gmsh_use_regions >>>> -dm_plex_gmsh_multiple_tags >>>> -dm_plex_gmsh_mark_vertices >>>> >>>> -- some operations with labels >>>> >>>> // u field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >>>> PETSC_DETERMINE, u_FE) >>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>> >>>> // p field >>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>>> PETSC_DETERMINE, p_FE) >>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>> >>>> DMCreateDS(dm_mesh) >>>> DMGetDS(dm_mesh, dm_DS) >>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>> >>>> with flags >>>> >>>> -disp_petscdualspace_lagrange_node_type equispaced >>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>> >>>> >>>> I believe these are all the DM related calls. >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>>> knepley at gmail.com> wrote: >>>> >>>> On Wed, May 6, 2026 at 6:56?AM Noam T. >>>> wrote: >>>> >>>>> Hello, >>>>> >>>>> That is wrong. Are you sure about 22? >>>>> >>>>> >>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>> >>>>> Here's the output of PetscDSView: >>>>> >>>>> Discrete System with 2 fields >>>>> cell total dim 11 total comp 5 >>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: u (mech_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 2 components >>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 2 components, size 8 >>>>> Sum space of 2 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 4 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 2 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Dual space with 2 components, size 8 >>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q1 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 4 >>>>> Continuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> >>>> >>>> 1. Why does pressure have 3 components in 2D? >>>> >>>>> PetscFE Object: p (pres_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 3 components >>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 3 components, size 3 >>>>> Sum space of 3 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 1 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 1 >>>>> Polynomial space of degree 0 >>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>> type: sum >>>>> Dual space with 3 components, size 3 >>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q0 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 1 >>>>> Discontinuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Weak Form System with 2 fields >>>>> >>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>>> setting the FE object name to "p". >>>>> >>>>> The entry "cell total dim 10" agrees with the output of >>>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>> >>>>> However, the closure of a Vec is still 22. >>>>> >>>> >>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>> this exact element. >>>> >>>> 3. Please send me that code that sets up your DM. It sounds like >>>> somehow you have a copy of your fields. >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>>> knepley at gmail.com> wrote: >>>>> >>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>>> petsc-users at mcs.anl.gov> wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> I am trying to work with a "mixed" FE discretization, where besides >>>>>> the usual displacements DoF in nodes, there is an additional field (e.g. >>>>>> pressure) that is also part of the system. This additional field has a >>>>>> certain number of additional dof : p0, p1, p2... >>>>>> >>>>>> Looking at example 77 ( >>>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W1bcMCjb$ >>>>>> ) >>>>>> this seems to be handled with an additional field, added to the DM. I've >>>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>>> not what I expected. >>>>>> >>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 >>>>>> Gauss rule for quadrature), with just one field, a call to >>>>>> DMPlexGetVecClosure() gives me an array with 8 entries (say, the >>>>>> coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>> >>>>>> Then add the new field: >>>>>> >>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>>> value of nc here */ >>>>>> DMAddField(dm, ..., p_FE) >>>>>> >>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + >>>>>> 3). This results in a closure of size 22. >>>>>> >>>>> >>>>> That is wrong. Are you sure about 22? >>>>> >>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>>> >>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>> >>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>>>>> combinations of dim / nc for the new PetscFE, but when creating the DM >>>>>> section I get errors e.g. >>>>>> >>>>> >>>>> This is what you should get. I definitely have examples that do this. >>>>> For example, here is Q1-P0 (I think that is what you are suggesting) for >>>>> incompressible Stokes >>>>> >>>>> >>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85Wx2HPV3Z$ >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>> >>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not >>>>>> deal with entries that I don't need? Or I am not setting up the section >>>>>> properly (works with just one field)? >>>>>> >>>>>> Thank you, >>>>>> Noam. >>>>>> >>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ >>>>> >>>>> >>>>> >>>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ > > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dBe0zmoP1EXuDC3Da6esPOb65iny79VkOAgA01sP84NE6TyW10KDbA-RSHT2uMS6hvXHo--Yav85W67yMHOl$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Fri May 8 14:34:03 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Fri, 08 May 2026 19:34:03 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: I was indeed confused before regarding how the element ended up with 3 unknowns. So for a P1, having three unknowns, means the field is interpolated as p = po + p1*x + p2*y? Then P2 has 6 components (total dim = 14), which agrees with a complete 2nd order polynomial. Then my question is, how can I have any other number of components? In particular, some of the implementations I am looking at use 4 and 7 additional DoF. Will this require a new field per DoF? Thanks, Noam On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley wrote: > On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: > >> Code attached. > > I think you misunderstand the definition of the element. I do not think you want 3 components for your pressure. You want 1 component. It is a scalar variable. In my original example, I had a single component. Components create tensor spaces. > > If you are using discontinuous P1, then it has 3 unknowns, which is what I think you are trying to specify. You should change the space you are using if you want to change the number of variables. > > Does that clear it up? > > Thanks, > > Matt > >> Noticed from PetscSectionView: >> >> PetscSectionSym Object: 1 MPI process >> type: label >> Label 'depth' >> Symmetry for stratum value 0 (0 dofs per point): no symmetries >> Symmetry for stratum value 1 (0 dofs per point): no symmetries >> Symmetry for stratum value 2 (12 dofs per point): <---------------------- 12 DoF ? >> Orientation range: [-4, 4) Symmetry for stratum value -1 (0 dofs per point): no symmetries >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 3:58 PM, Noam T. wrote: >> >>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>> >>> If I use the exact same arrays/values for constructing the section, I get the same closure arrangement in the code you provided. Not surprising I guess? A seemingly random number of coordinates / zeroes / more coordinates. >>> >>> I checked example 14 (https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2WmI-lhp$ ) for constructing the section. These are the values I used: >>> >>> - n_fields = 2 >>> >>> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >>> >>> The u field is defined in the nodes, with 2 components (u, v), hence the first "2". Then no components for edges/faces. >>> For the p field, what I am trying to simulate is having nc (independent) DoF, sort of like having nc scalar fields, if that makes sense? Hence using: >>> >>> - N = nc >>> - Also using the flag "-pres_petscspace_degree 0" >>> >>> But I'm not sure about those values. >>> >>> Then for simplicity numBC = 0 and all other arguments are NULL (will deal with boundary conditions later). >>> >>> With these arguments, I get the same as before e.g. >>> >>> -- nc = 3 (total dimension = 11) >>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>> >>> Thanks, >>> Noam >>> >>> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley wrote: >>> >>>> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >>>> >>>>> Moving on to the values of the closure. >>>>> >>>>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). >>>>> >>>>> I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: >>>>> >>>>> -- nc = 1 >>>>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>>>> >>>>> -- nc = 3 >>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>> >>>>> -- nc = 7 >>>>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>>>> >>>>> Looking at that output: >>>>> - The first value is always a y coordinate (second component of u field). >>>>> - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). >>>>> >>>>> Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2SV3HT11$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. >>>> >>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. >>>>> >>>>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. >>>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: >>>>> >>>>>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>>>>> >>>>>>> On the plus side, using the flags you provided in the previous email >>>>>>> >>>>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>>>> >>>>>>> the output of -ds_view is identical to yours, so setting up the fields should be correct. >>>>>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >>>>>>> >>>>>>> However, the closure size was still wrong. >>>>>>> >>>>>>> But, I figured out the reason: the manual set up of the section. >>>>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >>>>>>> So as you previously suggested >>>>>>> >>>>>>>> [...] It sounds like somehow you have a copy of your fields. >>>>>>> >>>>>>> the number of DoF per field were indeed "doubled" with the sum of both fields. >>>>>> >>>>>> Excellent. Let me know if you have any more issues. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>>> Thanks, >>>>>>> Noam >>>>>>> >>>>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >>>>>>> >>>>>>>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>>>>>>> >>>>>>>> Here is what I get >>>>>>>> >>>>>>>> Discrete System with 2 fields >>>>>>>> cell total dim 11 total comp 3 >>>>>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>>>>> type: vector >>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>> type: tensor >>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>> Polynomial space of degree 1 >>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Dual space with 2 components, size 8 >>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 4 >>>>>>>> Continuous tensor Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>>>>> type: basic >>>>>>>> Basic Finite Element in 2 dimensions with 1 components >>>>>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 2 variables with 1 components, size 3 >>>>>>>> Polynomial space of degree 1 >>>>>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 3 >>>>>>>> Discontinuous Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Weak Form System with 2 fields >>>>>>>> >>>>>>>> I have attached the code I used. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Matt >>>>>>>> >>>>>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>>>>>>> >>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>> >>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>> >>>>>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>>>>>>> >>>>>>>>> With nc = 1 the closure size is 18 instead. >>>>>>>>> >>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>> >>>>>>>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>>>>>>> >>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>> >>>>>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>>>>> >>>>>>>>> --- >>>>>>>>> Discrete System with 1 fields >>>>>>>>> cell total dim 8 total comp 2 >>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>>>>> type: vector >>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>>>>> type: tensor >>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>> type: poly >>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>> Polynomial space of degree 1 >>>>>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>> type: sum >>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>> type: lagrange >>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>> Weak Form System with 1 fields--- >>>>>>>>> >>>>>>>>> and -dm_view >>>>>>>>> >>>>>>>>> --- >>>>>>>>> DM Object: 1 MPI process >>>>>>>>> type: plex >>>>>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>>>>> Number of 0-cells per rank: 4 >>>>>>>>> Number of 1-cells per rank: 4 >>>>>>>>> Number of 2-cells per rank: 1 >>>>>>>>> Labels: >>>>>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>>>>> surf: 1 strata with value/size (1 (1)) >>>>>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>>>>> P1: 1 strata with value/size (4 (1)) >>>>>>>>> P2: 1 strata with value/size (5 (1)) >>>>>>>>> P3: 1 strata with value/size (6 (1)) >>>>>>>>> P4: 1 strata with value/size (7 (1)) >>>>>>>>> Field u: >>>>>>>>> adjacency FEM >>>>>>>>> /// With the second field, the two lines below are added >>>>>>>>> Field p: >>>>>>>>> adjacency FEM >>>>>>>>> --- >>>>>>>>> >>>>>>>>> DM set up >>>>>>>>> >>>>>>>>> DM :: dm_mesh >>>>>>>>> PetscFE :: u_FE, p_FE >>>>>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>>>>> PetscDS :: dm_ds >>>>>>>>> >>>>>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>>>>>>> >>>>>>>>> -- using flags >>>>>>>>> >>>>>>>>> -dm_plex_filename QUAD1.msh >>>>>>>>> -dm_plex_interpolate 1 >>>>>>>>> -dm_plex_gmsh_use_generic >>>>>>>>> -dm_plex_gmsh_use_regions >>>>>>>>> -dm_plex_gmsh_multiple_tags >>>>>>>>> -dm_plex_gmsh_mark_vertices >>>>>>>>> >>>>>>>>> -- some operations with labels >>>>>>>>> >>>>>>>>> // u field >>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>>>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>>>>> >>>>>>>>> // p field >>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>>>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>>>>> >>>>>>>>> DMCreateDS(dm_mesh) >>>>>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>>>>> >>>>>>>>> with flags >>>>>>>>> >>>>>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>>>>> >>>>>>>>> I believe these are all the DM related calls. >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Noam >>>>>>>>> >>>>>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>>>>>>> >>>>>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>>>>>>> >>>>>>>>>>> Hello, >>>>>>>>>>> >>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>> >>>>>>>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>>>>>>> >>>>>>>>>>> Here's the output of PetscDSView: >>>>>>>>>>> >>>>>>>>>>> Discrete System with 2 fields >>>>>>>>>>> cell total dim 11 total comp 5 >>>>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>>>>> type: vector >>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>>>> type: tensor >>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>> type: poly >>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>> type: lagrange >>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>> >>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>>> >>>>>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>>>>> type: vector >>>>>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>>>>> type: tensor >>>>>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>> type: poly >>>>>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>>>>> Polynomial space of degree 0 >>>>>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Dual space with 3 components, size 3 >>>>>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>>>>> type: lagrange >>>>>>>>>>> Dual space with 1 components, size 1 >>>>>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>> Weak Form System with 2 fields >>>>>>>>>>> >>>>>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>>>>>>> >>>>>>>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>>>>> >>>>>>>>>>> However, the closure of a Vec is still 22. >>>>>>>>>> >>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>>> >>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> Matt >>>>>>>>>> >>>>>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>>>>>>> >>>>>>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Hello, >>>>>>>>>>>>> >>>>>>>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>>>>>>> >>>>>>>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2UyvJen8$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>>>>>>> >>>>>>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>>>>>> >>>>>>>>>>>>> Then add the new field: >>>>>>>>>>>>> >>>>>>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>>>>>> >>>>>>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>>>>>>> >>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>>> >>>>>>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>>>>>> >>>>>>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>>>>>> >>>>>>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>>>>>>> >>>>>>>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>>>>>>> >>>>>>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2cwxv_v8$ >>>>>>>>>>>> >>>>>>>>>>>> Thanks, >>>>>>>>>>>> >>>>>>>>>>>> Matt >>>>>>>>>>>> >>>>>>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>>>>>> >>>>>>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>>>>>>> >>>>>>>>>>>>> Thank you, >>>>>>>>>>>>> Noam. >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> >>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>> >>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>> -- Norbert Wiener >>>>>>>>>> >>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ >>>>>>>> >>>>>>>> -- >>>>>>>> >>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>> -- Norbert Wiener >>>>>>>> >>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ >>>>>> >>>>>> -- >>>>>> >>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ >>>> >>>> -- >>>> >>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>> -- Norbert Wiener >>>> >>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!aFjajGFLkDiyYC1UgjN8b9QCym74RzcADVVBaCHOtEnbFz0QyrOJWDGfPaj-vfN47fuweu5C_zilFW5N6FsfqFdv2Q8o7bg-$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Fri May 8 15:28:58 2026 From: knepley at gmail.com (Matthew Knepley) Date: Fri, 8 May 2026 16:28:58 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Fri, May 8, 2026 at 3:34?PM Noam T. wrote: > I was indeed confused before regarding how the element ended up with 3 > unknowns. > > So for a P1, having three unknowns, means the field is interpolated as p = > po + p1*x + p2*y? > Then P2 has 6 components (total dim = 14), which agrees with a complete > 2nd order polynomial. > > Then my question is, how can I have any other number of components? In > particular, some of the implementations I am looking at use 4 and 7 > additional DoF. Will this require a new field per DoF? > No, you start with how these fields are supposed to behave. If you say I have a field that gives me five constant values in every cell Then you have a P0 field with five components, which will add 5 dofs to the DS. If instead you say I have a field that gives two values linearly interpolated over each cell Then you have a P1 field with two components, which will add 6 dofs (with triangles) to the DS. Thanks, Matt > Thanks, > Noam > On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley > wrote: > > On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: > >> Code attached. >> > > I think you misunderstand the definition of the element. I do not think > you want 3 components for your pressure. You want 1 component. It is a > scalar variable. In my original example, I had a single component. > Components create tensor spaces. > > If you are using discontinuous P1, then it has 3 unknowns, which is what I > think you are trying to specify. You should change the space you are using > if you want to change the number of variables. > > Does that clear it up? > > Thanks, > > Matt > >> Noticed from PetscSectionView: >> >> PetscSectionSym Object: 1 MPI process >> type: label >> Label 'depth' >> Symmetry for stratum value 0 (0 dofs per point): no symmetries >> Symmetry for stratum value 1 (0 dofs per point): no symmetries >> Symmetry for stratum value 2 (12 dofs per point): <---------------------- >> 12 DoF ? >> Orientation range: [-4, 4) >> Symmetry for stratum value -1 (0 dofs per point): no symmetries >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 3:58 PM, Noam T. >> wrote: >> >> This is likely to be a Section construction problem again. The Section >> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >> the fields in the Section. If you put these calls into the code that I sent >> you, what do you get? >> >> >> If I use the exact same arrays/values for constructing the section, I get >> the same closure arrangement in the code you provided. Not surprising I >> guess? A seemingly random number of coordinates / zeroes / more coordinates. >> >> I checked example 14 ( >> https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMnouheZB$ ) for >> constructing the section. These are the values I used: >> >> - n_fields = 2 >> >> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >> >> The u field is defined in the nodes, with 2 components (u, v), hence the >> first "2". Then no components for edges/faces. >> For the p field, what I am trying to simulate is having nc (independent) >> DoF, sort of like having nc scalar fields, if that makes sense? Hence using: >> >> - N = nc >> - Also using the flag "-pres_petscspace_degree 0" >> >> But I'm not sure about those values. >> >> Then for simplicity numBC = 0 and all other arguments are NULL (will deal >> with boundary conditions later). >> >> With these arguments, I get the same as before e.g. >> >> -- nc = 3 (total dimension = 11) >> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >> >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley >> wrote: >> >> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >> >>> Moving on to the values of the closure. >>> >>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, >>> which is used for e.g. the solution. Following the example before, it will >>> have size 8 (coordinates) + nc (for the p field). >>> >>> I am getting a seemingly random order when I test with different values >>> of nc. Say, I initialize the vector (VecSetValues) with the coordinates >>> x_i, y_i . The rest nc components are set to zero. The closure returns: >>> >>> -- nc = 1 >>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>> >>> -- nc = 3 >>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>> >>> -- nc = 7 >>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>> >>> Looking at that output: >>> - The first value is always a y coordinate (second component of u field). >>> - The position of the nc = 0 components change (starting with nc = 8, >>> all zero values come first, followed by the coordinates). >>> >>> Looking again at ex77.c ( >>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMov1NT81$ ), it says the >>> closure stacks up the fields, which aligns with the output above (all u >>> values, then all p values), but which is the starting point seems arbitrary. >>> >> >> This is likely to be a Section construction problem again. The Section >> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >> the fields in the Section. If you put these calls into the code that I sent >> you, what do you get? >> >> Thanks, >> >> Matt >> >>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not >>> be correct to start with. >>> >>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = >>> 0, ...) so that I only get the u field DoF. But I will need to deal with >>> the p field values as well at some point. >>> >>> Thanks, >>> Noam >>> >>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley >>> wrote: >>> >>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>> >>>> On the plus side, using the flags you provided in the previous email >>>> >>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 >>>> -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>> >>>> the output of -ds_view is identical to yours, so setting up the fields >>>> should be correct. >>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity >>>> 0" so as to have a discontinuous field. >>>> >>>> However, the closure size was still wrong. >>>> >>>> But, I figured out the reason: the manual set up of the section. >>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the >>>> number of DoF with PetscSectionGetDof() (which was fine until now, since >>>> there was a single field), instead of PetscSectionGetFieldDof(). >>>> So as you previously suggested >>>> >>>> [...] It sounds like somehow you have a copy of your fields. >>>> >>>> >>>> the number of DoF per field were indeed "doubled" with the sum of both >>>> fields. >>>> >>> >>> Excellent. Let me know if you have any more issues. >>> >>> Thanks, >>> >>> Matt >>> >>>> Thanks, >>>> Noam >>>> >>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >>>> knepley at gmail.com> wrote: >>>> >>>> Okay, this is a problem with specifying the space I believe. You want a >>>> discontinuous space for pressure. >>>> >>>> Here is what I get >>>> >>>> Discrete System with 2 fields >>>> cell total dim 11 total comp 3 >>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>> type: vector >>>> Vector Finite Element in 2 dimensions with 2 components >>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Space in 2 variables with 2 components, size 8 >>>> Sum space of 2 concatenated subspaces (all identical) >>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>> type: tensor >>>> Space in 2 variables with 1 components, size 4 >>>> Tensor space of 2 subspaces (all identical) >>>> PetscSpace Object: sum component tensor component >>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>> type: poly >>>> Space in 1 variables with 1 components, size 2 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>> type: sum >>>> Dual space with 2 components, size 8 >>>> Sum dual space of 2 concatenated subspaces (all identical) >>>> PetscDualSpace Object: Q1 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 4 >>>> Continuous tensor Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>> type: basic >>>> Basic Finite Element in 2 dimensions with 1 components >>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>> type: poly >>>> Space in 2 variables with 1 components, size 3 >>>> Polynomial space of degree 1 >>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>> type: lagrange >>>> Dual space with 1 components, size 3 >>>> Discontinuous Lagrange dual space >>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>> Weak Form System with 2 fields >>>> >>>> I have attached the code I used. >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>> On Wed, May 6, 2026 at 9:32?AM Noam T. >>>> wrote: >>>> >>>>> >>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> >>>>> >>>>> 1. Why does pressure have 3 components in 2D? >>>>> >>>>> >>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>>>> field. Confusion between wanting 3 addditional DoF and components. >>>>> >>>>> With nc = 1 the closure size is 18 instead. >>>>> >>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>> this exact element. >>>>> >>>>> >>>>> I changed some of my code following the example and got rid of some >>>>> errors. But I'll have a more thorough look again. >>>>> >>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>> somehow you have a copy of your fields. >>>>> >>>>> Thanks, >>>>> >>>>> >>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>> >>>>> --- >>>>> Discrete System with 1 fields >>>>> cell total dim 8 total comp 2 >>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: u (disp_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 2 components >>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 2 components, size 8 >>>>> Sum space of 2 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 4 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (disp_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 2 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>> type: sum >>>>> Dual space with 2 components, size 8 >>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q1 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 4 >>>>> Continuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Weak Form System with 1 fields >>>>> --- >>>>> >>>>> and -dm_view >>>>> >>>>> --- >>>>> DM Object: 1 MPI process >>>>> type: plex >>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>> Number of 0-cells per rank: 4 >>>>> Number of 1-cells per rank: 4 >>>>> Number of 2-cells per rank: 1 >>>>> Labels: >>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>> surf: 1 strata with value/size (1 (1)) >>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>> edge_right: 1 strata with value/size (3 (1)) >>>>> edge_left: 1 strata with value/size (2 (1)) >>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>> P1: 1 strata with value/size (4 (1)) >>>>> P2: 1 strata with value/size (5 (1)) >>>>> P3: 1 strata with value/size (6 (1)) >>>>> P4: 1 strata with value/size (7 (1)) >>>>> Field u: >>>>> adjacency FEM >>>>> /// With the second field, the two lines below are added >>>>> Field p: >>>>> adjacency FEM >>>>> --- >>>>> >>>>> DM set up >>>>> >>>>> DM :: dm_mesh >>>>> PetscFE :: u_FE, p_FE >>>>> PetscInt :: dim, dim_u_FE, tdim >>>>> PetscDS :: dm_ds >>>>> >>>>> >>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>> DMSetType(dm_mesh, DMPLEX) >>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>>>> removed; no changes that I can see >>>>> >>>>> -- using flags >>>>> >>>>> -dm_plex_filename QUAD1.msh >>>>> -dm_plex_interpolate 1 >>>>> -dm_plex_gmsh_use_generic >>>>> -dm_plex_gmsh_use_regions >>>>> -dm_plex_gmsh_multiple_tags >>>>> -dm_plex_gmsh_mark_vertices >>>>> >>>>> -- some operations with labels >>>>> >>>>> // u field >>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >>>>> PETSC_DETERMINE, u_FE) >>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>> >>>>> // p field >>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>>>> PETSC_DETERMINE, p_FE) >>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>> >>>>> DMCreateDS(dm_mesh) >>>>> DMGetDS(dm_mesh, dm_DS) >>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>> >>>>> with flags >>>>> >>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>> >>>>> >>>>> I believe these are all the DM related calls. >>>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>>>> knepley at gmail.com> wrote: >>>>> >>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. >>>>> wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> That is wrong. Are you sure about 22? >>>>>> >>>>>> >>>>>> That's what I get, from the argument "csize" in >>>>>> DMPlexGetVecClosure(). >>>>>> >>>>>> Here's the output of PetscDSView: >>>>>> >>>>>> Discrete System with 2 fields >>>>>> cell total dim 11 total comp 5 >>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component >>>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> >>>>> >>>>> 1. Why does pressure have 3 components in 2D? >>>>> >>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 3 components, size 3 >>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 1 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component >>>>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 1 >>>>>> Polynomial space of degree 0 >>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 3 components, size 3 >>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 1 >>>>>> Discontinuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 2 fields >>>>>> >>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>>>> setting the FE object name to "p". >>>>>> >>>>>> The entry "cell total dim 10" agrees with the output of >>>>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>> >>>>>> However, the closure of a Vec is still 22. >>>>>> >>>>> >>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>> this exact element. >>>>> >>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>> somehow you have a copy of your fields. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>>>> knepley at gmail.com> wrote: >>>>>> >>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>>>> petsc-users at mcs.anl.gov> wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> I am trying to work with a "mixed" FE discretization, where besides >>>>>>> the usual displacements DoF in nodes, there is an additional field (e.g. >>>>>>> pressure) that is also part of the system. This additional field has a >>>>>>> certain number of additional dof : p0, p1, p2... >>>>>>> >>>>>>> Looking at example 77 ( >>>>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMov1NT81$ >>>>>>> ) >>>>>>> this seems to be handled with an additional field, added to the DM. I've >>>>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>>>> not what I expected. >>>>>>> >>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 >>>>>>> Gauss rule for quadrature), with just one field, a call to >>>>>>> DMPlexGetVecClosure() gives me an array with 8 entries (say, the >>>>>>> coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>> >>>>>>> Then add the new field: >>>>>>> >>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>>>> value of nc here */ >>>>>>> DMAddField(dm, ..., p_FE) >>>>>>> >>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 >>>>>>> + 3). This results in a closure of size 22. >>>>>>> >>>>>> >>>>>> That is wrong. Are you sure about 22? >>>>>> >>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>> >>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>> >>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some >>>>>>> combinations of dim / nc for the new PetscFE, but when creating the DM >>>>>>> section I get errors e.g. >>>>>>> >>>>>> >>>>>> This is what you should get. I definitely have examples that do this. >>>>>> For example, here is Q1-P0 (I think that is what you are suggesting) for >>>>>> incompressible Stokes >>>>>> >>>>>> >>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMvSX71k5$ >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>> >>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not >>>>>>> deal with entries that I don't need? Or I am not setting up the section >>>>>>> properly (works with just one field)? >>>>>>> >>>>>>> Thank you, >>>>>>> Noam. >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> What most experimenters take for granted before they begin their >>>>>> experiments is infinitely more interesting than any results to which their >>>>>> experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ >>>>> >>>>> >>>>> >>>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ >> >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!cP9aUMsk0h6B0TP8LN-o6KeS5DUoqycfFJOuLYmU4gSo5kx4ivqdhEodvmnZ16VQW3AsR4qmMxVoMtW45maR$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Mon May 11 04:24:56 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Mon, 11 May 2026 09:24:56 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: > I have a field that gives me five constant values in every cell > > Then you have a P0 field with five components, which will add 5 dofs to the DS. Alright, thanks for the clarification. One additional question: for computing the jacobian/residual, I'm using DMSNESSetFunction/Jacobian(Local). It seems using this function expects a jacobian of full size (for all fields), so e.g. 11x11 (8 for u field, 3 for p field). Is that correct? At least when looking at MatView after AssemblyBegin/End, that's what I get (minus the number of constrained DoF, if any). Similarly for the residual. Thanks, Noam On Friday, May 8th, 2026 at 10:29 PM, Matthew Knepley wrote: > On Fri, May 8, 2026 at 3:34?PM Noam T. wrote: > >> I was indeed confused before regarding how the element ended up with 3 unknowns. >> >> So for a P1, having three unknowns, means the field is interpolated as p = po + p1*x + p2*y? >> Then P2 has 6 components (total dim = 14), which agrees with a complete 2nd order polynomial. >> >> Then my question is, how can I have any other number of components? In particular, some of the implementations I am looking at use 4 and 7 additional DoF. Will this require a new field per DoF? > > No, you start with how these fields are supposed to behave. If you say > > I have a field that gives me five constant values in every cell > > Then you have a P0 field with five components, which will add 5 dofs to the DS. If instead you say > > I have a field that gives two values linearly interpolated over each cell > > Then you have a P1 field with two components, which will add 6 dofs (with triangles) to the DS. > > Thanks, > > Matt > >> Thanks, >> Noam >> On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley wrote: >> >>> On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: >>> >>>> Code attached. >>> >>> I think you misunderstand the definition of the element. I do not think you want 3 components for your pressure. You want 1 component. It is a scalar variable. In my original example, I had a single component. Components create tensor spaces. >>> >>> If you are using discontinuous P1, then it has 3 unknowns, which is what I think you are trying to specify. You should change the space you are using if you want to change the number of variables. >>> >>> Does that clear it up? >>> >>> Thanks, >>> >>> Matt >>> >>>> Noticed from PetscSectionView: >>>> >>>> PetscSectionSym Object: 1 MPI process >>>> type: label >>>> Label 'depth' >>>> Symmetry for stratum value 0 (0 dofs per point): no symmetries >>>> Symmetry for stratum value 1 (0 dofs per point): no symmetries >>>> Symmetry for stratum value 2 (12 dofs per point): <---------------------- 12 DoF ? >>>> Orientation range: [-4, 4) Symmetry for stratum value -1 (0 dofs per point): no symmetries >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Friday, May 8th, 2026 at 3:58 PM, Noam T. wrote: >>>> >>>>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>>>> >>>>> If I use the exact same arrays/values for constructing the section, I get the same closure arrangement in the code you provided. Not surprising I guess? A seemingly random number of coordinates / zeroes / more coordinates. >>>>> >>>>> I checked example 14 (https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV24l2QmpY$ ) for constructing the section. These are the values I used: >>>>> >>>>> - n_fields = 2 >>>>> >>>>> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >>>>> >>>>> The u field is defined in the nodes, with 2 components (u, v), hence the first "2". Then no components for edges/faces. >>>>> For the p field, what I am trying to simulate is having nc (independent) DoF, sort of like having nc scalar fields, if that makes sense? Hence using: >>>>> >>>>> - N = nc >>>>> - Also using the flag "-pres_petscspace_degree 0" >>>>> >>>>> But I'm not sure about those values. >>>>> >>>>> Then for simplicity numBC = 0 and all other arguments are NULL (will deal with boundary conditions later). >>>>> >>>>> With these arguments, I get the same as before e.g. >>>>> >>>>> -- nc = 3 (total dimension = 11) >>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley wrote: >>>>> >>>>>> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >>>>>> >>>>>>> Moving on to the values of the closure. >>>>>>> >>>>>>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). >>>>>>> >>>>>>> I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: >>>>>>> >>>>>>> -- nc = 1 >>>>>>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>>>>>> >>>>>>> -- nc = 3 >>>>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>>>> >>>>>>> -- nc = 7 >>>>>>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>>>>>> >>>>>>> Looking at that output: >>>>>>> - The first value is always a y coordinate (second component of u field). >>>>>>> - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). >>>>>>> >>>>>>> Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV2_CaMvCu$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. >>>>>> >>>>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. >>>>>>> >>>>>>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. >>>>>>> >>>>>>> Thanks, >>>>>>> Noam >>>>>>> >>>>>>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: >>>>>>> >>>>>>>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>>>>>>> >>>>>>>>> On the plus side, using the flags you provided in the previous email >>>>>>>>> >>>>>>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>>>>>> >>>>>>>>> the output of -ds_view is identical to yours, so setting up the fields should be correct. >>>>>>>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >>>>>>>>> >>>>>>>>> However, the closure size was still wrong. >>>>>>>>> >>>>>>>>> But, I figured out the reason: the manual set up of the section. >>>>>>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >>>>>>>>> So as you previously suggested >>>>>>>>> >>>>>>>>>> [...] It sounds like somehow you have a copy of your fields. >>>>>>>>> >>>>>>>>> the number of DoF per field were indeed "doubled" with the sum of both fields. >>>>>>>> >>>>>>>> Excellent. Let me know if you have any more issues. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Matt >>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Noam >>>>>>>>> >>>>>>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >>>>>>>>> >>>>>>>>>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>>>>>>>>> >>>>>>>>>> Here is what I get >>>>>>>>>> >>>>>>>>>> Discrete System with 2 fields >>>>>>>>>> cell total dim 11 total comp 3 >>>>>>>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>>>>>>> type: vector >>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>> type: sum >>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>>> type: tensor >>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>> type: poly >>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>> type: sum >>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>> type: lagrange >>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>>>>>>> type: basic >>>>>>>>>> Basic Finite Element in 2 dimensions with 1 components >>>>>>>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>>>>>>> type: poly >>>>>>>>>> Space in 2 variables with 1 components, size 3 >>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>>>>>>> type: lagrange >>>>>>>>>> Dual space with 1 components, size 3 >>>>>>>>>> Discontinuous Lagrange dual space >>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>> Weak Form System with 2 fields >>>>>>>>>> >>>>>>>>>> I have attached the code I used. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> Matt >>>>>>>>>> >>>>>>>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>>>>>>>>> >>>>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>> >>>>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>>>> >>>>>>>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>>>>>>>>> >>>>>>>>>>> With nc = 1 the closure size is 18 instead. >>>>>>>>>>> >>>>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>>>> >>>>>>>>>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>>>>>>>>> >>>>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>>>> >>>>>>>>>>>> Thanks, >>>>>>>>>>> >>>>>>>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>>>>>>> >>>>>>>>>>> --- >>>>>>>>>>> Discrete System with 1 fields >>>>>>>>>>> cell total dim 8 total comp 2 >>>>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>>>>>>> type: vector >>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>>>>>>> type: tensor >>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>> type: poly >>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>>>> type: sum >>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>> type: lagrange >>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>> Weak Form System with 1 fields--- >>>>>>>>>>> >>>>>>>>>>> and -dm_view >>>>>>>>>>> >>>>>>>>>>> --- >>>>>>>>>>> DM Object: 1 MPI process >>>>>>>>>>> type: plex >>>>>>>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>>>>>>> Number of 0-cells per rank: 4 >>>>>>>>>>> Number of 1-cells per rank: 4 >>>>>>>>>>> Number of 2-cells per rank: 1 >>>>>>>>>>> Labels: >>>>>>>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>>>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>>>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>>>>>>> surf: 1 strata with value/size (1 (1)) >>>>>>>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>>>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>>>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>>>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>>>>>>> P1: 1 strata with value/size (4 (1)) >>>>>>>>>>> P2: 1 strata with value/size (5 (1)) >>>>>>>>>>> P3: 1 strata with value/size (6 (1)) >>>>>>>>>>> P4: 1 strata with value/size (7 (1)) >>>>>>>>>>> Field u: >>>>>>>>>>> adjacency FEM >>>>>>>>>>> /// With the second field, the two lines below are added >>>>>>>>>>> Field p: >>>>>>>>>>> adjacency FEM >>>>>>>>>>> --- >>>>>>>>>>> >>>>>>>>>>> DM set up >>>>>>>>>>> >>>>>>>>>>> DM :: dm_mesh >>>>>>>>>>> PetscFE :: u_FE, p_FE >>>>>>>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>>>>>>> PetscDS :: dm_ds >>>>>>>>>>> >>>>>>>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>>>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>>>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>>>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>>>>>>>>> >>>>>>>>>>> -- using flags >>>>>>>>>>> >>>>>>>>>>> -dm_plex_filename QUAD1.msh >>>>>>>>>>> -dm_plex_interpolate 1 >>>>>>>>>>> -dm_plex_gmsh_use_generic >>>>>>>>>>> -dm_plex_gmsh_use_regions >>>>>>>>>>> -dm_plex_gmsh_multiple_tags >>>>>>>>>>> -dm_plex_gmsh_mark_vertices >>>>>>>>>>> >>>>>>>>>>> -- some operations with labels >>>>>>>>>>> >>>>>>>>>>> // u field >>>>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>>>>>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>>>>>>> >>>>>>>>>>> // p field >>>>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>>>>>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>>>>>>> >>>>>>>>>>> DMCreateDS(dm_mesh) >>>>>>>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>>>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>>>>>>> >>>>>>>>>>> with flags >>>>>>>>>>> >>>>>>>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>>>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>>>>>>> >>>>>>>>>>> I believe these are all the DM related calls. >>>>>>>>>>> >>>>>>>>>>> Thanks, >>>>>>>>>>> Noam >>>>>>>>>>> >>>>>>>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>>>>>>>>> >>>>>>>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Hello, >>>>>>>>>>>>> >>>>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>>>> >>>>>>>>>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>>>>>>>>> >>>>>>>>>>>>> Here's the output of PetscDSView: >>>>>>>>>>>>> Discrete System with 2 fields >>>>>>>>>>>>> cell total dim 11 total comp 5 >>>>>>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>>>>>>> type: vector >>>>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>>>>>> type: tensor >>>>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>>> type: poly >>>>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>>>> type: lagrange >>>>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>> >>>>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>>>>> >>>>>>>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>>>>>>> type: vector >>>>>>>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>>>>>>> type: tensor >>>>>>>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>>> type: poly >>>>>>>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>>>>>>> Polynomial space of degree 0 >>>>>>>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Dual space with 3 components, size 3 >>>>>>>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>>>>>>> type: lagrange >>>>>>>>>>>>> Dual space with 1 components, size 1 >>>>>>>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>>> Weak Form System with 2 fields >>>>>>>>>>>>> >>>>>>>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>>>>>>>>> >>>>>>>>>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>>>>>>> >>>>>>>>>>>>> However, the closure of a Vec is still 22. >>>>>>>>>>>> >>>>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>>>>> >>>>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>>>> >>>>>>>>>>>> Thanks, >>>>>>>>>>>> >>>>>>>>>>>> Matt >>>>>>>>>>>> >>>>>>>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>>>>>>>>> >>>>>>>>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>>>>>>>>> >>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV2267XapN$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Then add the new field: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>>>>>>>>> >>>>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>>>>> >>>>>>>>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>>>>>>>>> >>>>>>>>>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>>>>>>>>> >>>>>>>>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV26W5pwTL$ >>>>>>>>>>>>>> >>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>> >>>>>>>>>>>>>> Matt >>>>>>>>>>>>>> >>>>>>>>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Thank you, >>>>>>>>>>>>>>> Noam. >>>>>>>>>>>>>> >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> >>>>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>>>> >>>>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> >>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>> >>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>> -- Norbert Wiener >>>>>>>>>> >>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ >>>>>>>> >>>>>>>> -- >>>>>>>> >>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>> -- Norbert Wiener >>>>>>>> >>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ >>>>>> >>>>>> -- >>>>>> >>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!bpb7GSnmSEmXckRBL7JXgbPdD0L8vXt6bF8jocj2fxmyd1UAO9MPOxA0XkgJeHn9IiDnMYXx5f5eL0HbgH1w2LfV20IsohZx$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Mon May 11 06:41:57 2026 From: knepley at gmail.com (Matthew Knepley) Date: Mon, 11 May 2026 07:41:57 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Mon, May 11, 2026 at 5:25?AM Noam T. wrote: > > I have a field that gives me five constant values in every cell > > Then you have a P0 field with five components, which will add 5 dofs to > the DS. > > > Alright, thanks for the clarification. > > One additional question: for computing the jacobian/residual, I'm using DMSNESSetFunction/Jacobian(Local). > It seems using this function expects a jacobian of full size (for all > fields), so e.g. 11x11 (8 for u field, 3 for p field). Is that correct? At > least when looking at MatView after AssemblyBegin/End, that's what I get > (minus the number of constrained DoF, if any). > Similarly for the residual. > Yes, that is completely true. More explanation. For the residual, you can always use DMCreateSubDM() to compute the residual over a subset of fields. However, Plex always computes square Jacobians. I did write the code to compute rectangular pieces of the Jacobian, but no one ever used it and eventually removed for maintenance reasons. Thanks, Matt > Thanks, > Noam > > > On Friday, May 8th, 2026 at 10:29 PM, Matthew Knepley > wrote: > > On Fri, May 8, 2026 at 3:34?PM Noam T. wrote: > >> I was indeed confused before regarding how the element ended up with 3 >> unknowns. >> >> So for a P1, having three unknowns, means the field is interpolated as p >> = po + p1*x + p2*y? >> Then P2 has 6 components (total dim = 14), which agrees with a complete >> 2nd order polynomial. >> >> Then my question is, how can I have any other number of components? In >> particular, some of the implementations I am looking at use 4 and 7 >> additional DoF. Will this require a new field per DoF? >> > > No, you start with how these fields are supposed to behave. If you say > > I have a field that gives me five constant values in every cell > > Then you have a P0 field with five components, which will add 5 dofs to > the DS. If instead you say > > I have a field that gives two values linearly interpolated over each cell > > Then you have a P1 field with two components, which will add 6 dofs (with > triangles) to the DS. > > Thanks, > > Matt > >> Thanks, >> Noam >> On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley >> wrote: >> >> On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: >> >>> Code attached. >>> >> >> I think you misunderstand the definition of the element. I do not think >> you want 3 components for your pressure. You want 1 component. It is a >> scalar variable. In my original example, I had a single component. >> Components create tensor spaces. >> >> If you are using discontinuous P1, then it has 3 unknowns, which is what >> I think you are trying to specify. You should change the space you are >> using if you want to change the number of variables. >> >> Does that clear it up? >> >> Thanks, >> >> Matt >> >>> Noticed from PetscSectionView: >>> >>> PetscSectionSym Object: 1 MPI process >>> type: label >>> Label 'depth' >>> Symmetry for stratum value 0 (0 dofs per point): no symmetries >>> Symmetry for stratum value 1 (0 dofs per point): no symmetries >>> Symmetry for stratum value 2 (12 dofs per point): >>> <---------------------- 12 DoF ? >>> Orientation range: [-4, 4) >>> Symmetry for stratum value -1 (0 dofs per point): no symmetries >>> >>> Thanks, >>> Noam >>> >>> On Friday, May 8th, 2026 at 3:58 PM, Noam T. >>> wrote: >>> >>> This is likely to be a Section construction problem again. The Section >>> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >>> the fields in the Section. If you put these calls into the code that I sent >>> you, what do you get? >>> >>> >>> If I use the exact same arrays/values for constructing the section, I >>> get the same closure arrangement in the code you provided. Not surprising I >>> guess? A seemingly random number of coordinates / zeroes / more coordinates. >>> >>> I checked example 14 ( >>> https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KucejXyYH$ ) for >>> constructing the section. These are the values I used: >>> >>> - n_fields = 2 >>> >>> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >>> >>> The u field is defined in the nodes, with 2 components (u, v), hence the >>> first "2". Then no components for edges/faces. >>> For the p field, what I am trying to simulate is having nc (independent) >>> DoF, sort of like having nc scalar fields, if that makes sense? Hence using: >>> >>> - N = nc >>> - Also using the flag "-pres_petscspace_degree 0" >>> >>> But I'm not sure about those values. >>> >>> Then for simplicity numBC = 0 and all other arguments are NULL (will >>> deal with boundary conditions later). >>> >>> With these arguments, I get the same as before e.g. >>> >>> -- nc = 3 (total dimension = 11) >>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>> >>> Thanks, >>> Noam >>> >>> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley >>> wrote: >>> >>> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >>> >>>> Moving on to the values of the closure. >>>> >>>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, >>>> which is used for e.g. the solution. Following the example before, it will >>>> have size 8 (coordinates) + nc (for the p field). >>>> >>>> I am getting a seemingly random order when I test with different values >>>> of nc. Say, I initialize the vector (VecSetValues) with the coordinates >>>> x_i, y_i . The rest nc components are set to zero. The closure returns: >>>> >>>> -- nc = 1 >>>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>>> >>>> -- nc = 3 >>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>> >>>> -- nc = 7 >>>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>>> >>>> Looking at that output: >>>> - The first value is always a y coordinate (second component of u >>>> field). >>>> - The position of the nc = 0 components change (starting with nc = 8, >>>> all zero values come first, followed by the coordinates). >>>> >>>> Looking again at ex77.c ( >>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuZIyGXkb$ ), it says the >>>> closure stacks up the fields, which aligns with the output above (all u >>>> values, then all p values), but which is the starting point seems arbitrary. >>>> >>> >>> This is likely to be a Section construction problem again. The Section >>> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >>> the fields in the Section. If you put these calls into the code that I sent >>> you, what do you get? >>> >>> Thanks, >>> >>> Matt >>> >>>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may >>>> not be correct to start with. >>>> >>>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = >>>> 0, ...) so that I only get the u field DoF. But I will need to deal with >>>> the p field values as well at some point. >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley < >>>> knepley at gmail.com> wrote: >>>> >>>> On Fri, May 8, 2026 at 5:08?AM Noam T. >>>> wrote: >>>> >>>>> On the plus side, using the flags you provided in the previous email >>>>> >>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 >>>>> -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>> >>>>> the output of -ds_view is identical to yours, so setting up the fields >>>>> should be correct. >>>>> Thanks. I forgot about the flag >>>>> "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous >>>>> field. >>>>> >>>>> However, the closure size was still wrong. >>>>> >>>>> But, I figured out the reason: the manual set up of the section. >>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing >>>>> the number of DoF with PetscSectionGetDof() (which was fine until now, >>>>> since there was a single field), instead of PetscSectionGetFieldDof(). >>>>> So as you previously suggested >>>>> >>>>> [...] It sounds like somehow you have a copy of your fields. >>>>> >>>>> >>>>> the number of DoF per field were indeed "doubled" with the sum of both >>>>> fields. >>>>> >>>> >>>> Excellent. Let me know if you have any more issues. >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >>>>> knepley at gmail.com> wrote: >>>>> >>>>> Okay, this is a problem with specifying the space I believe. You want >>>>> a discontinuous space for pressure. >>>>> >>>>> Here is what I get >>>>> >>>>> Discrete System with 2 fields >>>>> cell total dim 11 total comp 3 >>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>> type: vector >>>>> Vector Finite Element in 2 dimensions with 2 components >>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Space in 2 variables with 2 components, size 8 >>>>> Sum space of 2 concatenated subspaces (all identical) >>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>> type: tensor >>>>> Space in 2 variables with 1 components, size 4 >>>>> Tensor space of 2 subspaces (all identical) >>>>> PetscSpace Object: sum component tensor component >>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>> type: poly >>>>> Space in 1 variables with 1 components, size 2 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>> type: sum >>>>> Dual space with 2 components, size 8 >>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>> PetscDualSpace Object: Q1 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 4 >>>>> Continuous tensor Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>> type: basic >>>>> Basic Finite Element in 2 dimensions with 1 components >>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>> type: poly >>>>> Space in 2 variables with 1 components, size 3 >>>>> Polynomial space of degree 1 >>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>> type: lagrange >>>>> Dual space with 1 components, size 3 >>>>> Discontinuous Lagrange dual space >>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>> Weak Form System with 2 fields >>>>> >>>>> I have attached the code I used. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. >>>>> wrote: >>>>> >>>>>> >>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> >>>>>> >>>>>> 1. Why does pressure have 3 components in 2D? >>>>>> >>>>>> >>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>>>>> field. Confusion between wanting 3 addditional DoF and components. >>>>>> >>>>>> With nc = 1 the closure size is 18 instead. >>>>>> >>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>>> this exact element. >>>>>> >>>>>> >>>>>> I changed some of my code following the example and got rid of some >>>>>> errors. But I'll have a more thorough look again. >>>>>> >>>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>>> somehow you have a copy of your fields. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> >>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>> >>>>>> --- >>>>>> Discrete System with 1 fields >>>>>> cell total dim 8 total comp 2 >>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component >>>>>> (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 1 fields >>>>>> --- >>>>>> >>>>>> and -dm_view >>>>>> >>>>>> --- >>>>>> DM Object: 1 MPI process >>>>>> type: plex >>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>> Number of 0-cells per rank: 4 >>>>>> Number of 1-cells per rank: 4 >>>>>> Number of 2-cells per rank: 1 >>>>>> Labels: >>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>> surf: 1 strata with value/size (1 (1)) >>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>> P1: 1 strata with value/size (4 (1)) >>>>>> P2: 1 strata with value/size (5 (1)) >>>>>> P3: 1 strata with value/size (6 (1)) >>>>>> P4: 1 strata with value/size (7 (1)) >>>>>> Field u: >>>>>> adjacency FEM >>>>>> /// With the second field, the two lines below are added >>>>>> Field p: >>>>>> adjacency FEM >>>>>> --- >>>>>> >>>>>> DM set up >>>>>> >>>>>> DM :: dm_mesh >>>>>> PetscFE :: u_FE, p_FE >>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>> PetscDS :: dm_ds >>>>>> >>>>>> >>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>>>>> removed; no changes that I can see >>>>>> >>>>>> -- using flags >>>>>> >>>>>> -dm_plex_filename QUAD1.msh >>>>>> -dm_plex_interpolate 1 >>>>>> -dm_plex_gmsh_use_generic >>>>>> -dm_plex_gmsh_use_regions >>>>>> -dm_plex_gmsh_multiple_tags >>>>>> -dm_plex_gmsh_mark_vertices >>>>>> >>>>>> -- some operations with labels >>>>>> >>>>>> // u field >>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", >>>>>> PETSC_DETERMINE, u_FE) >>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>> >>>>>> // p field >>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>>>>> PETSC_DETERMINE, p_FE) >>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>> >>>>>> DMCreateDS(dm_mesh) >>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>> >>>>>> with flags >>>>>> >>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>> >>>>>> >>>>>> I believe these are all the DM related calls. >>>>>> >>>>>> Thanks, >>>>>> Noam >>>>>> >>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>>>>> knepley at gmail.com> wrote: >>>>>> >>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. >>>>>> wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> That is wrong. Are you sure about 22? >>>>>>> >>>>>>> >>>>>>> That's what I get, from the argument "csize" in >>>>>>> DMPlexGetVecClosure(). >>>>>>> >>>>>>> Here's the output of PetscDSView: >>>>>>> >>>>>>> Discrete System with 2 fields >>>>>>> cell total dim 11 total comp 5 >>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>> type: vector >>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>> type: sum >>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>> type: tensor >>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>> PetscSpace Object: sum component tensor component >>>>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>> type: poly >>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>> Polynomial space of degree 1 >>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>> type: sum >>>>>>> Dual space with 2 components, size 8 >>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>> type: lagrange >>>>>>> Dual space with 1 components, size 4 >>>>>>> Continuous tensor Lagrange dual space >>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> >>>>>> >>>>>> 1. Why does pressure have 3 components in 2D? >>>>>> >>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>> type: vector >>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>> type: sum >>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>> type: tensor >>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>> PetscSpace Object: sum component tensor component >>>>>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>> type: poly >>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>> Polynomial space of degree 0 >>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>> type: sum >>>>>>> Dual space with 3 components, size 3 >>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>> type: lagrange >>>>>>> Dual space with 1 components, size 1 >>>>>>> Discontinuous tensor Lagrange dual space >>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>> Weak Form System with 2 fields >>>>>>> >>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>>>>> setting the FE object name to "p". >>>>>>> >>>>>>> The entry "cell total dim 10" agrees with the output of >>>>>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>> >>>>>>> However, the closure of a Vec is still 22. >>>>>>> >>>>>> >>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>>> this exact element. >>>>>> >>>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>>> somehow you have a copy of your fields. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>>>>> knepley at gmail.com> wrote: >>>>>>> >>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>>>>> petsc-users at mcs.anl.gov> wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>> I am trying to work with a "mixed" FE discretization, where besides >>>>>>>> the usual displacements DoF in nodes, there is an additional field (e.g. >>>>>>>> pressure) that is also part of the system. This additional field has a >>>>>>>> certain number of additional dof : p0, p1, p2... >>>>>>>> >>>>>>>> Looking at example 77 ( >>>>>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuZIyGXkb$ >>>>>>>> ) >>>>>>>> this seems to be handled with an additional field, added to the DM. I've >>>>>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>>>>> not what I expected. >>>>>>>> >>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 >>>>>>>> Gauss rule for quadrature), with just one field, a call to >>>>>>>> DMPlexGetVecClosure() gives me an array with 8 entries (say, the >>>>>>>> coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>> >>>>>>>> Then add the new field: >>>>>>>> >>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>>>>> value of nc here */ >>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>> >>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 >>>>>>>> + 3). This results in a closure of size 22. >>>>>>>> >>>>>>> >>>>>>> That is wrong. Are you sure about 22? >>>>>>> >>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>> >>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>> >>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried >>>>>>>> some combinations of dim / nc for the new PetscFE, but when creating the DM >>>>>>>> section I get errors e.g. >>>>>>>> >>>>>>> >>>>>>> This is what you should get. I definitely have examples that do >>>>>>> this. For example, here is Q1-P0 (I think that is what you are suggesting) >>>>>>> for incompressible Stokes >>>>>>> >>>>>>> >>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuSgpU3xx$ >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Matt >>>>>>> >>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>> >>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not >>>>>>>> deal with entries that I don't need? Or I am not setting up the section >>>>>>>> properly (works with just one field)? >>>>>>>> >>>>>>>> Thank you, >>>>>>>> Noam. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> What most experimenters take for granted before they begin their >>>>>>> experiments is infinitely more interesting than any results to which their >>>>>>> experiments lead. >>>>>>> -- Norbert Wiener >>>>>>> >>>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> -- >>>>>> What most experimenters take for granted before they begin their >>>>>> experiments is infinitely more interesting than any results to which their >>>>>> experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >>>>> >>>>> >>>>> >>>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >>> >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!blgAbufRlZ05shY0R_LZ-jc4h4ItGucyIJbrAy_Gsds7p62MI2Fpg_5uf4wgmC6fJwAr0yCf8d3KuTKxFdNr$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontbugthedevs at proton.me Mon May 11 13:45:51 2026 From: dontbugthedevs at proton.me (Noam T.) Date: Mon, 11 May 2026 18:45:51 +0000 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: > Yes, that is completely true. > > More explanation. For the residual, you can always use DMCreateSubDM() to compute the residual over a subset of fields. However, Plex always computes square Jacobians. I did write the code to compute rectangular pieces of the Jacobian, but no one ever used it and eventually removed for maintenance reasons. > > Thanks, > > Mat Great, thanks. Then I wonder what would be simpler for this particular case: - Build the full system, with the two fields; the full size/number of DoF per cell is known, so each subblock matrix for the Jacobian/residual can be computed (need some additional care for the DoF ordering). - Since the p field is discontinuous, it can be condensed out. However there is still a residual to be computed for all DoF of the p field, for which I would need to pass around an extra Vec/array to keep track of these DoFs (or some other way). - Another approach (?) Any suggestions/recommendations for either -from the implementation point of view-, in case you have experience with a similar situation? Thanks, Noam On Monday, May 11th, 2026 at 1:42 PM, Matthew Knepley wrote: > On Mon, May 11, 2026 at 5:25?AM Noam T. wrote: > >>> I have a field that gives me five constant values in every cell >>> >>> Then you have a P0 field with five components, which will add 5 dofs to the DS. >> >> Alright, thanks for the clarification. >> >> One additional question: for computing the jacobian/residual, I'm using DMSNESSetFunction/Jacobian(Local). It seems using this function expects a jacobian of full size (for all fields), so e.g. 11x11 (8 for u field, 3 for p field). Is that correct? At least when looking at MatView after AssemblyBegin/End, that's what I get (minus the number of constrained DoF, if any). >> Similarly for the residual. > > Yes, that is completely true. > > More explanation. For the residual, you can always use DMCreateSubDM() to compute the residual over a subset of fields. However, Plex always computes square Jacobians. I did write the code to compute rectangular pieces of the Jacobian, but no one ever used it and eventually removed for maintenance reasons. > > Thanks, > > Matt > >> Thanks, >> Noam >> >> On Friday, May 8th, 2026 at 10:29 PM, Matthew Knepley wrote: >> >>> On Fri, May 8, 2026 at 3:34?PM Noam T. wrote: >>> >>>> I was indeed confused before regarding how the element ended up with 3 unknowns. >>>> >>>> So for a P1, having three unknowns, means the field is interpolated as p = po + p1*x + p2*y? >>>> Then P2 has 6 components (total dim = 14), which agrees with a complete 2nd order polynomial. >>>> >>>> Then my question is, how can I have any other number of components? In particular, some of the implementations I am looking at use 4 and 7 additional DoF. Will this require a new field per DoF? >>> >>> No, you start with how these fields are supposed to behave. If you say >>> >>> I have a field that gives me five constant values in every cell >>> >>> Then you have a P0 field with five components, which will add 5 dofs to the DS. If instead you say >>> >>> I have a field that gives two values linearly interpolated over each cell >>> >>> Then you have a P1 field with two components, which will add 6 dofs (with triangles) to the DS. >>> >>> Thanks, >>> >>> Matt >>> >>>> Thanks, >>>> Noam >>>> On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley wrote: >>>> >>>>> On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: >>>>> >>>>>> Code attached. >>>>> >>>>> I think you misunderstand the definition of the element. I do not think you want 3 components for your pressure. You want 1 component. It is a scalar variable. In my original example, I had a single component. Components create tensor spaces. >>>>> >>>>> If you are using discontinuous P1, then it has 3 unknowns, which is what I think you are trying to specify. You should change the space you are using if you want to change the number of variables. >>>>> >>>>> Does that clear it up? >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> Noticed from PetscSectionView: >>>>>> >>>>>> PetscSectionSym Object: 1 MPI process >>>>>> type: label >>>>>> Label 'depth' >>>>>> Symmetry for stratum value 0 (0 dofs per point): no symmetries >>>>>> Symmetry for stratum value 1 (0 dofs per point): no symmetries >>>>>> Symmetry for stratum value 2 (12 dofs per point): <---------------------- 12 DoF ? >>>>>> Orientation range: [-4, 4) Symmetry for stratum value -1 (0 dofs per point): no symmetries >>>>>> >>>>>> Thanks, >>>>>> Noam >>>>>> >>>>>> On Friday, May 8th, 2026 at 3:58 PM, Noam T. wrote: >>>>>> >>>>>>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>>>>>> >>>>>>> If I use the exact same arrays/values for constructing the section, I get the same closure arrangement in the code you provided. Not surprising I guess? A seemingly random number of coordinates / zeroes / more coordinates. >>>>>>> >>>>>>> I checked example 14 (https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7XfYLY7Y$ ) for constructing the section. These are the values I used: >>>>>>> >>>>>>> - n_fields = 2 >>>>>>> >>>>>>> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >>>>>>> >>>>>>> The u field is defined in the nodes, with 2 components (u, v), hence the first "2". Then no components for edges/faces. >>>>>>> For the p field, what I am trying to simulate is having nc (independent) DoF, sort of like having nc scalar fields, if that makes sense? Hence using: >>>>>>> >>>>>>> - N = nc >>>>>>> - Also using the flag "-pres_petscspace_degree 0" >>>>>>> >>>>>>> But I'm not sure about those values. >>>>>>> >>>>>>> Then for simplicity numBC = 0 and all other arguments are NULL (will deal with boundary conditions later). >>>>>>> >>>>>>> With these arguments, I get the same as before e.g. >>>>>>> >>>>>>> -- nc = 3 (total dimension = 11) >>>>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>>>> >>>>>>> Thanks, >>>>>>> Noam >>>>>>> >>>>>>> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley wrote: >>>>>>> >>>>>>>> On Fri, May 8, 2026 at 8:01?AM Noam T. wrote: >>>>>>>> >>>>>>>>> Moving on to the values of the closure. >>>>>>>>> >>>>>>>>> Initially I create a vector for the DM with DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following the example before, it will have size 8 (coordinates) + nc (for the p field). >>>>>>>>> >>>>>>>>> I am getting a seemingly random order when I test with different values of nc. Say, I initialize the vector (VecSetValues) with the coordinates x_i, y_i . The rest nc components are set to zero. The closure returns: >>>>>>>>> >>>>>>>>> -- nc = 1 >>>>>>>>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>>>>>>>> >>>>>>>>> -- nc = 3 >>>>>>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>>>>>> >>>>>>>>> -- nc = 7 >>>>>>>>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>>>>>>>> >>>>>>>>> Looking at that output: >>>>>>>>> - The first value is always a y coordinate (second component of u field). >>>>>>>>> - The position of the nc = 0 components change (starting with nc = 8, all zero values come first, followed by the coordinates). >>>>>>>>> >>>>>>>>> Looking again at ex77.c (https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aCnylm2$ ), it says the closure stacks up the fields, which aligns with the output above (all u values, then all p values), but which is the starting point seems arbitrary. >>>>>>>> >>>>>>>> This is likely to be a Section construction problem again. The Section fields are separated by DMPlexVecGetClosure(), sp you must not have defined the fields in the Section. If you put these calls into the code that I sent you, what do you get? >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Matt >>>>>>>> >>>>>>>>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may not be correct to start with. >>>>>>>>> >>>>>>>>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = 0, ...) so that I only get the u field DoF. But I will need to deal with the p field values as well at some point. >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Noam >>>>>>>>> >>>>>>>>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley wrote: >>>>>>>>> >>>>>>>>>> On Fri, May 8, 2026 at 5:08?AM Noam T. wrote: >>>>>>>>>> >>>>>>>>>>> On the plus side, using the flags you provided in the previous email >>>>>>>>>>> >>>>>>>>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>>>>>>>> >>>>>>>>>>> the output of -ds_view is identical to yours, so setting up the fields should be correct. >>>>>>>>>>> Thanks. I forgot about the flag "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous field. >>>>>>>>>>> >>>>>>>>>>> However, the closure size was still wrong. >>>>>>>>>>> >>>>>>>>>>> But, I figured out the reason: the manual set up of the section. >>>>>>>>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing the number of DoF with PetscSectionGetDof() (which was fine until now, since there was a single field), instead of PetscSectionGetFieldDof(). >>>>>>>>>>> So as you previously suggested >>>>>>>>>>> >>>>>>>>>>>> [...] It sounds like somehow you have a copy of your fields. >>>>>>>>>>> >>>>>>>>>>> the number of DoF per field were indeed "doubled" with the sum of both fields. >>>>>>>>>> >>>>>>>>>> Excellent. Let me know if you have any more issues. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> Matt >>>>>>>>>> >>>>>>>>>>> Thanks, >>>>>>>>>>> Noam >>>>>>>>>>> >>>>>>>>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley wrote: >>>>>>>>>>> >>>>>>>>>>>> Okay, this is a problem with specifying the space I believe. You want a discontinuous space for pressure. >>>>>>>>>>>> >>>>>>>>>>>> Here is what I get >>>>>>>>>>>> >>>>>>>>>>>> Discrete System with 2 fields >>>>>>>>>>>> cell total dim 11 total comp 3 >>>>>>>>>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>> type: vector >>>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>> type: sum >>>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>>>>> type: tensor >>>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>> type: poly >>>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>> type: sum >>>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>>> type: lagrange >>>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>>>>>>>>> type: basic >>>>>>>>>>>> Basic Finite Element in 2 dimensions with 1 components >>>>>>>>>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>>>>>>>>> type: poly >>>>>>>>>>>> Space in 2 variables with 1 components, size 3 >>>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>>>>>>>>> type: lagrange >>>>>>>>>>>> Dual space with 1 components, size 3 >>>>>>>>>>>> Discontinuous Lagrange dual space >>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>> Weak Form System with 2 fields >>>>>>>>>>>> >>>>>>>>>>>> I have attached the code I used. >>>>>>>>>>>> >>>>>>>>>>>> Thanks, >>>>>>>>>>>> >>>>>>>>>>>> Matt >>>>>>>>>>>> >>>>>>>>>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. wrote: >>>>>>>>>>>> >>>>>>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>>>> >>>>>>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>>>>>> >>>>>>>>>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure field. Confusion between wanting 3 addditional DoF and components. >>>>>>>>>>>>> >>>>>>>>>>>>> With nc = 1 the closure size is 18 instead. >>>>>>>>>>>>> >>>>>>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>>>>>> >>>>>>>>>>>>> I changed some of my code following the example and got rid of some errors. But I'll have a more thorough look again. >>>>>>>>>>>>> >>>>>>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>>>>>> >>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>> >>>>>>>>>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>>>>>>>>> >>>>>>>>>>>>> --- >>>>>>>>>>>>> Discrete System with 1 fields >>>>>>>>>>>>> cell total dim 8 total comp 2 >>>>>>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>>>>>>>>> type: vector >>>>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>>>>>>>>> type: tensor >>>>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>>> PetscSpace Object: sum component tensor component (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>>> type: poly >>>>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>>>>>>>>> type: sum >>>>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>>>> type: lagrange >>>>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>>> Weak Form System with 1 fields--- >>>>>>>>>>>>> >>>>>>>>>>>>> and -dm_view >>>>>>>>>>>>> >>>>>>>>>>>>> --- >>>>>>>>>>>>> DM Object: 1 MPI process >>>>>>>>>>>>> type: plex >>>>>>>>>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>>>>>>>>> Number of 0-cells per rank: 4 >>>>>>>>>>>>> Number of 1-cells per rank: 4 >>>>>>>>>>>>> Number of 2-cells per rank: 1 >>>>>>>>>>>>> Labels: >>>>>>>>>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>>>>>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>>>>>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>>>>>>>>> surf: 1 strata with value/size (1 (1)) >>>>>>>>>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>>>>>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>>>>>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>>>>>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>>>>>>>>> P1: 1 strata with value/size (4 (1)) >>>>>>>>>>>>> P2: 1 strata with value/size (5 (1)) >>>>>>>>>>>>> P3: 1 strata with value/size (6 (1)) >>>>>>>>>>>>> P4: 1 strata with value/size (7 (1)) >>>>>>>>>>>>> Field u: >>>>>>>>>>>>> adjacency FEM >>>>>>>>>>>>> /// With the second field, the two lines below are added >>>>>>>>>>>>> Field p: >>>>>>>>>>>>> adjacency FEM >>>>>>>>>>>>> --- >>>>>>>>>>>>> >>>>>>>>>>>>> DM set up >>>>>>>>>>>>> >>>>>>>>>>>>> DM :: dm_mesh >>>>>>>>>>>>> PetscFE :: u_FE, p_FE >>>>>>>>>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>>>>>>>>> PetscDS :: dm_ds >>>>>>>>>>>>> >>>>>>>>>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>>>>>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>>>>>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>>>>>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now removed; no changes that I can see >>>>>>>>>>>>> >>>>>>>>>>>>> -- using flags >>>>>>>>>>>>> >>>>>>>>>>>>> -dm_plex_filename QUAD1.msh >>>>>>>>>>>>> -dm_plex_interpolate 1 >>>>>>>>>>>>> -dm_plex_gmsh_use_generic >>>>>>>>>>>>> -dm_plex_gmsh_use_regions >>>>>>>>>>>>> -dm_plex_gmsh_multiple_tags >>>>>>>>>>>>> -dm_plex_gmsh_mark_vertices >>>>>>>>>>>>> >>>>>>>>>>>>> -- some operations with labels >>>>>>>>>>>>> >>>>>>>>>>>>> // u field >>>>>>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, "mech_", PETSC_DETERMINE, u_FE) >>>>>>>>>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>>>>>>>>> >>>>>>>>>>>>> // p field >>>>>>>>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", PETSC_DETERMINE, p_FE) >>>>>>>>>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>>>>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>>>>>>>>> >>>>>>>>>>>>> DMCreateDS(dm_mesh) >>>>>>>>>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>>>>>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>>>>>>>>> >>>>>>>>>>>>> with flags >>>>>>>>>>>>> >>>>>>>>>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>>>>>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>>>>>>>>> >>>>>>>>>>>>> I believe these are all the DM related calls. >>>>>>>>>>>>> >>>>>>>>>>>>> Thanks, >>>>>>>>>>>>> Noam >>>>>>>>>>>>> >>>>>>>>>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley wrote: >>>>>>>>>>>>> >>>>>>>>>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. wrote: >>>>>>>>>>>>>> >>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> That's what I get, from the argument "csize" in DMPlexGetVecClosure(). >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Here's the output of PetscDSView: >>>>>>>>>>>>>>> Discrete System with 2 fields >>>>>>>>>>>>>>> cell total dim 11 total comp 5 >>>>>>>>>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>>>>>>>>> type: vector >>>>>>>>>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>>>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>>>>> type: sum >>>>>>>>>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>>>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>>>>>>>>> type: tensor >>>>>>>>>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>>>>> PetscSpace Object: sum component tensor component (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>>>>> type: poly >>>>>>>>>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>>>>>>>>> Polynomial space of degree 1 >>>>>>>>>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>>>>>>>>> type: sum >>>>>>>>>>>>>>> Dual space with 2 components, size 8 >>>>>>>>>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>>>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>>>>>>>>> type: lagrange >>>>>>>>>>>>>>> Dual space with 1 components, size 4 >>>>>>>>>>>>>>> Continuous tensor Lagrange dual space >>>>>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>>>>>>>> >>>>>>>>>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>>>>>>>>> >>>>>>>>>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>>>>>>>>> type: vector >>>>>>>>>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>>>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>>>>>> type: sum >>>>>>>>>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>>>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>>>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>>>>>>>>> type: tensor >>>>>>>>>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>>>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>>>>>>>>> PetscSpace Object: sum component tensor component (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>>>>>>>>> type: poly >>>>>>>>>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>>>>>>>>> Polynomial space of degree 0 >>>>>>>>>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>>>>>>>>> type: sum >>>>>>>>>>>>>>> Dual space with 3 components, size 3 >>>>>>>>>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>>>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>>>>>>>>> type: lagrange >>>>>>>>>>>>>>> Dual space with 1 components, size 1 >>>>>>>>>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>>>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>>>>>>>>> Weak Form System with 2 fields >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and setting the FE object name to "p". >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> The entry "cell total dim 10" agrees with the output of PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> However, the closure of a Vec is still 22. >>>>>>>>>>>>>> >>>>>>>>>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up this exact element. >>>>>>>>>>>>>> >>>>>>>>>>>>>> 3. Please send me that code that sets up your DM. It sounds like somehow you have a copy of your fields. >>>>>>>>>>>>>> >>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>> >>>>>>>>>>>>>> Matt >>>>>>>>>>>>>> >>>>>>>>>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley wrote: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users wrote: >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> I am trying to work with a "mixed" FE discretization, where besides the usual displacements DoF in nodes, there is an additional field (e.g. pressure) that is also part of the system. This additional field has a certain number of additional dof : p0, p1, p2... >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Looking at example 77 ([https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html*5D(https:/*urldefense.us/v3/__https:/*petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!aZNOxZZeoHYqe6lRZV0wHMVVTu3YIEfc1Sr-dca7xiGVfG3enULFD4_g6_fxWIa7A_Cu9LcXU-MuxRj4sOwDRyWqvsdGdrEd$)__;JS8v!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7ZcTjOCd$ ) this seems to be handled with an additional field, added to the DM. I've tried so, but then I am getting from the DM arrays whose size/contents are not what I expected. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 Gauss rule for quadrature), with just one field, a call to DMPlexGetVecClosure() gives me an array with 8 entries (say, the coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Then add the new field: >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the value of nc here */ >>>>>>>>>>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 (8 + 3). This results in a closure of size 22. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> That is wrong. Are you sure about 22? >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried some combinations of dim / nc for the new PetscFE, but when creating the DM section I get errors e.g. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> This is what you should get. I definitely have examples that do this. For example, here is Q1-P0 (I think that is what you are suggesting) for incompressible Stokes >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7TrX8ksA$ >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> Matt >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not deal with entries that I don't need? Or I am not setting up the section properly (works with just one field)? >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Thank you, >>>>>>>>>>>>>>>>> Noam. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> -- >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>>>>>>>>>>>>> >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> >>>>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>>>> >>>>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> >>>>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>>>> -- Norbert Wiener >>>>>>>>>>>> >>>>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>>>> -- Norbert Wiener >>>>>>>>>> >>>>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>>>>>>> >>>>>>>> -- >>>>>>>> >>>>>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>>>>> -- Norbert Wiener >>>>>>>> >>>>>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>>>> >>>>> -- >>>>> >>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ >>> >>> -- >>> >>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. >>> -- Norbert Wiener >>> >>> [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ > > -- > > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener > > [https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/*5D(http:/*www.cse.buffalo.edu/*knepley/)__;fiUvfg!!G_uCfscf7eWS!ec75Imx32bPBGCC70h-0tZhD136Pu23jeIeeQ52iF9qkEep9liK2YyJjlkey0xvTF4PWYj9CcG4ipjYmNUOHu2ZK7aZbE10L$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Mon May 11 13:53:21 2026 From: knepley at gmail.com (Matthew Knepley) Date: Mon, 11 May 2026 14:53:21 -0400 Subject: [petsc-users] Additiional DoF per cell In-Reply-To: References: Message-ID: On Mon, May 11, 2026 at 2:45?PM Noam T. wrote: > Yes, that is completely true. > > More explanation. For the residual, you can always use DMCreateSubDM() to > compute the residual over a subset of fields. However, Plex always computes > square Jacobians. I did write the code to compute rectangular pieces of the > Jacobian, but no one ever used it and eventually removed for maintenance > reasons. > > Thanks, > > Mat > > > Great, thanks. > > Then I wonder what would be simpler for this particular case: > > - Build the full system, with the two fields; the full size/number of DoF > per cell is known, so each subblock matrix for the Jacobian/residual can be > computed (need some additional care for the DoF ordering). > - Since the p field is discontinuous, it can be condensed out. However > there is still a residual to be computed for all DoF of the p field, for > which I would need to pass around an extra Vec/array to keep track of these > DoFs (or some other way). > - Another approach (?) > I will preface my comments by saying that I am not the expert on static condensation. However, my feeling is that it is very beneficial at high order, but at first order it might be a wash. For P2-P1_disc for Stokes, I believe I solved it as Dave May had in the past, using PCFIELDSPLIT, using the mass matrix on the pressure space as the Schur preconditioner. If you build the full space, you can always create subspaces using DMCreateSubDM() if you want and solve subproblems. Thanks, Matt > Any suggestions/recommendations for either -from the implementation point > of view-, in case you have experience with a similar situation? > > Thanks, > Noam > > On Monday, May 11th, 2026 at 1:42 PM, Matthew Knepley > wrote: > > On Mon, May 11, 2026 at 5:25?AM Noam T. wrote: > >> >> I have a field that gives me five constant values in every cell >> >> Then you have a P0 field with five components, which will add 5 dofs to >> the DS. >> >> >> Alright, thanks for the clarification. >> >> One additional question: for computing the jacobian/residual, I'm using DMSNESSetFunction/Jacobian(Local). >> It seems using this function expects a jacobian of full size (for all >> fields), so e.g. 11x11 (8 for u field, 3 for p field). Is that correct? At >> least when looking at MatView after AssemblyBegin/End, that's what I get >> (minus the number of constrained DoF, if any). >> Similarly for the residual. >> > > Yes, that is completely true. > > More explanation. For the residual, you can always use DMCreateSubDM() to > compute the residual over a subset of fields. However, Plex always computes > square Jacobians. I did write the code to compute rectangular pieces of the > Jacobian, but no one ever used it and eventually removed for maintenance > reasons. > > Thanks, > > Matt > >> Thanks, >> Noam >> >> >> On Friday, May 8th, 2026 at 10:29 PM, Matthew Knepley >> wrote: >> >> On Fri, May 8, 2026 at 3:34?PM Noam T. wrote: >> >>> I was indeed confused before regarding how the element ended up with 3 >>> unknowns. >>> >>> So for a P1, having three unknowns, means the field is interpolated as p >>> = po + p1*x + p2*y? >>> Then P2 has 6 components (total dim = 14), which agrees with a complete >>> 2nd order polynomial. >>> >>> Then my question is, how can I have any other number of components? In >>> particular, some of the implementations I am looking at use 4 and 7 >>> additional DoF. Will this require a new field per DoF? >>> >> >> No, you start with how these fields are supposed to behave. If you say >> >> I have a field that gives me five constant values in every cell >> >> Then you have a P0 field with five components, which will add 5 dofs to >> the DS. If instead you say >> >> I have a field that gives two values linearly interpolated over each cell >> >> Then you have a P1 field with two components, which will add 6 dofs (with >> triangles) to the DS. >> >> Thanks, >> >> Matt >> >>> Thanks, >>> Noam >>> On Friday, May 8th, 2026 at 7:13 PM, Matthew Knepley >>> wrote: >>> >>> On Fri, May 8, 2026 at 2:54?PM Noam T. wrote: >>> >>>> Code attached. >>>> >>> >>> I think you misunderstand the definition of the element. I do not think >>> you want 3 components for your pressure. You want 1 component. It is a >>> scalar variable. In my original example, I had a single component. >>> Components create tensor spaces. >>> >>> If you are using discontinuous P1, then it has 3 unknowns, which is what >>> I think you are trying to specify. You should change the space you are >>> using if you want to change the number of variables. >>> >>> Does that clear it up? >>> >>> Thanks, >>> >>> Matt >>> >>>> Noticed from PetscSectionView: >>>> >>>> PetscSectionSym Object: 1 MPI process >>>> type: label >>>> Label 'depth' >>>> Symmetry for stratum value 0 (0 dofs per point): no symmetries >>>> Symmetry for stratum value 1 (0 dofs per point): no symmetries >>>> Symmetry for stratum value 2 (12 dofs per point): >>>> <---------------------- 12 DoF ? >>>> Orientation range: [-4, 4) >>>> Symmetry for stratum value -1 (0 dofs per point): no symmetries >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Friday, May 8th, 2026 at 3:58 PM, Noam T. >>>> wrote: >>>> >>>> This is likely to be a Section construction problem again. The Section >>>> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >>>> the fields in the Section. If you put these calls into the code that I sent >>>> you, what do you get? >>>> >>>> >>>> If I use the exact same arrays/values for constructing the section, I >>>> get the same closure arrangement in the code you provided. Not surprising I >>>> guess? A seemingly random number of coordinates / zeroes / more coordinates. >>>> >>>> I checked example 14 ( >>>> https://urldefense.us/v3/__https://petsc.org/release/src/dm/impls/plex/tutorials/ex14.c.html__;!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmFJJUck6$ ) for >>>> constructing the section. These are the values I used: >>>> >>>> - n_fields = 2 >>>> >>>> - numDof [n_fields*(dim+1)] = numDof[2*(2+1)] = [2 0 0 0 0 N] >>>> >>>> The u field is defined in the nodes, with 2 components (u, v), hence >>>> the first "2". Then no components for edges/faces. >>>> For the p field, what I am trying to simulate is having nc >>>> (independent) DoF, sort of like having nc scalar fields, if that makes >>>> sense? Hence using: >>>> >>>> - N = nc >>>> - Also using the flag "-pres_petscspace_degree 0" >>>> >>>> But I'm not sure about those values. >>>> >>>> Then for simplicity numBC = 0 and all other arguments are NULL (will >>>> deal with boundary conditions later). >>>> >>>> With these arguments, I get the same as before e.g. >>>> >>>> -- nc = 3 (total dimension = 11) >>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>> >>>> Thanks, >>>> Noam >>>> >>>> On Friday, May 8th, 2026 at 1:25 PM, Matthew Knepley >>>> wrote: >>>> >>>> On Fri, May 8, 2026 at 8:01?AM Noam T. >>>> wrote: >>>> >>>>> Moving on to the values of the closure. >>>>> >>>>> Initially I create a vector for the DM with >>>>> DMCreateLocal/GlobalVector, which is used for e.g. the solution. Following >>>>> the example before, it will have size 8 (coordinates) + nc (for the p >>>>> field). >>>>> >>>>> I am getting a seemingly random order when I test with different >>>>> values of nc. Say, I initialize the vector (VecSetValues) with the >>>>> coordinates x_i, y_i . The rest nc components are set to zero. The closure >>>>> returns: >>>>> >>>>> -- nc = 1 >>>>> closure = y0 x1 y1 x2 y2 x3 y3 0 x0 >>>>> >>>>> -- nc = 3 >>>>> closure = y1 x2 y2 x3 y3 0 0 0 x0 y0 x1 >>>>> >>>>> -- nc = 7 >>>>> closure = y3 0 0 0 0 0 0 0 x0 y0 x1 y1 x2 y2 >>>>> >>>>> Looking at that output: >>>>> - The first value is always a y coordinate (second component of u >>>>> field). >>>>> - The position of the nc = 0 components change (starting with nc = 8, >>>>> all zero values come first, followed by the coordinates). >>>>> >>>>> Looking again at ex77.c ( >>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmPEhFG2l$ ), it says >>>>> the closure stacks up the fields, which aligns with the output above (all u >>>>> values, then all p values), but which is the starting point seems arbitrary. >>>>> >>>> >>>> This is likely to be a Section construction problem again. The Section >>>> fields are separated by DMPlexVecGetClosure(), sp you must not have defined >>>> the fields in the Section. If you put these calls into the code that I sent >>>> you, what do you get? >>>> >>>> Thanks, >>>> >>>> Matt >>>> >>>>> The vector is initialized as [x0 y0 .... x3 y3 0 0 ... 0], which may >>>>> not be correct to start with. >>>>> >>>>> I noticed I could instead use DMPlexVecGetClosureAtDepth( ..., depth = >>>>> 0, ...) so that I only get the u field DoF. But I will need to deal with >>>>> the p field values as well at some point. >>>>> >>>>> Thanks, >>>>> Noam >>>>> >>>>> On Friday, May 8th, 2026 at 11:05 AM, Matthew Knepley < >>>>> knepley at gmail.com> wrote: >>>>> >>>>> On Fri, May 8, 2026 at 5:08?AM Noam T. >>>>> wrote: >>>>> >>>>>> On the plus side, using the flags you provided in the previous email >>>>>> >>>>>> -dm_plex_simplex 0 -mech_petscspace_degree 1 -pres_petscspace_degree >>>>>> 1 -pres_petscspace_poly_tensor 0 -pres_petscdualspace_lagrange_continuity 0 >>>>>> >>>>>> the output of -ds_view is identical to yours, so setting up the >>>>>> fields should be correct. >>>>>> Thanks. I forgot about the flag >>>>>> "-[]_petscdualspace_lagrange_continuity 0" so as to have a discontinuous >>>>>> field. >>>>>> >>>>>> However, the closure size was still wrong. >>>>>> >>>>>> But, I figured out the reason: the manual set up of the section. >>>>>> For the argument "numDof" in DMPlexCreateSection(), I was computing >>>>>> the number of DoF with PetscSectionGetDof() (which was fine until now, >>>>>> since there was a single field), instead of PetscSectionGetFieldDof(). >>>>>> So as you previously suggested >>>>>> >>>>>> [...] It sounds like somehow you have a copy of your fields. >>>>>> >>>>>> >>>>>> the number of DoF per field were indeed "doubled" with the sum of >>>>>> both fields. >>>>>> >>>>> >>>>> Excellent. Let me know if you have any more issues. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>>> Thanks, >>>>>> Noam >>>>>> >>>>>> On Wednesday, May 6th, 2026 at 2:06 PM, Matthew Knepley < >>>>>> knepley at gmail.com> wrote: >>>>>> >>>>>> Okay, this is a problem with specifying the space I believe. You want >>>>>> a discontinuous space for pressure. >>>>>> >>>>>> Here is what I get >>>>>> >>>>>> Discrete System with 2 fields >>>>>> cell total dim 11 total comp 3 >>>>>> Field Q1 FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: Q1 (mech_) 1 MPI process >>>>>> type: vector >>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Space in 2 variables with 2 components, size 8 >>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>> type: tensor >>>>>> Space in 2 variables with 1 components, size 4 >>>>>> Tensor space of 2 subspaces (all identical) >>>>>> PetscSpace Object: sum component tensor component >>>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>> type: poly >>>>>> Space in 1 variables with 1 components, size 2 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>> type: sum >>>>>> Dual space with 2 components, size 8 >>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 4 >>>>>> Continuous tensor Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Field Q1 FEM 1 component (implicit) (Nq 4 Nqc 1) 1-jet >>>>>> PetscFE Object: Q1 (pres_) 1 MPI process >>>>>> type: basic >>>>>> Basic Finite Element in 2 dimensions with 1 components >>>>>> PetscSpace Object: Q1 (pres_) 1 MPI process >>>>>> type: poly >>>>>> Space in 2 variables with 1 components, size 3 >>>>>> Polynomial space of degree 1 >>>>>> PetscDualSpace Object: Q1 (pres_) 1 MPI process >>>>>> type: lagrange >>>>>> Dual space with 1 components, size 3 >>>>>> Discontinuous Lagrange dual space >>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>> Weak Form System with 2 fields >>>>>> >>>>>> I have attached the code I used. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Matt >>>>>> >>>>>> On Wed, May 6, 2026 at 9:32?AM Noam T. >>>>>> wrote: >>>>>> >>>>>>> >>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> >>>>>>> >>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>> >>>>>>> >>>>>>> I used nc = 3 when calling PetscFECreateDefault() for the pressure >>>>>>> field. Confusion between wanting 3 addditional DoF and components. >>>>>>> >>>>>>> With nc = 1 the closure size is 18 instead. >>>>>>> >>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>>>> this exact element. >>>>>>> >>>>>>> >>>>>>> I changed some of my code following the example and got rid of some >>>>>>> errors. But I'll have a more thorough look again. >>>>>>> >>>>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>>>> somehow you have a copy of your fields. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> >>>>>>> For reference, -ds_view with only one (displacements) fields shows: >>>>>>> >>>>>>> --- >>>>>>> Discrete System with 1 fields >>>>>>> cell total dim 8 total comp 2 >>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>> PetscFE Object: u (disp_) 1 MPI process >>>>>>> type: vector >>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>> PetscSpace Object: Q1 (disp_) 1 MPI process >>>>>>> type: sum >>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>> PetscSpace Object: Q1 (disp_sumcomp_) 1 MPI process >>>>>>> type: tensor >>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>> PetscSpace Object: sum component tensor component >>>>>>> (disp_sumcomp_tensorcomp_) 1 MPI process >>>>>>> type: poly >>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>> Polynomial space of degree 1 >>>>>>> PetscDualSpace Object: Q1 (disp_) 1 MPI process >>>>>>> type: sum >>>>>>> Dual space with 2 components, size 8 >>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>> type: lagrange >>>>>>> Dual space with 1 components, size 4 >>>>>>> Continuous tensor Lagrange dual space >>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>> Weak Form System with 1 fields >>>>>>> --- >>>>>>> >>>>>>> and -dm_view >>>>>>> >>>>>>> --- >>>>>>> DM Object: 1 MPI process >>>>>>> type: plex >>>>>>> DM_0x55c117db1b00_2 in 2 dimensions: >>>>>>> Number of 0-cells per rank: 4 >>>>>>> Number of 1-cells per rank: 4 >>>>>>> Number of 2-cells per rank: 1 >>>>>>> Labels: >>>>>>> celltype: 3 strata with value/size (0 (4), 1 (4), 4 (1)) >>>>>>> depth: 3 strata with value/size (0 (4), 1 (4), 2 (1)) >>>>>>> Cell Sets: 1 strata with value/size (1 (1)) >>>>>>> surf: 1 strata with value/size (1 (1)) >>>>>>> Face Sets: 2 strata with value/size (2 (1), 3 (1)) >>>>>>> edge_right: 1 strata with value/size (3 (1)) >>>>>>> edge_left: 1 strata with value/size (2 (1)) >>>>>>> Vertex Sets: 4 strata with value/size (4 (1), 5 (1), 6 (1), 7 (1)) >>>>>>> P1: 1 strata with value/size (4 (1)) >>>>>>> P2: 1 strata with value/size (5 (1)) >>>>>>> P3: 1 strata with value/size (6 (1)) >>>>>>> P4: 1 strata with value/size (7 (1)) >>>>>>> Field u: >>>>>>> adjacency FEM >>>>>>> /// With the second field, the two lines below are added >>>>>>> Field p: >>>>>>> adjacency FEM >>>>>>> --- >>>>>>> >>>>>>> DM set up >>>>>>> >>>>>>> DM :: dm_mesh >>>>>>> PetscFE :: u_FE, p_FE >>>>>>> PetscInt :: dim, dim_u_FE, tdim >>>>>>> PetscDS :: dm_ds >>>>>>> >>>>>>> >>>>>>> DMCreate(PETSC_COMM_WORLD, dm_mesh) >>>>>>> DMSetType(dm_mesh, DMPLEX) >>>>>>> DMGetDimension(dm_mesh, dim) // dim = 2 >>>>>>> DMSetFromOptions(dm_mesh) // this was called twice by mistake, now >>>>>>> removed; no changes that I can see >>>>>>> >>>>>>> -- using flags >>>>>>> >>>>>>> -dm_plex_filename QUAD1.msh >>>>>>> -dm_plex_interpolate 1 >>>>>>> -dm_plex_gmsh_use_generic >>>>>>> -dm_plex_gmsh_use_regions >>>>>>> -dm_plex_gmsh_multiple_tags >>>>>>> -dm_plex_gmsh_mark_vertices >>>>>>> >>>>>>> -- some operations with labels >>>>>>> >>>>>>> // u field >>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, PETSC_FALSE, >>>>>>> "mech_", PETSC_DETERMINE, u_FE) >>>>>>> PetscFEGetDimension(u_FE, dim_u_FE) // dim_u_FE = 8 >>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)u_FE) >>>>>>> >>>>>>> // p field >>>>>>> PetscFECreateDefault(PETSC_COMM_SELF, dim , 1, PETSC_FALSE, "pres_", >>>>>>> PETSC_DETERMINE, p_FE) >>>>>>> PetscFEGetDimension(p_FE, dim_p_FE) // dim_p_FE = 1 >>>>>>> DMAddField(dm_mesh, NULL, (PetscObject)p_FE) >>>>>>> >>>>>>> DMCreateDS(dm_mesh) >>>>>>> DMGetDS(dm_mesh, dm_DS) >>>>>>> PetscDSGetTotalDimension(dm_DS, tdim) // tdim >>>>>>> >>>>>>> with flags >>>>>>> >>>>>>> -disp_petscdualspace_lagrange_node_type equispaced >>>>>>> -disp_petscdualspace_lagrange_node_endpoints 1 >>>>>>> >>>>>>> >>>>>>> I believe these are all the DM related calls. >>>>>>> >>>>>>> Thanks, >>>>>>> Noam >>>>>>> >>>>>>> On Wednesday, May 6th, 2026 at 11:39 AM, Matthew Knepley < >>>>>>> knepley at gmail.com> wrote: >>>>>>> >>>>>>> On Wed, May 6, 2026 at 6:56?AM Noam T. >>>>>>> wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>> That is wrong. Are you sure about 22? >>>>>>>> >>>>>>>> >>>>>>>> That's what I get, from the argument "csize" in >>>>>>>> DMPlexGetVecClosure(). >>>>>>>> >>>>>>>> Here's the output of PetscDSView: >>>>>>>> >>>>>>>> Discrete System with 2 fields >>>>>>>> cell total dim 11 total comp 5 >>>>>>>> Field u FEM 2 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> PetscFE Object: u (mech_) 1 MPI process >>>>>>>> type: vector >>>>>>>> Vector Finite Element in 2 dimensions with 2 components >>>>>>>> PetscSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Space in 2 variables with 2 components, size 8 >>>>>>>> Sum space of 2 concatenated subspaces (all identical) >>>>>>>> PetscSpace Object: Q1 (mech_sumcomp_) 1 MPI process >>>>>>>> type: tensor >>>>>>>> Space in 2 variables with 1 components, size 4 >>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>> PetscSpace Object: sum component tensor component >>>>>>>> (mech_sumcomp_tensorcomp_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 1 variables with 1 components, size 2 >>>>>>>> Polynomial space of degree 1 >>>>>>>> PetscDualSpace Object: Q1 (mech_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Dual space with 2 components, size 8 >>>>>>>> Sum dual space of 2 concatenated subspaces (all identical) >>>>>>>> PetscDualSpace Object: Q1 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 4 >>>>>>>> Continuous tensor Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Field p FEM 3 components (implicit) (Nq 4 Nqc 1) 1-jet >>>>>>>> >>>>>>> >>>>>>> 1. Why does pressure have 3 components in 2D? >>>>>>> >>>>>>>> PetscFE Object: p (pres_) 1 MPI process >>>>>>>> type: vector >>>>>>>> Vector Finite Element in 2 dimensions with 3 components >>>>>>>> PetscSpace Object: Q0 (pres_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Space in 2 variables with 3 components, size 3 >>>>>>>> Sum space of 3 concatenated subspaces (all identical) >>>>>>>> PetscSpace Object: Q0 (pres_sumcomp_) 1 MPI process >>>>>>>> type: tensor >>>>>>>> Space in 2 variables with 1 components, size 1 >>>>>>>> Tensor space of 2 subspaces (all identical) >>>>>>>> PetscSpace Object: sum component tensor component >>>>>>>> (pres_sumcomp_tensorcomp_) 1 MPI process >>>>>>>> type: poly >>>>>>>> Space in 1 variables with 1 components, size 1 >>>>>>>> Polynomial space of degree 0 >>>>>>>> PetscDualSpace Object: Q0 (pres_) 1 MPI process >>>>>>>> type: sum >>>>>>>> Dual space with 3 components, size 3 >>>>>>>> Sum dual space of 3 concatenated subspaces (all identical) >>>>>>>> PetscDualSpace Object: Q0 1 MPI process >>>>>>>> type: lagrange >>>>>>>> Dual space with 1 components, size 1 >>>>>>>> Discontinuous tensor Lagrange dual space >>>>>>>> Quadrature on a quadrilateral of order 3 on 4 points (dim 2) >>>>>>>> Weak Form System with 2 fields >>>>>>>> >>>>>>>> using as the second field (dim = 2, nc = 3, prefix = "pres") and >>>>>>>> setting the FE object name to "p". >>>>>>>> >>>>>>>> The entry "cell total dim 10" agrees with the output of >>>>>>>> PetscFEGetTotalDimension(); "comp = 5" I assume is 2 (u) + 3 (p) >>>>>>>> >>>>>>>> However, the closure of a Vec is still 22. >>>>>>>> >>>>>>> >>>>>>> 2. Did you look at the incompressible example SNES ex69? It sets up >>>>>>> this exact element. >>>>>>> >>>>>>> 3. Please send me that code that sets up your DM. It sounds like >>>>>>> somehow you have a copy of your fields. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Matt >>>>>>> >>>>>>>> On Tuesday, May 5th, 2026 at 1:58 PM, Matthew Knepley < >>>>>>>> knepley at gmail.com> wrote: >>>>>>>> >>>>>>>> On Tue, May 5, 2026 at 9:06?AM Noam T. via petsc-users < >>>>>>>> petsc-users at mcs.anl.gov> wrote: >>>>>>>> >>>>>>>>> Hello, >>>>>>>>> >>>>>>>>> I am trying to work with a "mixed" FE discretization, where >>>>>>>>> besides the usual displacements DoF in nodes, there is an additional field >>>>>>>>> (e.g. pressure) that is also part of the system. This additional field has >>>>>>>>> a certain number of additional dof : p0, p1, p2... >>>>>>>>> >>>>>>>>> Looking at example 77 ( >>>>>>>>> https://urldefense.us/v3/__https://petsc.org/release/src/snes/tutorials/ex77.c.html__;!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmPEhFG2l$ >>>>>>>>> ) >>>>>>>>> this seems to be handled with an additional field, added to the DM. I've >>>>>>>>> tried so, but then I am getting from the DM arrays whose size/contents are >>>>>>>>> not what I expected. >>>>>>>>> >>>>>>>>> For example, a four-noded Q1 element (PetscFE created with a 2x2 >>>>>>>>> Gauss rule for quadrature), with just one field, a call to >>>>>>>>> DMPlexGetVecClosure() gives me an array with 8 entries (say, the >>>>>>>>> coordinates of the initial mesh): x = x0, y0, .... x3, y3 >>>>>>>>> >>>>>>>>> Then add the new field: >>>>>>>>> >>>>>>>>> PetscFECreateDefault(..., nc = 3, ..., p_FE) /* not sure about the >>>>>>>>> value of nc here */ >>>>>>>>> DMAddField(dm, ..., p_FE) >>>>>>>>> >>>>>>>>> The total dimension, from PetscDSGetTotalDimension(), is now 11 >>>>>>>>> (8 + 3). This results in a closure of size 22. >>>>>>>>> >>>>>>>> >>>>>>>> That is wrong. Are you sure about 22? >>>>>>>> >>>>>>>>> However, what I am looking for is a closure of size 8 + 3 i.e. the >>>>>>>>> original 8 DoF at the nodes, plus exactly 3 DoF (for the cell, so to speak) >>>>>>>>> p0, p1, p2, so that in a system with "block" matrices of the form >>>>>>>>> >>>>>>>>> [K_uu, K_up | K_pu, K_pp] { u | p } = RHS >>>>>>>>> >>>>>>>>> the unknowns {p} has size 3 per cell. Is this possible? I tried >>>>>>>>> some combinations of dim / nc for the new PetscFE, but when creating the DM >>>>>>>>> section I get errors e.g. >>>>>>>>> >>>>>>>> >>>>>>>> This is what you should get. I definitely have examples that do >>>>>>>> this. For example, here is Q1-P0 (I think that is what you are suggesting) >>>>>>>> for incompressible Stokes >>>>>>>> >>>>>>>> >>>>>>>> https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c?ref_type=heads*L3454__;Iw!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmPlSHXHm$ >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Matt >>>>>>>> >>>>>>>>> "point X has a number of DoF not divisible by 2 field components" >>>>>>>>> >>>>>>>>> Is this a hint that I should have 3 x dim new DoF, and simply not >>>>>>>>> deal with entries that I don't need? Or I am not setting up the section >>>>>>>>> properly (works with just one field)? >>>>>>>>> >>>>>>>>> Thank you, >>>>>>>>> Noam. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> What most experimenters take for granted before they begin their >>>>>>>> experiments is infinitely more interesting than any results to which their >>>>>>>> experiments lead. >>>>>>>> -- Norbert Wiener >>>>>>>> >>>>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> What most experimenters take for granted before they begin their >>>>>>> experiments is infinitely more interesting than any results to which their >>>>>>> experiments lead. >>>>>>> -- Norbert Wiener >>>>>>> >>>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> -- >>>>>> What most experimenters take for granted before they begin their >>>>>> experiments is infinitely more interesting than any results to which their >>>>>> experiments lead. >>>>>> -- Norbert Wiener >>>>>> >>>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>>>> >>>>> >>>>> >>>>> >>>> >>>> -- >>>> What most experimenters take for granted before they begin their >>>> experiments is infinitely more interesting than any results to which their >>>> experiments lead. >>>> -- Norbert Wiener >>>> >>>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>>> >>>> >>>> >>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >>> >>> >>> >>> >> >> -- >> What most experimenters take for granted before they begin their >> experiments is infinitely more interesting than any results to which their >> experiments lead. >> -- Norbert Wiener >> >> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ >> >> >> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eTZ7-cMXaCSxKzC7g_41ZsK5pIg4Fdd0z7AJ40SQKQgVT3lQ0pCSfCirjFBE2PQRI8geiF16BOIrmINwyWz3$ -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Mon May 18 08:42:38 2026 From: knepley at gmail.com (Matthew Knepley) Date: Mon, 18 May 2026 09:42:38 -0400 Subject: [petsc-users] Problem with KSPGetPC within FieldSplit context In-Reply-To: <89fd0a84-8b6e-4243-b7b1-ef7ea647bbda@upc.edu> References: <89fd0a84-8b6e-4243-b7b1-ef7ea647bbda@upc.edu> Message-ID: On Tue, Mar 24, 2026 at 2:31?PM Lucia Barandiaran via petsc-users < petsc-users at mcs.anl.gov> wrote: > Dear PETSc community, > > We recently updated PETSc libraries and came across with a problem with > FieldSplit preconditioning (our code is implemented in Fortran 90). > Hi Lucia, It looks like no one has answered, so I will try. I found this example doing what you want: https://urldefense.us/v3/__https://petsc.org/main/src/ksp/ksp/tutorials/ex7f.F90.html__;!!G_uCfscf7eWS!ffhItiXPRGqL12Cm8zfgA3cJ-lq0wTR-Ps_Yfj0WcTtLylJ7w1bKSGfj7gfbUC-DkI-SOf_Sn1OyZD0ylKex$ It seems that you need to initialize the pointer to null, and also the array starts at 1. Can you run the example? Thanks, Matt > In the older version, when calling PCFieldSplitGetSubKSP we declared the > subksp array as KSP and it worked perfectly. However, now we must declare > it as a Fortran pointer and allocate it before > calling PCFieldSplitGetSubKSP otherwise the code won't compile... > > With the new modification, that part of the code is the following: > > ****Variable declarations > > PetscInt :: n_splits_retrieved > IS :: IS_field(max_field) > KSP, pointer :: subksp_array(:) > PC :: subpc(max_field) > INTEGER(iwp) :: nfield, ifield > > **** FieldSplit Part **** > > ! Allocate Fortran array to hold the KSP contexts > ALLOCATE(subksp_array(n_splits_retrieved)) > > ! Second call to get the actual KSP contexts > CALL PCFieldSplitGetSubKSP(solver%pc, n_splits_retrieved, & > subksp_array, ierr) > > IF (n_splits_retrieved >= 2) THEN > DO ifield = 1, n_splits_retrieved > > ! Configure the KSP for the velocity block (field 0) > CALL KSPGetPC(subksp_array(ifield), subpc(ifield), ierr) > CALL KSPSetType(subksp_array(ifield), KSPGMRES, ierr) > CALL PCSetType(subpc(ifield), PCJACOBI, ierr) > ! Allows runtime options for sub-KSP > CALL KSPSetFromOptions(subksp_array(ifield), ierr) > ! Choose a viewer (stdout for example) > ! viewer = PETSC_VIEWER_STDOUT_WORLD > ! CALL PCView(subpc(ifield),viewer,ierr) > END DO > END IF > > When debugging the fortran code we observed that it stops with an error > when calling KSPGetPC and we can't figure out what are we doing wrong... > Maybe we need an interface when calling that function? > > Thanks very much for your time, > > Sincerely, > > Luc?a Barandiar?n > > Scientific software developer - Dracsys > > Collaborator at MECMAT group - Universitat Polit?cnica de Catalunya (UPC) > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ffhItiXPRGqL12Cm8zfgA3cJ-lq0wTR-Ps_Yfj0WcTtLylJ7w1bKSGfj7gfbUC-DkI-SOf_Sn1OyZJC2yvOw$ -------------- next part -------------- An HTML attachment was scrubbed... URL: