https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParameterMesh.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "MooseTypes.h"
13#include "KDTree.h"
14
15#include "libmesh/id_types.h"
16#include <unordered_map>
17#include "libmesh/parallel.h"
18#include "libmesh/fe_type.h"
19#include "libmesh/point.h"
20#include "libmesh/replicated_mesh.h"
21#include "libmesh/equation_systems.h"
22#include "libmesh/point_locator_base.h"
23#include "libmesh/exodusII_io.h"
24#include <vector>
25#include <functional>
26
27namespace libMesh
28{
29class System;
30class DofMap;
31}
32
42{
43public:
44 ParameterMesh(const libMesh::FEType & param_type,
45 const std::string & exodus_mesh,
46 const bool find_closest = false,
47 const unsigned int kdtree_candidates = 5);
48
51 {
53 // Future regularization types can be added here:
54 // L1,
55 // H1,
56 // TV (Total Variation)
57 };
58
62 dof_id_type size() const { return _param_dofs; }
70 void getIndexAndWeight(const Point & pt,
71 std::vector<dof_id_type> & dof_indices,
72 std::vector<Real> & weights) const;
80 void getIndexAndWeight(const Point & pt,
81 std::vector<dof_id_type> & dof_indices,
82 std::vector<RealGradient> & weights) const;
89 Real computeRegularizationObjective(const std::vector<Real> & parameter_values,
90 RegularizationType reg_type) const;
91
98 std::vector<Real> computeRegularizationGradient(const std::vector<Real> & parameter_values,
99 RegularizationType reg_type) const;
100
101private:
108 template <typename T>
109 T computeRegularizationLoop(const std::vector<Real> & parameter_values,
110 RegularizationType reg_type) const;
111
112protected:
116 const bool _find_closest;
117 std::unique_ptr<libMesh::EquationSystems> _eq;
119 std::unique_ptr<libMesh::PointLocatorBase> _point_locator;
120 std::unique_ptr<libMesh::ExodusII_IO> _exodusII_io;
121
122 dof_id_type _param_dofs;
123
125 std::vector<Point> _mesh_nodes;
126 std::unique_ptr<KDTree> _node_kdtree;
127 std::unordered_map<dof_id_type, std::set<const libMesh::Elem *>> _node_to_elements;
128 unsigned int _kdtree_candidates;
129
130private:
136 Point projectToMesh(const Point & p) const;
137
144 Point closestPoint(const Elem & elem, const Point & p) const;
145
158 Real computeRegularizationQp(const std::vector<Real> & parameter_values,
159 const std::vector<std::vector<Real>> & phi,
160 const std::vector<std::vector<RealGradient>> & dphi,
161 const unsigned int qp,
162 const std::vector<dof_id_type> & dof_indices,
163 const std::vector<Real> & JxW,
164 RegularizationType reg_type) const;
165
178 void computeRegularizationGradientQp(const std::vector<Real> & parameter_values,
179 const std::vector<std::vector<Real>> & phi,
180 const std::vector<std::vector<RealGradient>> & dphi,
181 const unsigned int qp,
182 const std::vector<dof_id_type> & dof_indices,
183 const std::vector<Real> & JxW,
184 RegularizationType reg_type,
185 std::vector<Real> & gradient) const;
186 // Cached values for gradient computations
187 const unsigned short int _param_var_id;
190};
const Real p
const double T
Utility class to use an Exodus mesh to define controllable parameters for optimization problems This ...
dof_id_type _param_dofs
RegularizationType
Enumerations for regularization computations.
libMesh::System * _sys
unsigned int _kdtree_candidates
const bool _find_closest
Find closest projection points.
void computeRegularizationGradientQp(const std::vector< Real > &parameter_values, const std::vector< std::vector< Real > > &phi, const std::vector< std::vector< RealGradient > > &dphi, const unsigned int qp, const std::vector< dof_id_type > &dof_indices, const std::vector< Real > &JxW, RegularizationType reg_type, std::vector< Real > &gradient) const
Compute regularization gradient for a single quadrature point This is the main function users should ...
std::vector< Real > computeRegularizationGradient(const std::vector< Real > &parameter_values, RegularizationType reg_type) const
Computes regularization gradient for a given regularization type.
std::unordered_map< dof_id_type, std::set< const libMesh::Elem * > > _node_to_elements
dof_id_type size() const
Real computeRegularizationQp(const std::vector< Real > &parameter_values, const std::vector< std::vector< Real > > &phi, const std::vector< std::vector< RealGradient > > &dphi, const unsigned int qp, const std::vector< dof_id_type > &dof_indices, const std::vector< Real > &JxW, RegularizationType reg_type) const
Compute regularization objective for a single quadrature point This is the main function users should...
std::unique_ptr< libMesh::EquationSystems > _eq
std::unique_ptr< libMesh::ExodusII_IO > _exodusII_io
Point closestPoint(const Elem &elem, const Point &p) const
Find closest point on the element to the given point.
const unsigned short int _param_var_id
std::unique_ptr< libMesh::PointLocatorBase > _point_locator
T computeRegularizationLoop(const std::vector< Real > &parameter_values, RegularizationType reg_type) const
Template method containing the element loop for regularization computations.
Point projectToMesh(const Point &p) const
Returns the point on the parameter mesh that is projected from the test point.
libMesh::ReplicatedMesh _mesh
std::unique_ptr< KDTree > _node_kdtree
libMesh::Parallel::Communicator _communicator
Real computeRegularizationObjective(const std::vector< Real > &parameter_values, RegularizationType reg_type) const
Computes regularization objective value for a given regularization type.
const libMesh::DofMap * _dof_map
const libMesh::FEType _fe_type
void getIndexAndWeight(const Point &pt, std::vector< dof_id_type > &dof_indices, std::vector< Real > &weights) const
Interpolate parameters onto the computational mesh getIndexAndWeight is only used by ParameterMeshFun...
std::vector< Point > _mesh_nodes
Node-based KDTree optimization.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...