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
00033
00034 #ifndef __USERDATA_H
00035 #define __USERDATA_H
00036
00037
00038 #include <float.h>
00039 #include <stdlib.h>
00040 #include <math.h>
00041
00042 #include "OFELI_Config.h"
00043 #include "Mesh.h"
00044 #include "Vect.h"
00045 #include "BCVect.h"
00046 #include "Point.h"
00047
00048 namespace OFELI {
00049
00067 template <class T_> class UserData
00068 {
00069
00070 public :
00071
00073 UserData()
00074 {
00075 _time = 0.;
00076 #ifdef _OFELI_DEBUG
00077 std::clog << "An instance of class UserData is constructed.\n";
00078 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00079 #endif
00080 }
00081
00083 UserData(const class Mesh &mesh)
00084 {
00085 _theMesh = &mesh;
00086 _time = 0.;
00087 #ifdef _OFELI_DEBUG
00088 std::clog << "An instance of class UserData is constructed.\n";
00089 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00090 #endif
00091 }
00092
00094 virtual ~UserData()
00095 {
00096 #ifdef _OFELI_DEBUG
00097 std::clog << "An instance of class UserData is destructed.\n";
00098 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00099 #endif
00100 }
00101
00103 void setTime(double time) { _time = time; }
00104
00106 void setDBC(Vect<T_> &b)
00107 {
00108 const Node *nd;
00109 size_t k = 1;
00110 for (_theMesh->topNode(); (nd=_theMesh->getNode());) {
00111 Point<double> x(nd->getCoord(1),nd->getCoord(2),nd->getCoord(3));
00112 for (size_t i=1; i<=nd->getNbDOF(); i++)
00113 b(k++) = BoundaryCondition(x,nd->getCode(i),_time,i);
00114 }
00115 }
00116
00118 void setInitialData(Vect<T_> &b)
00119 {
00120 const Node *nd;
00121 for (_theMesh->topNode(); (nd=_theMesh->getNode());) {
00122 Point<double> x(nd->getCoord(1),nd->getCoord(2),nd->getCoord(3));
00123 for (size_t j=1; j<=nd->getNbDOF(); j++)
00124 b(nd->getDOF(j)) = InitialData(x,j);
00125 }
00126 }
00127
00131 void setBodyForce(Vect<T_> &b)
00132 {
00133 const Node *nd;
00134 for (_theMesh->topNode(); nd=_theMesh->getNode();) {
00135 Point<double> x(nd->getCoord(1),nd->getCoord(2),nd->getCoord(3));
00136 for (size_t j=1; j<=nd->getNbDOF(); j++)
00137 b(nd->getDOF(j)) = BodyForce(x,time,j);
00138 }
00139 }
00140
00144 void setBodyForce(NodeVect<T_> &b)
00145 {
00146 const Node *nd;
00147 for (_theMesh->topNode(); nd=_theMesh->getNode();) {
00148 Point<double> x(nd->getCoord(1),nd->getCoord(2),nd->getCoord(3));
00149 for (size_t j=1; j<=nd->getNbDOF(); j++)
00150 b(nd->getDOF(j)) = BodyForce(x,time,j);
00151 }
00152 }
00153
00158 void setBodyForce(ElementVect<T_> &b)
00159 {
00160 Point<double> c;
00161 const Element *el;
00162 size_t dim = _theMesh->getDim();
00163 for (_theMesh->topElement(); el=_theMesh->getElement();) {
00164 if (dim==1 && el->getShape()==Mesh::LINE) {
00165 class Line2 ln(el);
00166 c = ln.getCenter();
00167 }
00168 else if (dim==2 && el->getShape()==Mesh::TRIANGLE) {
00169 class Triang3 tr(el);
00170 c = tr.getCenter();
00171 }
00172 else if (dim==2 && el->getShape()==Mesh::QUADRILATERAL) {
00173 class Quad qd(el);
00174 c = qd.getCenter();
00175 }
00176 else if (dim==3 && el->getShape()==Mesh::TETRAHEDRON) {
00177 class Tetra4 tt(el);
00178 c = tt.getCenter();
00179 }
00180 else if (dim==3 && el->getShape()==Mesh::HEXAHEDRON) {
00181 class Hexa8 hx(el);
00182 c = hx.getCenter();
00183 }
00184 else
00185 ;
00186 b(el->getLabel()) = BodyForce(c,time,1);
00187 }
00188 }
00189
00191 void setSurfaceForce(Vect<T_> &b)
00192 {
00193 const Node *nd;
00194 for (_theMesh->topNode(); nd=_theMesh->getNode();) {
00195 Point<double> coord(nd->getCoord(1),nd->getCoord(2),nd->getCoord(3));
00196 for (size_t j=1; j<=nd->getNbDOF(); j++)
00197 b(nd->getDOF(j)) = SurfaceForce(coord,nd->getCode(j),_time,j);
00198 }
00199 }
00200
00204 virtual T_ BoundaryCondition(const Point<double> &x, int code, double time=0., size_t dof=1)
00205 {
00206 if (&x) { }
00207 time = 0;
00208 dof = 1;
00209 code = 0;
00210 return T_(0);
00211 }
00212
00217 virtual T_ BodyForce(const Point<double> &x, double time=0., size_t dof=1)
00218 {
00219 if (&x) { }
00220 time = 0;
00221 dof = 1;
00222 return T_(0);
00223 }
00224
00229 virtual T_ SurfaceForce(const Point<double> &x, int code, double time=0., size_t dof=1)
00230 {
00231 if (&x) { }
00232 time = 0;
00233 dof = 1;
00234 code = 0;
00235 return T_(0);
00236 }
00237
00240 virtual T_ InitialData(const Point<double> &x, size_t dof=1)
00241 {
00242 if (&x){ }
00243 dof = 1;
00244 return T_(0.);
00245 }
00246
00247
00248 protected :
00249
00250 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00251 double _time;
00252 const Mesh *_theMesh;
00253 #endif
00254 };
00255
00256 }
00257
00258 #endif