00001 #pragma once
00002
00003 #include <iostream>
00004 #include <memory>
00005 #include "basics/typedefs.hh"
00006 #include "basics/outputOperator.hh"
00007 #include "basics/vectorsMatrices.hh"
00008 #include "geometry/cell2D.hh"
00009 #include "geometry/integral.hh"
00010 #include "integration/quadRule.hh"
00011 #include "space/integral.hh"
00012 #include "space/element.hh"
00013 #include "function/vector.hh"
00014 #include "integration/karniadakis.hh"
00015 #include "hp2D/quad.hh"
00016 #include "unitcell.h"
00017 #include "gfemOverlapCondition.h"
00018 #include "gfemDofIterator.h"
00019 #include "geometry/cell2D.hh"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 namespace concepts {
00031 namespace gfem {
00032
00033
00034 class GfemQuad : public concepts::ElementWithCell<Real> {
00035 public:
00036 enum EvalMode { EVAL_ON_MICRO = 0, EVAL_ON_MACRO };
00037
00038 GfemQuad(concepts::Quad2d& macroC, const Unitcell& uc
00039 , concepts::TColumn<Real>* T, int p_macro[2]
00040 , GfemOverlapCondition& overC, EvalMode eval_mode = EVAL_ON_MICRO);
00041 virtual ~GfemQuad();
00042
00043 private:
00044 GfemQuad(const GfemQuad& other);
00045 GfemQuad& operator=(const GfemQuad& other);
00046
00047 public:
00048
00049 virtual const Quad2d& cell() const {
00050 return macroC;
00051 }
00052
00053 void recomputeShapefunctions() {
00054 clear();
00055 initialise();
00056 }
00057
00058 static int disableFull(int mask, int i_edge) {
00059 return mask | (1024 << i_edge);
00060 }
00061
00062 static int disablePartly(int mask, int i_elm) {
00063 return mask | (1 << i_elm);
00064 }
00065
00066 static bool partlyDisabled(int mask, int i_elm) {
00067 return (mask & (1024 << i_elm)) | (mask & (1 << i_elm));
00068 }
00069
00070 static bool fullyDisabled(int mask, int i_elm) {
00071 return mask & (1024 << i_elm);
00072 }
00073
00074 static bool partlyDisabled(int mask) {
00075 return mask != 0;
00076 }
00077
00078 static bool fullyDisabled(int mask) {
00079 return mask > 1024;
00080 }
00081
00086 virtual const TMatrixBase<Real>& T() const {
00087 return T_;
00088 }
00089
00090
00091
00092 virtual const ElementGraphics<Real>* graphics() const;
00093
00094 const concepts::Quad& support () const
00095 {
00096
00097 return macroC.connector();
00098 }
00099
00101 MapReal2d getMacroJacobian(const Real& xi, const Real& eta) const {
00102 return macroC.jacobian(xi, eta);
00103 }
00104
00105 MapReal2d getMacroJacobian(int i_quad) const {
00106 const Real pos_x = abscissas_x[i_quad];
00107 const Real pos_y = abscissas_x[i_quad];
00108
00109
00110 return (getMacroJacobian((pos_x+1)/2, (pos_y+1)/2));
00111 }
00112
00113 int getNRepX() const {
00114 return n_repX;
00115 }
00116
00117 int getNRepY() const {
00118 return n_repY;
00119 }
00120
00121 MapReal2d getMicroJacobian(int i_quad) const {
00122 return (uc_jacobian[i_quad] * 2).scaleCols(Real2d(n_repX, n_repY));
00123 }
00124
00125 const Cmplx& getMicroShape(int i_micro, int i_quad) const {
00126 return const_cast<GfemQuad*>(this)->uc_shape_val(i_micro, i_quad);
00127 }
00128
00130 const Cmplx& uc_shape_val(int i_ucfun, int i_quad) const {
00131 return const_cast<GfemQuad*>(this)->uc_shape_val(i_ucfun, i_quad);
00132 }
00133
00134 Cmplx& uc_shape_val(int i_ucfun, int i_quad) {
00135 assert(i_quad < nquad);
00136 assert(i_ucfun < numMicro());
00137 return uc_shape[i_ucfun * nquad + i_quad];
00138 }
00139
00140 const Cmplx2d& uc_shape_valD(int i_ucfun, int i_quad) const {
00141 return const_cast<GfemQuad*>(this)->uc_shape_valD(i_ucfun, i_quad);
00142 }
00143
00144 Cmplx2d& uc_shape_valD(int i_ucfun, int i_quad) {
00145 assert(i_quad < nquad);
00146 assert(i_ucfun < numMicro());
00147 return uc_shape_D[i_ucfun * nquad + i_quad];
00148 }
00149
00150 const Real& getWeight(int i_quad) const {
00151 return weights[i_quad];
00152 }
00153
00154 Real2d getWorldPoint(int i_quad) const {
00155 return macroC.chi((abscissas_x[i_quad]+1)/2, (abscissas_y[i_quad]+1)/2);
00156 }
00157
00158 Real2d getUCPoint(int i_quad) const {
00159 return Real2d((abscissas_x[i_quad]+1)/2, (abscissas_y[i_quad]+1)/2);
00160 }
00161
00162 Real2d getAbscissa(int i_quad) const {
00163 return Real2d(abscissas_x[i_quad], abscissas_y[i_quad]);
00164 }
00165
00166 Real getMacroShapeX(int i_func, int i_quad) const {
00167 if(i_func < 0)
00168 return 1;
00169 return macro_shapeX->values()[i_func*nquad + i_quad];
00170 }
00171
00172 Real getMacroShapeY(int i_func, int i_quad) const {
00173 if(i_func < 0)
00174 return 1;
00175 return macro_shapeY->values()[i_func*nquad + i_quad];
00176 }
00177
00178 Real2d getMacroShapeD(int i_funcX, int i_funcY, int i_quad) const {
00179
00180 return Real2d(2*getMacroShapeDX(i_funcX, i_quad)*getMacroShapeY(i_funcY, i_quad)
00181 , 2*getMacroShapeDY(i_funcY, i_quad)*getMacroShapeX(i_funcX, i_quad) );
00182 }
00183
00184 Real getMacroShapeDX(int i_func, int i_quad) const {
00185 if(i_func < 0)
00186 return 0;
00187 return macro_shapeDX->values()[i_func*nquad + i_quad];
00188 }
00189
00190 Real getMacroShapeDY(int i_func, int i_quad) const {
00191 if(i_func < 0)
00192 return 0;
00193 return macro_shapeDY->values()[i_func*nquad + i_quad];
00194 }
00195
00199 static int packLdofUC(int i_shape_x, int i_shape_y, int n_shape_macro_x) {
00200 assert(i_shape_x < n_shape_macro_x);
00201 return i_shape_y * n_shape_macro_x + i_shape_x;
00202 }
00203
00204 int numMacro() const {
00205 return macro_shapeX->n() * macro_shapeY->n();
00206 }
00207
00208 int numMacroX() const {
00209 return macro_shapeX->n();
00210 }
00211
00212 int numMacroY() const {
00213 return macro_shapeY->n();
00214 }
00215
00216 int numMicro() const {
00217 return n_micro;
00218 }
00219
00220 int numUCFun() const {
00221 return n_ucfun;
00222 }
00223
00224 int numQuadPoints() const {
00225 return nquad;
00226 }
00227
00228 const Real* getAbscissas_x() const {
00229 return abscissas_x;
00230 }
00231
00232 const Real* getAbscissas_y() const {
00233 return abscissas_y;
00234 }
00235
00236 const Real* getWeights() const {
00237 return weights;
00238 }
00239
00240 const Cmplx* getUCShape() const {
00241 return uc_shape;
00242 }
00243
00244 const Cmplx2d* getUCShapeD() const {
00245 return uc_shape_D;
00246 }
00247
00248 const Unitcell& getUC() const {
00249 return uc;
00250 }
00251
00253 int num_shape() const {
00254 return numTidx();
00255 }
00256
00257 const concepts::Karniadakis<1,0>& getMacroShapeX() const {
00258 return *macro_shapeX;
00259 }
00260
00261 const concepts::Karniadakis<1,0>& getMacroShapeY() const {
00262 return *macro_shapeY;
00263 }
00264
00265 const concepts::Karniadakis<1,1>& getMacroShapeDX() const {
00266 return *macro_shapeDX;
00267 }
00268
00269 const concepts::Karniadakis<1,1>& getMacroShapeDY() const {
00270 return *macro_shapeDY;
00271 }
00272
00277 const int* getPMax() {
00278 return p_max;
00279 }
00280
00284 const int* getPMacro() {
00285 return p_macro;
00286 }
00287
00288 const ElementWithCell<Real>* getMicroElem(int i_quad) const {
00289 return micro_elems[i_quad];
00290 }
00291
00293 int numTidx() const {
00294 return numLDof();
00295 }
00296
00297 int numLDof() const {
00298 return begin().numLdofs();
00299 }
00300
00301
00302 EvalMode getEvalMode() const {
00303 return eval_mode;
00304 }
00305
00306 const GfemDofIterator& begin() const {
00307 return it_begin;
00308 }
00309
00310 protected:
00311 void initialise();
00312 void clear();
00313
00314 private:
00315 Quad2d& macroC;
00316 const Unitcell& uc;
00317 concepts::TMatrix<Real> T_;
00318 GfemOverlapCondition overC;
00319 GfemDofIterator it_begin;
00320 int p_max[2];
00321 int p_macro[2];
00322 int n_micro;
00323 int n_borderFuns;
00324 int n_ucfun;
00325
00326 int nquad;
00327 int n_shape_macro_x;
00328 int n_shape_macro_y;
00329
00338 Real offX;
00339 Real offY;
00340 Real sizeX;
00341 Real sizeY;
00344 Real* abscissas_x;
00345 Real* abscissas_y;
00346 Real* weights;
00347 MapReal2d* uc_jacobian;
00348
00349 Cmplx* uc_shape;
00350 Cmplx2d* uc_shape_D;
00351 const ElementWithCell<Real>** micro_elems;
00352
00354 Karniadakis<1,0>* macro_shapeX;
00355 Karniadakis<1,0>* macro_shapeY;
00357 Karniadakis<1,1>* macro_shapeDX;
00358 Karniadakis<1,1>* macro_shapeDY;
00359
00360 int n_repX;
00361 int n_repY;
00362
00363 EvalMode eval_mode;
00364 };
00365
00366 }
00367 }