libMesh
Loading...
Searching...
No Matches
heatsystem.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
25#include <memory>
26
27using namespace libMesh;
28
29// FEMSystem, TimeSolver and NewtonSolver will handle most tasks,
30// but we must specify element residuals
31class HeatSystem : public FEMSystem
32{
33public:
34 // Constructor
36 const std::string & name_in,
37 const unsigned int number_in)
38 : FEMSystem(es, name_in, number_in),
39 _k(1.0),
40 _fe_family("LAGRANGE"),
41 _fe_order(1),
43 dp(1.e-6)
44 { this->init_qois(1); }
45
46 std::string & fe_family() { return _fe_family; }
47 unsigned int & fe_order() { return _fe_order; }
48 Real & k() { return _k; }
50
51 // A function to compute and accumulate residuals
53
54 // Sensitivity Calculation
56 {
58
59 // Use the trapezoidal rule to compute the sensitivity integral
60 for(unsigned int i = 0; i < R_plus_dp.size()-1; i++)
61 {
62 Number left_contribution = -(R_plus_dp[i] - R_minus_dp[i])/(2.*dp);
63 Number right_contribution = -(R_plus_dp[i+1] - R_minus_dp[i+1])/(2.*dp);
64
65 final_sensitivity += ( (left_contribution + right_contribution)/2. )*deltat_vector[i];
66 }
67
68 return final_sensitivity;
69 }
70
71 void set_tf(Real val)
72 {
73 tf = val;
74 }
75
77 {
79 for (std::size_t i = 0; i != parameters.size(); ++i)
81
82 return parameter_vector;
83 }
84
85 Number & get_QoI_value(unsigned int QoI_index)
86 {
87 return computed_QoI[QoI_index];
88 }
89
90protected:
91 // System initialization
92 virtual void init_data ();
93
94 // Context initialization
95 virtual void init_context (DiffContext & context);
96
97 // Element residual and jacobian calculations
98 // Time dependent parts
99 virtual bool element_time_derivative (bool request_jacobian,
100 DiffContext & context);
101
102 // Constraint parts
103 // virtual bool side_constraint (bool request_jacobian,
104 // DiffContext & context);
105
106 // RHS for adjoint problem
107 virtual void element_qoi_derivative (DiffContext & context,
108 const QoISet & /* qois */);
109
110 //virtual void element_qoi (DiffContext & context, const QoISet & qois);
111
112 // Parameters associated with the system
113 std::vector<Number> parameters;
114
115 // The ParameterVector object that will contain pointers to
116 // the system parameters
118
119 // The parameters to solve for
121
122 // The final time parameter
124
125 // Variables to hold the computed QoIs
127
128 // The FE type to use
129 std::string _fe_family;
130 unsigned int _fe_order;
131
132 // Index for T variable
133 unsigned int T_var;
134
135 // Calculate Jacobians analytically or not?
137
138 // Variables to hold the perturbed residuals
139 std::vector<Number> R_plus_dp;
140 std::vector<Number> R_minus_dp;
141
142 // A vector to hold the possibly adaptive deltats
143 std::vector<Number> deltat_vector;
144
145 // Perturbation parameter
147
148 // The final computed sensitivity
150};
unsigned int _fe_order
Definition heatsystem.h:130
Real & k()
Definition heatsystem.h:48
std::vector< Number > parameters
Definition heatsystem.h:113
unsigned int & fe_order()
Definition heatsystem.h:47
void set_tf(Real val)
Definition heatsystem.h:71
void perturb_accumulate_residuals(ParameterVector &parameters)
Definition heatsystem.C:162
bool & analytic_jacobians()
Definition heatsystem.h:49
std::vector< Number > R_minus_dp
Definition heatsystem.h:140
Number final_sensitivity
Definition heatsystem.h:149
std::string _fe_family
Definition heatsystem.h:129
ParameterVector parameter_vector
Definition heatsystem.h:117
std::vector< Number > deltat_vector
Definition heatsystem.h:143
ParameterVector & get_parameter_vector()
Definition heatsystem.h:76
Number dp
Definition heatsystem.h:146
std::string & fe_family()
Definition heatsystem.h:46
HeatSystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Definition heatsystem.h:35
unsigned int T_var
Definition heatsystem.h:133
virtual bool element_time_derivative(bool request_jacobian, DiffContext &context)
Adds the time derivative contribution on elem to elem_residual.
Definition heatsystem.C:78
Number & get_QoI_value(unsigned int QoI_index)
Definition heatsystem.h:85
virtual void init_context(DiffContext &context)
Definition heatsystem.C:48
Number & compute_final_sensitivity()
Definition heatsystem.h:55
virtual void init_data()
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
Definition heatsystem.C:37
Number computed_QoI[1]
Definition heatsystem.h:126
std::vector< Number > R_plus_dp
Definition heatsystem.h:139
bool _analytic_jacobians
Definition heatsystem.h:136
virtual void element_qoi_derivative(DiffContext &context, const QoISet &)
Does any work that needs to be done on elem in a quantity of interest derivative assembly loop,...
This class provides all data required for a physics package (e.g.
This is the EquationSystems class.
This class provides a specific system class.
Definition fem_system.h:55
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
void push_back(std::unique_ptr< ParameterAccessor< Number > > new_accessor)
Adds an additional parameter accessor to the end of the vector.
std::size_t size() const
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition qoi_set.h:46
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors.
Definition system.C:2169
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real