libMesh
examples
adjoints
adjoints_ex5
heatsystem.h
Go to the documentation of this file.
1
// The libMesh Finite Element Library.
2
// Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
8
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
13
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20
#include "libmesh/enum_fe_family.h"
21
#include "libmesh/fem_system.h"
22
#include "libmesh/parameter_pointer.h"
23
#include "libmesh/parameter_vector.h"
24
#include "libmesh/auto_ptr.h"
// libmesh_make_unique
25
26
using namespace
libMesh
;
27
28
// FEMSystem, TimeSolver and NewtonSolver will handle most tasks,
29
// but we must specify element residuals
30
class
HeatSystem
:
public
FEMSystem
31
{
32
public
:
33
// Constructor
34
HeatSystem
(
EquationSystems
& es,
35
const
std::string & name_in,
36
const
unsigned
int
number_in)
37
:
FEMSystem
(es, name_in, number_in),
38
_k(1.0),
39
_fe_family(
"LAGRANGE"
),
40
_fe_order(1),
41
_analytic_jacobians(true),
42
R_plus_dp(0.0),
43
R_minus_dp(0.0),
44
dp(1.e-6)
45
{ qoi.resize(1); }
46
47
std::string &
fe_family
() {
return
_fe_family; }
48
unsigned
int
&
fe_order
() {
return
_fe_order; }
49
Real
&
k
() {
return
_k; }
50
bool
&
analytic_jacobians
() {
return
_analytic_jacobians; }
51
52
// A function to compute and accumulate residuals
53
void
perturb_accumulate_residuals(
ParameterVector
& parameters);
54
55
// Sensitivity Calculation
56
Number
&
compute_final_sensitivity
()
57
{
58
final_sensitivity = -(R_plus_dp - R_minus_dp)/(2*dp);
59
60
return
final_sensitivity;
61
}
62
63
void
set_tf
(
Real
val)
64
{
65
tf = val;
66
}
67
68
ParameterVector
&
get_parameter_vector
()
69
{
70
if
(!parameter_vector.size())
71
for
(std::size_t i = 0; i != parameters.size(); ++i)
72
parameter_vector.
push_back
(libmesh_make_unique<
ParameterPointer<Number>
>(¶meters[i]));
73
74
return
parameter_vector;
75
}
76
77
Number
&
get_QoI_value
(
unsigned
int
QoI_index)
78
{
79
return
computed_QoI[QoI_index];
80
}
81
82
protected
:
83
// System initialization
84
virtual
void
init_data ();
85
86
// Context initialization
87
virtual
void
init_context (
DiffContext
& context);
88
89
// Element residual and jacobian calculations
90
// Time dependent parts
91
virtual
bool
element_time_derivative (
bool
request_jacobian,
92
DiffContext
& context);
93
94
// Constraint parts
95
// virtual bool side_constraint (bool request_jacobian,
96
// DiffContext & context);
97
98
// RHS for adjoint problem
99
virtual
void
element_qoi_derivative (
DiffContext
& context,
100
const
QoISet
&
/* qois */
);
101
102
//virtual void element_qoi (DiffContext & context, const QoISet & qois);
103
104
// Parameters associated with the system
105
std::vector<Number>
parameters
;
106
107
// The ParameterVector object that will contain pointers to
108
// the system parameters
109
ParameterVector
parameter_vector
;
110
111
// The parameters to solve for
112
Real
_k
;
113
114
// The final time parameter
115
Real
tf
;
116
117
// Variables to hold the computed QoIs
118
Number
computed_QoI[1];
119
120
// The FE type to use
121
std::string
_fe_family
;
122
unsigned
int
_fe_order
;
123
124
// Index for T variable
125
unsigned
int
T_var
;
126
127
// Calculate Jacobians analytically or not?
128
bool
_analytic_jacobians
;
129
130
// Variables to hold the perturbed residuals
131
Number
R_plus_dp
;
132
Number
R_minus_dp
;
133
134
// Perturbation parameter
135
Real
dp
;
136
137
// The final computed sensitivity
138
Number
final_sensitivity
;
139
};
libMesh::Number
Real Number
Definition:
libmesh_common.h:195
libMesh::ParameterVector::push_back
void push_back(std::unique_ptr< ParameterAccessor< Number >> new_accessor)
Adds an additional parameter accessor to the end of the vector.
Definition:
parameter_vector.h:183
HeatSystem::_fe_order
unsigned int _fe_order
Definition:
heatsystem.h:122
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition:
factoryfunction.C:55
HeatSystem::analytic_jacobians
bool & analytic_jacobians()
Definition:
heatsystem.h:50
HeatSystem::get_QoI_value
Number & get_QoI_value(unsigned int QoI_index)
Definition:
heatsystem.h:77
HeatSystem::final_sensitivity
Number final_sensitivity
Definition:
heatsystem.h:138
HeatSystem::fe_order
unsigned int & fe_order()
Definition:
heatsystem.h:48
libMesh::FEMSystem
This class provides a specific system class.
Definition:
fem_system.h:53
HeatSystem::HeatSystem
HeatSystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Definition:
heatsystem.h:34
HeatSystem::fe_family
std::string & fe_family()
Definition:
heatsystem.h:47
HeatSystem::parameter_vector
ParameterVector parameter_vector
Definition:
heatsystem.h:109
HeatSystem::_fe_family
std::string _fe_family
Definition:
heatsystem.h:121
HeatSystem
Definition:
heatsystem.h:30
libMesh::QoISet
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition:
qoi_set.h:45
HeatSystem::R_plus_dp
Number R_plus_dp
Definition:
heatsystem.h:131
HeatSystem::R_minus_dp
Number R_minus_dp
Definition:
heatsystem.h:132
libMesh::ParameterVector
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
Definition:
parameter_vector.h:44
HeatSystem::dp
Real dp
Definition:
heatsystem.h:135
HeatSystem::tf
Real tf
Definition:
heatsystem.h:115
libMesh::DiffContext
This class provides all data required for a physics package (e.g.
Definition:
diff_context.h:55
libMesh::EquationSystems
This is the EquationSystems class.
Definition:
equation_systems.h:74
HeatSystem::set_tf
void set_tf(Real val)
Definition:
heatsystem.h:63
HeatSystem::compute_final_sensitivity
Number & compute_final_sensitivity()
Definition:
heatsystem.h:56
HeatSystem::_k
Real _k
Definition:
heatsystem.h:112
HeatSystem::k
Real & k()
Definition:
heatsystem.h:49
HeatSystem::parameters
std::vector< Number > parameters
Definition:
heatsystem.h:105
HeatSystem::T_var
unsigned int T_var
Definition:
heatsystem.h:125
libMesh::ParameterPointer
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
Definition:
parameter_pointer.h:45
HeatSystem::get_parameter_vector
ParameterVector & get_parameter_vector()
Definition:
heatsystem.h:68
HeatSystem::_analytic_jacobians
bool _analytic_jacobians
Definition:
heatsystem.h:128
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition:
libmesh_common.h:121
Generated on Sat Jan 25 2020 12:06:50 for libMesh by
1.8.16