32 _level_set_func (nullptr) {
45 libmesh_assert(!
_phi);
64 const libMesh::Point& p,
73 const libMesh::Point& p,
80 val = RealVectorX::Zero(1),
81 grad = RealVectorX::Zero(
_dim),
82 dval = RealVectorX::Zero(1);
85 gradmat = RealMatrixX::Zero(1,
_dim);
103 grad = gradmat.row(0);
115 v = -dval(0)/grad.squaredNorm()*grad;
140 const unsigned int side,
141 const libMesh::Point& p,
150 elem = e.neighbor_ptr(side);
152 libmesh_assert(elem);
156 _mesh->max_elem_id(),
157 _mesh->max_node_id());
161 pt(0) = p2(0); pt(1) = p2(1); pt(2) = p2(2);
172 const libMesh::Elem& e,
173 const unsigned int side,
174 const libMesh::Point& p,
178 libmesh_assert(
_phi);
186 pt(v(0), v(1), v(2));
202 bool allow_sub_search)
const {
204 libmesh_assert(
_phi);
207 phi = RealVectorX::Zero(1),
208 grad_phi = RealVectorX::Zero(
_dim),
209 grad0 = RealVectorX::Zero(3),
210 grad1 = RealVectorX::Zero(3),
211 z = RealVectorX::Zero(3),
212 dval = RealVectorX::Zero(1),
213 p_ref = RealVectorX::Zero(3),
214 dv0 = RealVectorX::Zero(4),
215 dv1 = RealVectorX::Zero(4),
216 dx = RealVectorX::Zero(4),
217 gradL = RealVectorX::Zero(4);
220 hess = RealMatrixX::Zero(3, 3),
221 gradmat = RealMatrixX::Zero(1,
_dim),
222 coeffs = RealMatrixX::Zero(3, 3);
257 dv0.topRows(3) = p_ref;
264 (*_phi) (p_opt, t, phi);
268 gradL.topRows(3) = (dv0.topRows(3)-p_ref) + dv0(3) * gradmat.row(0).transpose();
273 for (
unsigned int i=0; i<3; i++) {
275 coeffs(3,i) = coeffs(i,3) = gradmat(0,i);
277 coeffs.topLeftCorner(3, 3) += hess;
279 Eigen::FullPivLU<RealMatrixX> solver(coeffs);
282 continue_search =
true;
283 dx = - solver.solve(gradL);
293 while (continue_search) {
297 dv1 = dv0 + damp*factor * dx;
299 continue_search =
false;
305 if (n_it == max_it) {
308 v.topRows(
_dim) = dv0.topRows(
_dim);
312 continue_search =
true;
316 p_opt(0) = dv1(0); p_opt(1) = dv1(1); p_opt(2) = dv1(2);
320 grad1 = gradmat.row(0);
321 z = (dv1.topRows(3)-dv0.topRows(3)) - hess * (grad1-grad0);
331 if (n_iters == max_iters) {
335 if (allow_sub_search) {
338 p_opt(0) = v(0); p_opt(1) = v(1); p_opt(2) = v(2);
340 (*_phi) (p_opt, t, phi);
344 libMesh::Point dp = p_opt - p;
346 <<
"Warning: nearest interface point search did not converge. Point found from sub-search. " 350 << p(0) <<
" , " << p(1) <<
" , " << p(2)
351 <<
") -> mapped pt: (" 352 << p_opt(0) <<
" , " << p_opt(1) <<
" , " << p_opt(2)
353 <<
"). phi = " << phi(0)
354 <<
" d/h = " << dp.norm()/length << std::endl;
356 if (std::fabs(gradL.norm()) <= tol) if_cont =
false;
357 if (std::fabs((L1-L0)/L0) <= tol) if_cont =
false;
364 v.topRows(
_dim) = dv0.topRows(
_dim);
372 const libMesh::Point& p,
377 libmesh_assert(
_phi);
385 pt(v(0), v(1), v(2));
400 libmesh_assert(
_phi);
403 gradmat = RealMatrixX::Zero(1,
_dim);
410 n.topRows(3) = -gradmat.row(0);
419 const libMesh::Point& p,
423 libmesh_assert(
_phi);
426 gradmat = RealMatrixX::Zero(1,
_dim),
427 dgrad = RealMatrixX::Zero(1,
_dim);
440 n.topRows(3) = (-dv/v.norm() + v.dot(dv)/std::pow(v.dot(v),1.5) * v);
451 libMesh::Point p1(dv(0), dv(1), dv(2));
455 return .5 * p1.norm_sq() + dv(3)*phi(0);
virtual void perturbation_gradient(const libMesh::Point &p, const Real t, RealMatrixX &v) const
calculates the value of the function at the specified point, p, and time, t, and returns it in v...
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.
MAST::NonlinearSystem & system()
void init(MAST::SystemInitialization &sys, const MAST::MeshFieldFunction &phi)
virtual void derivative(const MAST::FunctionBase &f, const libMesh::Point &p, const Real t, RealVectorX &v) const
calculates the value of the derivative of function with respect to the function f at the specified po...
const MAST::MeshFieldFunction * _phi
This provides a wrapper FieldFunction compatible class that interpolates the solution using libMesh's...
virtual ~LevelSetBoundaryVelocity()
virtual void derivative(const MAST::FunctionBase &f, 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...
void attach_level_set_function(const MAST::FieldFunction< Real > &phi)
attaches the level set function phi with this object.
LevelSetBoundaryVelocity(const unsigned int dim)
void search_nearest_interface_point_derivative_old(const MAST::FunctionBase &f, const libMesh::Point &p, const Real t, const Real length, RealVectorX &v) const
serches for a point pt in the vicinity of p on the level set interface, where level set function is z...
libMesh::MeshBase * _mesh
void normal_at_point(const libMesh::Point &p, const Real t, RealVectorX &n) const
void search_nearest_interface_point(const libMesh::Elem &e, const unsigned int side, const libMesh::Point &p, const Real t, RealVectorX &pt) const
void init(const MAST::FieldFunction< Real > &phi, const libMesh::Elem &e, const Real t, unsigned int max_elem_id, unsigned int max_node_id)
void velocity(const MAST::FunctionBase &f, const libMesh::Point &p, const Real t, RealVectorX &v) const
Matrix< Real, Dynamic, Dynamic > RealMatrixX
void search_nearest_interface_point_old(const libMesh::Point &p, const Real t, const Real length, RealVectorX &pt, bool allow_sub_search=true) const
serches for a point pt in the vicinity of p on the level set interface, where level set function is z...
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.
const MAST::FieldFunction< Real > * _level_set_func
Real _evaluate_point_search_obj(const libMesh::Point &p, const Real t, const RealVectorX &dv) const
Matrix< Real, Dynamic, 1 > RealVectorX
void search_nearest_interface_point_derivative(const MAST::FunctionBase &f, const libMesh::Elem &e, const unsigned int side, const libMesh::Point &p, const Real t, RealVectorX &v) const
void get_nearest_intersection_point(const libMesh::Point &p, libMesh::Point &pt)
void clear_level_set_function()
clears the attached level set function
void normal_derivative_at_point(const MAST::FunctionBase &f, const libMesh::Point &p, const Real t, RealVectorX &n) const