FirstOrderTerm.h 23.6 KB
Newer Older
1 2 3 4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6 7
// ==                                                                        ==
// ============================================================================
8 9 10 11 12 13 14 15 16 17 18 19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20 21 22 23 24 25

/** \file FirstOrderTerm.h */

#ifndef AMDIS_FIRST_ORDER_TERM_H
#define AMDIS_FIRST_ORDER_TERM_H

26
#include <vector>
27 28 29 30 31 32 33
#include "AMDiS_fwd.h"
#include "OperatorTerm.h"
#include "AbstractFunction.h"
#include "ElInfo.h"

namespace AMDiS {

34 35
  using namespace std;

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  /**
   * \ingroup Assembler
   * 
   * \brief
   * Describes the first order terms: \f$ b \cdot \nabla u(\vec{x}) \f$
   */
  class FirstOrderTerm : public OperatorTerm
  {
  public:
    /// Constructor.
    FirstOrderTerm(int deg) 
      : OperatorTerm(deg) 
    {}

    /// Destructor.
    virtual ~FirstOrderTerm() {}

    /// Evaluation of \f$ \Lambda b \f$.
    virtual void getLb(const ElInfo *elInfo,
55
		       vector<mtl::dense_vector<double> >& result) const = 0;
56 57 58

    /// Implenetation of FirstOrderTerm::eval().
    void eval(int nPoints,
59 60 61 62
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
63 64 65 66
	      double factor)  
    {
      int dow = Global::getGeo(WORLD);

67
      if (num_rows(grdUhAtQP) > 0) {
68 69 70 71 72 73 74 75 76 77
	for (int iq = 0; iq < nPoints; iq++) {
	  double resultQP = 0.0;
	  for (int i = 0; i < dow; i++)
	    resultQP += grdUhAtQP[iq][i];
	  
	  result[iq] += resultQP * factor;
	}
      }
    }

78
  protected:
79 80
    /// Evaluation of \f$ \Lambda \cdot b\f$ if b contains the value 1.0
    /// in each component.
81
    inline void l1(const DimVec<WorldVector<double> >& Lambda,
82
		   mtl::dense_vector<double>& Lb,
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
		   double factor) const
    {
      const int dim = Lambda.getSize();

      for (int i = 0; i < dim; i++) {
	double val = 0.0;
      
	for (int j = 0; j < dimOfWorld; j++)
	  val += Lambda[i][j];

	Lb[i] += val * factor;
      }    
    }

    /// Evaluation of \f$ \Lambda \cdot b\f$.
    inline void lb(const DimVec<WorldVector<double> >& Lambda,
		   const WorldVector<double>& b,
100
		   mtl::dense_vector<double>& Lb,
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
		   double factor) const
    {
      const int dim = Lambda.getSize();

      for (int i = 0; i < dim; i++) {
	double val = 0.0;
	
	for (int j = 0; j < dimOfWorld; j++)
	  val += Lambda[i][j] * b[j];
	
	Lb[i] += val * factor;
      }    
    }

    /// Evaluation of \f$ \Lambda \cdot b\f$.
    inline void lb_one(const DimVec<WorldVector<double> >& Lambda,
117
		       mtl::dense_vector<double>& Lb,
118 119 120 121 122 123 124 125
		       double factor) const
    {
      const int dim = Lambda.getSize();

      for (int i = 0; i < dim; i++)
	Lb[i] += Lambda[i][bOne] * factor;
    }

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b \cdot \nabla u(\vec{x}) \f$ with a vector b which 
   * only consits of entries equal to one.
   */
  class Simple_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    Simple_FOT() 
      : FirstOrderTerm(0) 
    {}

    /// Implements FirstOrderTerm::getLb().
    inline void getLb(const ElInfo *elInfo, 
145
		      vector<mtl::dense_vector<double> >& Lb) const 
146
    {
147
      const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
148
      const int nPoints = static_cast<int>(Lb.size());
149 150

      for (int iq = 0; iq < nPoints; iq++)
151
	l1(grdLambda, Lb[iq], 1.0);
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    }
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b \cdot \nabla u(\vec{x}) \f$ with a vector b which 
   * only consits of entries equal to one.
   */
  class FactorSimple_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    FactorSimple_FOT(double f) 
      : FirstOrderTerm(0)
    {
      factor = new double;
      *factor = f;
    }

    /// Constructor.
    FactorSimple_FOT(double *fptr) 
      : FirstOrderTerm(0), factor(fptr) 
    {}

    /// Implements FirstOrderTerm::getLb().
179 180
    inline void getLb(const ElInfo *elInfo,
		      vector<mtl::dense_vector<double> >& Lb) const
181
    {
182
      const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
183
      const int nPoints = static_cast<int>(Lb.size());
184 185

      for (int iq = 0; iq < nPoints; iq++)
186
	l1(grdLambda, Lb[iq], (*factor));
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    }

  private:
    /// Pointer to the factor.
    double *factor;
  };

  /**
   * \ingroup Assembler
   *
   * \brief 
   * First order term: \f$ b \cdot \nabla u(\vec{x}) \f$ with a given vector b.
   */
  class Vector_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
Praetorius, Simon's avatar
Praetorius, Simon committed
204 205
    Vector_FOT(WorldVector<double> *wv, double fac_ = 1.0) 
      : FirstOrderTerm(0), b(wv), fac(fac_)
206 207 208
    {}

    /// Constructor.
Praetorius, Simon's avatar
Praetorius, Simon committed
209 210
    Vector_FOT(int bIdx, double fac_ = 1.0) 
      : FirstOrderTerm(0), fac(fac_)
211 212 213 214 215
    {
      bOne = bIdx;
    }

    /// Implements FirstOrderTerm::getLb().
216 217
    void getLb(const ElInfo *elInfo, 
	       vector<mtl::dense_vector<double> >& Lb) const 
218
    {
219
      const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
220
      const int nPoints = static_cast<int>(Lb.size());
221 222 223

      if (bOne > -1) {
	for (int iq = 0; iq < nPoints; iq++)
Praetorius, Simon's avatar
Praetorius, Simon committed
224
	  lb_one(grdLambda, Lb[iq], fac);
225 226
      } else {
	for (int iq = 0; iq < nPoints; iq++)
Praetorius, Simon's avatar
Praetorius, Simon committed
227
	  lb(grdLambda, *b, Lb[iq], fac);
228 229 230 231 232
      }
    }

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
233 234 235 236
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
237 238
	      double factor)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
239 240
      if (num_rows(grdUhAtQP) > 0) {
	double factor_ = factor * fac;
241
	for (int iq = 0; iq < nPoints; iq++)
Praetorius, Simon's avatar
Praetorius, Simon committed
242 243
	  result[iq] += *b * grdUhAtQP[iq] * factor_;
      }
244 245 246 247
    }

  protected:
    /// Vector which is multiplied with \f$ \nabla u(\vec{x}) \f$
248
    WorldVector<double> *b;
Praetorius, Simon's avatar
Praetorius, Simon committed
249
    double fac;
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
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * Simple_FOT multiplied with \f$ f(v(\vec{x})) \f$.
   */
  class VecAtQP_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VecAtQP_FOT(DOFVectorBase<double> *dv, 
		AbstractFunction<double, double> *af,
		WorldVector<double> *wv);

    /// Constructor.
    VecAtQP_FOT(DOFVectorBase<double> *dv,
		AbstractFunction<double, double> *af,
		int bIdx);

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

275 276 277 278 279 280
    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

281
    /// Implements FirstOrderTerm::getLb().
282 283
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
284 285 286

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
287 288 289 290
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
291 292 293 294 295 296 297
	      double factor);

  protected:
    /// DOFVector to be evaluated at quadrature points.
    DOFVectorBase<double>* vec;

    /// v at quadrature points.
298
    mtl::dense_vector<double> vecAtQPs;
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

    /// Function f.
    AbstractFunction<double, double> *f;

    ///
    WorldVector<double> *b;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * Simple_FOT multiplied with \f$ f(\vec{x}) \f$.
   */
  class CoordsAtQP_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    CoordsAtQP_FOT(AbstractFunction<double, WorldVector<double> > *af)
      : FirstOrderTerm(af->getDegree()), g(af) 
    {}

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implements FistOrderTerm::getLb().
326 327
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
328 329 330

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
331 332 333 334
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
	      double factor);

  protected:
    /// Stores coordinates at quadrature points. Set in \ref initElement().
    WorldVector<double>* coordsAtQPs;

    /// Function avaluated at world coordinates.
    AbstractFunction<double, WorldVector<double> > *g;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * Vector_FOT multiplied with \f$ f(\vec{x}) \f$.
   */
  class VecCoordsAtQP_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VecCoordsAtQP_FOT(AbstractFunction<double, WorldVector<double> > *af,
356
		      WorldVector<double> *wv)
357 358 359 360 361 362 363 364
      : FirstOrderTerm(af->getDegree()), g(af), b(wv)
    {}

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implements FistOrderTerm::getLb().
365 366
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
367 368 369

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
370 371 372 373
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
374 375 376 377 378 379 380 381 382 383
	      double factor);

  protected:
    /// Stores coordinates at quadrature points. Set in \ref initElement().
    WorldVector<double>* coordsAtQPs;

    /// Function evaluated at world coordinates.
    AbstractFunction<double, WorldVector<double> > *g;

    /// Coefficient vector.
384
    WorldVector<double> *b;
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b(\nabla v(\vec{x})) \cdot \nabla u(\vec{x})\f$.
   */
  class VectorGradient_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VectorGradient_FOT(DOFVectorBase<double> *dv,
		       AbstractFunction<WorldVector<double>, WorldVector<double> > *af);

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implements FirstOrderTerm::getLb().
405 406
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
407 408 409

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
410 411 412 413
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
414 415 416 417 418 419 420 421 422
	      double factor);

  protected:
    DOFVectorBase<double>* vec;

    /// Function for b.
    AbstractFunction<WorldVector<double>, WorldVector<double> > *f;

    /// Gradient of v at quadrature points.
423
    mtl::dense_vector<WorldVector<double> > gradAtQPs;
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b(v(\vec{x})) \cdot \nabla u(\vec{x})\f$.
   */
  class VectorFct_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VectorFct_FOT(DOFVectorBase<double> *dv,
		  AbstractFunction<WorldVector<double>, double> *fct);

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implements FirstOrderTerm::getLb().
444 445
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const; 
446 447 448

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
449 450 451 452
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
453 454 455 456 457 458 459
	      double factor);

  protected:
    /// DOFVector to be evaluated at quadrature points.
    DOFVectorBase<double>* vec;

    /// Vector v at quadrature points.
460
    mtl::dense_vector<double> vecAtQPs;
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484

    /// Function for b.
    AbstractFunction<WorldVector<double>, double> *vecFct;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * 
   */
  class VecFctAtQP_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VecFctAtQP_FOT(AbstractFunction<WorldVector<double>, WorldVector<double> > *af)
      : FirstOrderTerm(af->getDegree()), g(af) 
    {}

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implements FistOrderTerm::getLb().
485 486
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
487 488 489

    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
490 491 492 493
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
	      double factor);

  protected:
    /// Stores coordinates at quadrature points. Set in \ref initElement().
    WorldVector<double>* coordsAtQPs;

    /// Function avaluated at world coordinates.
    AbstractFunction<WorldVector<double>, WorldVector<double> > *g;
  };


  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b(v(\vec{x}), \nabla w(\vec{x})) \cdot \nabla u(\vec{x})\f$.
   */
  class VecGrad_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor.
    VecGrad_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
		BinaryAbstractFunction<WorldVector<double>, double, WorldVector<double> > *fct);

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
    /// Implements FirstOrderTerm::getLb().
529 530
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const; 
531 532 533
    
    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
534 535 536 537
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
538 539 540 541 542 543 544 545
	      double factor);
    
  protected:
    /// DOFVector to be evaluated at quadrature points.
    DOFVectorBase<double>* vec1;
    DOFVectorBase<double>* vec2;
    
    /// Vector v at quadrature points.
546
    mtl::dense_vector<double> vecAtQPs;
547

548
    mtl::dense_vector<WorldVector<double> > gradAtQPs;
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
    
    /// Function for b.
    BinaryAbstractFunction<WorldVector<double>, double, WorldVector<double> > *vecFct;
  };


  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b(\nabla v(\vec{x}), \nabla w(\vec{x})) \cdot \nabla u(\vec{x})\f$.
   */
  class FctGrad2_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor
    FctGrad2_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
		BinaryAbstractFunction<WorldVector<double>, WorldVector<double>, WorldVector<double> > *vecFct_)
      : FirstOrderTerm(vecFct_->getDegree()), vec1(dv1), vec2(dv2), vecFct(vecFct_) 
    {}

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
    /// Implements FirstOrderTerm::getLb().
575 576
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const; 
577 578 579
    
    /// Implements FirstOrderTerm::eval().
    void eval(int nPoints,
580 581 582 583
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
584 585 586 587 588 589 590 591 592 593
	      double factor);
    
  protected:
    /// DOFVector to be evaluated at quadrature points.
    DOFVectorBase<double>* vec1;

    /// DOFVector to be evaluated at quadrature points.
    DOFVectorBase<double>* vec2;
    
    /// Gradient v at quadrature points.
594
    mtl::dense_vector<WorldVector<double> > grad1AtQPs;
595 596

    /// Gradient v at quadrature points.
597
    mtl::dense_vector<WorldVector<double> > grad2AtQPs;
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615

    /// Function for b.
    BinaryAbstractFunction<WorldVector<double>, WorldVector<double>, WorldVector<double> > *vecFct;
  };


  class Vec2AndGradAtQP_FOT : public FirstOrderTerm
  {
  public:
    Vec2AndGradAtQP_FOT(DOFVectorBase<double> *dv1, 
			DOFVectorBase<double> *dv2,
			TertiaryAbstractFunction<double, double, double, WorldVector<double> > *f_, WorldVector<double> *b_);

    void initElement(const ElInfo* elInfo, 
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
    void getLb(const ElInfo *elInfo, 
616
	       vector<mtl::dense_vector<double> >& Lb) const;
617 618
    
    void eval(int nPoints,
619 620 621 622
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
623 624 625
	      double factor);

  protected:
626 627 628
    DOFVectorBase<double> *vec1, *vec2;

    mtl::dense_vector<double> vec1AtQPs, vec2AtQPs;
629

630
    mtl::dense_vector<WorldVector<double> > gradAtQPs1;
631 632

    TertiaryAbstractFunction<double, double, double, WorldVector<double> > *f;
633

634 635 636 637 638 639 640 641 642 643 644 645 646 647
    WorldVector<double> *b;
  };


  class FctVecAtQP_FOT : public FirstOrderTerm
  {
  public:
    FctVecAtQP_FOT(DOFVectorBase<double> *dv,
		   BinaryAbstractFunction<double, WorldVector<double>, double> *f_,
		   WorldVector<double> *b_);
    
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
648 649
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
650 651
    
    void eval(int nPoints,
652 653 654 655
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
656 657 658 659
	      double factor);
    
  protected:
    DOFVectorBase<double>* vec;
660
    mtl::dense_vector<double> vecAtQPs;
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
    WorldVector<double> *coordsAtQPs;
    BinaryAbstractFunction<double, WorldVector<double>, double> *f;
    WorldVector<double> *b;
  };


  class Vec2AtQP_FOT : public FirstOrderTerm
  {
  public:
    Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
		 BinaryAbstractFunction<double, double, double> *af,
		 WorldVector<double> *b_);

    Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
		 BinaryAbstractFunction<double, double, double> *af,
		 int bIdx);
    
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
681 682
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
683 684
    
    void eval(int nPoints,
685 686 687 688
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
689 690 691
	      double factor);
    
  protected:
692 693 694 695
    DOFVectorBase<double> *vec1, *vec2;

    mtl::dense_vector<double> vec1AtQPs, vec2AtQPs;

696
    BinaryAbstractFunction<double, double, double> *f;
697

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    WorldVector<double> *b;
  };


  class Vec3FctAtQP_FOT : public FirstOrderTerm
  {
  public:
    Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, DOFVectorBase<double> *dv3,
		    TertiaryAbstractFunction<double, double, double, double> *f,
		    WorldVector<double> *b);
    
    Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, DOFVectorBase<double> *dv3,
		    TertiaryAbstractFunction<double, double, double, double> *f,
		    int b);
    
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
    
716 717
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& Lb) const;
718 719
    
    void eval(int nPoints,
720 721 722 723
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
724 725 726
	      double factor);
    
  protected:
727 728
    DOFVectorBase<double> *vec1, *vec2, *vec3;

729
    TertiaryAbstractFunction<double, double, double, double>* f;
730 731 732

    mtl::dense_vector<double> vec1AtQPs, vec2AtQPs, vec3AtQPs;

733 734 735 736 737 738 739 740
    WorldVector<double> *b;
  };


  class General_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor
741 742
    General_FOT(vector<DOFVectorBase<double>*> vecs,
		vector<DOFVectorBase<double>*> grads,
743 744
		TertiaryAbstractFunction<WorldVector<double>, 
		WorldVector<double>,
745 746
		vector<double>, 
		vector<WorldVector<double> > > *f);
747 748 749 750 751 752 753

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo*, 
		     SubAssembler* ,
		     Quadrature *quad= NULL);

    /// Implements FirstOrderTerm::getLb().
754 755
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& result) const;
756 757 758

    /// Implenetation of FirstOrderTerm::eval().
    void eval(int nPoints,
759 760 761 762
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
763 764 765
	      double factor);

  protected:
766
    vector<DOFVectorBase<double>*> vecs_; 
767

768
    vector<DOFVectorBase<double>*> grads_;
769 770 771

    TertiaryAbstractFunction<WorldVector<double>, 
			     WorldVector<double>,
772 773
			     vector<double>, 
			     vector<WorldVector<double> > > *f_;
774 775 776

    WorldVector<double> *coordsAtQPs_;

777
    vector<mtl::dense_vector<double> > vecsAtQPs;
778

779
    vector<mtl::dense_vector<WorldVector<double> > > gradsAtQPs_;
780 781 782 783 784 785 786
  };


  class GeneralParametric_FOT : public FirstOrderTerm
  {
  public:
    /// Constructor
787 788
    GeneralParametric_FOT(vector<DOFVectorBase<double>*> vecs,
			  vector<DOFVectorBase<double>*> grads,
789 790 791
			  QuartAbstractFunction<WorldVector<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
792 793
			  vector<double>, 
			  vector<WorldVector<double> > > *f);
794 795 796 797 798

    /// Implementation of \ref OperatorTerm::initElement().
    void initElement(const ElInfo*, SubAssembler*, Quadrature *quad = NULL);

    /// Implements FirstOrderTerm::getLb().
799 800
    void getLb(const ElInfo *elInfo,
	       vector<mtl::dense_vector<double> >& result) const;
801 802 803

    /// Implenetation of FirstOrderTerm::eval().
    void eval(int nPoints,
804 805 806 807
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
808 809 810
	      double factor);

  protected:
811
    vector<DOFVectorBase<double>*> vecs_; 
812

813
    vector<DOFVectorBase<double>*> grads_;
814 815 816 817

    QuartAbstractFunction<WorldVector<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
818 819
			  vector<double>, 
			  vector<WorldVector<double> > > *f_;
820 821 822 823

    WorldVector<double> *coordsAtQPs_;
    WorldVector<double> elementNormal_;

824
    vector<mtl::dense_vector<double> > vecsAtQPs;
825

826
    vector<mtl::dense_vector<WorldVector<double> > > gradsAtQPs_;
827 828 829 830 831
  };

}

#endif