Extracting a component of FESystem for use elsewhere

57 views
Skip to first unread message

Corbin Foucart

unread,
Jun 16, 2021, 11:21:56 PM6/16/21
to deal.II User Group
Hi everyone,

This might be a simple question, but I haven't found a straightforward answer in the "handling vector-valued problems" documentation.

If I have a Vector<double> which stores the solution to an FESystem, say 3 FE_DGQ fields for u, v, p, and I want to extract a new Vector<double> which corresponds to only the pressure, what's the best way to do this?

I'm not looking to write the data out for visualization, how to use the DataComponentInterpretation classes is clear to me. What I want to do is extract a separate Vector<double> which I can then add to another DG scalar field of the same type as p in the (u,v,p) system.

I don't need p at the quadrature points, only the nodal values to add to another nodal field.

Any advice would be appreciated!
Corbin

Corbin Foucart

unread,
Jun 17, 2021, 1:34:02 AM6/17/21
to deal.II User Group
I've found one way to do this, but I imagine it's not optimal:
  • call DoFRenumbering::component_wise(fesys_dofh)
  • Do the finite element solve
  • then copy from one vector to another using the number of dofs in that component and an offset
  • This isn't great, however, because I'd rather store the fesys dofh cell-by-cell for memory-friendliness, as almost all other operations are elemental
If there's a better way, I'd be glad to know :)

Best,
Corbin 

Paras Kumar

unread,
Jun 17, 2021, 2:47:49 AM6/17/21
to dea...@googlegroups.com
Hi Corbin,

The cell-wise solution corresponding to the p field could be determined as follows:
```
dealii::FEValuesExtractorScalar pressureExtractor(2); //assuming you have three scalar fields and pressure is the last one
dealii::Vector<double> solVecPerCell(nDOFsPerCell);
feValues[pressureExtractor].get_function_values(totalSolution, solVecPerCell); // here only the values corresponding to pressure are filled.
```
You could then use this cell-wise values of the p-field in whatever manner you wish.

Another alternative approach, which I employ, is to use BlockVector object, wherein one can easily get the total solution vector corresponding to any of the fields.

Best regards,
Paras

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/2bb1442a-830e-46a2-8639-8eec8b101e15n%40googlegroups.com.

Corbin Foucart

unread,
Jun 17, 2021, 3:13:43 AM6/17/21
to deal.II User Group
Hi Paras,

Thanks for the reply!

```
dealii::FEValuesExtractorScalar pressureExtractor(2); //assuming you have three scalar fields and pressure is the last one
dealii::Vector<double> solVecPerCell(nDOFsPerCell);
feValues[pressureExtractor].get_function_values(totalSolution, solVecPerCell); // here only the values corresponding to pressure are filled.
```
 
Suppose I have 2 DG elements of order 3, i.e., 16 DoFs per element. U, v, p -> 2*(16)*3 = 96 DoF in totalSolution.

It's my understanding that this will extract the pressure values from totalSolution into the *cell-local* Vector<double> solVecPerCell of length 16 (assuming FEValues was instantiated with a quadrature rule that contained the nodal locations, rather than the usual quadrature points). However, this isn't what I want to do. I want to take all 32 of the p nodal values and add them to another field with a DoFHandler instantiated using a single FE_DGQ element, rather than a system--therefore with a solution Vector<double> containing 32 DoF.

Maybe the way to go is a BlockVector object as you alternatively suggest, but my problem doesn't inherently have blocks. I'm simply looking to add, for example, the pressure field to another scalar DG field unrelated to the system; I'd rather keep the FESystem organized by (u,v,p) on each cell.

Best,
Corbin  

Wolfgang Bangerth

unread,
Jun 17, 2021, 11:48:14 AM6/17/21
to dea...@googlegroups.com
On 6/17/21 1:13 AM, Corbin Foucart wrote:
>
> Maybe the way to go is a BlockVector object as you alternatively suggest, but
> my problem doesn't inherently have blocks. I'm simply looking to add, for
> example, the pressure field to another scalar DG field unrelated to the
> system; I'd rather keep the FESystem organized by (u,v,p) on each cell.

Corbin,
if you don't want to go the route of block vectors, take a look at
DoFTools::extract_dofs(), which provides you with an index set of all of the
DoFs that correspond to specific vector components.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Reply all
Reply to author
Forward
0 new messages