Extension of Step-18

55 views
Skip to first unread message

Raghunandan Pratoori

unread,
Sep 4, 2023, 10:57:19 PM9/4/23
to deal.II User Group
Hello team,

I want to implement Refinement during timesteps as described in Step-18, but for a much larger problem. I want to do this using a parallel vector for history_field. I want to clarify if the below is the correct implementation of it -

std::vector<std::vector<TrilinosWrappers::MPI::Vector<double>>> history_field_stress (dim, std::vector<TrilinosWrappers::MPI::Vector<double>>(dim)),
....

history_field.compress(VectorOperation::add);
....

Thanks in advance,
Raghunandan.

Wolfgang Bangerth

unread,
Sep 4, 2023, 10:59:49 PM9/4/23
to dea...@googlegroups.com
On 9/4/23 20:57, Raghunandan Pratoori wrote:
> I want to clarify if the below is the correct implementation of it -
>
> std::vector<std::vector<TrilinosWrappers::MPI::Vector<double>>>
> history_field_stress (dim,
> std::vector<TrilinosWrappers::MPI::Vector<double>>(dim)),
> ....
>
> history_field.compress(VectorOperation::add);
> ....

A good first test is to try and see what happens! In fact, that's often faster
than writing a question, and then waiting to see whether anyone answers it :-)

Best
W.

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


Raghunandan Pratoori

unread,
Sep 14, 2023, 5:50:15 PM9/14/23
to deal.II User Group
Thank you, Dr. Bangerth, for the prompt reply.

It took me some time to get around to trying it out. I am unable to figure out how to compress the vector.
The simple 'history_field.compress(VectorOperation::add);' did not work as expected. Can you tell me how to use it for type  std::vector<std::vector<TrilinosWrappers::MPI::Vector>>?

Best,
Raghunandan.

Wolfgang Bangerth

unread,
Sep 14, 2023, 7:49:11 PM9/14/23
to dea...@googlegroups.com
On 9/14/23 15:50, Raghunandan Pratoori wrote:
>
> It took me some time to get around to trying it out. I am unable to figure out
> how to compress the vector.
> The simple 'history_field.compress(VectorOperation::add);' did not work as
> expected. Can you tell me how to use it for type
> std::vector<std::vector<TrilinosWrappers::MPI::Vector>>?

Pratoori:
you will have to be more specific in explaining what doesn't work. "did not
work" is not enough for me to understand what you are doing, nor what is going
wrong. It's as if you were saying "I've tried to prove the Riemann hypothesis,
but the proof doesn't work. Can you tell me how to fix it?" without showing
what you already did :-)

Show us the code and the error message, and then we can perhaps help!

Raghunandan Pratoori

unread,
Sep 14, 2023, 10:13:53 PM9/14/23
to deal.II User Group
Hello Dr. Bangerth,

I apologize for the poor communication from my side.
Below are the changes I made to the refinement process in Step-18 in red:

typedef TrilinosWrappers::MPI::Vector vectorType;
std::vector<std::vector<vectorType>>   history_field (dim, std::vector< Vector<double> >(dim));
std::vector< std::vector< Vector<double> > >
             local_history_values_at_qpoints (dim, std::vector< Vector<double> >(dim)),
             local_history_fe_values (dim, std::vector< Vector<double> >(dim));

for (unsigned int i=0; i<dim; ++i)
  for (unsigned int j=0; j<dim; ++j)
  {
    history_field[i][j].reinit(locally_owned_dofs, locally_relevant_dofs, mpi_communicator);
    local_history_values_at_qpoints[i][j].reinit(quadrature.size());
    local_history_fe_values[i][j].reinit(history_fe.n_dofs_per_cell());
  }
.
.
[Calculate the global field]
.
.
history_field.compress(VectorOperation::add);

The above section of code gives an error during the compress operation. The error message is - 
‘class std::vector<std::vector<dealii::TrilinosWrappers::MPI::Vector, std::allocator<dealii::TrilinosWrappers::MPI::Vector> > >’ has no member named ‘compress’

The above error message is expected as the compress operation is not defined for that datatype. However, I am unsure how to do the compress operation, as mentioned in Step-18. Please advice.

Best,
Raghunandan.

Wolfgang Bangerth

unread,
Sep 14, 2023, 10:28:23 PM9/14/23
to dea...@googlegroups.com
On 9/14/23 20:13, Raghunandan Pratoori wrote:
>
> The above section of code gives an error during the compress operation. The
> error message is -
> ‘class std::vector<std::vector<dealii::TrilinosWrappers::MPI::Vector,
> std::allocator<dealii::TrilinosWrappers::MPI::Vector> > >’ has no member named
> ‘compress’
>
> The above error message is expected as the compress operation is not defined
> for that datatype. However, I am unsure how to do the compress operation, as
> mentioned in Step-18. Please advice.

Well, as you already note, there is no compress() member function on
std::vector. But you don't want to call compress() on the std::vector anyway,
you want to call it on the individual TrilinosWrappers::MPI::Vector objects
that are stored in the std::vector. The following should do:

for (unsigned int i=0; i<history_field.size(); ++i)
for (unsigned int j=0; j<history_field[i].size(); ++j)
history_field[i][j].compress(...);
Reply all
Reply to author
Forward
0 new messages