Separate components from the solution vector

62 views
Skip to first unread message

Alberto Salvadori

unread,
Apr 17, 2017, 10:09:22 AM4/17/17
to deal.II User Group

Hi,

thanks in advance for your suggestions.

I have been working on a small strain version of the three-fields formulation proposed in step 44. To this aim, I have been extended step 18, including some non linear material models.
It is my understanding that there are two ways of assembling and solving the system. One way simply extends the data structure of step 18, by using a different FESystem and solving a larger linear system at the end.
The second way is using block data-structures and solving via Shur complement. I aim at doing both, to get to learn.

The first strategy seems a little easier. I defined the FESystem following step 44

fe(FE_Q<dim>(poly_degree), dim, // displacement

   FE_DGPMonomial<dim>(poly_degree - 1), 1, // pressure

   FE_DGPMonomial<dim>(poly_degree - 1), 1), // dilatation


and with some minor adjustments I got to solve the system. I am having a little trouble in output data, since I want to separate displacements, pressure, and dilatation from the solution vector and I am not sure how this can be achieved.
This set of instructions:

  DataOut<dim> data_out;

  data_out.attach_dof_handler(dof_handler);

  

  // displacement output


  const std::vector<DataComponentInterpretation::DataComponentInterpretation>

    data_component_interpretation(dim, DataComponentInterpretation::component_is_part_of_vector);

  data_out.add_data_vector(system_solution,

                           std::vector<std::string> (dim, "displacement"),

                           DataOut<dim>::type_dof_data, data_component_interpretation);



is inappropriate as it stands, since the system_solution contains u,p,J and I want to extract u, p and J separately. Any hint?
Thanks 

Alberto

Wolfgang Bangerth

unread,
Apr 17, 2017, 10:24:23 AM4/17/17
to dea...@googlegroups.com
On 04/17/2017 08:09 AM, Alberto Salvadori wrote:
> DataOut<dim> data_out;
>
> data_out.attach_dof_handler(dof_handler);
>
>
>
> // displacement output
>
>
> conststd::vector<DataComponentInterpretation::DataComponentInterpretation>
>
> data_component_interpretation(dim,
> DataComponentInterpretation::component_is_part_of_vector);
>
> data_out.add_data_vector(system_solution,
>
> std::vector<std::string> (dim, "displacement"),
>
> DataOut<dim>::type_dof_data,
> data_component_interpretation);
>
>
>
> is inappropriate as it stands, since the system_solution contains u,p,J and I
> want to extract u, p and J separately. Any hint?

Alberto -- what happens if you do this? I suspect that if the DoFHandler you
attach above has components for both u,p,J and I, then passing in a
data_component_interpretation that only contains 'dim' elements will not work
-- you need to account for *all* vector components of the finite element upon
which the DoFhandler is built.

Best
W.

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

Alberto Salvadori

unread,
Apr 17, 2017, 10:37:58 AM4/17/17
to deal.II User Group, bang...@colostate.edu
Thanks Wolfgang.
What you surmised is exactly what it is happening, see the error message below.
I have no run-time errors in running this code

  const std::vector<DataComponentInterpretation::DataComponentInterpretation>

    data_component_interpretation(dim+2, DataComponentInterpretation::component_is_part_of_vector);

  data_out.add_data_vector(system_solution,

                           std::vector<std::string> (dim+2, "displacement"),

                           DataOut<dim>::type_dof_data, data_component_interpretation);


but I believe it is not what I want. I suppose that the data_out contains now 4 components for each node, two displacements, plus pressure and dilatation. I'd love to export displacements 
and the other two separately, but I am not sure how to achieve this. Doing this:

  data_out.add_data_vector(system_solution,

                           std::vector<std::string> (dim"displacement"),

                           DataOut<dim>::type_dof_data, data_component_interpretation);


provides an run-time error, which makes sense. 
Thanks,
Alberto



--------------------------------------------------------

An error occurred in line <984> of file <../source/numerics/data_out_dof_data.cc> in function

    void dealii::DataOut_DoFData<dealii::DoFHandler<2, 2>, 2, 2>::add_data_vector(const VectorType &, const std::vector<std::string> &, const dealii::DataOut_DoFData::DataVectorType, const std::vector<DataComponentInterpretation::DataComponentInterpretation> &) [VectorType = dealii::Vector<double>]

The violated condition was: 

    names.size() == dofs->get_fe().n_components()

The name and call sequence of the exception was:

    Exceptions::DataOut::ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components())

Additional Information: 

You have to give one name per component in your data vector. The number you gave was 2, but the number of components is 4.

Wolfgang Bangerth

unread,
Apr 17, 2017, 10:43:56 AM4/17/17
to Alberto Salvadori, deal.II User Group
On 04/17/2017 08:37 AM, Alberto Salvadori wrote:
> Thanks Wolfgang.
> What you surmised is exactly what it is happening, see the error message below.
> I have no run-time errors in running this code
>
> conststd::vector<DataComponentInterpretation::DataComponentInterpretation>
>
> data_component_interpretation(dim+2,
> DataComponentInterpretation::component_is_part_of_vector);
>
> data_out.add_data_vector(system_solution,
>
> std::vector<std::string> (dim+2, "displacement"),
>
> DataOut<dim>::type_dof_data,
> data_component_interpretation);
>
>
> but I believe it is not what I want. I suppose that the data_out contains now
> 4 components for each node, two displacements, plus pressure and dilatation.
> I'd love to export displacements
> and the other two separately, but I am not sure how to achieve this. Doing this:
>
> data_out.add_data_vector(system_solution,
>
> std::vector<std::string> (dim, "displacement"),
>
> DataOut<dim>::type_dof_data,
> data_component_interpretation);
>
>
> provides an run-time error, which makes sense.

Just provide the missing components to the data_out_interpretation -- take a
look at step-22 how this looks like.

Why do you want to output things separately? Why not have everything in one
output file? (It's possible to extract individual components using a
DataPostprocessor, but I don't usually understand why one would want to do that.)

Alberto Salvadori

unread,
Apr 17, 2017, 10:55:29 AM4/17/17
to deal.II User Group, alberto....@unibs.it, bang...@colostate.edu
Thanks Wolfgang,
step-22 is exactly what I was looking for. 
It works just fine, now.
Alberto

llf m

unread,
May 13, 2019, 10:45:29 PM5/13/19
to deal.II User Group
Dear Wolfgang,
I meet almost the same situation but a little different:
As I am dealing with a vector-valued problem like (disp_x,disp_y,another_quantitied), 
I want to output the strain tensor and I use the DataPostprocessorTensor which described in 
But as I am dealing with a vector-valued problem, 
how can I pass the displacement component of the solution to DataOut object?
...
StrainPostprocessor<dim> strain_disp;
...
data_out
.add_data_vector(present_solution, strain_disp);
...
in
 template <int dim>
 
void MartTran<dim>::output()
 
{
 std
::vector<std::string> solution_names(dim, "displacement");
 solution_names
.emplace_back("order_parameter");


 std
::vector<DataComponentInterpretation::DataComponentInterpretation>
 data_component_interpretation
(dim, DataComponentInterpretation::component_is_part_of_vector);

 data_component_interpretation
.push_back(DataComponentInterpretation::component_is_scalar);

 
StrainPostprocessor<dim> strain_disp;
 
DataOut<dim> data_out;
 data_out
.attach_dof_handler(dof_handler);
 data_out
.add_data_vector(present_solution,
 solution_names
,
 
DataOut<dim>::type_dof_data,
 data_component_interpretation
);
 
data_out.add_data_vector(present_solution, strain_disp);
 data_out
.build_patches();
 
const std::string filename =
   
"solution-" + Utilities::int_to_string(timestep_number, 5) + ".vtk";
 std
::ofstream output(filename);
 data_out
.write_vtk(output);
 
}

Obviously, the code aboved is wrong(?), because the solution is not only contains displacement  component,
but while running the code it seems that nothing is wrong and the vtk file also can be viewed with the strain_xx,strain_xy, strain_yx,strain_yy. 
Is it the right way to do that (and why it can?)
or
has to extract displacement component of solution and send it to data_out/datapostprocessor?


>(It's possible to extract individual components using a 
>DataPostprocessor, but I don't usually understand why one would want to do that.) 
Maybe this is the situation some one want to do that? :-x

Best,
M.
在 2017年4月17日星期一 UTC+8下午10:43:56,Wolfgang Bangerth写道:

Wolfgang Bangerth

unread,
May 16, 2019, 1:21:06 PM5/16/19
to dea...@googlegroups.com
On 5/13/19 8:45 PM, llf m wrote:
> I want to output the strain tensor and I use the *DataPostprocessorTensor
> *which described in
> https://dealii.org/developer/doxygen/deal.II/classDataPostprocessorTensor.html .
> But as I am dealing with a vector-valued problem,
> how can I pass the displacement component of the solution to *DataOut* object?

You can't. You will always pass *all* solution variables associated with one
DoFHandler to DataOut, and DataOut will always pass all solution variables on
to the DataPostprocessor object. The question is simply what you do in a
DataPostprocessor object with this information. You are, for example, free to
ignore certain components of the input vector. If you just copied the strain
postprocessor, this is probably exactly what happened: You just computed the
strain from the first dim vector components of your solution, and whether or
not there are additional vector components is none of your concerns -- i.e.,
you are simply ignoring them.

llf m

unread,
May 16, 2019, 7:53:20 PM5/16/19
to dea...@googlegroups.com
Thanks Wolfgang, I get the point!
Best
M.

Wolfgang Bangerth <bang...@colostate.edu> 于2019年5月17日周五 上午1:21写道:
--
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/27d0ba99-fa31-8cf8-c392-fec78f831481%40colostate.edu.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages