Debian Codegraph @

include/deal.II/lac/trilinos_vector.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2008 - 2025 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_trilinos_vector_h
16 #define dealii_trilinos_vector_h
17
18
19 #include <deal.II/base/config.h>
20
21 #ifdef DEAL_II_WITH_TRILINOS
22 # include <deal.II/base/index_set.h>
23 # include <deal.II/base/mpi_stub.h>
24 # include <deal.II/base/partitioner.h>
25
26 # include <deal.II/lac/exceptions.h>
27 # include <deal.II/lac/read_vector.h>
28 # include <deal.II/lac/vector.h>
29 # include <deal.II/lac/vector_operation.h>
30 # include <deal.II/lac/vector_type_traits.h>
31
32 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
33 # include <Epetra_ConfigDefs.h>
34 # include <Epetra_FEVector.h>
35 # include <Epetra_LocalMap.h>
36 # include <Epetra_Map.h>
37 # include <Epetra_MpiComm.h>
38 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
39
40 # include <memory>
41 # include <utility>
42 # include <vector>
43
44 DEAL_II_NAMESPACE_OPEN
45
46 // Forward declarations
47 # ifndef DOXYGEN
48 namespace LinearAlgebra
49 {
50 // Forward declaration
51 template <typename Number>
52 class ReadWriteVector;
53 } // namespace LinearAlgebra
54 # endif
55
56 /**
57 * @addtogroup TrilinosWrappers
58 * @{
59 */
60
61 /**
62 * A namespace in which wrapper classes for Trilinos objects reside.
63 *
64 * @ingroup TrilinosWrappers
65 */
66 namespace TrilinosWrappers
67 {
68 class SparseMatrix;
69
70 /**
71 * This class defines type aliases that are used in vector classes
72 * within the TrilinosWrappers namespace.
73 */
74 class VectorTraits
75 {
76 public:
77 using size_type = dealii::types::global_dof_index;
78 };
79
80 /**
81 * @cond internal
82 */
83
84 /**
85 * A namespace for internal implementation details of the TrilinosWrapper
86 * members.
87 *
88 * @ingroup TrilinosWrappers
89 */
90 namespace internal
91 {
92 /**
93 * This class implements a wrapper for accessing the Trilinos vector in
94 * the same way as we access deal.II objects: it is initialized with a
95 * vector and an element within it, and has a conversion operator to
96 * extract the scalar value of this element. It also has a variety of
97 * assignment operator for writing to this one element.
98 *
99 * @ingroup TrilinosWrappers
100 */
101 class VectorReference
102 {
103 private:
104 using size_type = VectorTraits::size_type;
105
106 /**
107 * Constructor. It is made private so as to only allow the actual vector
108 * class to create it.
109 */
110 VectorReference(MPI::Vector &vector, const size_type index);
111
112 public:
113 /**
114 * Copy constructor.
115 */
116 VectorReference(const VectorReference &) = default;
117
118 /**
119 * This looks like a copy operator, but does something different than
120 * usual. In particular, it does not copy the member variables of this
121 * reference. Rather, it handles the situation where we have two vectors
122 * @p v and @p w, and assign elements like in <tt>v(i)=w(i)</tt>. Here,
123 * both left and right hand side of the assignment have data type
124 * VectorReference, but what we really mean is to assign the vector
125 * elements represented by the two references. This operator implements
126 * this operation. Note also that this allows us to make the assignment
127 * operator const.
128 */
129 const VectorReference &
130 operator=(const VectorReference &r) const;
131
132 /**
133 * Same as above but for non-const reference objects.
134 */
135 VectorReference &
136 operator=(const VectorReference &r);
137
138 /**
139 * Set the referenced element of the vector to <tt>s</tt>.
140 */
141 const VectorReference &
142 operator=(const TrilinosScalar &s) const;
143
144 /**
145 * Add <tt>s</tt> to the referenced element of the vector->
146 */
147 const VectorReference &
148 operator+=(const TrilinosScalar &s) const;
149
150 /**
151 * Subtract <tt>s</tt> from the referenced element of the vector->
152 */
153 const VectorReference &
154 operator-=(const TrilinosScalar &s) const;
155
156 /**
157 * Multiply the referenced element of the vector by <tt>s</tt>.
158 */
159 const VectorReference &
160 operator*=(const TrilinosScalar &s) const;
161
162 /**
163 * Divide the referenced element of the vector by <tt>s</tt>.
164 */
165 const VectorReference &
166 operator/=(const TrilinosScalar &s) const;
167
168 /**
169 * Convert the reference to an actual value, i.e. return the value of
170 * the referenced element of the vector.
171 */
172 operator TrilinosScalar() const;
173
174 /**
175 * Exception
176 */
177 DeclException1(ExcTrilinosError,
178 int,
179 << "An error with error number " << arg1
180 << " occurred while calling a Trilinos function");
181
182 private:
183 /**
184 * Point to the vector we are referencing.
185 */
186 MPI::Vector &vector;
187
188 /**
189 * Index of the referenced element of the vector.
190 */
191 const size_type index;
192
193 // Make the vector class a friend, so that it can create objects of the
194 // present type.
195 friend class ::dealii::TrilinosWrappers::MPI::Vector;
196 };
197 } // namespace internal
198 /**
199 * @endcond
200 */
201
202 # ifndef DEAL_II_WITH_64BIT_INDICES
203 // define a helper function that queries the global ID of local ID of
204 // an Epetra_BlockMap object by calling either the 32- or 64-bit
205 // function necessary.
206 inline int
207 gid(const Epetra_BlockMap &map, int i)
208 {
209 return map.GID(i);
210 }
211 # else
212 // define a helper function that queries the global ID of local ID of
213 // an Epetra_BlockMap object by calling either the 32- or 64-bit
214 // function necessary.
215 inline long long int
216 gid(const Epetra_BlockMap &map, int i)
217 {
218 return map.GID64(i);
219 }
220 # endif
221
222 /**
223 * Namespace for Trilinos vector classes that work in parallel over MPI.
224 *
225 * @ingroup TrilinosWrappers
226 */
227 namespace MPI
228 {
229 class BlockVector;
230
231 /**
232 * This class implements a wrapper to use the Trilinos distributed vector
233 * class Epetra_FEVector, the (parallel) partitioning of which
234 * is governed by an Epetra_Map.
235 * The Epetra_FEVector is precisely the kind of vector
236 * we deal with all the time - we probably get it from some assembly
237 * process, where also entries not locally owned might need to written and
238 * hence need to be forwarded to the owner.
239 *
240 * The interface of this class is modeled after the existing Vector class in
241 * deal.II. It has almost the same member functions, and is often
242 * exchangeable. However, since Trilinos only supports a single scalar type
243 * (double), it is not templated, and only works with that type.
244 *
245 * Note that Trilinos only guarantees that operations do what you expect
246 * if the function @p GlobalAssemble has been called after vector assembly
247 * in order to distribute the data. This is necessary since some processes
248 * might have accumulated data of elements that are not owned by
249 * themselves, but must be sent to the owning process. In order to avoid
250 * using the wrong data, you need to call Vector::compress() before you
251 * actually use the vectors.
252 *
253 * <h3>Parallel communication model</h3>
254 *
255 * The parallel functionality of Trilinos is built on top of the Message
256 * Passing Interface (MPI). MPI's communication model is built on
257 * collective communications: if one process wants something from another,
258 * that other process has to be willing to accept this communication. A
259 * process cannot query data from another process by calling a remote
260 * function, without that other process expecting such a transaction. The
261 * consequence is that most of the operations in the base class of this
262 * class have to be called collectively. For example, if you want to
263 * compute the l2 norm of a parallel vector, @em all processes across
264 * which this vector is shared have to call the @p l2_norm function. If
265 * you don't do this, but instead only call the @p l2_norm function on one
266 * process, then the following happens: This one process will call one of
267 * the collective MPI functions and wait for all the other processes to
268 * join in on this. Since the other processes don't call this function,
269 * you will either get a time-out on the first process, or, worse, by the
270 * time the next a call to a Trilinos function generates an MPI message on
271 * the other processes, you will get a cryptic message that only a subset
272 * of processes attempted a communication. These bugs can be very hard to
273 * figure out, unless you are well-acquainted with the communication model
274 * of MPI, and know which functions may generate MPI messages.
275 *
276 * One particular case, where an MPI message may be generated unexpectedly
277 * is discussed below.
278 *
279 *
280 * <h3>Accessing individual elements of a vector</h3>
281 *
282 * Trilinos does of course allow read access to individual elements of a
283 * vector, but in the distributed case only to elements that are stored
284 * locally. We implement this through calls like <tt>d=vec(i)</tt>.
285 * However, if you access an element outside the locally stored range, an
286 * exception is generated.
287 *
288 * In contrast to read access, Trilinos (and the respective deal.II
289 * wrapper classes) allow to write (or add) to individual elements of
290 * vectors, even if they are stored on a different process. You can do
291 * this by writing into or adding to elements using the syntax
292 * <tt>vec(i)=d</tt> or <tt>vec(i)+=d</tt>, or similar operations. There
293 * is one catch, however, that may lead to very confusing error messages:
294 * Trilinos requires application programs to call the compress() function
295 * when they switch from performing a set of operations that add to
296 * elements, to performing a set of operations that write to elements. The
297 * reasoning is that all processes might accumulate addition operations to
298 * elements, even if multiple processes write to the same elements. By the
299 * time we call compress() the next time, all these additions are
300 * executed. However, if one process adds to an element, and another
301 * overwrites to it, the order of execution would yield non-deterministic
302 * behavior if we don't make sure that a synchronization with compress()
303 * happens in between.
304 *
305 * In order to make sure these calls to compress() happen at the
306 * appropriate time, the deal.II wrappers keep a state variable that store
307 * which is the presently allowed operation: additions or writes. If it
308 * encounters an operation of the opposite kind, it calls compress() and
309 * flips the state. This can sometimes lead to very confusing behavior, in
310 * code that may for example look like this:
311 *
312 * @code
313 * TrilinosWrappers::MPI::Vector vector;
314 * // do some write operations on the vector
315 * for (size_type i=0; i<vector->size(); ++i)
316 * vector(i) = i;
317 *
318 * // do some additions to vector elements, but
319 * // only for some elements
320 * for (size_type i=0; i<vector->size(); ++i)
321 * if (some_condition(i) == true)
322 * vector(i) += 1;
323 *
324 * // do another collective operation
325 * const double norm = vector->l2_norm();
326 * @endcode
327 *
328 * This code can run into trouble: by the time we see the first addition
329 * operation, we need to flush the overwrite buffers for the vector, and
330 * the deal.II library will do so by calling compress(). However, it will
331 * only do so for all processes that actually do an addition -- if the
332 * condition is never true for one of the processes, then this one will
333 * not get to the actual compress() call, whereas all the other ones do.
334 * This gets us into trouble, since all the other processes hang in the
335 * call to flush the write buffers, while the one other process advances
336 * to the call to compute the l2 norm. At this time, you will get an error
337 * that some operation was attempted by only a subset of processes. This
338 * behavior may seem surprising, unless you know that write/addition
339 * operations on single elements may trigger this behavior.
340 *
341 * The problem described here may be avoided by placing additional calls
342 * to compress(), or making sure that all processes do the same type of
343 * operations at the same time, for example by placing zero additions if
344 * necessary.
345 *
346 *
347 * <h3>Ghost elements of vectors</h3>
348 *
349 * Parallel vectors come in two kinds: without and with ghost elements.
350 * Vectors without ghost elements uniquely partition the vector elements
351 * between processors: each vector entry has exactly one processor that
352 * owns it. For such vectors, you can read those elements that the
353 * processor you are currently on owns, and you can write into any element
354 * whether you own it or not: if you don't own it, the value written or
355 * added to a vector element will be shipped to the processor that owns
356 * this vector element the next time you call compress(), as described
357 * above.
358 *
359 * What we call a 'ghosted' vector (see
360 * @ref GlossGhostedVector "vectors with ghost elements"
361 * ) is simply a view of the parallel vector where the element
362 * distributions overlap. The 'ghosted' Trilinos vector in itself has no
363 * idea of which entries are ghosted and which are locally owned. In fact,
364 * a ghosted vector may not even store all of the elements a non- ghosted
365 * vector would store on the current processor. Consequently, for
366 * Trilinos vectors, there is no notion of an 'owner' of vector elements
367 * in the way we have it in the non-ghost case view.
368 *
369 * This explains why we do not allow writing into ghosted vectors on the
370 * Trilinos side: Who would be responsible for taking care of the
371 * duplicated entries, given that there is not such information as locally
372 * owned indices? In other words, since a processor doesn't know which
373 * other processors own an element, who would it send a value to if one
374 * were to write to it? The only possibility would be to send this
375 * information to <i>all</i> other processors, but that is clearly not
376 * practical. Thus, we only allow reading from ghosted vectors, which
377 * however we do very often.
378 *
379 * So how do you fill a ghosted vector if you can't write to it? This only
380 * happens through the assignment with a non-ghosted vector. It can go
381 * both ways (non-ghosted is assigned to a ghosted vector, and a ghosted
382 * vector is assigned to a non-ghosted one; the latter one typically only
383 * requires taking out the locally owned part as most often ghosted
384 * vectors store a superset of elements of non-ghosted ones). In general,
385 * you send data around with that operation and it all depends on the
386 * different views of the two vectors. Trilinos also allows you to get
387 * subvectors out of a big vector that way.
388 *
389 *
390 * <h3>Thread safety of Trilinos vectors</h3>
391 *
392 * When writing into Trilinos vectors from several threads in shared
393 * memory, several things must be kept in mind as there is no built-in
394 * locks in this class to prevent data races. Simultaneous access to the
395 * same vector entry at the same time results in data races and must be
396 * explicitly avoided by the user. However, it is possible to access
397 * <b>different</b> entries of the vector from several threads
398 * simultaneously when only one MPI process is present or the vector has
399 * been constructed with an additional index set for ghost entries in
400 * write mode.
401 *
402 * @ingroup TrilinosWrappers
403 * @ingroup Vectors
404 */
405 class Vector : public ReadVector<TrilinosScalar>
406 {
407 public:
408 /**
409 * Declare some of the standard types used in all containers. These types
410 * parallel those in the <tt>C</tt> standard libraries
411 * <tt>vector<...></tt> class.
412 */
413 using value_type = TrilinosScalar;
414 using real_type = TrilinosScalar;
415 using size_type = VectorTraits::size_type;
416 using iterator = value_type *;
417 using const_iterator = const value_type *;
418 using reference = internal::VectorReference;
419 using const_reference = const internal::VectorReference;
420
421 /**
422 * @name 1: Basic Object-handling
423 */
424 /** @{ */
425 /**
426 * Default constructor that generates an empty (zero size) vector. The
427 * function <tt>reinit()</tt> will have to give the vector the correct
428 * size and distribution among processes in case of an MPI run.
429 */
430 Vector();
431
432 /**
433 * Copy constructor using the given vector.
434 */
435 Vector(const Vector &v);
436
437 /**
438 * This constructor takes an IndexSet that defines how to distribute the
439 * individual components among the MPI processors. Since it also
440 * includes information about the size of the vector, this is all we
441 * need to generate a %parallel vector.
442 *
443 * Depending on whether the @p parallel_partitioning argument uniquely
444 * subdivides elements among processors or not, the resulting vector may
445 * or may not have ghost elements. See the general documentation of this
446 * class for more information.
447 *
448 * In case the provided IndexSet forms an overlapping partitioning,
449 * it is not clear which elements are owned by which process and
450 * locally_owned_elements() will return an IndexSet of size zero.
451 *
452 * @see
453 * @ref GlossGhostedVector "vectors with ghost elements"
454 */
455 explicit Vector(const IndexSet &parallel_partitioning,
456 const MPI_Comm communicator = MPI_COMM_WORLD);
457
458 /**
459 * Creates a ghosted parallel vector.
460 *
461 * Depending on whether the @p ghost argument uniquely subdivides
462 * elements among processors or not, the resulting vector may or may not
463 * have ghost elements. See the general documentation of this class for
464 * more information.
465 *
466 * @see
467 * @ref GlossGhostedVector "vectors with ghost elements"
468 */
469 Vector(const IndexSet &local,
470 const IndexSet &ghost,
471 const MPI_Comm communicator = MPI_COMM_WORLD);
472
473 /**
474 * Copy constructor from the TrilinosWrappers vector class. Since a
475 * vector of this class does not necessarily need to be distributed
476 * among processes, the user needs to supply us with an IndexSet and an
477 * MPI communicator that set the partitioning details.
478 *
479 * Depending on whether the @p parallel_partitioning argument uniquely
480 * subdivides elements among processors or not, the resulting vector may
481 * or may not have ghost elements. See the general documentation of this
482 * class for more information.
483 *
484 * @see
485 * @ref GlossGhostedVector "vectors with ghost elements"
486 */
487 Vector(const IndexSet &parallel_partitioning,
488 const Vector &v,
489 const MPI_Comm communicator = MPI_COMM_WORLD);
490
491 /**
492 * Copy-constructor from deal.II vectors. Sets the dimension to that of
493 * the given vector, and copies all the elements.
494 *
495 * Depending on whether the @p parallel_partitioning argument uniquely
496 * subdivides elements among processors or not, the resulting vector may
497 * or may not have ghost elements. See the general documentation of this
498 * class for more information.
499 *
500 * @see
501 * @ref GlossGhostedVector "vectors with ghost elements"
502 */
503 template <typename Number>
504 Vector(const IndexSet &parallel_partitioning,
505 const dealii::Vector<Number> &v,
506 const MPI_Comm communicator = MPI_COMM_WORLD);
507
508 /**
509 * Move constructor. Creates a new vector by stealing the internal data
510 * of the vector @p v.
511 *
512 * @note In order for this constructor to leave the moved-from object in a
513 * valid state it must allocate memory (in this case, an empty
514 * Epetra_FEVector) - hence it cannot be marked as noexcept.
515 */
516 Vector(Vector &&v); // NOLINT
517
518 /**
519 * Destructor.
520 */
521 ~Vector() override = default;
522
523 /**
524 * Release all memory and return to a state just like after having called
525 * the default constructor.
526 */
527 void
528 clear();
529
530 /**
531 * Reinit functionality. This function sets the calling vector to the
532 * dimension and the parallel distribution of the input vector, but does
533 * not copy the elements in <tt>v</tt>. If <tt>omit_zeroing_entries</tt>
534 * is <tt>false</tt>, the elements in the vector are initialized with
535 * zero. If it is set to <tt>true</tt>, the vector entries are in an
536 * unspecified state and the user has to set all elements. In the
537 * current implementation, this method does not touch the vector entries
538 * in case the vector layout is unchanged from before, otherwise entries
539 * are set to zero. Note that this behavior might change between
540 * releases without notification.
541 *
542 * This function has a third argument, <tt>allow_different_maps</tt>,
543 * that allows for an exchange of data between two equal-sized vectors
544 * (but being distributed differently among the processors). A trivial
545 * application of this function is to generate a replication of a whole
546 * vector on each machine, when the calling vector is built with a map
547 * consisting of all indices on each process, and <tt>v</tt>
548 * is a distributed vector. In this case, the variable
549 * <tt>omit_zeroing_entries</tt> needs to be set to <tt>false</tt>,
550 * since it does not make sense to exchange data between differently
551 * parallelized vectors without touching the elements.
552 */
553 void
554 reinit(const Vector &v,
555 const bool omit_zeroing_entries = false,
556 const bool allow_different_maps = false);
557
558 /**
559 * Reinit functionality. This function destroys the old vector content
560 * and generates a new one based on the input partitioning. The flag
561 * <tt>omit_zeroing_entries</tt> determines whether the vector should be
562 * filled with zeros (if set to <tt>false</tt>) or left in an unspecified
563 * state (if the flag is set to <tt>true</tt>). In the current
564 * implementation, this method still sets the entries to zero, but this
565 * might change between releases without notification.
566 *
567 * Depending on whether the @p parallel_partitioning argument uniquely
568 * subdivides elements among processors or not, the resulting vector may
569 * or may not have ghost elements. See the general documentation of this
570 * class for more information.
571 *
572 * In case @p parallel_partitioning is overlapping, it is not clear which
573 * process should own which elements. Hence, locally_owned_elements()
574 * returns an empty IndexSet in this case.
575 *
576 * @see
577 * @ref GlossGhostedVector "vectors with ghost elements"
578 */
579 void
580 reinit(const IndexSet &parallel_partitioning,
581 const MPI_Comm communicator = MPI_COMM_WORLD,
582 const bool omit_zeroing_entries = false);
583
584 /**
585 * Reinit functionality. This function destroys the old vector content
586 * and generates a new one based on the input partitioning. In addition
587 * to just specifying one index set as in all the other methods above,
588 * this method allows to supply an additional set of ghost entries.
589 *
590 * There are two different versions of a vector that can be created. If
591 * the flag @p vector_writable is set to @p false, the vector only
592 * allows read access to the joint set of @p parallel_partitioning and
593 * @p locally_relevant_or_ghost_entries. The effect of the reinit method
594 * is then equivalent to calling the other reinit method with an index set
595 * containing the union of the two provided index sets. In this case,
596 * it does not matter whether the second argument contains all
597 * locally relevant DoF indices, or only the ones indicating ghost
598 * indices: The union between the two index sets is the same in either
599 * case.
600 *
601 * If the flag @p vector_writable is set to true, this creates an
602 * alternative storage scheme for ghost elements that allows multiple
603 * threads to write into the vector (for the other reinit methods, only
604 * one thread is allowed to write into the ghost entries at a time). In
605 * this case, the set of ghost elements of the resulting vector is the
606 * *set difference* between the second and first argument -- where again
607 * it does not matter whether the second argument does or does not
608 * contain the locally owned entries specified by the first argument.
609 *
610 * Depending on whether the @p locally_relevant_or_ghost_entries argument uniquely
611 * subdivides elements among processors or not, the resulting vector may
612 * or may not have ghost elements. See the general documentation of this
613 * class for more information.
614 *
615 * @see
616 * @ref GlossGhostedVector "vectors with ghost elements"
617 */
618 void
619 reinit(const IndexSet &locally_owned_entries,
620 const IndexSet &locally_relevant_or_ghost_entries,
621 const MPI_Comm communicator = MPI_COMM_WORLD,
622 const bool vector_writable = false);
623
624 /**
625 * Initialize the vector given to the parallel partitioning described in
626 * @p partitioner using the function above.
627 *
628 * You can decide whether your vector will contain ghost elements with
629 * @p make_ghosted.
630 *
631 * The parameter @p vector_writable only has effect on ghosted vectors
632 * and is ignored for non-ghosted vectors.
633 */
634 void
635 reinit(
636 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
637 const bool make_ghosted = true,
638 const bool vector_writable = false);
639
640 /**
641 * Create vector by merging components from a block vector.
642 */
643 void
644 reinit(const BlockVector &v, const bool import_data = false);
645
646 /**
647 * Compress the underlying representation of the Trilinos object, i.e.
648 * flush the buffers of the vector object if it has any. This function is
649 * necessary after writing into a vector element-by-element and before
650 * anything else can be done on it.
651 *
652 * The (defaulted) argument can be used to specify the compress mode
653 * (<code>Add</code> or <code>Insert</code>) in case the vector has not
654 * been written to since the last time this function was called. The
655 * argument is ignored if the vector has been added or written to since
656 * the last time compress() was called.
657 *
658 * See
659 * @ref GlossCompress "Compressing distributed objects"
660 * for more information.
661 */
662 void
663 compress(VectorOperation::values operation);
664
665 /**
666 * Set all components of the vector to the given number @p s. Simply
667 * pass this down to the base class, but we still need to declare this
668 * function to make the example given in the discussion about making the
669 * constructor explicit work.
670 * the constructor explicit work.
671 *
672 * Since the semantics of assigning a scalar to a vector are not
673 * immediately clear, this operator can only be used if you want
674 * to set the entire vector to zero. This allows the intuitive notation
675 * <tt>v=0</tt>.
676 */
677 Vector &
678 operator=(const TrilinosScalar s);
679
680 /**
681 * Copy the given vector. Resize the present vector if necessary. In
682 * this case, also the `Epetra_Map` that designs the parallel partitioning
683 * is taken from the input vector.
684 *
685 * The semantics of this operator are complex. If the two vectors have
686 * the same size, and
687 * if either the left or right hand side vector of the assignment (i.e.,
688 * either the input vector on the right hand side, or the calling vector
689 * to the left of the assignment operator) currently has ghost elements,
690 * then the left hand side vector will also have ghost values and will
691 * consequently be a read-only vector (see also the
692 * @ref GlossGhostedVector "glossary entry" on the issue). Otherwise, the
693 * left hand vector will be a writable vector after this operation.
694 * These semantics facilitate having a vector with ghost elements on the
695 * left hand side of the assignment, and a vector without ghost elements
696 * on the right hand side, with the resulting left hand side vector
697 * having the correct values in both its locally owned and its ghost
698 * elements.
699 *
700 * On the other hand, if the left hand side vector does not have the
701 * correct size yet, or is perhaps an entirely uninitialized vector,
702 * then the assignment is simply a copy operation in the usual sense:
703 * In that case, if the right hand side has no ghost elements (i.e.,
704 * is a completely distributed vector), then the left hand side will
705 * have no ghost elements either. And if the right hand side has
706 * ghost elements (and is consequently read-only), then the left
707 * hand side will have these same properties after the operation.
708 */
709 Vector &
710 operator=(const Vector &v);
711
712 /**
713 * Move the given vector. This operator replaces the present vector with
714 * @p v by efficiently swapping the internal data structures.
715 */
716 Vector &
717 operator=(Vector &&v) noexcept;
718
719 /**
720 * Another copy function. This one takes a deal.II vector and copies it
721 * into a TrilinosWrapper vector. Note that since we do not provide any
722 * Epetra_Map that tells about the partitioning of the vector among the
723 * MPI processes, the size of the TrilinosWrapper vector has to be the
724 * same as the size of the input vector.
725 */
726 template <typename Number>
727 Vector &
728 operator=(const ::dealii::Vector<Number> &v);
729
730 /**
731 * This reinit function is meant to be used for parallel calculations
732 * where some non-local data has to be used. The typical situation where
733 * one needs this function is the call of the
734 * FEValues<dim>::get_function_values function (or of some derivatives)
735 * in parallel. Since it is usually faster to retrieve the data in
736 * advance, this function can be called before the assembly forks out to
737 * the different processors. What this function does is the following:
738 * It takes the information in the columns of the given matrix and looks
739 * which data couples between the different processors. That data is
740 * then queried from the input vector. Note that you should not write to
741 * the resulting vector any more, since the some data can be stored
742 * several times on different processors, leading to unpredictable
743 * results. In particular, such a vector cannot be used for
744 * matrix-vector products as for example done during the solution of
745 * linear systems.
746 */
747 void
748 import_nonlocal_data_for_fe(
749 const dealii::TrilinosWrappers::SparseMatrix &matrix,
750 const Vector &vector);
751
752 /**
753 * Imports all the elements present in the vector's IndexSet from the
754 * input vector @p rwv. VectorOperation::values @p operation is used to decide if
755 * the elements in @p rwv should be added to the current vector or replace the
756 * current elements.
757 */
758 void
759 import_elements(const LinearAlgebra::ReadWriteVector<double> &rwv,
760 const VectorOperation::values operation);
761
762 /**
763 * @deprecated Use import_elements() instead.
764 */
765 DEAL_II_DEPRECATED
766 void
767 import(const LinearAlgebra::ReadWriteVector<double> &rwv,
768 const VectorOperation::values operation)
769 {
770 import_elements(rwv, operation);
771 }
772
773
774 /**
775 * Test for equality. This function assumes that the present vector and
776 * the one to compare with have the same size already, since comparing
777 * vectors of different sizes makes not much sense anyway.
778 */
779 bool
780 operator==(const Vector &v) const;
781
782 /**
783 * Test for inequality. This function assumes that the present vector and
784 * the one to compare with have the same size already, since comparing
785 * vectors of different sizes makes not much sense anyway.
786 */
787 bool
788 operator!=(const Vector &v) const;
789
790 /**
791 * Return the global dimension of the vector.
792 */
793 size_type
794 size() const override;
795
796 /**
797 * Return the local size of the vector, i.e., the number of indices
798 * owned locally.
799 */
800 size_type
801 locally_owned_size() const;
802
803 /**
804 * Return a pair of indices indicating which elements of this vector are
805 * stored locally. The first number is the index of the first element
806 * stored, the second the index of the one past the last one that is
807 * stored locally. If this is a sequential vector, then the result will be
808 * the pair <code>(0,N)</code>, otherwise it will be a pair
809 * <code>(i,i+n)</code>, where <code>n</code> is the number of elements
810 * stored on this processor and and <code>i</code> is the first element of
811 * the vector stored on this processor, corresponding to the half open
812 * interval $[i,i+n)$
813 *
814 * @note The description above is true most of the time, but not always.
815 * In particular, Trilinos vectors need not store contiguous ranges of
816 * elements such as $[i,i+n)$. Rather, it can store vectors where the
817 * elements are distributed in an arbitrary way across all processors and
818 * each processor simply stores a particular subset, not necessarily
819 * contiguous. In this case, this function clearly makes no sense since it
820 * could, at best, return a range that includes all elements that are
821 * stored locally. Thus, the function only succeeds if the locally stored
822 * range is indeed contiguous. It will trigger an assertion if the local
823 * portion of the vector is not contiguous.
824 */
825 std::pair<size_type, size_type>
826 local_range() const;
827
828 /**
829 * Return whether @p index is in the local range or not, see also
830 * local_range().
831 *
832 * @note The same limitation for the applicability of this function
833 * applies as listed in the documentation of local_range().
834 */
835 bool
836 in_local_range(const size_type index) const;
837
838 /**
839 * Return an index set that describes which elements of this vector are
840 * owned by the current processor. Note that this index set does not
841 * include elements this vector may store locally as ghost elements but
842 * that are in fact owned by another processor. As a consequence, the
843 * index sets returned on different processors if this is a distributed
844 * vector will form disjoint sets that add up to the complete index set.
845 * Obviously, if a vector is created on only one processor, then the
846 * result would satisfy
847 * @code
848 * vec.locally_owned_elements() == complete_index_set (vec.size())
849 * @endcode
850 */
851 IndexSet
852 locally_owned_elements() const;
853
854 /**
855 * Return if the vector contains ghost elements. This answer is true if
856 * there are ghost elements on at least one process.
857 *
858 * @see
859 * @ref GlossGhostedVector "vectors with ghost elements"
860 */
861 bool
862 has_ghost_elements() const;
863
864 /**
865 * This function only exists for compatibility with the @p
866 * LinearAlgebra::distributed::Vector class and does nothing: this class
867 * implements ghost value updates in a different way that is a better fit
868 * with the underlying Trilinos vector object.
869 */
870 void
871 update_ghost_values() const;
872
873 /**
874 * Return the scalar (inner) product of two vectors. The vectors must have
875 * the same size.
876 */
877 TrilinosScalar
878 operator*(const Vector &vec) const;
879
880 /**
881 * Return the square of the $l_2$-norm.
882 */
883 real_type
884 norm_sqr() const;
885
886 /**
887 * Mean value of the elements of this vector.
888 */
889 TrilinosScalar
890 mean_value() const;
891
892 /**
893 * Compute the minimal value of the elements of this vector.
894 */
895 TrilinosScalar
896 min() const;
897
898 /**
899 * Compute the maximal value of the elements of this vector.
900 */
901 TrilinosScalar
902 max() const;
903
904 /**
905 * $l_1$-norm of the vector. The sum of the absolute values.
906 */
907 real_type
908 l1_norm() const;
909
910 /**
911 * $l_2$-norm of the vector. The square root of the sum of the squares of
912 * the elements.
913 */
914 real_type
915 l2_norm() const;
916
917 /**
918 * $l_p$-norm of the vector. The <i>p</i>th root of the sum of the
919 * <i>p</i>th powers of the absolute values of the elements.
920 */
921 real_type
922 lp_norm(const TrilinosScalar p) const;
923
924 /**
925 * Maximum absolute value of the elements.
926 */
927 real_type
928 linfty_norm() const;
929
930 /**
931 * Performs a combined operation of a vector addition and a subsequent
932 * inner product, returning the value of the inner product. In other
933 * words, the result of this function is the same as if the user called
934 * @code
935 * this->add(a, V);
936 * return_value = *this * W;
937 * @endcode
938 *
939 * The reason this function exists is for compatibility with deal.II's own
940 * vector classes which can implement this functionality with less memory
941 * transfer. However, for Trilinos vectors such a combined operation is
942 * not natively supported and thus the cost is completely equivalent as
943 * calling the two methods separately.
944 *
945 * For complex-valued vectors, the scalar product in the second step is
946 * implemented as
947 * $\left<v,w\right>=\sum_i v_i \bar{w_i}$.
948 */
949 TrilinosScalar
950 add_and_dot(const TrilinosScalar a, const Vector &V, const Vector &W);
951
952 /**
953 * Return whether the vector contains only elements with value zero. This
954 * is a @ref GlossCollectiveOperation "collective operation". This function is expensive, because
955 * potentially all elements have to be checked.
956 */
957 bool
958 all_zero() const;
959
960 /**
961 * Return @p true if the vector has no negative entries, i.e. all entries
962 * are zero or positive. This function is used, for example, to check
963 * whether refinement indicators are really all positive (or zero).
964 */
965 bool
966 is_non_negative() const;
967 /** @} */
968
969
970 /**
971 * @name 2: Data-Access
972 */
973 /** @{ */
974
975 /**
976 * Provide access to a given element, both read and write.
977 *
978 * When using a vector distributed with MPI, this operation only makes
979 * sense for elements that are actually present on the calling processor.
980 * Otherwise, an exception is thrown.
981 */
982 reference
983 operator()(const size_type index);
984
985 /**
986 * Provide read-only access to an element.
987 *
988 * When using a vector distributed with MPI, this operation only makes
989 * sense for elements that are actually present on the calling processor.
990 * Otherwise, an exception is thrown.
991 */
992 TrilinosScalar
993 operator()(const size_type index) const;
994
995 /**
996 * Provide access to a given element, both read and write.
997 *
998 * Exactly the same as operator().
999 */
1000 reference
1001 operator[](const size_type index);
1002
1003 /**
1004 * Provide read-only access to an element.
1005 *
1006 * Exactly the same as operator().
1007 */
1008 TrilinosScalar
1009 operator[](const size_type index) const;
1010
1011 /**
1012 * Instead of getting individual elements of a vector via operator(),
1013 * this function allows getting a whole set of elements at once. The
1014 * indices of the elements to be read are stated in the first argument,
1015 * the corresponding values are returned in the second.
1016 *
1017 * If the current vector is called @p v, then this function is the equivalent
1018 * to the code
1019 * @code
1020 * for (unsigned int i=0; i<indices.size(); ++i)
1021 * values[i] = v[indices[i]];
1022 * @endcode
1023 *
1024 * @pre The sizes of the @p indices and @p values arrays must be identical.
1025 */
1026 void
1027 extract_subvector_to(const std::vector<size_type> &indices,
1028 std::vector<TrilinosScalar> &values) const;
1029
1030 /**
1031 * Extract a range of elements all at once.
1032 */
1033 virtual void
1034 extract_subvector_to(
1035 const ArrayView<const size_type> &indices,
1036 const ArrayView<TrilinosScalar> &elements) const override;
1037
1038 /**
1039 * Instead of getting individual elements of a vector via operator(),
1040 * this function allows getting a whole set of elements at once. In
1041 * contrast to the previous function, this function obtains the
1042 * indices of the elements by dereferencing all elements of the iterator
1043 * range provided by the first two arguments, and puts the vector
1044 * values into memory locations obtained by dereferencing a range
1045 * of iterators starting at the location pointed to by the third
1046 * argument.
1047 *
1048 * If the current vector is called @p v, then this function is the equivalent
1049 * to the code
1050 * @code
1051 * ForwardIterator indices_p = indices_begin;
1052 * OutputIterator values_p = values_begin;
1053 * while (indices_p != indices_end)
1054 * {
1055 * *values_p = v[*indices_p];
1056 * ++indices_p;
1057 * ++values_p;
1058 * }
1059 * @endcode
1060 *
1061 * @pre It must be possible to write into as many memory locations
1062 * starting at @p values_begin as there are iterators between
1063 * @p indices_begin and @p indices_end.
1064 */
1065 template <typename ForwardIterator, typename OutputIterator>
1066 void
1067 extract_subvector_to(ForwardIterator indices_begin,
1068 const ForwardIterator indices_end,
1069 OutputIterator values_begin) const;
1070
1071 /**
1072 * Make the Vector class a bit like the <tt>vector<></tt> class of the C++
1073 * standard library by returning iterators to the start and end of the
1074 * locally owned elements of this vector. The ordering of local elements
1075 * corresponds to the one given by the global indices in case the vector
1076 * is constructed from an IndexSet or other methods in deal.II (note that
1077 * an Epetra_Map can contain elements in arbitrary orders, though).
1078 */
1079 iterator
1080 begin();
1081
1082 /**
1083 * Return constant iterator to the start of the locally owned elements of
1084 * the vector.
1085 */
1086 const_iterator
1087 begin() const;
1088
1089 /**
1090 * Return an iterator pointing to the element past the end of the array of
1091 * locally owned entries.
1092 */
1093 iterator
1094 end();
1095
1096 /**
1097 * Return a constant iterator pointing to the element past the end of the
1098 * array of the locally owned entries.
1099 */
1100 const_iterator
1101 end() const;
1102
1103 /** @} */
1104
1105
1106 /**
1107 * @name 3: Modification of vectors
1108 */
1109 /** @{ */
1110
1111 /**
1112 * A collective set operation: instead of setting individual elements of a
1113 * vector, this function allows to set a whole set of elements at once.
1114 * The indices of the elements to be set are stated in the first argument,
1115 * the corresponding values in the second.
1116 */
1117 void
1118 set(const std::vector<size_type> &indices,
1119 const std::vector<TrilinosScalar> &values);
1120
1121 /**
1122 * This is a second collective set operation. As a difference, this
1123 * function takes a deal.II vector of values.
1124 */
1125 void
1126 set(const std::vector<size_type> &indices,
1127 const ::dealii::Vector<TrilinosScalar> &values);
1128
1129 /**
1130 * This collective set operation is of lower level and can handle anything
1131 * else &mdash; the only thing you have to provide is an address where all
1132 * the indices are stored and the number of elements to be set.
1133 */
1134 void
1135 set(const size_type n_elements,
1136 const size_type *indices,
1137 const TrilinosScalar *values);
1138
1139 /**
1140 * A collective add operation: This function adds a whole set of values
1141 * stored in @p values to the vector components specified by @p indices.
1142 */
1143 void
1144 add(const std::vector<size_type> &indices,
1145 const std::vector<TrilinosScalar> &values);
1146
1147 /**
1148 * This is a second collective add operation. As a difference, this
1149 * function takes a deal.II vector of values.
1150 */
1151 void
1152 add(const std::vector<size_type> &indices,
1153 const ::dealii::Vector<TrilinosScalar> &values);
1154
1155 /**
1156 * Take an address where <tt>n_elements</tt> are stored contiguously and
1157 * add them into the vector. Handles all cases which are not covered by
1158 * the other two <tt>add()</tt> functions above.
1159 */
1160 void
1161 add(const size_type n_elements,
1162 const size_type *indices,
1163 const TrilinosScalar *values);
1164
1165 /**
1166 * Multiply the entire vector by a fixed factor.
1167 */
1168 Vector &
1169 operator*=(const TrilinosScalar factor);
1170
1171 /**
1172 * Divide the entire vector by a fixed factor.
1173 */
1174 Vector &
1175 operator/=(const TrilinosScalar factor);
1176
1177 /**
1178 * Add the given vector to the present one.
1179 */
1180 Vector &
1181 operator+=(const Vector &V);
1182
1183 /**
1184 * Subtract the given vector from the present one.
1185 */
1186 Vector &
1187 operator-=(const Vector &V);
1188
1189 /**
1190 * Addition of @p s to all components. Note that @p s is a scalar and not
1191 * a vector.
1192 */
1193 void
1194 add(const TrilinosScalar s);
1195
1196 /**
1197 * Simple vector addition, equal to the <tt>operator+=</tt>.
1198 *
1199 * Though, if the second argument <tt>allow_different_maps</tt> is set,
1200 * then it is possible to add data from a vector that uses a different
1201 * map, i.e., a vector whose elements are split across processors
1202 * differently. This may include vectors with ghost elements, for example.
1203 * In general, however, adding vectors with a different
1204 * element-to-processor map requires communicating data among processors
1205 * and, consequently, is a slower operation than when using vectors using
1206 * the same map.
1207 */
1208 void
1209 add(const Vector &V, const bool allow_different_maps = false);
1210
1211 /**
1212 * Simple addition of a multiple of a vector, i.e. <tt>*this += a*V</tt>.
1213 */
1214 void
1215 add(const TrilinosScalar a, const Vector &V);
1216
1217 /**
1218 * Multiple addition of scaled vectors, i.e. <tt>*this += a*V + b*W</tt>.
1219 */
1220 void
1221 add(const TrilinosScalar a,
1222 const Vector &V,
1223 const TrilinosScalar b,
1224 const Vector &W);
1225
1226 /**
1227 * Scaling and simple vector addition, i.e. <tt>*this = s*(*this) +
1228 * V</tt>.
1229 */
1230 void
1231 sadd(const TrilinosScalar s, const Vector &V);
1232
1233 /**
1234 * Scaling and simple addition, i.e. <tt>*this = s*(*this) + a*V</tt>.
1235 */
1236 void
1237 sadd(const TrilinosScalar s, const TrilinosScalar a, const Vector &V);
1238
1239 /**
1240 * Scale each element of this vector by the corresponding element in the
1241 * argument. This function is mostly meant to simulate multiplication (and
1242 * immediate re-assignment) by a diagonal scaling matrix.
1243 */
1244 void
1245 scale(const Vector &scaling_factors);
1246
1247 /**
1248 * Assignment <tt>*this = a*V</tt>.
1249 */
1250 void
1251 equ(const TrilinosScalar a, const Vector &V);
1252 /** @} */
1253
1254 /**
1255 * @name 4: Mixed stuff
1256 */
1257 /** @{ */
1258
1259 /**
1260 * Return a const reference to the underlying Trilinos Epetra_MultiVector
1261 * class.
1262 */
1263 const Epetra_MultiVector &
1264 trilinos_vector() const;
1265
1266 /**
1267 * Return a (modifiable) reference to the underlying Trilinos
1268 * Epetra_FEVector class.
1269 */
1270 Epetra_FEVector &
1271 trilinos_vector();
1272
1273 /**
1274 * Return a const reference to the underlying Trilinos Epetra_BlockMap
1275 * that sets the parallel partitioning of the vector.
1276 */
1277 const Epetra_BlockMap &
1278 trilinos_partitioner() const;
1279
1280 /**
1281 * Print to a stream. @p precision denotes the desired precision with
1282 * which values shall be printed, @p scientific whether scientific
1283 * notation shall be used. If @p across is @p true then the vector is
1284 * printed in a line, while if @p false then the elements are printed on a
1285 * separate line each.
1286 */
1287 void
1288 print(std::ostream &out,
1289 const unsigned int precision = 3,
1290 const bool scientific = true,
1291 const bool across = true) const;
1292
1293 /**
1294 * Swap the contents of this vector and the other vector @p v. One could
1295 * do this operation with a temporary variable and copying over the data
1296 * elements, but this function is significantly more efficient since it
1297 * only swaps the pointers to the data of the two vectors and therefore
1298 * does not need to allocate temporary storage and move data around. Note
1299 * that the vectors need to be of the same size and base on the same map.
1300 *
1301 * This function is analogous to the @p swap function of all C++
1302 * standard containers. Also, there is a global function
1303 * <tt>swap(u,v)</tt> that simply calls <tt>u.swap(v)</tt>, again in
1304 * analogy to standard functions.
1305 */
1306 void
1307 swap(Vector &v) noexcept;
1308
1309 /**
1310 * Estimate for the memory consumption in bytes.
1311 */
1312 std::size_t
1313 memory_consumption() const;
1314
1315 /**
1316 * Return the underlying MPI communicator.
1317 */
1318 MPI_Comm
1319 get_mpi_communicator() const;
1320 /** @} */
1321
1322 /**
1323 * Exception
1324 */
1325 DeclException0(ExcDifferentParallelPartitioning);
1326
1327 /**
1328 * Exception
1329 */
1330 DeclException1(ExcTrilinosError,
1331 int,
1332 << "An error with error number " << arg1
1333 << " occurred while calling a Trilinos function");
1334
1335 /**
1336 * Exception
1337 */
1338 DeclException4(
1339 ExcAccessToNonLocalElement,
1340 size_type,
1341 size_type,
1342 size_type,
1343 size_type,
1344 << "You are trying to access element " << arg1
1345 << " of a distributed vector, but this element is not stored "
1346 << "on the current processor. Note: There are " << arg2
1347 << " elements stored "
1348 << "on the current processor from within the range [" << arg3 << ','
1349 << arg4 << "] but Trilinos vectors need not store contiguous "
1350 << "ranges on each processor, and not every element in "
1351 << "this range may in fact be stored locally."
1352 << "\n\n"
1353 << "A common source for this kind of problem is that you "
1354 << "are passing a 'fully distributed' vector into a function "
1355 << "that needs read access to vector elements that correspond "
1356 << "to degrees of freedom on ghost cells (or at least to "
1357 << "'locally active' degrees of freedom that are not also "
1358 << "'locally owned'). You need to pass a vector that has these "
1359 << "elements as ghost entries.");
1360
1361 private:
1362 /**
1363 * Trilinos doesn't allow to mix additions to matrix entries and
1364 * overwriting them (to make synchronization of parallel computations
1365 * simpler). The way we do it is to, for each access operation, store
1366 * whether it is an insertion or an addition. If the previous one was of
1367 * different type, then we first have to flush the Trilinos buffers;
1368 * otherwise, we can simply go on. Luckily, Trilinos has an object for
1369 * this which does already all the parallel communications in such a case,
1370 * so we simply use their model, which stores whether the last operation
1371 * was an addition or an insertion.
1372 */
1373 Epetra_CombineMode last_action;
1374
1375 /**
1376 * A boolean variable to hold information on whether the vector is
1377 * compressed or not.
1378 */
1379 bool compressed;
1380
1381 /**
1382 * Whether this vector has ghost elements. This is true on all processors
1383 * even if only one of them has any ghost elements.
1384 */
1385 bool has_ghosts;
1386
1387 /**
1388 * Pointer to the actual Epetra vector object. This may represent a vector
1389 * that is in fact distributed among multiple processors. The object
1390 * requires an existing Epetra_Map for storing data when setting it up.
1391 */
1392 std::unique_ptr<Epetra_FEVector> vector;
1393
1394 /**
1395 * A vector object in Trilinos to be used for collecting the non-local
1396 * elements if the vector was constructed with an additional IndexSet
1397 * describing ghost elements.
1398 */
1399 std::unique_ptr<Epetra_MultiVector> nonlocal_vector;
1400
1401 /**
1402 * An IndexSet storing the indices this vector owns exclusively.
1403 */
1404 IndexSet owned_elements;
1405
1406 // Make the reference class a friend.
1407 friend class internal::VectorReference;
1408 };
1409
1410
1411
1412 // ------------------- inline and template functions --------------
1413
1414
1415 /**
1416 * Global function @p swap which overloads the default implementation of
1417 * the C++ standard library which uses a temporary object. The function
1418 * simply exchanges the data of the two vectors.
1419 *
1420 * @relatesalso TrilinosWrappers::MPI::Vector
1421 */
1422 inline void
1423 swap(Vector &u, Vector &v) noexcept
1424 {
1425 u.swap(v);
1426 }
1427 } // namespace MPI
1428
1429 # ifndef DOXYGEN
1430
1431 namespace internal
1432 {
1433 inline VectorReference::VectorReference(MPI::Vector &vector,
1434 const size_type index)
1435 : vector(vector)
1436 , index(index)
1437 {}
1438
1439
1440 inline const VectorReference &
1441 VectorReference::operator=(const VectorReference &r) const
1442 {
1443 // as explained in the class
1444 // documentation, this is not the copy
1445 // operator. so simply pass on to the
1446 // "correct" assignment operator
1447 *this = static_cast<TrilinosScalar>(r);
1448
1449 return *this;
1450 }
1451
1452
1453
1454 inline VectorReference &
1455 VectorReference::operator=(const VectorReference &r)
1456 {
1457 // as above
1458 *this = static_cast<TrilinosScalar>(r);
1459
1460 return *this;
1461 }
1462
1463
1464 inline const VectorReference &
1465 VectorReference::operator=(const TrilinosScalar &value) const
1466 {
1467 vector.set(1, &index, &value);
1468 return *this;
1469 }
1470
1471
1472
1473 inline const VectorReference &
1474 VectorReference::operator+=(const TrilinosScalar &value) const
1475 {
1476 vector.add(1, &index, &value);
1477 return *this;
1478 }
1479
1480
1481
1482 inline const VectorReference &
1483 VectorReference::operator-=(const TrilinosScalar &value) const
1484 {
1485 TrilinosScalar new_value = -value;
1486 vector.add(1, &index, &new_value);
1487 return *this;
1488 }
1489
1490
1491
1492 inline const VectorReference &
1493 VectorReference::operator*=(const TrilinosScalar &value) const
1494 {
1495 TrilinosScalar new_value = static_cast<TrilinosScalar>(*this) * value;
1496 vector.set(1, &index, &new_value);
1497 return *this;
1498 }
1499
1500
1501
1502 inline const VectorReference &
1503 VectorReference::operator/=(const TrilinosScalar &value) const
1504 {
1505 TrilinosScalar new_value = static_cast<TrilinosScalar>(*this) / value;
1506 vector.set(1, &index, &new_value);
1507 return *this;
1508 }
1509 } // namespace internal
1510
1511 namespace MPI
1512 {
1513 inline bool
1514 Vector::in_local_range(const size_type index) const
1515 {
1516 std::pair<size_type, size_type> range = local_range();
1517
1518 return ((index >= range.first) && (index < range.second));
1519 }
1520
1521
1522
1523 inline IndexSet
1524 Vector::locally_owned_elements() const
1525 {
1526 Assert(owned_elements.size() == size(),
1527 ExcMessage(
1528 "The locally owned elements have not been properly initialized!"
1529 " This happens for example if this object has been initialized"
1530 " with exactly one overlapping IndexSet."));
1531 return owned_elements;
1532 }
1533
1534
1535
1536 inline bool
1537 Vector::has_ghost_elements() const
1538 {
1539 return has_ghosts;
1540 }
1541
1542
1543
1544 inline void
1545 Vector::update_ghost_values() const
1546 {}
1547
1548
1549
1550 inline internal::VectorReference
1551 Vector::operator()(const size_type index)
1552 {
1553 return internal::VectorReference(*this, index);
1554 }
1555
1556
1557
1558 inline internal::VectorReference
1559 Vector::operator[](const size_type index)
1560 {
1561 return operator()(index);
1562 }
1563
1564
1565
1566 inline TrilinosScalar
1567 Vector::operator[](const size_type index) const
1568 {
1569 return operator()(index);
1570 }
1571
1572
1573
1574 inline void
1575 Vector::extract_subvector_to(const std::vector<size_type> &indices,
1576 std::vector<TrilinosScalar> &values) const
1577 {
1578 for (size_type i = 0; i < indices.size(); ++i)
1579 values[i] = operator()(indices[i]);
1580 }
1581
1582
1583
1584 inline void
1585 Vector::extract_subvector_to(
1586 const ArrayView<const size_type> &indices,
1587 const ArrayView<TrilinosScalar> &elements) const
1588 {
1589 AssertDimension(indices.size(), elements.size());
1590 for (unsigned int i = 0; i < indices.size(); ++i)
1591 {
1592 AssertIndexRange(indices[i], size());
1593 elements[i] = (*this)[indices[i]];
1594 }
1595 }
1596
1597
1598
1599 template <typename ForwardIterator, typename OutputIterator>
1600 inline void
1601 Vector::extract_subvector_to(ForwardIterator indices_begin,
1602 const ForwardIterator indices_end,
1603 OutputIterator values_begin) const
1604 {
1605 while (indices_begin != indices_end)
1606 {
1607 *values_begin = operator()(*indices_begin);
1608 ++indices_begin;
1609 ++values_begin;
1610 }
1611 }
1612
1613
1614
1615 inline Vector::iterator
1616 Vector::begin()
1617 {
1618 return (*vector)[0];
1619 }
1620
1621
1622
1623 inline Vector::iterator
1624 Vector::end()
1625 {
1626 return (*vector)[0] + locally_owned_size();
1627 }
1628
1629
1630
1631 inline Vector::const_iterator
1632 Vector::begin() const
1633 {
1634 return (*vector)[0];
1635 }
1636
1637
1638
1639 inline Vector::const_iterator
1640 Vector::end() const
1641 {
1642 return (*vector)[0] + locally_owned_size();
1643 }
1644
1645
1646
1647 inline void
1648 Vector::set(const std::vector<size_type> &indices,
1649 const std::vector<TrilinosScalar> &values)
1650 {
1651 // if we have ghost values, do not allow
1652 // writing to this vector at all.
1653 Assert(!has_ghost_elements(), ExcGhostsPresent());
1654
1655 AssertDimension(indices.size(), values.size());
1656
1657 set(indices.size(), indices.data(), values.data());
1658 }
1659
1660
1661
1662 inline void
1663 Vector::set(const std::vector<size_type> &indices,
1664 const ::dealii::Vector<TrilinosScalar> &values)
1665 {
1666 // if we have ghost values, do not allow
1667 // writing to this vector at all.
1668 Assert(!has_ghost_elements(), ExcGhostsPresent());
1669
1670 AssertDimension(indices.size(), values.size());
1671
1672 set(indices.size(), indices.data(), values.begin());
1673 }
1674
1675
1676
1677 inline void
1678 Vector::set(const size_type n_elements,
1679 const size_type *indices,
1680 const TrilinosScalar *values)
1681 {
1682 // if we have ghost values, do not allow
1683 // writing to this vector at all.
1684 Assert(!has_ghost_elements(), ExcGhostsPresent());
1685
1686 if (last_action == Add)
1687 {
1688 const int ierr = vector->GlobalAssemble(Add);
1689 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1690 }
1691
1692 if (last_action != Insert)
1693 last_action = Insert;
1694
1695 for (size_type i = 0; i < n_elements; ++i)
1696 {
1697 const TrilinosWrappers::types::int_type row = indices[i];
1698 const TrilinosWrappers::types::int_type local_row =
1699 vector->Map().LID(row);
1700 if (local_row != -1)
1701 (*vector)[0][local_row] = values[i];
1702 else
1703 {
1704 const int ierr = vector->ReplaceGlobalValues(1, &row, &values[i]);
1705 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1706 compressed = false;
1707 }
1708 // in set operation, do not use the pre-allocated vector for nonlocal
1709 // entries even if it exists. This is to ensure that we really only
1710 // set the elements touched by the set() method and not all contained
1711 // in the nonlocal entries vector (there is no way to distinguish them
1712 // on the receiving processor)
1713 }
1714 }
1715
1716
1717
1718 inline void
1719 Vector::add(const std::vector<size_type> &indices,
1720 const std::vector<TrilinosScalar> &values)
1721 {
1722 // if we have ghost values, do not allow
1723 // writing to this vector at all.
1724 Assert(!has_ghost_elements(), ExcGhostsPresent());
1725 AssertDimension(indices.size(), values.size());
1726
1727 add(indices.size(), indices.data(), values.data());
1728 }
1729
1730
1731
1732 inline void
1733 Vector::add(const std::vector<size_type> &indices,
1734 const ::dealii::Vector<TrilinosScalar> &values)
1735 {
1736 // if we have ghost values, do not allow
1737 // writing to this vector at all.
1738 Assert(!has_ghost_elements(), ExcGhostsPresent());
1739 AssertDimension(indices.size(), values.size());
1740
1741 add(indices.size(), indices.data(), values.begin());
1742 }
1743
1744
1745
1746 inline void
1747 Vector::add(const size_type n_elements,
1748 const size_type *indices,
1749 const TrilinosScalar *values)
1750 {
1751 // if we have ghost values, do not allow
1752 // writing to this vector at all.
1753 Assert(!has_ghost_elements(), ExcGhostsPresent());
1754
1755 if (last_action != Add)
1756 {
1757 if (last_action == Insert)
1758 {
1759 const int ierr = vector->GlobalAssemble(Insert);
1760 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1761 }
1762 last_action = Add;
1763 }
1764
1765 for (size_type i = 0; i < n_elements; ++i)
1766 {
1767 const size_type row = indices[i];
1768 const TrilinosWrappers::types::int_type local_row = vector->Map().LID(
1769 static_cast<TrilinosWrappers::types::int_type>(row));
1770 if (local_row != -1)
1771 (*vector)[0][local_row] += values[i];
1772 else if (nonlocal_vector.get() == nullptr)
1773 {
1774 const int ierr = vector->SumIntoGlobalValues(
1775 1,
1776 reinterpret_cast<const TrilinosWrappers::types::int_type *>(
1777 &row),
1778 &values[i]);
1779 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1780 compressed = false;
1781 }
1782 else
1783 {
1784 // use pre-allocated vector for non-local entries if it exists for
1785 // addition operation
1786 const TrilinosWrappers::types::int_type my_row =
1787 nonlocal_vector->Map().LID(
1788 static_cast<TrilinosWrappers::types::int_type>(row));
1789 Assert(my_row != -1,
1790 ExcMessage(
1791 "Attempted to write into off-processor vector entry "
1792 "that has not be specified as being writable upon "
1793 "initialization"));
1794 (*nonlocal_vector)[0][my_row] += values[i];
1795 compressed = false;
1796 }
1797 }
1798 }
1799
1800
1801
1802 inline Vector::size_type
1803 Vector::size() const
1804 {
1805 # ifndef DEAL_II_WITH_64BIT_INDICES
1806 return vector->Map().MaxAllGID() + 1 - vector->Map().MinAllGID();
1807 # else
1808 return vector->Map().MaxAllGID64() + 1 - vector->Map().MinAllGID64();
1809 # endif
1810 }
1811
1812
1813
1814 inline Vector::size_type
1815 Vector::locally_owned_size() const
1816 {
1817 return owned_elements.n_elements();
1818 }
1819
1820
1821
1822 inline std::pair<Vector::size_type, Vector::size_type>
1823 Vector::local_range() const
1824 {
1825 # ifndef DEAL_II_WITH_64BIT_INDICES
1826 const TrilinosWrappers::types::int_type begin = vector->Map().MinMyGID();
1827 const TrilinosWrappers::types::int_type end =
1828 vector->Map().MaxMyGID() + 1;
1829 # else
1830 const TrilinosWrappers::types::int_type begin =
1831 vector->Map().MinMyGID64();
1832 const TrilinosWrappers::types::int_type end =
1833 vector->Map().MaxMyGID64() + 1;
1834 # endif
1835
1836 Assert(
1837 end - begin == vector->Map().NumMyElements(),
1838 ExcMessage(
1839 "This function only makes sense if the elements that this "
1840 "vector stores on the current processor form a contiguous range. "
1841 "This does not appear to be the case for the current vector."));
1842
1843 return std::make_pair(begin, end);
1844 }
1845
1846
1847
1848 inline TrilinosScalar
1849 Vector::operator*(const Vector &vec) const
1850 {
1851 Assert(vector->Map().SameAs(vec.vector->Map()),
1852 ExcDifferentParallelPartitioning());
1853 Assert(!has_ghost_elements(), ExcGhostsPresent());
1854
1855 TrilinosScalar result;
1856
1857 const int ierr = vector->Dot(*(vec.vector), &result);
1858 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1859
1860 return result;
1861 }
1862
1863
1864
1865 inline Vector::real_type
1866 Vector::norm_sqr() const
1867 {
1868 const TrilinosScalar d = l2_norm();
1869 return d * d;
1870 }
1871
1872
1873
1874 inline TrilinosScalar
1875 Vector::mean_value() const
1876 {
1877 Assert(!has_ghost_elements(), ExcGhostsPresent());
1878
1879 TrilinosScalar mean;
1880 const int ierr = vector->MeanValue(&mean);
1881 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1882
1883 return mean;
1884 }
1885
1886
1887
1888 inline TrilinosScalar
1889 Vector::min() const
1890 {
1891 TrilinosScalar min_value;
1892 const int ierr = vector->MinValue(&min_value);
1893 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1894
1895 return min_value;
1896 }
1897
1898
1899
1900 inline TrilinosScalar
1901 Vector::max() const
1902 {
1903 TrilinosScalar max_value;
1904 const int ierr = vector->MaxValue(&max_value);
1905 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1906
1907 return max_value;
1908 }
1909
1910
1911
1912 inline Vector::real_type
1913 Vector::l1_norm() const
1914 {
1915 Assert(!has_ghost_elements(), ExcGhostsPresent());
1916
1917 TrilinosScalar d;
1918 const int ierr = vector->Norm1(&d);
1919 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1920
1921 return d;
1922 }
1923
1924
1925
1926 inline Vector::real_type
1927 Vector::l2_norm() const
1928 {
1929 Assert(!has_ghost_elements(), ExcGhostsPresent());
1930
1931 TrilinosScalar d;
1932 const int ierr = vector->Norm2(&d);
1933 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1934
1935 return d;
1936 }
1937
1938
1939
1940 inline Vector::real_type
1941 Vector::lp_norm(const TrilinosScalar p) const
1942 {
1943 Assert(!has_ghost_elements(), ExcGhostsPresent());
1944
1945 TrilinosScalar norm = 0;
1946 TrilinosScalar sum = 0;
1947 const size_type n_local = locally_owned_size();
1948
1949 // loop over all the elements because
1950 // Trilinos does not support lp norms
1951 for (size_type i = 0; i < n_local; ++i)
1952 sum += std::pow(std::fabs((*vector)[0][i]), p);
1953
1954 norm = std::pow(sum, static_cast<TrilinosScalar>(1. / p));
1955
1956 return norm;
1957 }
1958
1959
1960
1961 inline Vector::real_type
1962 Vector::linfty_norm() const
1963 {
1964 // while we disallow the other
1965 // norm operations on ghosted
1966 // vectors, this particular norm
1967 // is safe to run even in the
1968 // presence of ghost elements
1969 TrilinosScalar d;
1970 const int ierr = vector->NormInf(&d);
1971 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
1972
1973 return d;
1974 }
1975
1976
1977
1978 inline TrilinosScalar
1979 Vector::add_and_dot(const TrilinosScalar a,
1980 const Vector &V,
1981 const Vector &W)
1982 {
1983 this->add(a, V);
1984 return *this * W;
1985 }
1986
1987
1988
1989 // inline also scalar products, vector
1990 // additions etc. since they are all
1991 // representable by a single Trilinos
1992 // call. This reduces the overhead of the
1993 // wrapper class.
1994 inline Vector &
1995 Vector::operator*=(const TrilinosScalar a)
1996 {
1997 AssertIsFinite(a);
1998
1999 const int ierr = vector->Scale(a);
2000 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2001
2002 return *this;
2003 }
2004
2005
2006
2007 inline Vector &
2008 Vector::operator/=(const TrilinosScalar a)
2009 {
2010 AssertIsFinite(a);
2011
2012 const TrilinosScalar factor = 1. / a;
2013
2014 AssertIsFinite(factor);
2015
2016 const int ierr = vector->Scale(factor);
2017 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2018
2019 return *this;
2020 }
2021
2022
2023
2024 inline Vector &
2025 Vector::operator+=(const Vector &v)
2026 {
2027 AssertDimension(size(), v.size());
2028 Assert(vector->Map().SameAs(v.vector->Map()),
2029 ExcDifferentParallelPartitioning());
2030
2031 const int ierr = vector->Update(1.0, *(v.vector), 1.0);
2032 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2033
2034 return *this;
2035 }
2036
2037
2038
2039 inline Vector &
2040 Vector::operator-=(const Vector &v)
2041 {
2042 AssertDimension(size(), v.size());
2043 Assert(vector->Map().SameAs(v.vector->Map()),
2044 ExcDifferentParallelPartitioning());
2045
2046 const int ierr = vector->Update(-1.0, *(v.vector), 1.0);
2047 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2048
2049 return *this;
2050 }
2051
2052
2053
2054 inline void
2055 Vector::add(const TrilinosScalar s)
2056 {
2057 // if we have ghost values, do not allow
2058 // writing to this vector at all.
2059 Assert(!has_ghost_elements(), ExcGhostsPresent());
2060 AssertIsFinite(s);
2061
2062 size_type n_local = locally_owned_size();
2063 for (size_type i = 0; i < n_local; ++i)
2064 (*vector)[0][i] += s;
2065 }
2066
2067
2068
2069 inline void
2070 Vector::add(const TrilinosScalar a, const Vector &v)
2071 {
2072 // if we have ghost values, do not allow
2073 // writing to this vector at all.
2074 Assert(!has_ghost_elements(), ExcGhostsPresent());
2075 AssertDimension(locally_owned_size(), v.locally_owned_size());
2076
2077 AssertIsFinite(a);
2078
2079 const int ierr = vector->Update(a, *(v.vector), 1.);
2080 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2081 }
2082
2083
2084
2085 inline void
2086 Vector::add(const TrilinosScalar a,
2087 const Vector &v,
2088 const TrilinosScalar b,
2089 const Vector &w)
2090 {
2091 // if we have ghost values, do not allow
2092 // writing to this vector at all.
2093 Assert(!has_ghost_elements(), ExcGhostsPresent());
2094 AssertDimension(locally_owned_size(), v.locally_owned_size());
2095 AssertDimension(locally_owned_size(), w.locally_owned_size());
2096
2097 AssertIsFinite(a);
2098 AssertIsFinite(b);
2099
2100 const int ierr = vector->Update(a, *(v.vector), b, *(w.vector), 1.);
2101
2102 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2103 }
2104
2105
2106
2107 inline void
2108 Vector::sadd(const TrilinosScalar s, const Vector &v)
2109 {
2110 // if we have ghost values, do not allow
2111 // writing to this vector at all.
2112 Assert(!has_ghost_elements(), ExcGhostsPresent());
2113 AssertDimension(size(), v.size());
2114
2115 AssertIsFinite(s);
2116
2117 // We assume that the vectors have the same Map
2118 // if the local size is the same and if the vectors are not ghosted
2119 if (locally_owned_size() == v.locally_owned_size() &&
2120 !v.has_ghost_elements())
2121 {
2122 Assert(this->vector->Map().SameAs(v.vector->Map()) == true,
2123 ExcDifferentParallelPartitioning());
2124 const int ierr = vector->Update(1., *(v.vector), s);
2125 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2126 }
2127 else
2128 {
2129 (*this) *= s;
2130 this->add(v, true);
2131 }
2132 }
2133
2134
2135
2136 inline void
2137 Vector::sadd(const TrilinosScalar s,
2138 const TrilinosScalar a,
2139 const Vector &v)
2140 {
2141 // if we have ghost values, do not allow
2142 // writing to this vector at all.
2143 Assert(!has_ghost_elements(), ExcGhostsPresent());
2144 AssertDimension(size(), v.size());
2145 AssertIsFinite(s);
2146 AssertIsFinite(a);
2147
2148 // We assume that the vectors have the same Map
2149 // if the local size is the same and if the vectors are not ghosted
2150 if (locally_owned_size() == v.locally_owned_size() &&
2151 !v.has_ghost_elements())
2152 {
2153 Assert(this->vector->Map().SameAs(v.vector->Map()) == true,
2154 ExcDifferentParallelPartitioning());
2155 const int ierr = vector->Update(a, *(v.vector), s);
2156 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2157 }
2158 else
2159 {
2160 (*this) *= s;
2161 Vector tmp = v;
2162 tmp *= a;
2163 this->add(tmp, true);
2164 }
2165 }
2166
2167
2168
2169 inline void
2170 Vector::scale(const Vector &factors)
2171 {
2172 // if we have ghost values, do not allow
2173 // writing to this vector at all.
2174 Assert(!has_ghost_elements(), ExcGhostsPresent());
2175 AssertDimension(locally_owned_size(), factors.locally_owned_size());
2176
2177 const int ierr = vector->Multiply(1.0, *(factors.vector), *vector, 0.0);
2178 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2179 }
2180
2181
2182
2183 inline void
2184 Vector::equ(const TrilinosScalar a, const Vector &v)
2185 {
2186 // if we have ghost values, do not allow
2187 // writing to this vector at all.
2188 Assert(!has_ghost_elements(), ExcGhostsPresent());
2189 AssertIsFinite(a);
2190
2191 // If we don't have the same map, copy.
2192 if (vector->Map().SameAs(v.vector->Map()) == false)
2193 {
2194 this->sadd(0., a, v);
2195 }
2196 else
2197 {
2198 // Otherwise, just update
2199 int ierr = vector->Update(a, *v.vector, 0.0);
2200 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2201
2202 last_action = Zero;
2203 }
2204 }
2205
2206
2207
2208 inline const Epetra_MultiVector &
2209 Vector::trilinos_vector() const
2210 {
2211 return static_cast<const Epetra_MultiVector &>(*vector);
2212 }
2213
2214
2215
2216 inline Epetra_FEVector &
2217 Vector::trilinos_vector()
2218 {
2219 return *vector;
2220 }
2221
2222
2223
2224 inline const Epetra_BlockMap &
2225 Vector::trilinos_partitioner() const
2226 {
2227 return vector->Map();
2228 }
2229
2230
2231
2232 inline MPI_Comm
2233 Vector::get_mpi_communicator() const
2234 {
2235 const Epetra_MpiComm *mpi_comm =
2236 dynamic_cast<const Epetra_MpiComm *>(&vector->Map().Comm());
2237 return mpi_comm->Comm();
2238 }
2239
2240
2241
2242 template <typename number>
2243 Vector::Vector(const IndexSet &parallel_partitioner,
2244 const dealii::Vector<number> &v,
2245 const MPI_Comm communicator)
2246 {
2247 *this =
2248 Vector(parallel_partitioner.make_trilinos_map(communicator, true), v);
2249 owned_elements = parallel_partitioner;
2250 }
2251
2252
2253
2254 inline Vector &
2255 Vector::operator=(const TrilinosScalar s)
2256 {
2257 AssertIsFinite(s);
2258
2259 int ierr = vector->PutScalar(s);
2260 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2261
2262 if (nonlocal_vector.get() != nullptr)
2263 {
2264 ierr = nonlocal_vector->PutScalar(0.);
2265 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2266 }
2267
2268 return *this;
2269 }
2270 } /* end of namespace MPI */
2271
2272 # endif /* DOXYGEN */
2273
2274 } /* end of namespace TrilinosWrappers */
2275
2276 /** @} */
2277
2278
2279 namespace internal
2280 {
2281 namespace LinearOperatorImplementation
2282 {
2283 template <typename>
2284 class ReinitHelper;
2285
2286 /**
2287 * A helper class used internally in linear_operator.h. Specialization for
2288 * TrilinosWrappers::MPI::Vector.
2289 */
2290 template <>
2291 class ReinitHelper<TrilinosWrappers::MPI::Vector>
2292 {
2293 public:
2294 template <typename Matrix>
2295 static void
2296 reinit_range_vector(const Matrix &matrix,
2297 TrilinosWrappers::MPI::Vector &v,
2298 bool omit_zeroing_entries)
2299 {
2300 v.reinit(matrix.locally_owned_range_indices(),
2301 matrix.get_mpi_communicator(),
2302 omit_zeroing_entries);
2303 }
2304
2305 template <typename Matrix>
2306 static void
2307 reinit_domain_vector(const Matrix &matrix,
2308 TrilinosWrappers::MPI::Vector &v,
2309 bool omit_zeroing_entries)
2310 {
2311 v.reinit(matrix.locally_owned_domain_indices(),
2312 matrix.get_mpi_communicator(),
2313 omit_zeroing_entries);
2314 }
2315 };
2316
2317 } // namespace LinearOperatorImplementation
2318 } /* namespace internal */
2319
2320
2321
2322 /**
2323 * Declare dealii::TrilinosWrappers::MPI::Vector as distributed vector.
2324 */
2325 template <>
2326 struct is_serial_vector<TrilinosWrappers::MPI::Vector> : std::false_type
2327 {};
2328
2329
2330 DEAL_II_NAMESPACE_CLOSE
2331
2332 #else
2333
2334 // Make sure the scripts that create the C++20 module input files have
2335 // something to latch on if the preprocessor #ifdef above would
2336 // otherwise lead to an empty content of the file.
2337 DEAL_II_NAMESPACE_OPEN
2338 DEAL_II_NAMESPACE_CLOSE
2339
2340 #endif
2341
2342 #endif