00001
00029 #ifndef _STANDARD_AVI_H_
00030 #define _STANDARD_AVI_H_
00031
00032 #include "AVI.h"
00033
00038 class StandardAVI: public AVI {
00039 public:
00041 typedef double (*BCFunc) (int, int, double);
00042
00045 enum BCImposedType {
00046 ZERO, ONE, TWO
00047 };
00048
00060
00061 StandardAVI(
00062 const LocalToGlobalMap& L2G,
00063 const DResidue& MyRes,
00064 const VecDouble& MassVec,
00065 size_t globalIdx,
00066 const MatBool& IFlag,
00067 const MatDouble& IVal,
00068 const double delta,
00069 const double time)
00070
00071 : AVI (),
00072 operation (MyRes),
00073 globalIdx (globalIdx),
00074 imposedFlags (IFlag),
00075 imposedValues (IVal),
00076 delta (delta),
00077 timeStamp (time) {
00078
00079 init(L2G, MassVec);
00080
00081
00082 imposedTypes = std::vector< std::vector<BCImposedType> > (IFlag.size (), std::vector<BCImposedType> ());
00083
00084 for (size_t f = 0; f < IFlag.size (); ++f) {
00085
00086 for (size_t a = 0; a < IFlag[f].size (); ++f) {
00087 if (!IFlag[f][a]) {
00088 imposedTypes[f].push_back (StandardAVI::ONE);
00089
00090 } else {
00091 imposedTypes[f].push_back (StandardAVI::ZERO);
00092 }
00093 }
00094 }
00095 }
00096
00108 StandardAVI(
00109 const LocalToGlobalMap& L2G,
00110 const DResidue& MyRes,
00111 const VecDouble& MassVec,
00112 size_t globalIdx,
00113 const std::vector<std::vector<BCImposedType> >& IType,
00114 const std::vector<BCFunc>& bcfunc_vec,
00115 const double delta,
00116 const double time)
00117
00118 : AVI (),
00119 operation (MyRes),
00120 globalIdx (globalIdx),
00121 imposedTypes (IType),
00122 delta (delta),
00123 timeStamp (time) {
00124
00125 init (L2G, MassVec);
00126
00127
00128 if(imposedFlags.size() != IType.size()) {
00129 imposedFlags.resize(IType.size());
00130 }
00131
00132 if(imposedValues.size() != IType.size()) {
00133 imposedValues.resize(IType.size());
00134 }
00135
00136 if(imposedTypes.size() != IType.size()) {
00137 imposedTypes.resize(IType.size());
00138 }
00139
00140 for(size_t f = 0;f < IType.size();f++){
00141 if(imposedFlags[f].size() != IType[f].size()) {
00142 imposedFlags[f].resize(IType[f].size());
00143 }
00144
00145 if(imposedValues[f].size() != IType[f].size()) {
00146 imposedValues[f].resize(IType[f].size());
00147 }
00148
00149 if(imposedTypes[f].size() != IType[f].size()) {
00150 imposedTypes[f].resize(IType[f].size());
00151 }
00152
00153 for(size_t a = 0;a < IType[f].size();a++){
00154 if(IType[f][a] != StandardAVI::ZERO){
00155 imposedFlags[f][a] = false;
00156 }else{
00157 imposedFlags[f][a] = true;
00158 }
00159 imposedValues[f][a] = 0.0;
00160 imposedTypes[f][a] = IType[f][a];
00161 }
00162
00163 }
00164
00165 for(size_t a = 0;a < bcfunc_vec.size();a++){
00166 avi_bc_func.push_back(bcfunc_vec[a]);
00167 }
00168 }
00169
00170
00172 StandardAVI (const StandardAVI& that) :
00173 AVI (that),
00174 operation (that.operation),
00175 MMdiag (that.MMdiag),
00176 globalIdx (that.globalIdx),
00177 avi_bc_func (that.avi_bc_func),
00178 imposedTypes (that.imposedTypes),
00179 imposedFlags (that.imposedFlags),
00180 imposedValues (that.imposedValues),
00181 nfields (that.nfields),
00182 delta (that.delta),
00183 timeStamp (that.timeStamp) {
00184
00185 setTimeStep ();
00186 }
00187
00188 virtual StandardAVI* clone () const {
00189 return new StandardAVI (*this);
00190 }
00191
00193 double getTimeStep () const {
00194 return timeStep;
00195 }
00196
00198 double getTimeStamp () const {
00199 return timeStamp;
00200 }
00201
00202 bool setTimeStamp (double timeval) {
00203 assert (timeval >= 0.0);
00204 timeStamp = timeval;
00205 return true;
00206 }
00207 ;
00208
00209
00211 virtual double getNextTimeStamp () const { return getTimeStamp() + getTimeStep();}
00213 virtual void incTimeStamp () { setTimeStamp(getNextTimeStamp()); }
00214
00215 virtual const DResidue& getOperation () const { return operation; }
00216
00217 size_t getFieldDof (size_t fieldnumber) const {
00218 return operation.getFieldDof (fieldnumber);
00219 }
00220 ;
00221
00222 const std::vector<size_t>& getFields () const {
00223 return operation.getFields ();
00224 }
00225 ;
00226
00228 const ElementGeometry& getGeometry () const {
00229 return operation.getElement ().getGeometry ();
00230 }
00231 ;
00232
00234 const Element& getElement () const {
00235 return operation.getElement ();
00236 }
00237 ;
00238
00240 bool getForceField (const MatDouble& argval, MatDouble& forcefield) const {
00241 operation.getVal (argval, forcefield);
00242 return (true);
00243 }
00244 ;
00245
00246
00247 size_t getGlobalIndex (void) const {
00248 return (globalIdx);
00249 }
00250 ;
00251
00254 virtual void computeLocalTvec (MatDouble& tnew) const;
00255
00256 virtual bool vbInit (
00257 const MatDouble& q,
00258 const MatDouble& v,
00259 const MatDouble& vb,
00260 const MatDouble& ti,
00261 const MatDouble& tnew,
00262 MatDouble& qnew,
00263 MatDouble& vbinit,
00264 MatDouble& forcefield,
00265 MatDouble& funcval,
00266 MatDouble& deltaV
00267 ) const;
00268
00269
00270 virtual bool update (const MatDouble& q,
00271 const MatDouble& v,
00272 const MatDouble& vb,
00273 const MatDouble& ti,
00274 const MatDouble& tnew,
00275 MatDouble& qnew,
00276 MatDouble& vnew,
00277 MatDouble& vbnew,
00278 MatDouble& forcefield,
00279 MatDouble& funcval,
00280 MatDouble& deltaV
00281 ) const ;
00282
00283 bool gather (
00284 const LocalToGlobalMap& L2G,
00285 const VecDouble& Qval,
00286 const VecDouble& Vval,
00287 const VecDouble& Vbval,
00288 const VecDouble& Tval,
00289 MatDouble& q,
00290 MatDouble& v,
00291 MatDouble& vb,
00292 MatDouble& ti
00293 ) const;
00294
00295 bool assemble (const LocalToGlobalMap& L2G,
00296 const MatDouble& qnew,
00297 const MatDouble& vnew,
00298 const MatDouble& vbnew,
00299 const MatDouble& tnew,
00300 VecDouble& Qval,
00301 VecDouble& Vval,
00302 VecDouble& Vbval,
00303 VecDouble& Tval,
00304 VecDouble& LUpdate) const;
00305
00306 protected:
00310 virtual void setTimeStep (double epsilon = 1.0) {
00311 timeStep = epsilon * delta * (operation.getElement ().getGeometry ().getInRadius ()) / operation.getMaterial ().getSoundSpeed ();
00312
00313 };
00314
00315 virtual void computeDeltaV (const MatDouble& funcval, MatDouble& DeltaV) const;
00316
00317 virtual bool getImposedValues (const GlobalElementIndex& ElementIndex,
00318 const LocalToGlobalMap& L2G, size_t field, size_t dof,
00319 double& qvalue, double& vvalue) const;
00320
00324 void roundTimeStep (double min_ts) {
00325 char val[80], val2[80];
00326 sprintf (val, "%0.3e", min_ts / 1000.);
00327 double cut_off = strtod (val, NULL);
00328 strncpy (val2, val, 5);
00329 cut_off = cut_off / strtod (val2, NULL);
00330 timeStep = floor (timeStep / cut_off) * cut_off;
00331 }
00332 ;
00333
00334
00335 private:
00336
00337 StandardAVI& operator = (const StandardAVI& that) {
00338 return *this;
00339 }
00340
00341 void init(const LocalToGlobalMap& L2G, const VecDouble& MassVec) {
00342 nfields = operation.getFields().size();
00343 setTimeStep();
00344 setDiagVals(MassVec, L2G, globalIdx);
00345 }
00346
00347
00353 void setDiagVals (const VecDouble& MassVec, const LocalToGlobalMap& L2G,
00354 const GlobalElementIndex& elem_index);
00355
00360 void setBCs (const MatBool&IFlag,
00361 const MatDouble& IVal);
00362
00363
00364
00365
00366
00367 const DResidue& operation;
00368 MatDouble MMdiag;
00369
00370 size_t globalIdx;
00371
00372
00373 std::vector<BCFunc> avi_bc_func;
00374 std::vector<std::vector<BCImposedType> > imposedTypes;
00375 MatBool imposedFlags;
00376 MatDouble imposedValues;
00377
00378 size_t nfields;
00379 double delta;
00380 double timeStamp;
00381 double timeStep;
00382
00383
00384
00385 };
00386
00387 #endif // _STANDARD_AVI_H_