00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __FEEQUA_UTIL_H
00033 #define __FEEQUA_UTIL_H
00034
00035 #include <float.h>
00036 #include <stdlib.h>
00037 #include <math.h>
00038
00039 #include "OFELI_Config.h"
00040 #include "Mesh.h"
00041 #include "Element.h"
00042 #include "Side.h"
00043 #include "Vect.h"
00044 #include "BCVect.h"
00045 #include "SpMatrix.h"
00046 #include "SkMatrix.h"
00047 #include "SkSMatrix.h"
00048 #include "LocalMatrix.h"
00049 #include "LocalVect.h"
00050 #include "Material.h"
00051
00052 namespace OFELI {
00053
00054 #define eMat (M_)
00055 #define sMat (sM_)
00056 #define eRHS (B_)
00057 #define ePrev (P_)
00058
00059 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00060 void getMatrix(const SpMatrix<T_> &A)
00061 {
00062 _M.Localize(_theElement,A);
00063 }
00064
00065
00066 void getMatrix(const SkMatrix<T_> &A)
00067 {
00068 _M.Localize(_theElement,A);
00069 }
00070
00071
00072 void getMatrix(const SkSMatrix<T_> &A)
00073 {
00074 _M.Localize(_theElement,A);
00075 }
00076
00077
00078 void getSolution(const Vect<T_> &u)
00079 {
00080 _P.Localize(_theElement,u);
00081 }
00082
00083
00084 void getRHS(const Vect<T_> &b)
00085 {
00086 _B.Localize(_theElement,b);
00087 }
00088
00089
00090 void Residual()
00091 {
00092 _M.Mult(_P,_R); _R -= _B;
00093 }
00094
00095
00096
00097 inline void setTime(double t)
00098 {
00099 _time = t;
00100 }
00101
00102
00103
00104 size_t getNbNodes() const
00105 {
00106 if (_theElement)
00107 return NEN_;
00108 else return NSN_;
00109 }
00110
00111
00112
00113 size_t getNbEq() const
00114 {
00115 if (_theElement)
00116 return NEE_;
00117 else
00118 return NSE_;
00119 }
00120 #endif
00121
00124 T_ *A() { if (theElement_) return _M.Val(); else return _sM.Val(); }
00125
00128 T_ *b() { return _B.Val(); }
00129
00132 T_ *Prev() { return _P.Val(); }
00133
00134
00135 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00136 T_ *Res() { return _R.Val(); }
00137 LocalMatrix<T_,NEE_,NEE_> &EA() { return _M; }
00138 LocalMatrix<T_,NSE_,NSE_> &SA() { return _sM; }
00139 LocalVect<T_,NEE_> &Eb() { return _B; }
00140 LocalVect<T_,NEE_> &Ep() { return _P; }
00141
00142 template < class T_, class E_ >
00143 void ElementVect(const E_ &e, const Vect<T_> &b, Vect<T_> &p, int dof, int dof_type)
00144 {
00145 size_t k = 0;
00146 if (dof_type==NODE_DOF) {
00147 Node *nd;
00148 if (dof) {
00149 for (size_t n=1; n<=e.getNbNodes(); n++)
00150 p[k++] = b(e.getNodeLabel(n));
00151 }
00152 else {
00153 for (size_t n=1; n<=e.getNbNodes(); n++) {
00154 nd = e.getPtrNode(n);
00155 for (size_t j=1; j<=nd->getNbDOF(); j++)
00156 p[k++] = b(nd->getDOF(j));
00157 }
00158 }
00159 }
00160 else if (dof_type==SIDE_DOF) {
00161 Side *sd;
00162 if (dof) {
00163 for (size_t n=1; n<=e.getNbNodes(); n++)
00164 p[k++] = b(el.getSideLabel(n));
00165 }
00166 else {
00167 for (size_t n=1; n<=NEN_; n++) {
00168 sd = el.getPtrSide(n);
00169 for (size_t j=1; j<=sd->getNbDOF(); j++)
00170 p[k++] = b(sd->getDOF(j));
00171 }
00172 }
00173 }
00174 }
00175
00176
00177 template < class T_, class E_ >
00178 void SideVect(const E_ &e, const Vect<T_> &b, Vect<T_> &p)
00179 {
00180 Node *nd;
00181 size_t k = 0;
00182 for (size_t n=1; n<=e.getNbNodes(); n++) {
00183 nd = e.getPtrNode(n);
00184 for (size_t j=1; j<=nd->getNbDOF(); j++)
00185 p[k++] = b(nd->getDOF(j));
00186 }
00187 }
00188
00189
00190 template <class T_, class E_ >
00191 void updateBC(const E_ &e, const BCVect<T_> &bc)
00192 {
00193 size_t in = 0;
00194 for (size_t i=1; i<=e.getNbNodes(); i++) {
00195 for (size_t k=1; k<=_nb_dof; k++) {
00196 in++;
00197 size_t nn = _theElement->getPtrNode(i)->getFirstDOF() + k - 1;
00198 if (_theElement->getPtrNode(i)->getDOF(k) == 0) {
00199 size_t jn = 0;
00200 for (size_t j=1; j<=NEN_; j++)
00201 for (size_t l=1; l<=_nb_dof; l++) {
00202 jn++;
00203 if (_theElement->getPtrNode(j)->getDOF(l) > 0)
00204 eRHS(jn) -= eMat(jn,in) * bc(nn);
00205 }
00206 }
00207 }
00208 }
00209 }
00210
00211
00212 template <class T_, class E_ >
00213 void updateBC(const E_ &e, const Vect<T_> &bc)
00214 {
00215 size_t in = 0;
00216 for (size_t i=1; i<=e.getNbNodes(); i++) {
00217 for (size_t k=1; k<=_nb_dof; k++) {
00218 in++;
00219 size_t nn = _theElement->getPtrNode(i)->getFirstDOF() + k - 1;
00220 if (_theElement->getPtrNode(i)->getDOF(k) == 0) {
00221 size_t jn = 0;
00222 for (size_t j=1; j<=NEN_; j++) {
00223 for (size_t l=1; l<=nb_dof_; l++) {
00224 jn++;
00225 if (_theElement->getPtrNode(j)->getDOF(l) > 0)
00226 eRHS(jn) -= eMat(jn,in) * bc(nn);
00227 }
00228 }
00229 }
00230 }
00231 }
00232 }
00233
00234
00235 template <class T_, size_t NEN_, size_t NEE_, size_t NSN_, size_t NSE_>
00236 void DiagBC(int dof_type, int dof)
00237 {
00238 if (dof_type==NODE_DOF) {
00239 if (dof) {
00240 for (size_t i=1; i<=NEN_; i++) {
00241 Node *nd1 = _theElement->getPtrNode(i);
00242 if (nd1->getCode(dof)) {
00243 size_t in = nd1->Label();
00244 for (size_t j=1; j<=NEN_; j++) {
00245 Node *nd2 = _theElement->getPtrNode(j);
00246 if (nd2->getCode(dof)) {
00247 size_t jn = nd2->getLabel();
00248 if (in != jn)
00249 eMat(in,jn) = 0;
00250 }
00251 }
00252 }
00253 }
00254 }
00255 else {
00256 for (size_t i=1; i<=NEN_; i++) {
00257 for (size_t k=1; k<=_nb_dof; k++) {
00258 if (_theElement->getPtrNode(i)->getCode(k)) {
00259 size_t in = _theElement->getPtrNode(i)->getDOF(k);
00260 for (size_t j=1; j<=NEN_; j++) {
00261 for (size_t l=1; l<=_nb_dof; l++) {
00262 size_t jn = _theElement->getPtrNode(j)->getDOF(l);
00263 if (in != jn)
00264 eMat(in,jn) = 0;
00265 }
00266 }
00267 }
00268 }
00269 }
00270 }
00271 }
00272
00273 else if (dof_type==SIDE_DOF) {
00274 if (dof) {
00275 for (size_t i=1; i<=NEN_; i++) {
00276 Side *sd1 = gettheElement->getPtrSide(i);
00277 if (sd1->Code(dof))
00278 for (size_t j=1; j<=NEN_; j++)
00279 if (i != j)
00280 eMat(i,j) = 0;
00281 }
00282 }
00283 else {
00284 for (size_t i=1; i<=NEN_; i++) {
00285 for (size_t k=1; k<=_nb_dof; k++) {
00286 if (_theElement->getPtrSide(i)->getCode(k)) {
00287 size_t in = _theElement->getPtrNode(i)->getDOF(k);
00288 for (size_t j=1; j<=NEN_; j++) {
00289 for (size_t l=1; l<=_nb_dof; l++) {
00290 size_t jn = _theElement->getPtrSide(j)->getDOF(l);
00291 if (in != jn)
00292 eMat(in,jn) = 0;
00293 }
00294 }
00295 }
00296 }
00297 }
00298 }
00299 }
00300 }
00301 #endif
00302
00303
00304 }
00305
00306 #endif