// GenFem - A high-level finite element library
// Copyright (C) 2010-2026 Eric Bechet
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//
// Initial design: Eric Bechet (rev.8804 in gmsh)


#include "genMiscTerms.h"

template<class T> void LaplaceTerm<T,T>::get(MElement* ele, int npts, IntPt* GP, ContainerValType &vals) const
{
  int nbFF = BilinearTerm<T,T>::space1->getNumKeys(ele);
  double jac[3][3];
  vals.resize(nbFF, nbFF);
  vals.setAll(0.);
  for(int i = 0; i < npts; ++i)
  {
    const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
    const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
    typename genFSpace<T>::ContainerGradType grads1;
    BilinearTerm<T,T>::space1->gradf(ele, u, v, w, grads1);
    for(int j = 0; j < nbFF; ++j)
    {
      for(int k = j; k < nbFF; ++k)
      {
        double contrib = weight * detJ * dot(grads1(j), grads1(k)) * diffusivity;
        vals(j, k) += contrib;
        if(j != k) vals(k, j) += contrib;
      }
    }
  }
}

//--------------------------------------------------------------------------
// ElasticTerm
//--------------------------------------------------------------------------

template <int n1,int n2> ElasticTerm<n1,n2>::ElasticTerm(typename diffTerm<genTensor1<double>,n1>::ConstHandle space1_,typename diffTerm<genTensor1<double>,n2>::ConstHandle space2_ ) : space1(space1_), space2(space2_),H(6, 6)
{
  sym = (&(*space1_) == &(*space2_));
}

template <int n1,int n2> ElasticTerm<n1,n2>::ElasticTerm( typename diffTerm<genTensor1<double>,n1>::ConstHandle space1_) : space1(space1_), space2(space1_), H(6, 6)
{
  sym = true;
}

