MAST
level_set_boundary_velocity.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 // MAST includes
22 
23 
26 _dim(dim),
27 _phi(nullptr) {
28 
29 }
30 
32 
33  if (_phi)
34  delete _phi;
35 }
36 
37 void
39  const libMesh::NumericVector<Real>& sol,
40  const libMesh::NumericVector<Real>& dsol) {
41 
42  if (!_phi)
43  _phi = new MAST::MeshFieldFunction(sys, "phi");
44  else
45  _phi->clear();
46  _phi->init(sol, &dsol);
47 }
48 
49 
50 void
52  const Real t,
53  RealVectorX& v) const {
54 
55  libmesh_assert(_phi);
56 
57  Real
58  tol = 1.e-6;
59 
61  val = RealVectorX::Zero(1),
62  grad = RealVectorX::Zero(_dim),
63  dval = RealVectorX::Zero(1);
64 
66  gradmat = RealMatrixX::Zero(1, _dim);
67 
68  // the velocity is identified using the level set function gradient
69  // and its sensitivity
70  (*_phi)(p, t, val);
71 
72  // since the function provides the velocity at the boundary, the
73  // level set value should be close to zero. This is commented out since
74  // for a coarse level set mesh used to define geometry on a fine analysis
75  // mesh, the boundary can exist on locations that are not necessarily phi=0.
76  //libmesh_assert_less_equal(std::fabs(val(0)), tol);
77  //if (std::fabs(val(0)) > tol)
78  // libMesh::out << "**** !!! level-set not zero at boundary: " << val(0) << std::endl;
79 
80  _phi->gradient(p, t, gradmat);
81  _phi->perturbation(p, t, dval);
82 
83  // copy the matrix to the vector for further calculations
84  grad = gradmat.row(0);
85 
86  // at boundary, phi(x) = 0
87  // so, dphi/dp + grad(phi) . V = 0
88  // dphi/dp + grad(phi) . (-grad(phi)/|grad(phi)| Vn) = 0 [since V = -grad(phi)/|grad(phi)| Vn]
89  // dphi/dp -(grad(phi) . grad(phi))/|grad(phi)| Vn = 0
90  // Vn = (dphi/dp) |grad(phi)| / |grad(phi)|^2
91  // = (dphi/dp) / |grad(phi)|
92  // V = -grad(phi)/ |grad(phi)| Vn
93  // = -grad(phi)/ |grad(phi)| * (dphi/dp) / |grad(phi)|
94  // = -grad(phi) * (dphi/dp)/|grad(phi)|^2
95  //
96  v = -dval(0)/grad.squaredNorm()*grad;
97 }
98 
virtual void gradient(const libMesh::Point &p, const Real t, RealMatrixX &g) const
calculates the gradient of value of the function at the specified point, p, and time, t, and returns it in g.
virtual void perturbation(const libMesh::Point &p, const Real t, RealVectorX &v) const
calculates the value of perturbation in the function at the specified point, p, and time...
This provides a wrapper FieldFunction compatible class that interpolates the solution using libMesh&#39;s...
void init(MAST::SystemInitialization &sys, const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > &dsol)
LevelSetBoundaryVelocity(const unsigned int dim)
libMesh::Real Real
Matrix< Real, Dynamic, Dynamic > RealMatrixX
This creates the base class for functions that have a saptial and temporal dependence, and provide sensitivity operations with respect to the functions and parameters.
void clear()
clear the solution
Matrix< Real, Dynamic, 1 > RealVectorX
void init(const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > *dsol=nullptr)
initializes the data structures to perform the interpolation function of sol.
virtual void operator()(const libMesh::Point &p, const Real t, RealVectorX &v) const
calculates the value of the function at the specified point, p, and time, t, and returns it in v...