Go to the documentation of this file.00001 #pragma once
00002
00003 #include "gfemQuad.h"
00004 #include "space/space.hh"
00005 #include "geometry/mesh.hh"
00006 #include "hp2D/quad.hh"
00007 #include <vector>
00008 #include <new>
00009 #include <iostream>
00010 #include "limits"
00011
00012 namespace concepts {
00013 namespace gfem {
00014
00015 template<uint dim>
00016 struct GfemControl : public concepts::AdaptiveControlTag {
00017 using AdaptiveControlTag::tagInfo;
00018 const static bool NO_SCALE_RES = false;
00019 const static bool USE_SCALE_RES = true;
00020
00021 GfemControl(tagInfo tag = NO_TAG)
00022 : AdaptiveControlTag((uchar)tag)
00023 , firstGDof(UNSET_DOF)
00024 , firstOverlapDof(UNSET_DOF)
00025 , numDofs(0)
00026 , uc(NULL)
00027 , scaleResolution(NO_SCALE_RES)
00028 , overlapping(false)
00029 {
00030 for(uint i=0; i < dim; ++i) {
00031 if(dim == 1) {
00032 Ps[i] = std::numeric_limits<int>::max();
00033 } else {
00034 Ps[i] = -1;
00035 }
00036 }
00037 }
00038
00039 ~GfemControl()
00040 {
00041 if(uc) {
00042 delete uc;
00043 uc = NULL;
00044 }
00045 }
00046
00047 GfemControl(const GfemControl& other)
00048 {
00049
00050 new(this) GfemControl( (tagInfo)other.data_);
00051
00052 if(uc) {
00053 setMicroStruct(*uc, other.scaleResolution);
00054 }
00055
00056 setPs(other.getPs());
00057 firstGDof = other.firstGDof;
00058 firstOverlapDof = other.firstOverlapDof;
00059 numDofs = other.numDofs;
00060 overlapping = other.overlapping;
00061 }
00062
00063 private:
00064 GfemControl& operator=(const GfemControl& other);
00065
00066 public:
00067
00068 void setMicroStruct(const Unitcell& uc, bool scaleRes) {
00069 if(this->uc)
00070 delete this->uc;
00071 this->uc = new UnitcellMask(uc);
00072 scaleResolution = scaleRes;
00073 }
00074
00076 bool hasMicroStructure() const {
00077 return uc != NULL;
00078 }
00079
00083 bool hasScaleRes() const {
00084 return scaleResolution == USE_SCALE_RES;
00085 }
00086
00088 const int* getPs() const {
00089 return Ps;
00090 }
00091
00093 void setPs(const int* ps) {
00094 for(uint i=0; i < dim; ++i) {
00095 Ps[i] = ps[i];
00096 }
00097 }
00098
00100 void minPs(const int* ps) {
00101 for(uint i=0; i < dim; ++i) {
00102 Ps[i] = min(ps[i], Ps[i]);
00103 }
00104 }
00105
00106 bool hasDof() const {
00107 return firstGDof != UNSET_DOF;
00108 }
00109
00110 int getGdof(int num) const {
00111 assert(num < numDofs);
00112 return firstGDof + num;
00113 }
00114
00115 int getNumDofs() const {
00116 return numDofs;
00117 }
00118
00119 bool isOverlap() const {
00120 return overlapping;
00121 }
00122
00123 void setOverlap(bool overlap) {
00124 overlapping = overlap;
00125 }
00126
00127 void setGdof(int dof, int numDofs = 1) {
00128 assert(firstGDof == UNSET_DOF || firstGDof == dof);
00129 assert(this->numDofs == 0);
00130 assert(numDofs > 0);
00131 firstGDof = dof;
00132 this->numDofs = numDofs;
00133 takeIn();
00134 }
00135
00136 int& getFirstOverlapDof() const {
00137 return firstOverlapDof;
00138 }
00139
00141 const UnitcellMask* getUC() const {
00142 return uc;
00143 }
00144
00145 UnitcellMask* getUC() {
00146 return uc;
00147 }
00148
00149 static const int UNSET_DOF = -1;
00150 private:
00151 int firstGDof;
00152 int firstOverlapDof;
00153 int numDofs;
00154
00155
00156 int Ps[dim];
00157
00158 UnitcellMask* uc;
00159 bool scaleResolution;
00160 bool overlapping;
00161
00162
00163 };
00164
00165 typedef GfemControl<0> GfemControlVert;
00166 typedef GfemControl<1> GfemControlEdge;
00167 typedef GfemControl<2> GfemControlCell;
00168
00169 template<uint dim>
00170 inline std::ostream& operator<<(std::ostream& os, const GfemControl<dim>& c)
00171 {
00172 os << (AdaptiveControlTag)c;
00173 if(c.hasDof()) {
00174 assert(c.getNumDofs() > 0);
00175 os << " gdof=" << c.getGdof(0) << " .. " << c.getGdof(c.getNumDofs()-1);
00176 }
00177 if(dim > 0) {
00178 const int* Ps = c.getPs();
00179 os << " Ps: ";
00180 for(int i=0; i < (int)dim; ++i) {
00181 os << Ps[i] << " ";
00182 }
00183 }
00184 if(c.hasMicroStructure()) {
00185 os << " with micro structure.";
00186 if(c.hasScaleRes()) {
00187 os << " (scale res)";
00188 }
00189 } else {
00190
00191 }
00192 if(c.isOverlap()) {
00193 os << " (overlapping)";
00194 }
00195 return os;
00196 }
00197
00198 }
00199 }