AntiSymTenzor.h 18.8 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

#ifndef	ANTI_SYM_TENZOR_H
#define	ANTI_SYM_TENZOR_H

// include files
#include "Utility/PAssert.h"
#include "Message/Message.h"
#include "PETE/IpplExpressions.h"
#include "AppTypes/TSVMeta.h"
#include "AppTypes/Tenzor.h"

#include <iostream>


//////////////////////////////////////////////////////////////////////
//
// Definition of class AntiSymTenzor.
//
//////////////////////////////////////////////////////////////////////

//
//		|  O -x10  -x20 |
//		| x10   0  -x21 |
//		| x20  x21   0  |
//

template<class T, unsigned D>
class AntiSymTenzor
{
public:

  typedef T Element_t;
  enum { ElemDim = 2 };
  enum { Size = D*(D-1)/2 };

  // Default Constructor 
  AntiSymTenzor() {
    TSV_MetaAssignScalar< AntiSymTenzor<T,D>,T,OpAssign>::apply(*this,T(0));
  } 

  // A noninitializing ctor.
  class DontInitialize {};
  AntiSymTenzor(DontInitialize) {}

  // Construct an AntiSymTenzor from a single T.
  // This doubles as the 2D AntiSymTenzor initializer.
  AntiSymTenzor(const T& x00) {
    TSV_MetaAssignScalar< AntiSymTenzor<T,D>,T,OpAssign>::apply(*this,x00);
  }
  // construct a 3D AntiSymTenzor
  AntiSymTenzor(const T& x10, const T& x20, const T& x21) { 
    PInsist(D==3,
            "Number of arguments does not match AntiSymTenzor dimension!!");
    X[0]= x10; X[1]= x20; X[2]= x21;
  }

  // Copy Constructor
  AntiSymTenzor(const AntiSymTenzor<T,D> &rhs) {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T,D> ,OpAssign > :: 
      apply(*this,rhs);
  }

  // Construct from a Tenzor.
  // Extract the antisymmetric part.
  AntiSymTenzor( const Tenzor<T,D>& t ) {
    for (int i=1; i<D; ++i) {
      for (int j=0; j<i; ++j)
	(*this)[((i-1)*i/2)+j] = (t(i,j)-t(j,i))*0.5;
    }
  }

  ~AntiSymTenzor() { };

  // assignment operators
  const AntiSymTenzor<T,D>& operator= (const AntiSymTenzor<T,D> &rhs) {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T,D> ,OpAssign > :: 
      apply(*this,rhs);
    return *this;
  }
  template<class T1>
  const AntiSymTenzor<T,D>& operator= (const AntiSymTenzor<T1,D> &rhs) {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T1,D> ,OpAssign > :: 
      apply(*this,rhs);
    return *this;
  }
  const AntiSymTenzor<T,D>& operator= (const T& rhs) {
    TSV_MetaAssignScalar< AntiSymTenzor<T,D> , T ,OpAssign > :: 
      apply(*this,rhs);
    return *this;
  }

  // accumulation operators
  template<class T1>
  AntiSymTenzor<T,D>& operator+=(const AntiSymTenzor<T1,D> &rhs)
  {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T1,D> , OpAddAssign > 
      :: apply(*this,rhs);
    return *this;
  }

  template<class T1>
  AntiSymTenzor<T,D>& operator-=(const AntiSymTenzor<T1,D> &rhs)
  {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T1,D> , 
      OpSubtractAssign > :: apply(*this,rhs);
    return *this;
  }

  template<class T1>
  AntiSymTenzor<T,D>& operator*=(const AntiSymTenzor<T1,D> &rhs)
  {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T1,D> , 
      OpMultipplyAssign > :: apply(*this,rhs);
    return *this;
  }
  AntiSymTenzor<T,D>& operator*=(const T& rhs)
  {
    TSV_MetaAssignScalar< AntiSymTenzor<T,D> , T , OpMultipplyAssign > :: 
      apply(*this,rhs);
    return *this;
  }

  template<class T1>
  AntiSymTenzor<T,D>& operator/=(const AntiSymTenzor<T1,D> &rhs)
  {
    TSV_MetaAssign< AntiSymTenzor<T,D> , AntiSymTenzor<T1,D> , 
      OpDivideAssign > :: apply(*this,rhs);
    return *this;
  }
  AntiSymTenzor<T,D>& operator/=(const T& rhs)
  {
    TSV_MetaAssignScalar< AntiSymTenzor<T,D> , T , OpDivideAssign > :: 
      apply(*this,rhs);
    return *this;
  }

  // Methods

  int len(void)  const { return Size; }
  int size(void) const { return sizeof(*this); }
  int get_Size(void) const { return Size; }

  class AssignProxy {
  public:
    AssignProxy(Element_t &elem, int where)
      : elem_m(elem), where_m(where) { }
    AssignProxy(const AssignProxy &model)
      : elem_m(model.elem_m), where_m(model.where_m) { }
    const AssignProxy &operator=(const AssignProxy &a)
      {
160
	PAssert_EQ(where_m != 0 || a.elem_m == -a.elem_m, true);
gsell's avatar
gsell committed
161 162 163 164 165
	elem_m = where_m < 0 ? -a.elem_m : a.elem_m;
	return *this;
      }
    const AssignProxy &operator=(const Element_t &e)
      {
166
	PAssert_EQ(where_m != 0 || e == -e, true);
gsell's avatar
gsell committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
	elem_m = where_m < 0 ? -e : e;
	return *this;
      }

    operator Element_t() const
      {
	return (where_m < 0 ? -elem_m : elem_m);
      }

  private:

    Element_t &elem_m;
    int where_m;
  };

  // Operators
  
  Element_t operator()(unsigned int i, unsigned int j) const {
    if (i == j)
      return T(0.0);
    else if (i < j)
      return -X[((j-1)*j/2) + i];
    else
      return X[((i-1)*i/2) + j];
  }

  Element_t operator()( std::pair<int,int> a) const {
    int i = a.first;
    int j = a.second;
    return (*this)(i, j);
  }

  AssignProxy operator()(unsigned int i, unsigned int j) {
    if (i == j)
      return AssignProxy(AntiSymTenzor<T,D>::Zero, 0);
    else
      {
	int lo = i < j ? i : j;
	int hi = i > j ? i : j;
	return AssignProxy(X[((hi-1)*hi/2) + lo], i - j);
      }
  }

  AssignProxy operator()(std::pair<int,int> a) {
    int i = a.first;
    int j = a.second;
    return (*this)(i, j);
  }

  Element_t& operator[](unsigned int i) { 
    PAssert (i < Size);
    return X[i];
  }

  Element_t operator[](unsigned int i) const { 
    PAssert (i < Size);
    return X[i];
  }

  // These are the same as operator[] but with () instead:

  Element_t& operator()(unsigned int i) { 
    PAssert (i < Size);
    return X[i];
  }

  Element_t operator()(unsigned int i) const { 
    PAssert (i < Size);
    return X[i];
  }

  //----------------------------------------------------------------------
  // Comparison operators.
  bool operator==(const AntiSymTenzor<T,D>& that) const {
    return TSV_MetaCompareArrays<T,T,D*(D-1)/2>::apply(X,that.X);
  }
  bool operator!=(const AntiSymTenzor<T,D>& that) const {
    return !(*this == that);
  }

  //----------------------------------------------------------------------
  // parallel communication
  Message& putMessage(Message& m) const {
    m.setCopy(true);
    ::putMessage(m, X, X + Size);
    return m;
  }

  Message& getMessage(Message& m) {
    ::getMessage(m, X, X + Size);
    return m;
  }

private:

  friend class AssignProxy;

  // The elements themselves.
  T X[Size];

  // A place to store a zero element.
  // We need to return a reference to this
  // for the diagonal element.
  static T Zero;
};


// Assign the static zero element value:
template<class T, unsigned int D>
T AntiSymTenzor<T,D>::Zero = 0;



///////////////////////////////////////////////////////////////////////////
// Specialization for 1D  -- this is basically just the zero tensor
///////////////////////////////////////////////////////////////////////////

template <class T>
class AntiSymTenzor<T,1>
{
public:

  typedef T Element_t;
  enum { ElemDim = 2 };

  // Default Constructor 
  AntiSymTenzor() {} 

  // Copy Constructor 
  AntiSymTenzor(const AntiSymTenzor<T,1>&) {}

  // A noninitializing ctor.
  class DontInitialize {};
  AntiSymTenzor(DontInitialize) {}

  // Construct from a Tenzor: still a no-op here:
  AntiSymTenzor( const Tenzor<T,1>& t ) { }

  ~AntiSymTenzor() {}

  // assignment operators
  const AntiSymTenzor<T,1>& operator=(const AntiSymTenzor<T,1>&) {
    return *this;
  }
  template <class T1>
  const AntiSymTenzor<T,1>& operator=(const AntiSymTenzor<T1,1>&) {
    return *this;
  }
  const AntiSymTenzor<T,1>& operator=(const T& rhs) {
    PInsist(rhs==0, "Cannot assign non-zero value to a 1D AntiSymTenzor!");
    return *this;
  }

  // accumulation operators
  template <class T1>
  AntiSymTenzor<T,1>& operator+=(const AntiSymTenzor<T1,1>&) {
    return *this;
  }

  template <class T1>
  AntiSymTenzor<T,1>& operator-=(const AntiSymTenzor<T1,1>&) {
    return *this;
  }

  template <class T1>
  AntiSymTenzor<T,1>& operator*=(const AntiSymTenzor<T1,1>&) {
    return *this;
  }
  AntiSymTenzor<T,1>& operator*=(const T&) {
    return *this;
  }

  template <class T1>
  AntiSymTenzor<T,1>& operator/=(const AntiSymTenzor<T1,1>&) {
    return *this;
  }
  AntiSymTenzor<T,1>& operator/=(const T&) {
    return *this;
  }

  // Methods

  int len(void)  const { return Size; }
  int size(void) const { return sizeof(*this); }
  int get_Size(void) const { return Size; }

  class AssignProxy {
  public:
    AssignProxy(Element_t &elem, int where)
      : elem_m(elem), where_m(where) {}
    AssignProxy(const AssignProxy& model)
      : elem_m(model.elem_m), where_m(model.where_m) {}
    const AssignProxy& operator=(const AssignProxy& a)
      {
361
	PAssert_EQ(where_m != 0 || a.elem_m == -a.elem_m, true);
gsell's avatar
gsell committed
362 363 364 365 366
	elem_m = where_m < 0 ? -a.elem_m : a.elem_m;
	return *this;
      }
    const AssignProxy& operator=(const Element_t& e)
      {
367
	PAssert_EQ(where_m != 0 || e == -e, true);
gsell's avatar
gsell committed
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
	elem_m = where_m < 0 ? -e : e;
	return *this;
      }

    operator Element_t() const
      {
	return (where_m < 0 ? -elem_m : elem_m);
      }

  private:

    Element_t &elem_m;
    int where_m;
  };

  // Operators
  
  Element_t operator()(unsigned int i, unsigned int j) const {
386
    PAssert_EQ(i, j);
gsell's avatar
gsell committed
387 388 389 390 391 392 393 394 395 396
    return T(0.0);
  }

  Element_t operator()( std::pair<int,int> a) const {
    int i = a.first;
    int j = a.second;
    return (*this)(i, j);
  }

  AssignProxy operator()(unsigned int i, unsigned int j) {
397
    PAssert_EQ(i, j);
gsell's avatar
gsell committed
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
    return AssignProxy(AntiSymTenzor<T,1>::Zero, 0);
  }

  AssignProxy operator()(std::pair<int,int> a) {
    int i = a.first;
    int j = a.second;
    return (*this)(i, j);
  }

  Element_t operator[](unsigned int i) const { 
    PAssert (i == 0);
    return AntiSymTenzor<T,1>::Zero;
  }

  // These are the same as operator[] but with () instead:

  Element_t operator()(unsigned int i) const { 
    PAssert (i == 0);
    return AntiSymTenzor<T,1>::Zero;
  }

  //----------------------------------------------------------------------
  // Comparison operators.
  bool operator==(const AntiSymTenzor<T,1>& that) const {
    return true;
  }
  bool operator!=(const AntiSymTenzor<T,1>& that) const {
    return !(*this == that);
  }

  //----------------------------------------------------------------------
  // parallel communication
  Message& putMessage(Message& m) const {
    m.setCopy(true);
    m.put(AntiSymTenzor<T,1>::Zero);
    return m;
  }

  Message& getMessage(Message& m) {
    T zero;
    m.get(zero);
    return m;
  }

private:

  friend class AssignProxy;

  // The number of elements.
  enum { Size = 0 };

  // A place to store a zero element.
  // We need to return a reference to this
  // for the diagonal element.
  static T Zero;
};


// Assign the static zero element value:
template<class T>
T AntiSymTenzor<T,1U>::Zero = 0;



//////////////////////////////////////////////////////////////////////
//
// Free functions
//
//////////////////////////////////////////////////////////////////////

template <class T, unsigned D>
469
inline T trace(const AntiSymTenzor<T,D>&) {
gsell's avatar
gsell committed
470 471 472 473
  return T(0.0);
}

template <class T, unsigned D>
474
inline AntiSymTenzor<T,D> transpose(const AntiSymTenzor<T,D>& rhs) {
gsell's avatar
gsell committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
  return -rhs;
}

// Determinant: only implement for 1D, 2D, 3D:

// For D=3, det is zero, because diagonal elements are zero:
template<class T>
inline T
det(const AntiSymTenzor<T,3>& t)
{
  return T(0.0);
}
// For D=2, det is nonzero; use linear indexing of only stored element:
template<class T>
inline T
det(const AntiSymTenzor<T,2>& t)
{
  T result;
  result = t(0)*t(0);
  return result;
}
// For D=1, det is zero, because diagonal elements are zero:
template<class T>
inline T
det(const AntiSymTenzor<T,1>& t)
{
  return T(0.0);
}

// cofactors() - pow(-1, i+j)*M(i,j), where M(i,j) is a minor of the tensor.
// See, for example, Arfken, Mathematical Methods for Physicists, 2nd Edition,
// p. 157 (the section where the determinant of a matrix is defined).

// Only implement for 1D, 2D, 3D:

template <class T, unsigned D>
511
inline Tenzor<T,D> cofactors(const AntiSymTenzor<T,D>& rhs) {
gsell's avatar
gsell committed
512 513 514 515 516
  PInsist(D<4, "AntiSymTenzor cofactors() function not implemented for D>3!");
  return Tenzor<T,D>(-999999.999999);
}

template <class T>
517
inline Tenzor<T,3> cofactors(const AntiSymTenzor<T,3>& rhs) {
gsell's avatar
gsell committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533

  Tenzor<T,3> result = typename Tenzor<T,3>::DontInitialize();

  result(0,0) = rhs(1,1)*rhs(2,2) - rhs(1,2)*rhs(2,1);
  result(1,0) = rhs(0,2)*rhs(2,1) - rhs(0,1)*rhs(2,2);
  result(2,0) = rhs(0,1)*rhs(1,2) - rhs(1,1)*rhs(0,2);
  result(0,1) = rhs(2,0)*rhs(1,2) - rhs(1,0)*rhs(2,2);
  result(1,1) = rhs(0,0)*rhs(2,2) - rhs(0,2)*rhs(2,0);
  result(2,1) = rhs(1,0)*rhs(0,2) - rhs(0,0)*rhs(1,2);
  result(0,2) = rhs(1,0)*rhs(2,1) - rhs(2,0)*rhs(1,1);
  result(1,2) = rhs(0,1)*rhs(2,0) - rhs(0,0)*rhs(2,1);
  result(2,2) = rhs(0,0)*rhs(1,1) - rhs(1,0)*rhs(0,1);
  return result;
}

template <class T>
534
inline Tenzor<T,2> cofactors(const AntiSymTenzor<T,2>& rhs) {
gsell's avatar
gsell committed
535 536 537 538 539 540 541 542 543 544 545 546 547

  Tenzor<T,2> result = typename Tenzor<T,2>::DontInitialize();

  result(0,0) =  rhs(1,1);
  result(1,0) = -rhs(0,1);
  result(0,1) = -rhs(1,0);
  result(1,1) =  rhs(0,0);
  return result;
}

// For D=1, cofactor is the unit tensor, because det = single tensor element
// value:
template <class T>
548
inline Tenzor<T,1> cofactors(const AntiSymTenzor<T,1>& rhs) {
gsell's avatar
gsell committed
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
  Tenzor<T,1> result = Tenzor<T,1>(1);
  return result;
}


//////////////////////////////////////////////////////////////////////
//
// Unary Operators
//
//////////////////////////////////////////////////////////////////////

//----------------------------------------------------------------------
// unary operator-
template<class T, unsigned D>
inline AntiSymTenzor<T,D> operator-(const AntiSymTenzor<T,D> &op)
{
  return TSV_MetaUnary< AntiSymTenzor<T,D> , OpUnaryMinus > :: apply(op);
}

//----------------------------------------------------------------------
// unary operator+
template<class T, unsigned D>
inline const AntiSymTenzor<T,D> &operator+(const AntiSymTenzor<T,D> &op)
{
  return op;
}

//////////////////////////////////////////////////////////////////////
//
// Binary Operators
//
//////////////////////////////////////////////////////////////////////

//
// Elementwise operators.
//

TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,operator+,OpAdd)
TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,operator-,OpSubtract)
TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,operator*,OpMultipply)
TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,operator/,OpDivide)
TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,Min,FnMin)
TSV_ELEMENTWISE_OPERATOR(AntiSymTenzor,Max,FnMax)

//----------------------------------------------------------------------
// dot products.
//----------------------------------------------------------------------

template < class T1, class T2, unsigned D >
inline Tenzor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const AntiSymTenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< AntiSymTenzor<T1,D> , AntiSymTenzor<T2,D> > :: 
    apply(lhs,rhs);
}

template < class T1, class T2, unsigned D >
inline Tenzor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const AntiSymTenzor<T1,D> &lhs, const Tenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),rhs);
}

template < class T1, class T2, unsigned D >
inline Tenzor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const Tenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(lhs,Tenzor<T2,D>(rhs));
}

template < class T1, class T2, unsigned D >
inline Tenzor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const AntiSymTenzor<T1,D> &lhs, const SymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),Tenzor<T2,D>(rhs));
}

template < class T1, class T2, unsigned D >
inline Tenzor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const SymTenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),Tenzor<T2,D>(rhs));
}

template < class T1, class T2, unsigned D >
inline Vektor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const Vektor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDot< Vektor<T1,D> , AntiSymTenzor<T2,D> > :: apply(lhs,rhs);
}

template < class T1, class T2, unsigned D >
inline Vektor<typename PETEBinaryReturn<T1,T2,OpMultipply>::type,D>
dot(const AntiSymTenzor<T1,D> &lhs, const Vektor<T2,D> &rhs) 
{
  return TSV_MetaDot< AntiSymTenzor<T1,D> , Vektor<T2,D> > :: apply(lhs,rhs);
}

//----------------------------------------------------------------------
// double dot products.
//----------------------------------------------------------------------

template < class T1, class T2, unsigned D >
inline typename PETEBinaryReturn<T1,T2,OpMultipply>::type
dotdot(const AntiSymTenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDotDot< AntiSymTenzor<T1,D> , AntiSymTenzor<T2,D> > :: 
    apply(lhs,rhs);
}

template < class T1, class T2, unsigned D >
inline typename PETEBinaryReturn<T1,T2,OpMultipply>::type
dotdot(const AntiSymTenzor<T1,D> &lhs, const Tenzor<T2,D> &rhs) 
{
  return TSV_MetaDotDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),rhs);
}

template < class T1, class T2, unsigned D >
inline typename PETEBinaryReturn<T1,T2,OpMultipply>::type
dotdot(const Tenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDotDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(lhs,Tenzor<T2,D>(rhs));
}

template < class T1, class T2, unsigned D >
inline typename PETEBinaryReturn<T1,T2,OpMultipply>::type
dotdot(const AntiSymTenzor<T1,D> &lhs, const SymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDotDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),Tenzor<T2,D>(rhs));
}

template < class T1, class T2, unsigned D >
inline typename PETEBinaryReturn<T1,T2,OpMultipply>::type
dotdot(const SymTenzor<T1,D> &lhs, const AntiSymTenzor<T2,D> &rhs) 
{
  return TSV_MetaDotDot< Tenzor<T1,D> , Tenzor<T2,D> > :: 
    apply(Tenzor<T1,D>(lhs),Tenzor<T2,D>(rhs));
}

//----------------------------------------------------------------------
// I/O
template<class T, unsigned D>
698
inline std::ostream& operator<<(std::ostream& out, const AntiSymTenzor<T,D>& rhs) {
gsell's avatar
gsell committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
  if (D >= 1) {
    for (int i=0; i<D; i++) {
      out << "(";
      for (int j=0; j<D-1; j++) {
	out << rhs(i,j) << " , ";
      }
      out << rhs(i,D-1) << ")";
      // I removed this. --TJW: if (i < D - 1) out << endl;
    }
  } else {
    out << "( " << rhs(0,0) << " )";
  }
  return out;
}

//////////////////////////////////////////////////////////////////////

#endif // ANTI_SYM_TENZOR_H

/***************************************************************************
 * $RCSfile: AntiSymTenzor.h,v $
 * $Revision: 1.1.1.1 $
 * IPPL_VERSION_ID: $Id: AntiSymTenzor.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
 ***************************************************************************/