43 #include "AbstractLinAlgPack_VectorMutable.hpp"
44 #include "AbstractLinAlgPack_VectorSubView.hpp"
50 #include "RTOpPack_RTOpC.hpp"
51 #include "RTOpPack_print_sub_vector.hpp"
52 #include "Teuchos_dyn_cast.hpp"
53 #include "Teuchos_Assert.hpp"
54 #include "Teuchos_FancyOStream.hpp"
89 class init_rtop_server_t {
91 init_rtop_server_t() {
94 sum_targ = sum_op.reduct_obj_create();
97 num_nonzeros_targ = num_nonzeros_op.reduct_obj_create();
100 norm_1_targ = norm_1_op.reduct_obj_create();
103 norm_2_targ = norm_2_op.reduct_obj_create();
106 norm_inf_targ = norm_inf_op.reduct_obj_create();
114 init_rtop_server_t init_rtop_server;
120 namespace AbstractLinAlgPack {
124 :num_nonzeros_(-1), norm_1_(-1.0), norm_2_(-1.0), norm_inf_(-1.0)
136 #ifdef ALAP_VECTOR_IGNORE_CACHE_DATA
139 if( num_nonzeros_ < 0 ) {
141 num_nonzeros_op.reduct_obj_reinit(num_nonzeros_targ.ptr());
142 const Vector *vecs[1] = {
this };
143 AbstractLinAlgPack::apply_op(num_nonzeros_op,1,vecs,0,NULL,&*num_nonzeros_targ);
144 num_nonzeros_ = RTOp_ROp_num_nonzeros_val(num_nonzeros_op(*num_nonzeros_targ));
146 return num_nonzeros_;
151 std::ostream& out_arg,
bool print_dim,
bool newline,
152 index_type global_offset
157 RTOpPack::SubVector sub_vec;
159 RTOpPack::SubVector sub_vec_print( sub_vec.globalOffset() + global_offset, sub_vec.subDim(), sub_vec.values(), sub_vec.stride() );
160 RTOpPack::output(*out,sub_vec_print,print_dim,newline);
177 sum_op.reduct_obj_reinit(sum_targ.ptr());
178 const Vector *vecs[1] = {
this };
179 AbstractLinAlgPack::apply_op(
180 sum_op,1,vecs,0,NULL,&*sum_targ
183 return RTOp_ROp_sum_val(sum_op(*sum_targ));
189 #ifdef ALAP_VECTOR_IGNORE_CACHE_DATA
192 if( norm_1_ < 0.0 ) {
194 norm_1_op.reduct_obj_reinit(norm_1_targ.ptr());
195 const Vector *vecs[1] = {
this };
196 AbstractLinAlgPack::apply_op(norm_1_op,1,vecs,0,NULL,&*norm_1_targ);
197 norm_1_ = RTOp_ROp_norm_1_val(norm_1_op(*norm_1_targ));
205 #ifdef ALAP_VECTOR_IGNORE_CACHE_DATA
208 if( norm_2_ < 0.0 ) {
210 norm_2_op.reduct_obj_reinit(norm_2_targ.ptr());
211 const Vector *vecs[1] = {
this };
212 AbstractLinAlgPack::apply_op(norm_2_op,1,vecs,0,NULL,&*norm_2_targ);
213 norm_2_ = RTOp_ROp_norm_2_val(norm_2_op(*norm_2_targ));
221 #ifdef ALAP_VECTOR_IGNORE_CACHE_DATA
224 if( norm_inf_ < 0.0 ) {
226 norm_inf_op.reduct_obj_reinit(norm_inf_targ.ptr());
227 const Vector *vecs[1] = {
this };
228 AbstractLinAlgPack::apply_op(norm_inf_op,1,vecs,0,NULL,&*norm_inf_targ);
229 norm_inf_ = RTOp_ROp_norm_inf_val(norm_inf_op(*norm_inf_targ));
243 namespace rcp = MemMngPack;
244 const index_type
dim = this->
dim();
249 ,
"Vector::sub_view(rng): Error, rng = ["<<rng.
lbound()<<
","<<rng.
ubound()<<
"] "
250 "is not in the range [1,this->dim()] = [1,"<<dim<<
"]" );
267 ,
"Vector::get_sub_vector(rng,...): Error, rng = ["<<rng.
lbound()<<
","<<rng.
ubound()
268 <<
"] is not in range = [1,"<<this->
space().
dim()<<
"]" );
271 if( sub_vec_inout->values() ) {
272 std::free( (
void*)sub_vec_inout->values() );
280 const size_t num_vecs = 1;
281 const Vector* sub_vecs[num_vecs] = {
this };
282 AbstractLinAlgPack::apply_op(
283 get_sub_vector_op,num_vecs,sub_vecs,0,NULL,&*reduct_obj
289 RTOp_ReductTarget reduct_obj_raw = get_sub_vector_op(*reduct_obj);
291 sub_vec_inout->initialize(sub_vec.global_offset,sub_vec.sub_dim,sub_vec.values,sub_vec.values_stride);\
292 reduct_obj.release();
293 std::free(reduct_obj_raw);
300 if( sub_vec->values() )
301 std::free( (
void*)sub_vec->values() );
302 sub_vec->set_uninitialized();
309 norm_1_ = norm_2_ = norm_inf_ = -1.0;
320 for(
size_t k = 0; k < num_targ_vecs; ++k )
331 void AbstractLinAlgPack::apply_op(
332 const RTOpPack::RTOp &op
333 ,
const size_t num_vecs
335 ,
const size_t num_targ_vecs
336 ,VectorMutable* targ_vecs[]
338 ,
const index_type first_ele
339 ,
const index_type sub_dim
340 ,
const index_type global_offset
344 vecs[0]->apply_op(op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj,first_ele,sub_dim,global_offset);
345 else if (num_targ_vecs)
346 targ_vecs[0]->apply_op(op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj,first_ele,sub_dim,global_offset);
virtual vec_ptr_t sub_view(const Range1D &rng) const
Create an abstract view of a vector object .
virtual const VectorSpace & space() const =0
Return the vector space that this vector belongs to.
virtual void get_sub_vector(const Range1D &rng, RTOpPack::SubVector *sub_vec) const
Get a non-mutable explicit view of a sub-vector.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
virtual value_type norm_1() const
One norm. ||v||_1 = sum( |v(i)|, i = 1,,,this->dim() )
virtual void finalize_apply_op(const size_t num_targ_vecs, VectorMutable **targ_vecs) const
This method usually needs to be called by subclasses at the end of the apply_op() method implementati...
Concrete subclass for a default sub-view implementation for a Vector object.
virtual vec_mut_ptr_t clone() const
Create a clone of this vector objet.
virtual value_type norm_inf() const
Infinity norm. ||v||_inf = max( |v(i)|, i = 1,,,this->dim() )
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Vector > vec_ptr_t
virtual value_type norm_2() const
Two norm. ||v||_2 = sqrt( sum( v(i)^2, i = 1,,,this->dim() ) )
struct RTOp_SubVector RTOp_ROp_get_sub_vector_val(RTOp_ReductTarget reduct_obj)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void has_changed() const
Must be called by any vector subclass that modifies this vector object!
virtual std::ostream & output(std::ostream &out, bool print_dim=true, bool newline=true, index_type global_offset=0) const
Virtual output function.
virtual void free_sub_vector(RTOpPack::SubVector *sub_vec) const
Free an explicit view of a sub-vector.
Teuchos::RCP< ReductTarget > reduct_obj_create() const
virtual index_type dim() const =0
Return the dimmension of the vector space.
virtual index_type dim() const
Return the dimension of this vector.
virtual index_type nz() const
Return the number of nonzero elements in the vector.
virtual value_type get_ele(index_type i) const
Fetch an element in the vector.
Abstract interface for mutable coordinate vectors {abstract}.
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
virtual value_type inner_product(const Vector &v) const
Return the inner product of *this with v.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual value_type inner_prod(const Vector &v1, const Vector &v2) const =0
Compute the inner product of two vectors.