MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sbm_aux.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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 #include "../../mfem.hpp"
13 #include <fstream>
14 #include <iostream>
15 
16 using namespace std;
17 using namespace mfem;
18 
19 /// Analytic distance to the 0 level set. Positive value if the point is inside
20 /// the domain, and negative value if outside.
21 double dist_value(const Vector &x, const int type)
22 {
23  double ring_radius = 0.2;
24  if (type == 1 || type == 2) // circle of radius 0.2 - centered at 0.5, 0.5
25  {
26  double dx = x(0) - 0.5,
27  dy = x(1) - 0.5,
28  rv = dx*dx + dy*dy;
29  if (x.Size() == 3)
30  {
31  double dz = x(2) - 0.5;
32  rv += dz*dz;
33  }
34  rv = rv > 0 ? pow(rv, 0.5) : 0;
35  return rv - ring_radius; // positive is the domain
36  }
37  else if (type == 3) // walls at y = 0.0
38  {
39  return x(1);
40  }
41  else if (type == 4)
42  {
43  const int num_circ = 3;
44  double rad[num_circ] = {0.3, 0.15, 0.2};
45  double c[num_circ][2] = { {0.6, 0.6}, {0.3, 0.3}, {0.25, 0.75} };
46 
47  const double xc = x(0), yc = x(1);
48 
49  // circle 0
50  double r0 = (xc-c[0][0])*(xc-c[0][0]) + (yc-c[0][1])*(yc-c[0][1]);
51  r0 = (r0 > 0) ? std::sqrt(r0) : 0.0;
52  if (r0 <= 0.2) { return -1.0; }
53 
54  for (int i = 0; i < num_circ; i++)
55  {
56  double r = (xc-c[i][0])*(xc-c[i][0]) + (yc-c[i][1])*(yc-c[i][1]);
57  r = (r > 0) ? std::sqrt(r) : 0.0;
58  if (r <= rad[i]) { return 1.0; }
59  }
60 
61  // rectangle 1
62  if (0.7 <= xc && xc <= 0.8 && 0.1 <= yc && yc <= 0.8) { return 1.0; }
63 
64  // rectangle 2
65  if (0.3 <= xc && xc <= 0.8 && 0.15 <= yc && yc <= 0.2) { return 1.0; }
66  return -1.0;
67  }
68  else
69  {
70  MFEM_ABORT(" Function type not implement yet.");
71  }
72  return 0.;
73 }
74 
75 /// Level set coefficient - +1 inside the domain, -1 outside, 0 at the boundary.
77 {
78 private:
79  int type;
80 
81 public:
83  : Coefficient(), type(type_) { }
84 
85  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
86  {
87  Vector x(3);
88  T.Transform(ip, x);
89  double dist = dist_value(x, type);
90  if (dist >= 0.) { return 1.; }
91  else { return -1.; }
92  }
93 };
94 
95 /// Distance vector to the zero level-set.
97 {
98 private:
99  int type;
100 
101 public:
102  Dist_Vector_Coefficient(int dim_, int type_)
103  : VectorCoefficient(dim_), type(type_) { }
104 
105  using VectorCoefficient::Eval;
106 
107  virtual void Eval(Vector &p, ElementTransformation &T,
108  const IntegrationPoint &ip)
109  {
110  Vector x;
111  T.Transform(ip, x);
112  const int dim = x.Size();
113  p.SetSize(dim);
114  if (type == 1 || type == 2)
115  {
116  double dist0 = dist_value(x, type);
117  for (int i = 0; i < dim; i++) { p(i) = 0.5 - x(i); }
118  double length = p.Norml2();
119  p *= dist0/length;
120  }
121  else if (type == 3)
122  {
123  double dist0 = dist_value(x, type);
124  p(0) = 0.;
125  p(1) = -dist0;
126  }
127  }
128 };
129 
130 /// Boundary conditions
132 {
133  return 0.;
134 }
135 
137 {
138  double xy_p = 2.; // exponent for level set 2 where u = x^p+y^p;
139  return pow(x(0), xy_p) + pow(x(1), xy_p);
140 }
141 
143 {
144  return 1./(M_PI*M_PI)*std::sin(M_PI*x(0)*x(1));
145 }
146 
147 
148 /// `f` for the Poisson problem (-nabla^2 u = f).
149 double rhs_fun_circle(const Vector &x)
150 {
151  return 1;
152 }
153 
154 double rhs_fun_xy_exponent(const Vector &x)
155 {
156  double xy_p = 2.; // exponent for level set 2 where u = x^p+y^p;
157  double coeff = std::max(xy_p*(xy_p-1), 1.);
158  double expon = std::max(0., xy_p-2);
159  if (xy_p == 1)
160  {
161  return 0.;
162  }
163  else
164  {
165  return -coeff*std::pow(x(0), expon) - coeff*std::pow(x(1), expon);
166  }
167 }
168 
170 {
171  return std::sin(M_PI*x(0)*x(1))*(x(0)*x(0)+x(1)*x(1));
172 }
double rhs_fun_circle(const Vector &x)
f for the Poisson problem (-nabla^2 u = f).
Definition: sbm_aux.hpp:149
Base class for vector Coefficients that optionally depend on time and space.
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:513
double Norml2() const
Returns the l2 norm of the vector.
Definition: vector.cpp:783
int Size() const
Returns the size of the vector.
Definition: vector.hpp:190
double dirichlet_velocity_xy_exponent(const Vector &x)
Definition: sbm_aux.hpp:136
double dirichlet_velocity_circle(const Vector &x)
Boundary conditions.
Definition: sbm_aux.hpp:131
virtual void Eval(Vector &p, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
Definition: sbm_aux.hpp:107
Distance vector to the zero level-set.
Definition: sbm_aux.hpp:96
Level set coefficient - +1 inside the domain, -1 outside, 0 at the boundary.
Definition: sbm_aux.hpp:76
Dist_Vector_Coefficient(int dim_, int type_)
Definition: sbm_aux.hpp:102
double rhs_fun_xy_sinusoidal(const Vector &x)
Definition: sbm_aux.hpp:169
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Definition: coefficient.hpp:39
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
Definition: sbm_aux.hpp:85
Dist_Level_Set_Coefficient(int type_)
Definition: sbm_aux.hpp:82
double rhs_fun_xy_exponent(const Vector &x)
Definition: sbm_aux.hpp:154
Class for integration point with weight.
Definition: intrules.hpp:25
double dirichlet_velocity_xy_sinusoidal(const Vector &x)
Definition: sbm_aux.hpp:142
int dim
Definition: ex24.cpp:53
Vector data type.
Definition: vector.hpp:60
virtual void Transform(const IntegrationPoint &, Vector &)=0
Transform integration point from reference coordinates to physical coordinates and store them in the ...
double dist_value(const Vector &x, const int type)
Definition: sbm_aux.hpp:21