isoparametric.h 10.6 KB
Newer Older
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
// This file is a part of nla3d project. For information about authors and
// licensing go to project's repository on github:
// https://github.com/dmitryikh/nla3d 

#pragma once
#include "sys.h"

// Formulations for isoparametric FE for different shapes. Isoparametic formulation means usage of the
// same shape functions for geometry interpolation and for field (displacement, for instance)
//   interpolation.
// These derived classes specify next things:
// 1. Specify form functions
// 2. Specify integration rule (Gauss quadrature)
// 3. Specify field derivatives in local and global coordinates

namespace nla3d {

// structures for convenient keeping of quadrature constants
struct QuadPt1D {
  double r;
  double w;
};


struct QuadPt2D {
  double r;
  double s;
  double w;
};


struct QuadPt3D {
  double r;
  double s;
  double t;
  double w;
};


// gauss quadrature for 1D line from (-1) to (1)
// 1st order
const static QuadPt1D _quad_line_o1[] = {
  {+0.0000000000000000, +2.0000000000000000}
};

// 2nd order
const static QuadPt1D _quad_line_o2[] = {
  {-0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, +1.0000000000000000}
};

// 3rd order
const static QuadPt1D _quad_line_o3[] = {
  {-0.7745966692414834, +0.5555555555555556},
  {+0.0000000000000000, +0.8888888888888888},
  {+0.7745966692414834, +0.5555555555555556}
};

// array of number of quadrature points in integration scheme
const static uint16 _np_line[] = {
  sizeof(_quad_line_o1) / sizeof(QuadPt1D),
  sizeof(_quad_line_o2) / sizeof(QuadPt1D),
  sizeof(_quad_line_o3) / sizeof(QuadPt1D)
};

const static QuadPt1D* _table_line[] = {
  _quad_line_o1,
  _quad_line_o2,
  _quad_line_o3
};


// gauss quadrature for 2D rect from (-1,-1) to (1,1)
// 1st order
const static QuadPt2D _quad_quad_o1[] = {
  {+0.0000000000000000, +0.0000000000000000, +4.0000000000000000}
};

// 2nd order
const static QuadPt2D _quad_quad_o2[] = {
  {-0.5773502691896258, -0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, -0.5773502691896258, +1.0000000000000000},
  {-0.5773502691896258, +0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, +0.5773502691896258, +1.0000000000000000}
};

// 3rd order
const static QuadPt2D _quad_quad_o3[] = {
  {-0.7745966692414834, -0.7745966692414834, +0.3086419753086420},
  {+0.0000000000000000, -0.7745966692414834, +0.4938271604938271},
  {+0.7745966692414834, -0.7745966692414834, +0.3086419753086420},

  {-0.7745966692414834, +0.0000000000000000, +0.4938271604938271},
  {+0.0000000000000000, +0.0000000000000000, +0.7901234567901234},
  {+0.7745966692414834, +0.0000000000000000, +0.4938271604938271},

  {-0.7745966692414834, +0.7745966692414834, +0.3086419753086420},
  {+0.0000000000000000, +0.7745966692414834, +0.4938271604938271},
  {+0.7745966692414834, +0.7745966692414834, +0.3086419753086420}
};


// array of number of quadrature points in integration scheme
const static uint16 _np_quad[] = {
  sizeof(_quad_quad_o1) / sizeof(QuadPt2D),
  sizeof(_quad_quad_o2) / sizeof(QuadPt2D),
  sizeof(_quad_quad_o3) / sizeof(QuadPt2D)
};


const static QuadPt2D* _table_quad[] = {
  _quad_quad_o1,
  _quad_quad_o2,
  _quad_quad_o3
};


// gauss quadrature for 3D brick from (-1,-1,-1) to (1,1,1)
// 1st order
const static QuadPt3D _quad_hexahedron_o1[] = {
  {+0.0000000000000000, +0.0000000000000000, +0.0000000000000000, +8.0000000000000000}
};


// 2nd order
const static QuadPt3D _quad_hexahedron_o2[] = {
  {-0.5773502691896258, -0.5773502691896258, -0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, -0.5773502691896258, -0.5773502691896258, +1.0000000000000000},
  {-0.5773502691896258, +0.5773502691896258, -0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, +0.5773502691896258, -0.5773502691896258, +1.0000000000000000},

  {-0.5773502691896258, -0.5773502691896258, +0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, -0.5773502691896258, +0.5773502691896258, +1.0000000000000000},
  {-0.5773502691896258, +0.5773502691896258, +0.5773502691896258, +1.0000000000000000},
  {+0.5773502691896258, +0.5773502691896258, +0.5773502691896258, +1.0000000000000000}
};


// 3rd order
const static QuadPt3D _quad_hexahedron_o3[] = {
  {-0.7745966692414834, -0.7745966692414834, -0.7745966692414834, +0.1714677640603567},
  {+0.0000000000000000, -0.7745966692414834, -0.7745966692414834, +0.2743484224965707},
  {+0.7745966692414834, -0.7745966692414834, -0.7745966692414834, +0.1714677640603567},

  {-0.7745966692414834, +0.0000000000000000, -0.7745966692414834, +0.2743484224965707},
  {+0.0000000000000000, +0.0000000000000000, -0.7745966692414834, +0.4389574759945130},
  {+0.7745966692414834, +0.0000000000000000, -0.7745966692414834, +0.2743484224965707},

  {-0.7745966692414834, +0.7745966692414834, -0.7745966692414834, +0.1714677640603567},
  {+0.0000000000000000, +0.7745966692414834, -0.7745966692414834, +0.2743484224965707},
  {+0.7745966692414834, +0.7745966692414834, -0.7745966692414834, +0.1714677640603567},


  {-0.7745966692414834, -0.7745966692414834, +0.0000000000000000, +0.2743484224965707},
  {+0.0000000000000000, -0.7745966692414834, +0.0000000000000000, +0.4389574759945130},
  {+0.7745966692414834, -0.7745966692414834, +0.0000000000000000, +0.2743484224965707},

  {-0.7745966692414834, +0.0000000000000000, +0.0000000000000000, +0.4389574759945130},
  {+0.0000000000000000, +0.0000000000000000, +0.0000000000000000, +0.7023319615912207},
  {+0.7745966692414834, +0.0000000000000000, +0.0000000000000000, +0.4389574759945130},

  {-0.7745966692414834, +0.7745966692414834, +0.0000000000000000, +0.2743484224965707},
  {+0.0000000000000000, +0.7745966692414834, +0.0000000000000000, +0.4389574759945130},
  {+0.7745966692414834, +0.7745966692414834, +0.0000000000000000, +0.2743484224965707},


  {-0.7745966692414834, -0.7745966692414834, +0.7745966692414834, +0.1714677640603567},
  {+0.0000000000000000, -0.7745966692414834, +0.7745966692414834, +0.2743484224965707},
  {+0.7745966692414834, -0.7745966692414834, +0.7745966692414834, +0.1714677640603567},

  {-0.7745966692414834, +0.0000000000000000, +0.7745966692414834, +0.2743484224965707},
  {+0.0000000000000000, +0.0000000000000000, +0.7745966692414834, +0.4389574759945130},
  {+0.7745966692414834, +0.0000000000000000, +0.7745966692414834, +0.2743484224965707},

  {-0.7745966692414834, +0.7745966692414834, +0.7745966692414834, +0.1714677640603567},
  {+0.0000000000000000, +0.7745966692414834, +0.7745966692414834, +0.2743484224965707},
  {+0.7745966692414834, +0.7745966692414834, +0.7745966692414834, +0.1714677640603567}
};


const static uint16 _np_hexahedron[] = {
  sizeof(_quad_hexahedron_o1) / sizeof(QuadPt3D),
  sizeof(_quad_hexahedron_o2) / sizeof(QuadPt3D),
  sizeof(_quad_hexahedron_o3) / sizeof(QuadPt3D)
};


const static QuadPt3D* _table_hexahedron[] = {
  _quad_hexahedron_o1,
  _quad_hexahedron_o2,
  _quad_hexahedron_o3
};


class ElementIsoParamLINE : public ElementLINE {
  public:
    double det; //Jacobian

    void makeJacob();

    double intWeight(uint16 np);
    double volume();
    void np2rst(uint16 np, double *xi); //by number of gauss point find local coordinates
    uint16 nOfIntPoints();

    // get form function values in local point (r, s)
    math::Vec<2> formFunc(double r);
    // get form function values in integration point np
    math::Vec<2> formFunc(uint16 np);
    math::Mat<2, 1> formFuncDeriv(double r);

  protected:
    uint16 i_int = 0; // index of integration scheme
};

class ElementIsoParamQUAD : public ElementQUAD {
  public:
    std::vector<math::Mat<4, 2> > NiXj; //derivates form function / local coordinates
    std::vector<double> det;  //Jacobian

    double sideDet[4]; //Jacobian for side integration

    // function to calculate all staff for isoparametric FE
    void makeJacob(); 
    double intWeight(uint16 np);
    double volume();
    void np2rst(uint16 np, double *xi); //by number of gauss point find local coordinates
    uint16 nOfIntPoints();

    // get form function values in local point (r, s)
    math::Vec<4> formFunc(double r, double s);
    // get form function values in integration point np
    math::Vec<4> formFunc(uint16 np);
    math::Mat<4, 2> formFuncDeriv(double r, double s);

  protected:
    uint16 i_int = 0; // index of integration scheme
};


class ElementIsoParamHEXAHEDRON : public ElementHEXAHEDRON {
  public:
    std::vector<math::Mat<8, 3> > NiXj; //derivates form function / local coordinates
    std::vector<double> det;  //Jacobian

    // function to calculate all staff for isoparametric FE
    void makeJacob(); 
    double intWeight(uint16 np);
    double volume();
    void np2rst(uint16 np, double *xi); //by number of gauss point find local coordinates
    uint16 nOfIntPoints();
    // get form function values in local point (r, s, t)
    math::Vec<8> formFunc(double r, double s, double t);
    // get form function values in integration point np
    math::Vec<8> formFunc(uint16 np);
    // get form function derivatives (vs. r,s,t) in local point (r,s,t)
    math::Mat<8, 3> formFuncDeriv(double r, double s, double t);

  protected:
    uint16 i_int = 0; // index of integration scheme
};


inline double ElementIsoParamLINE::intWeight(uint16 np) {
  assert(np < _np_line[i_int]);
  assert(det > 0.0);

  return _table_line[i_int][np].w * det;
}


inline void ElementIsoParamLINE::np2rst (uint16 np, double *v) {
  assert(np < _np_line[i_int]);
  v[0] = _table_line[i_int][np].r;
}


inline uint16 ElementIsoParamLINE::nOfIntPoints() {
  return _np_line[i_int];
}


inline double ElementIsoParamQUAD::intWeight(uint16 np) {
  assert(np < _np_quad[i_int]);
  assert(det.size() != 0);

  return _table_quad[i_int][np].w * det[np];
}


inline void ElementIsoParamQUAD::np2rst (uint16 np, double *v) {
  assert(np < _np_quad[i_int]);
  v[0] = _table_quad[i_int][np].r;
  v[1] = _table_quad[i_int][np].s;
}


inline uint16 ElementIsoParamQUAD::nOfIntPoints() {
  return _np_quad[i_int];
}


inline double ElementIsoParamHEXAHEDRON::intWeight(uint16 np) {
  assert(np < _np_hexahedron[i_int]);
  assert(det.size() != 0);

  return _table_hexahedron[i_int][np].w * det[np];
}


inline void ElementIsoParamHEXAHEDRON::np2rst (uint16 np, double *v) {
  assert(np < _np_hexahedron[i_int]);
  v[0] = _table_hexahedron[i_int][np].r;
  v[1] = _table_hexahedron[i_int][np].s;
  v[2] = _table_hexahedron[i_int][np].t;
}


inline uint16 ElementIsoParamHEXAHEDRON::nOfIntPoints() {
  return _np_hexahedron[i_int];
}

} // namespace nla3d