Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

HL_SignedDist.h 12.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.




22 23 24 25 26 27 28
#ifndef HL_SIGNEDDIST
#define HL_SIGNEDDIST

#include "Global.h"
#include "AdaptInfo.h"
#include "DOFVector.h"
#include "ElementFunction.h"
29
#include "io/FileWriter.h"
30 31
#include "FixVec.h"
#include "Flag.h"
32
#include "Initfile.h"
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
#include "ElementLevelSet.h"
#include "BoundaryElementDist.h"
#include "BoundaryElementLevelSetDist.h"
#include "BoundaryElementTopDist.h"
#include "BoundaryElementEdgeDist.h"
#include "BoundaryElementNormalDist.h"
#include "ElementUpdate.h"
#include "ElementUpdate_2d.h"
#include "ElementUpdate_3d.h"
#include "VelocityExt.h"
#include "VelocityExtFromVelocityField.h"

using namespace AMDiS;

//////////////////////////////////////////////////////////////////////////////
//
//   class HL_SignedDist:
//   --------------------
//   Holds functionality for 
//   - calculation of signed distance function for a level set function
//     (calcSignedDistFct())
//   - extension of velocity from an interface on complete mesh in direction 
//     normal to the interface, where the interface is given implicitly
//     by a level set function
//     (calcVelocityExt())
//
//////////////////////////////////////////////////////////////////////////////
class HL_SignedDist
{
62
public:
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  HL_SignedDist(const char *name_, 
		int dim_,
		bool doVelocityExt = false,
		Flag velExtType_ = VEL_EXT)
    : name(name_),
    adaptInfo(NULL),
    dim(dim_),
    lS_DOF(NULL),
    sD_DOF(NULL),
    bound_DOF(NULL),
    feSpace(NULL),
    elUpdate(NULL),
    bndElDist(NULL),
    elLS(NULL),
    phi(NULL),
    velExt(NULL),
    velExtType(velExtType_)
  {
    FUNCNAME("HL_SignedDist::HL_SignedDist");

    TEST_EXIT(dim == 2 || dim == 3)("only works for dimension 2 and 3 !\n");

    // ===== Read parameters from init file. =====
86
    Parameters::get(name + "->infinity value", inftyValue);
87 88 89 90 91 92

    TEST_EXIT(inftyValue > 1000)("illegal infinity value !\n");

    // ===== Create functionality for velocity extension. =====
    if (doVelocityExt) {
      if (velExtType.isSet(VEL_EXT))
93
	velExt = new VelocityExt(dim);
94
      else
95
	velExt = new VelocityExtFromVelocityField(dim);
96
    }
97
  }
98 99 100 101 102 103 104

  /**
   * Virtual destructor.
   */
  virtual ~HL_SignedDist()
  {
    if (elUpdate)
105
      delete elUpdate;
106
    if (bndElDist)
107
      delete bndElDist;
108 109

    if (elLS)
110
      delete elLS;
111
    if (phi)
112
      delete phi;
113 114

    if (bound_DOF)
115
      delete bound_DOF;
116

117
    delete velExt;
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  };

  /**
   * Calculates the signed distance function for the interface given
   * implicitly by the zero level set of lS_DOF_. The result
   * is stored in sD_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcSignedDistFct(AdaptInfo *adaptInfo_,
			 const DOFVector<double> *lS_DOF_, 
			 DOFVector<double> *sD_DOF_,
			 ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the signed distance function for the interface given
   * implicitly by the zero level set of lS_DOF_. The result
   * is stored in lS_DOF_.
   */
  void calcSignedDistFct(AdaptInfo *adaptInfo_,
			 DOFVector<double> *lS_DOF_);

  /**
   * Calculates the extension of a velocity origVel_DOF_ from the interface
   * on the complete mesh in direction normal to the interface. The interface
   * is given implicitly as the zero level set of lS_DOF_. The result
   * is stored in vel_DOF_. If calcSDFct is true, the signed distance function
   * which is calculated during the extension of the velocity anyway is
   * stored in sD_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExt(AdaptInfo *adaptInfo_,
		       DOFVector<double> *origVel_DOF_,
		       DOFVector<double> *vel_DOF_,
		       const DOFVector<double> *lS_DOF_,
		       DOFVector<double> *sD_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the extension of a velocity vel_DOF_ from the interface
   * on the complete mesh in direction normal to the interface. The interface
   * is given implicitly as the zero level set of lS_DOF_. The result
   * is stored in origVel_DOF_. If calcSDFct is true, the signed distance
   * function, which is calculated during the extension of the velocity
   * anyway, is stored in lS_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExt(AdaptInfo *adaptInfo_,
		       DOFVector<double> *vel_DOF_,
		       DOFVector<double> *lS_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the extension of the velocity vectors in origVel_DOF_ 
   * from the interface on the complete mesh in direction normal to the 
   * interface. The interface is given implicitly as the zero level set of 
   * lS_DOF_. The result is stored in vel_DOF_. 
   * If calcSDFct is true, the signed distance function,
   * which is calculated during the extension of the velocity anyway, is 
   * stored in sD_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExt(AdaptInfo *adaptInfo_,
		       std::vector<DOFVector<double> *> origVel_DOF_, 
		       std::vector<DOFVector<double> *> vel_DOF_,
		       const DOFVector<double> *lS_DOF_,
		       DOFVector<double> *sD_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the extension of the velocity vectors in vel_DOF_ 
   * from the interface on the complete mesh in direction normal to the 
   * interface. The interface is given implicitly as the zero level set 
   * of lS_DOF_. The result is stored in vel_DOF_. 
   * If calcSDFct is true, the signed distance function, which is calculated 
   * during the extension of the velocity anyway, is stored in lS_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExt(AdaptInfo *adaptInfo_,
		       std::vector<DOFVector<double> *> vel_DOF_, 
		       DOFVector<double> *lS_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the normal velocity for the velocity field velField_ and its
   * extension from the interface on the complete mesh in direction normal 
   * to the interface. The interface is given implicitly as the 
   * zero level set of lS_DOF_. The result is stored in vel_DOF_. 
   * If calcSDFct is true, the signed distance function
   * which is calculated during the extension of the velocity anyway is 
   * stored in sD_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExtFromVelocityField(
		       AdaptInfo *adaptInfo_,
		       std::vector<DOFVector<double> *> &velField_, 
		       DOFVector<double> *vel_DOF_,
		       const DOFVector<double> *lS_DOF_,
		       DOFVector<double> *sD_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Calculates the normal velocity for the velocity field velField_ and its
   * extension from the interface on the complete mesh in direction normal 
   * to the interface. The interface is given implicitly as the 
   * zero level set of lS_DOF_. The result is stored in vel_DOF_. 
   * If calcSDFct is true, the signed distance function
   * which is calculated during the extension of the velocity anyway is 
   * stored in lS_DOF_.
   *
   * Alternative to level set function as DOF vector:
   * If elFct != NULL, this ElementFunction is used as level set function.
   * In this case: only calculation of distance function (positive sign) !
   */
  void calcVelocityExtFromVelocityField(
		       AdaptInfo *adaptInfo_,
		       std::vector<DOFVector<double> *> &velField_, 
		       DOFVector<double> *vel_DOF_,
		       DOFVector<double> *lS_DOF_,
		       bool calcSDFct,
		       ElementFunction<double> *elFct = NULL);

  /**
   * Print initial function: level set function defining the interface.
   */
  void printLevelSetFct()
  {
267
    FileWriter *fileWriter = new FileWriter(
268 269 270 271 272
			     "SignedDist->level set fct output", 
			     feSpace->getMesh(),
			     const_cast<DOFVector<double> *>(lS_DOF));
    fileWriter->writeFiles(adaptInfo, false);

273
    delete fileWriter;
274 275 276 277 278 279 280
  };

  /**
   * Print signed distance function.
   */
  void printSignedDistFct()
  {
281
    FileWriter *fileWriter = new FileWriter(
282 283 284 285 286
			     "SignedDist->result output", 
			     feSpace->getMesh(),
			     sD_DOF);
    fileWriter->writeFiles(adaptInfo, false);

287
    delete fileWriter;
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
  };

 protected:
  /**
   * Initialization.
   */
  virtual void initialize(ElementFunction<double> *elFct = NULL);

  /**
   * Initializes the boundary: calculation of the distance of boundary 
   * vertices to the interface. 
   * Interface is given by lS_DOF and result is stored in 
   * sD_DOF.
   */
  virtual void initializeBoundary() = 0;

  /**
   * Calculates the distance function and stores result in sD_DOF.
   * Requirement: The boundary values are already set in sD_DOF.
   */
  virtual void HL_updateIteration() = 0;

  /**
   * Transforms the distance function into a signed distance function.
   * The sign is given by the level set function lS_DOF. The 
   * signed distance function is stored in sD_DOF.
   */
  void setSign();

  /**
   * Print boundary initialization (initial function for Hopf-Lax iteration).
   */
  void printBoundInitFct()
  {
322 323 324
    FileWriter *fileWriter = new FileWriter("SignedDist->boundary initialization output", 
					    feSpace->getMesh(),
					    sD_DOF);
325 326
    fileWriter->writeFiles(adaptInfo, false);

327
    delete fileWriter;
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
  };

 public:
  /**
   * Flags to distinguish velocity extension types.
   */
  static const Flag VEL_EXT;
  static const Flag VEL_EXT_FROM_VEL_FIELD;

 protected:
  /**
   * Name of this instantiation of HL_SignedDist.
   */
  std::string name;

  /**
   * AdaptInfo.
   */
  AdaptInfo *adaptInfo;

  /**
   * Dimension.
   */
  int dim;

  /**
   * Level set function giving implicitely (as zero level set) the
   * interface for which the signed distance function is calculated.
   */
  const DOFVector<double> *lS_DOF;

  /**
   * DOF vector for the calculated signed distance function.
   * Also used during calculation.
   */
  DOFVector<double> *sD_DOF;

  /**
   * Marker for boundary vertices:
   *   0 - vertex is no boundary vertex
   *   1 - vertex is boundary vertex
   */
  DOFVector<double> *bound_DOF;

  /**
   * Finite element space.
   */
  const FiniteElemSpace *feSpace;

  /**
   * Initialization value "inifinity" for non-boundary vertices.
   */
  double inftyValue;

  /**
   * Pointer to ElementUpdate. Used for Hopf-Lax element update.
   */
  ElementUpdate *elUpdate;

  /**
   * Used for boundary vertex initialization: calculation of the distance
   * to the interface for all vertices of a boundary element.
   */
  BoundaryElementDist *bndElDist;

  /**
   * Holds level set function and functionalities for intersection point
   * calculation.
   */
  ElementLevelSet *elLS;

  /*
   * Level set function which implicitely gives the interface as its
   * zero level set.
   * This representation is needed for the use of class ElementLevelSet.
   */
  ElementFunction<double> *phi;

  /**
   * Object needed to extrapolate velocity from the interface.
   */  
  VelocityExt *velExt;

  /**
   * Type of velocity extension method. Possible types:
   *     VEL_EXT                - object of class VelocityExt
   *     VEL_EXT_FROM_VEL_FIELD - object of class VelocityExtFromVelocityField
   */
  Flag velExtType;
};

#endif  // HL_SIGNEDDIST