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 160 161 162 163 164 165 166 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
|
// Gmsh - Copyright (C) 1997-2020 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
//
// Contributor(s):
// Eric Bechet
//
#ifndef TERMS_H
#define TERMS_H
#include "SVector3.h"
#include "STensor3.h"
#include "STensor43.h"
#include "Numeric.h"
#include "functionSpace.h"
#include "groupOfElements.h"
#include "materialLaw.h"
#include <vector>
#include <iterator>
template <class T2> class ScalarTermBase;
template <class T2> class LinearTermBase;
template <class T2> class PlusTerm;
class BilinearTermBase;
inline double dot(const double &a, const double &b) { return a * b; }
inline int delta(int i, int j)
{
if(i == j)
return 1;
else
return 0;
}
inline void setDirection(double &a, const double &b) { a = b; }
inline void setDirection(SVector3 &a, const SVector3 &b)
{
for(int i = 0; i < 3; i++) a(i) = b(i);
}
template <class T2 = double> class ScalarTermBase {
public:
virtual ~ScalarTermBase() {}
virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const = 0;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<T2> &vval) const = 0;
virtual ScalarTermBase<T2> *clone() const = 0;
};
template <class T2 = double> class ScalarTerm : public ScalarTermBase<T2> {
public:
virtual ~ScalarTerm() {}
};
template <class T2 = double> class ScalarTermConstant : public ScalarTerm<T2> {
protected:
T2 cst;
public:
ScalarTermConstant(T2 val_ = T2()) : cst(val_) {}
virtual ~ScalarTermConstant() {}
virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<T2> &vval) const;
virtual void get(MVertex *ver, T2 &val) const;
virtual ScalarTermBase<T2> *clone() const
{
return new ScalarTermConstant<T2>(cst);
}
};
class BilinearTermToScalarTerm : public ScalarTerm<double> {
protected:
BilinearTermBase &bilterm;
public:
BilinearTermToScalarTerm(BilinearTermBase &bilterm_) : bilterm(bilterm_) {}
virtual ~BilinearTermToScalarTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP, double &val) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<double> &vval) const {};
virtual ScalarTermBase<double> *clone() const
{
return new BilinearTermToScalarTerm(bilterm);
}
};
class BilinearTermBase {
public:
virtual ~BilinearTermBase() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &mv) const = 0;
virtual BilinearTermBase *clone() const = 0;
};
template <class T2> class BilinearTermContract : public BilinearTermBase {
protected:
const LinearTermBase<T2> *a;
const LinearTermBase<T2> *b;
public:
BilinearTermContract(const LinearTermBase<T2> &a_,
const LinearTermBase<T2> &b_)
: a(a_.clone()), b(b_.clone())
{
}
virtual ~BilinearTermContract()
{
delete a;
delete b;
}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &mv) const {};
virtual BilinearTermBase *clone() const
{
return new BilinearTermContract<T2>(*a, *b);
}
};
template <class T2>
class BilinearTermContractWithLaw : public BilinearTermContract<T2> {
public:
protected:
const ScalarTermBase<typename TensorialTraits<T2>::TensProdType> *c;
public:
BilinearTermContractWithLaw(
const LinearTermBase<T2> &a_,
const ScalarTermBase<typename TensorialTraits<T2>::TensProdType> &c_,
const LinearTermBase<T2> &b_)
: BilinearTermContract<T2>(a_, b_), c(c_.clone())
{
}
virtual ~BilinearTermContractWithLaw() { delete c; }
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &mv) const;
virtual BilinearTermBase *clone() const
{
return new BilinearTermContractWithLaw<T2>(*BilinearTermContract<T2>::a, *c,
*BilinearTermContract<T2>::b);
}
};
template <class T2>
BilinearTermContract<T2> operator|(const LinearTermBase<T2> &L1,
const LinearTermBase<T2> &L2);
template <class T1, class T2> class BilinearTerm : public BilinearTermBase {
protected:
FunctionSpace<T1> &space1;
FunctionSpace<T2> &space2;
public:
BilinearTerm(FunctionSpace<T1> &space1_, FunctionSpace<T2> &space2_)
: space1(space1_), space2(space2_)
{
}
virtual ~BilinearTerm() {}
};
template <class T2 = double> class LinearTermBase {
public:
virtual ~LinearTermBase() {}
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullVector<T2> > &vv) const = 0;
virtual LinearTermBase<T2> *clone() const = 0;
PlusTerm<T2> operator+(const LinearTermBase<T2> &other);
};
template <class T2> class PlusTerm : public LinearTermBase<T2> {
const LinearTermBase<T2> *a;
const LinearTermBase<T2> *b;
public:
PlusTerm(const LinearTermBase<T2> &a_, const LinearTermBase<T2> &b_)
: a(a_.clone()), b(b_.clone())
{
}
virtual ~PlusTerm()
{
delete a;
delete b;
}
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullVector<T2> > &vv) const {};
virtual LinearTermBase<T2> *clone() const { return new PlusTerm<T2>(*a, *b); }
};
template <class T1, class T2 = double>
class LinearTerm : public LinearTermBase<T2> {
protected:
FunctionSpace<T1> &space1;
public:
LinearTerm(FunctionSpace<T1> &space1_) : space1(space1_) {}
virtual ~LinearTerm() {}
};
template <class T1>
class GradTerm : public LinearTerm<T1, typename TensorialTraits<T1>::GradType> {
public:
GradTerm(FunctionSpace<T1> &space1_)
: LinearTerm<T1, typename TensorialTraits<T1>::GradType>(space1_)
{
}
virtual void
get(MElement *ele, int npts, IntPt *GP,
fullVector<typename TensorialTraits<T1>::GradType> &vec) const
{
LinearTermBase<typename TensorialTraits<T1>::GradType>::get(ele, npts, GP,
vec);
}
virtual void
get(MElement *ele, int npts, IntPt *GP,
std::vector<fullVector<typename TensorialTraits<T1>::GradType> > &vvec)
const;
virtual LinearTermBase<typename TensorialTraits<T1>::GradType> *clone() const
{
return new GradTerm<T1>(
LinearTerm<T1, typename TensorialTraits<T1>::GradType>::space1);
}
virtual ~GradTerm() {}
};
template <class T1, class T2> class LaplaceTerm : public BilinearTerm<T1, T2> {
public:
LaplaceTerm(FunctionSpace<T1> &space1_, FunctionSpace<T2> &space2_)
: BilinearTerm<T1, T2>(space1_, space2_)
{
}
virtual ~LaplaceTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const
{
Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented");
}
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &vm) const
{
Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented");
}
virtual void get(MVertex *ver, fullMatrix<double> &m)
{
Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented");
}
virtual BilinearTermBase *clone() const
{
return new LaplaceTerm<T1, T2>(BilinearTerm<T1, T2>::space1,
BilinearTerm<T1, T2>::space2);
}
}; // class
template <class T1>
class LaplaceTerm<T1, T1>
: public BilinearTerm<T1, T1> // symmetric
{
protected:
double diffusivity;
public:
LaplaceTerm(FunctionSpace<T1> &space1_, double diff = 1)
: BilinearTerm<T1, T1>(space1_, space1_), diffusivity(diff)
{
}
virtual ~LaplaceTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &vm) const {};
virtual BilinearTermBase *clone() const
{
return new LaplaceTerm<T1, T1>(BilinearTerm<T1, T1>::space1, diffusivity);
}
}; // class
class IsotropicElasticTerm : public BilinearTerm<SVector3, SVector3> {
protected:
double E, nu;
bool sym;
fullMatrix<double> H; /* =
{ {C11, C12, C12, 0, 0, 0},
{C12, C11, C12, 0, 0, 0},
{C12, C12, C11, 0, 0, 0},
{ 0, 0, 0, C44, 0, 0},
{ 0, 0, 0, 0, C44, 0},
{ 0, 0, 0, 0, 0, C44} };*/
public:
IsotropicElasticTerm(FunctionSpace<SVector3> &space1_,
FunctionSpace<SVector3> &space2_, double E_, double nu_);
IsotropicElasticTerm(FunctionSpace<SVector3> &space1_, double E_, double nu_);
virtual ~IsotropicElasticTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &vm) const {};
virtual BilinearTermBase *clone() const
{
return new IsotropicElasticTerm(BilinearTerm<SVector3, SVector3>::space1,
BilinearTerm<SVector3, SVector3>::space2, E,
nu);
}
}; // class
template <class T1> class LoadTerm : public LinearTerm<T1> {
protected:
simpleFunction<typename TensorialTraits<T1>::ValType> *Load;
public:
LoadTerm(FunctionSpace<T1> &space1_,
simpleFunction<typename TensorialTraits<T1>::ValType> *Load_)
: LinearTerm<T1>(space1_), Load(Load_)
{
}
virtual ~LoadTerm() {}
virtual LinearTermBase<double> *clone() const
{
return new LoadTerm<T1>(LinearTerm<T1>::space1, Load);
}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullVector<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullVector<double> > &vv) const {};
};
template <class T1>
class LagrangeMultiplierTerm : public BilinearTerm<T1, double> {
T1 _d;
public:
LagrangeMultiplierTerm(FunctionSpace<T1> &space1_,
FunctionSpace<double> &space2_, const T1 &d)
: BilinearTerm<T1, double>(space1_, space2_)
{
setDirection(_d, d);
}
virtual ~LagrangeMultiplierTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &vm) const {};
virtual BilinearTermBase *clone() const
{
return new LagrangeMultiplierTerm(BilinearTerm<T1, double>::space1,
BilinearTerm<T1, double>::space2, _d);
}
};
class LagMultTerm : public BilinearTerm<SVector3, SVector3> {
private:
double _eqfac;
public:
LagMultTerm(FunctionSpace<SVector3> &space1_,
FunctionSpace<SVector3> &space2_, double eqfac = 1.0)
: BilinearTerm<SVector3, SVector3>(space1_, space2_), _eqfac(eqfac)
{
}
virtual ~LagMultTerm() {}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullMatrix<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullMatrix<double> > &vm) const {};
virtual BilinearTermBase *clone() const
{
return new LagMultTerm(BilinearTerm<SVector3, SVector3>::space1,
BilinearTerm<SVector3, SVector3>::space2, _eqfac);
}
};
template <class T1> class LoadTermOnBorder : public LinearTerm<T1> {
private:
double _eqfac;
simpleFunction<typename TensorialTraits<T1>::ValType> *Load;
public:
LoadTermOnBorder(FunctionSpace<T1> &space1_,
simpleFunction<typename TensorialTraits<T1>::ValType> *Load_,
double eqfac = 1.0)
: LinearTerm<T1>(space1_), _eqfac(eqfac), Load(Load_)
{
}
virtual ~LoadTermOnBorder() {}
virtual LinearTermBase<double> *clone() const
{
return new LoadTermOnBorder<T1>(LinearTerm<T1>::space1, Load, _eqfac);
}
virtual void get(MElement *ele, int npts, IntPt *GP,
fullVector<double> &m) const;
virtual void get(MElement *ele, int npts, IntPt *GP,
std::vector<fullVector<double> > &vv) const {};
};
#include "terms.hpp"
#endif
|