MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mesh_extras.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_MESH_EXTRAS
13 #define MFEM_MESH_EXTRAS
14 
15 #include "mfem.hpp"
16 #include <sstream>
17 
18 namespace mfem
19 {
20 
21 namespace common
22 {
23 
24 class ElementMeshStream : public std::stringstream
25 {
26 public:
28 };
29 
30 /// Merges vertices which lie at the same location
31 void MergeMeshNodes(Mesh * mesh, int logging);
32 
33 /// Convert a set of attribute numbers to a marker array
34 /** The marker array will be of size max_attr and it will contain only zeroes
35  and ones. Ones indicate which attribute numbers are present in the attrs
36  array. In the special case when attrs has a single entry equal to -1 the
37  marker array will contain all ones. */
38 void AttrToMarker(int max_attr, const Array<int> &attrs, Array<int> &marker);
39 
40 
41 /// Generalized Kershaw mesh transformation in 2D and 3D, see D. Kershaw,
42 /// "Differencing of the diffusion equation in Lagrangian hydrodynamic codes",
43 /// JCP, 39:375–395, 1981.
44 /** The input mesh should be Cartesian nx x ny x nz with nx divisible by 6 and
45  ny, nz divisible by 2.
46  The parameters @a epsy and @a epsz must be in (0, 1].
47  Uniform mesh is recovered for epsy=epsz=1.
48  The @a smooth parameter controls the transition between different layers. */
49 // Usage:
50 // common::KershawTransformation kershawT(pmesh->Dimension(), 0.3, 0.3, 2);
51 // pmesh->Transform(kershawT);
53 {
54 private:
55  int dim;
56  double epsy, epsz;
57  int smooth;
58 
59 public:
60  KershawTransformation(const int dim_, double epsy_ = 0.3,
61  double epsz_ = 0.3, int smooth_ = 1)
62  : VectorCoefficient(dim_), dim(dim_), epsy(epsy_),
63  epsz(epsz_), smooth(smooth_)
64  {
65  MFEM_VERIFY(dim > 1,"Kershaw transformation only works for 2D and 3D"
66  "meshes.");
67  MFEM_VERIFY(smooth >= 1 && smooth <= 3,
68  "Kershaw parameter smooth must be in [1, 3]");
69  MFEM_VERIFY(epsy > 0 && epsy <=1,
70  "Kershaw parameter epsy must be in (0, 1].");
71  if (dim == 3)
72  {
73  MFEM_VERIFY(epsz > 0 && epsz <=1,
74  "Kershaw parameter epsz must be in (0, 1].");
75  }
76  }
77 
78  // 1D transformation at the right boundary.
79  double right(const double eps, const double x)
80  {
81  return (x <= 0.5) ? (2-eps) * x : 1 + eps*(x-1);
82  }
83 
84  // 1D transformation at the left boundary
85  double left(const double eps, const double x)
86  {
87  return 1-right(eps,1-x);
88  }
89 
90  // Transition from a value of "a" for x=0, to a value of "b" for x=1.
91  // Controlled through "smooth" parameter.
92  double step(const double a, const double b, double x)
93  {
94  if (x <= 0) { return a; }
95  if (x >= 1) { return b; }
96  if (smooth == 1) { return a + (b-a) * (x); }
97  else if (smooth == 2) { return a + (b-a) * (x*x*(3-2*x)); }
98  else { return a + (b-a) * (x*x*x*(x*(6*x-15)+10)); }
99  }
100 
101  virtual void Eval(Vector &V, ElementTransformation &T,
102  const IntegrationPoint &ip);
103 
105 };
106 
107 
108 } // namespace common
109 
110 } // namespace mfem
111 
112 #endif
Base class for vector Coefficients that optionally depend on time and space.
void AttrToMarker(int max_attr, const Array< int > &attrs, Array< int > &marker)
Convert a set of attribute numbers to a marker array.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
double left(const double eps, const double x)
Definition: mesh_extras.hpp:85
ElementMeshStream(Element::Type e)
Definition: mesh_extras.cpp:22
void MergeMeshNodes(Mesh *mesh, int logging)
Merges vertices which lie at the same location.
double step(const double a, const double b, double x)
Definition: mesh_extras.hpp:92
double b
Definition: lissajous.cpp:42
Type
Constants for the classes derived from Element.
Definition: element.hpp:41
double right(const double eps, const double x)
Definition: mesh_extras.hpp:79
double a
Definition: lissajous.cpp:41
Class for integration point with weight.
Definition: intrules.hpp:25
KershawTransformation(const int dim_, double epsy_=0.3, double epsz_=0.3, int smooth_=1)
Definition: mesh_extras.hpp:60
Vector data type.
Definition: vector.hpp:60
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...