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
|
// Gmsh - Copyright (C) 1997-2012 C. Geuzaine, J.-B-> Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
#include "BasisFactory.h"
#include "GmshDefines.h"
#include "polynomialBasis.h"
#include "pyramidalBasis.h"
#include "bezierBasis.h"
#include "miniBasis.h"
#include "CondNumBasis.h"
#include "JacobianBasis.h"
#include <map>
#include <cstddef>
std::map<int, nodalBasis *> BasisFactory::fs;
std::map<int, CondNumBasis *> BasisFactory::cs;
std::map<FuncSpaceData, JacobianBasis *> BasisFactory::js;
std::map<FuncSpaceData, bezierBasis *> BasisFactory::bs;
std::map<FuncSpaceData, GradientBasis *> BasisFactory::gs;
const nodalBasis *BasisFactory::getNodalBasis(int tag)
{
// If the Basis has already been built, return it.
auto it = fs.find(tag);
if(it != fs.end()) { return it->second; }
// Get the parent type to see which kind of basis
// we want to create
nodalBasis *F = nullptr;
if(tag == MSH_TRI_MINI)
F = new miniBasisTri();
else if(tag == MSH_TET_MINI)
F = new miniBasisTet();
else {
int parentType = ElementType::getParentType(tag);
switch(parentType) {
case(TYPE_PNT):
case(TYPE_LIN):
case(TYPE_TRI):
case(TYPE_QUA):
case(TYPE_PRI):
case(TYPE_TET):
case(TYPE_HEX): F = new polynomialBasis(tag); break;
case(TYPE_PYR): F = new pyramidalBasis(tag); break;
default:
Msg::Error("Unknown type of element %d (in BasisFactory)", tag);
return nullptr;
}
}
std::pair<std::map<int, nodalBasis *>::const_iterator, bool> inserted;
#if defined(_OPENMP)
#pragma omp critical
#endif
{
inserted = fs.insert(std::make_pair(tag, F));
if(!inserted.second) delete F;
}
return inserted.first->second;
}
const JacobianBasis *BasisFactory::getJacobianBasis(int tag, FuncSpaceData fsd)
{
FuncSpaceData data = fsd.getForNonSerendipitySpace();
auto it = js.find(data);
if(it != js.end()) return it->second;
JacobianBasis *J = new JacobianBasis(tag, data);
js.insert(std::make_pair(data, J));
return J;
}
const JacobianBasis *BasisFactory::getJacobianBasis(int tag, int order)
{
const int type = ElementType::getParentType(tag);
if(type != TYPE_PYR)
return getJacobianBasis(tag, FuncSpaceData(type, order, false));
else
return getJacobianBasis(
tag, FuncSpaceData(type, false, order + 1, order, false));
}
const JacobianBasis *BasisFactory::getJacobianBasis(int tag)
{
const int jacOrder = JacobianBasis::jacobianOrder(tag);
const int type = ElementType::getParentType(tag);
if(type != TYPE_PYR)
return getJacobianBasis(tag, FuncSpaceData(type, jacOrder, false));
else
return getJacobianBasis(
tag, FuncSpaceData(type, false, jacOrder + 2, jacOrder, false));
}
const CondNumBasis *BasisFactory::getCondNumBasis(int tag, int cnOrder)
{
auto it = cs.find(tag);
if(it != cs.end()) return it->second;
CondNumBasis *M = new CondNumBasis(tag, cnOrder);
cs.insert(std::make_pair(tag, M));
return M;
}
const GradientBasis *BasisFactory::getGradientBasis(int tag, FuncSpaceData fsd)
{
FuncSpaceData data = fsd.getForNonSerendipitySpace();
auto it = gs.find(data);
if(it != gs.end()) return it->second;
GradientBasis *G = new GradientBasis(tag, data);
gs.insert(std::make_pair(data, G));
return G;
}
const GradientBasis *BasisFactory::getGradientBasis(int tag, int order)
{
const int type = ElementType::getParentType(tag);
return getGradientBasis(tag, FuncSpaceData(type, order, false));
}
const GradientBasis *BasisFactory::getGradientBasis(int tag)
{
return getGradientBasis(tag, FuncSpaceData(tag));
}
const bezierBasis *BasisFactory::getBezierBasis(FuncSpaceData fsd)
{
FuncSpaceData data = fsd.getForNonSerendipitySpace();
auto it = bs.find(data);
if(it != bs.end()) return it->second;
bezierBasis *B = new bezierBasis(data);
bs.insert(std::make_pair(data, B));
return B;
}
const bezierBasis *BasisFactory::getBezierBasis(int parentType, int order)
{
return getBezierBasis(FuncSpaceData(parentType, order, false));
}
const bezierBasis *BasisFactory::getBezierBasis(int tag)
{
return getBezierBasis(FuncSpaceData(tag));
}
void BasisFactory::clearAll()
{
auto itF = fs.begin();
while(itF != fs.end()) {
delete itF->second;
itF++;
}
fs.clear();
auto itJ = js.begin();
while(itJ != js.end()) {
delete itJ->second;
itJ++;
}
js.clear();
auto itG = gs.begin();
while(itG != gs.end()) {
delete itG->second;
itG++;
}
gs.clear();
auto itB = bs.begin();
while(itB != bs.end()) {
delete itB->second;
itB++;
}
bs.clear();
}
|