Debian Codegraph @

packages/rol/example/PDE-OPT/topo-opt/multimat/src/obj_volume.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 /*! \file obj.hpp
11 \brief Provides the interface for local (cell-based) objective function computations.
12 */
13
14 #ifndef PDEOPT_QOI_VOLUME_MULTIMAT_HPP
15 #define PDEOPT_QOI_VOLUME_MULTIMAT_HPP
16
17 #include "../../../TOOLS/qoi.hpp"
18 #include "pde_elasticity.hpp"
19
20 template <class Real>
21 class QoI_MultiMat_Weight : public QoI<Real> {
22 private:
23 const ROL::Ptr<FE<Real>> fe_;
24 const ROL::Ptr<FieldUtils::FieldInfo> fieldInfo_;
25 ROL::Ptr<Intrepid::FieldContainer<Real>> ones_;
26 ROL::Ptr<Intrepid::FieldContainer<Real>> volFrac_;
27 std::vector<Real> w_;
28
29 public:
30 QoI_MultiMat_Weight(const ROL::Ptr<FE<Real>> &fe,
31 const ROL::Ptr<FieldUtils::FieldInfo> &fieldInfo,
32 ROL::ParameterList &list)
33 : fe_(fe), fieldInfo_(fieldInfo) {
34 Real w0 = list.sublist("Problem").get("Maximum Weight Fraction", 0.5);
35 w_ = ROL::getArrayFromStringParameter<Real>(list.sublist("Problem"), "Density");
36 Real mw(0);
37 int T = w_.size();
38 for (int i = 0; i < T; ++i) {
39 mw = std::max(mw,w_[i]);
40 }
41 // Get relevant dimensions
42 int c = fe_->cubPts()->dimension(0);
43 int p = fe_->cubPts()->dimension(1);
44 ones_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
45 volFrac_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
46 ones_->initialize(static_cast<Real>(1));
47 volFrac_->initialize(w0 * mw);
48 }
49
50 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
51 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
52 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
53 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
54 // Get relevant dimensions
55 int c = fe_->gradN()->dimension(0);
56 int p = fe_->gradN()->dimension(2);
57 int T = w_.size();
58
59 // Initialize output val
60 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
61 // Split z_coeff into components.
62 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> Z;
63 FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfo_);
64 // Evaluate on FE basis
65 ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, sumZ;
66 valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
67 sumZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
68 for (int t=0; t<T; ++t) {
69 valZ_eval->initialize();
70 fe_->evaluateValue(valZ_eval, Z[t]);
71 // Compute weight
72 Intrepid::RealSpaceTools<Real>::scale(*valZ_eval,w_[t]);
73 Intrepid::RealSpaceTools<Real>::add(*sumZ,*valZ_eval);
74 }
75 Intrepid::RealSpaceTools<Real>::subtract(*sumZ,*volFrac_);
76 fe_->computeIntegral(val,sumZ,ones_,true);
77 return static_cast<Real>(0);
78 }
79
80 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
81 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
82 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
83 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
84 throw Exception::Zero(">>> QoI_Volume_TopoOpt::gradient_1 is zero.");
85 }
86
87 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
88 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
89 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
90 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
91 // Get relevant dimensions
92 int c = fe_->gradN()->dimension(0);
93 int f = fe_->gradN()->dimension(1);
94 int T = w_.size();
95
96 // Initialize output grad
97 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(T);
98 for (int t=0; t<T; ++t) {
99 G[t] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
100 // Compute gradient of energy
101 Intrepid::FunctionSpaceTools::integrate<Real>(*G[t],
102 *ones_,
103 *fe_->NdetJ(),
104 Intrepid::COMP_CPP, false);
105 Intrepid::RealSpaceTools<Real>::scale(*G[t],w_[t]);
106 }
107 // Combine the gradients.
108 FieldUtils::combineFieldCoeff<Real>(grad, G, fieldInfo_);
109 }
110
111 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
112 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
113 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
114 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
115 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
116 throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_11 is zero.");
117 }
118
119 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
120 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
121 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
122 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
123 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
124 throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_12 is zero.");
125 }
126
127 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
128 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
129 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
130 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
131 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
132 throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_21 is zero.");
133 }
134
135 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
136 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
137 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
138 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
139 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
140 throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_22 is zero.");
141 }
142
143 }; // QoI_MultiMat_Weight
144
145 #endif