DataPostprocessor Implementation For Evaluating Vector Field

50 views
Skip to first unread message

Baoyun Ge

unread,
Jul 25, 2017, 3:07:19 PM7/25/17
to deal.II User Group
Hi,

I am converting a scalar field (solution from the Laplace's equation) to a gradient field for visualization in software like Paraview. After searching around the forum, I got a sense that I need to implement a derived class from DataPostprocessor and implement the function evaluate_vector_field(&, &).

Here's my first attempt:

class Postprocessor : public DataPostprocessor<2>
{
public:
 
virtual void evaluate_vector_field (const DataPostprocessorInputs::Vector<2> &inputs,
                      std
::vector<Vector<double> >             &computed_quantities) const;

 
virtual std::vector<std::string> get_names () const;

 
virtual std::vector<DataComponentInterpretation::DataComponentInterpretation> get_data_component_interpretation () const;

 
virtual UpdateFlags get_needed_update_flags () const;
};

std
::vector<std::string> Postprocessor :: get_names () const
{
  std
::vector<std::string> solution_names (2, "elecfield");
 
return solution_names;
}

std
::vector<DataComponentInterpretation::DataComponentInterpretation> Postprocessor :: get_data_component_interpretation () const
{
  std
::vector<DataComponentInterpretation::DataComponentInterpretation> interpretation (2,
                                           
DataComponentInterpretation::component_is_part_of_vector);

 
return interpretation;
}

UpdateFlags Postprocessor :: get_needed_update_flags ()  const
{
 
return update_gradients;
}

void Postprocessor :: evaluate_vector_field (const DataPostprocessorInputs::Vector<2> &inputs,
                         std
::vector<Vector<double> >             &computed_quantities) const
{
 
const unsigned int n_quadrature_points = inputs.solution_gradients.size ();

 
// for (unsigned int q = 0; q < n_quadrature_points; ++q)  
 
for (unsigned int q = 0; q < 1; ++q)
   
{
     
for (unsigned int d = 0; d < 2; ++d)
   
{
     
const Tensor<1, 2> gradient_comp = inputs.solution_gradients[q][d];
      computed_quantities
[q](d) = gradient_comp;
   
}
   
}
}

At the end, I know it's wrong to assign a Tensor<1, 2> type to a double type, but I don't know what I should do next to "parse" the tensor into the x-, y-component of the gradients. Any suggestions?

Also, I don't understand the description about solution_gradients in this page. Specifically the following line. What are the outer vector and inner vector? and What's the difference between the places where they are evaluated? Isn't the evaluation points the same as the finite element field for which output will be generated? I guess this is tide to the index d in the above code.

The outer vector runs over the evaluation points, whereas the inner vector runs over the components of the finite element field for which output will be generated.

Thanks!
Baoyun Ge

Wolfgang Bangerth

unread,
Jul 26, 2017, 2:06:44 PM7/26/17
to dea...@googlegroups.com, Baoyun Ge
On 07/25/2017 01:07 PM, Baoyun Ge wrote:
> |
>
> voidPostprocessor::evaluate_vector_field
> (constDataPostprocessorInputs::Vector<2>&inputs,
> std::vector<Vector<double>>&computed_quantities)const
> {
> constunsignedintn_quadrature_points =inputs.solution_gradients.size ();
>
> // for (unsigned int q = 0; q < n_quadrature_points; ++q)
> for(unsignedintq =0;q <1;++q)
> {
> for(unsignedintd =0;d <2;++d)
> {
> constTensor<1,2>gradient_comp =inputs.solution_gradients[q][d];
> computed_quantities[q](d)=gradient_comp;
> }
> }
> }
> |
>
> At the end, I know it's wrong to assign a Tensor<1, 2> type to a double type,
> but I don't know what I should do next to "parse" the tensor into the x-,
> y-component of the gradients. Any suggestions?

The function in question needs to compute two output quantities (d=1 and 2),
and you have the components of gradient_comp. So the correct look would simply be

for (unsigned int d = 0; d < 2; ++d)
{
const Tensor<1, 2> gradient_comp = inputs.solution_gradients[q][d];
computed_quantities[q](d) = gradient_comp[d];
}

By the way, to make your code simpler, you may want to derive your class from
DataPostprocessorVector instead of simply DataPostprocessor.

Best
W.


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

Reply all
Reply to author
Forward
0 new messages