v0.15.5
Loading...
Searching...
No Matches
OperatorsTester.hpp
Go to the documentation of this file.
1/**
2 * @file OperatorsTester.hpp
3 * @brief Used to calculate derivatives and testing tangent matrix, i.e. hessian.
4 * @version 0.13.2
5 * @date 2022-12-04
6 *
7 * @copyright Copyright (c) 2022
8 *
9 */
10
11#ifndef __OPERATORS_TESTER_HPP__
12#define __OPERATORS_TESTER_HPP__
13
14namespace MoFEM {
15
16/**
17 * @brief Calculate directional derivative of the right hand side and compare it
18 * with tangent matrix derivative.
19 *
20 */
22
23 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
24 UnknownInterface **iface) const;
25
26 OperatorsTester(const MoFEM::Core &core);
27 virtual ~OperatorsTester() = default;
28
29 using RandomFieldData = std::pair<std::string, std::array<double, 2>>;
30
31 /**
32 * @brief Generate random fields
33 *
34 * Example: generate random vector for DM (problem) from simple interface,
35 where FIELD random values of DOFs are in range from -1 to 1, and FIELD2
36 random values are in range from 0 to 1.
37 * @code {.cpp}
38 * auto x = opt->setRandomFields(simple->getDM(),
39 {{"FIELD1", {-1, 1}}, {"FIELD2", {0,1}}});
40 * @endcode
41 *
42 *
43 * TODO: Set random field to specific entities, and potentially order for
44 testing proposes to dissect error in tangent matrix.
45 *
46 * @param dm
47 * @param random_fields look at definition @ref RandomFieldData
48 * @return SmartPetscObj<Vec> smart vector
49 */
51 std::vector<RandomFieldData> random_fields,
52 boost::shared_ptr<Range> ents = nullptr,
54
55 /**
56 * @brief Assemble the right hand side vector
57 *
58 * @param dm
59 * @param fe_name // fe name
60 * @param pipeline // pipeline, i.e. fe instance
61 * @param x // problem (dm) vector
62 * @param delta_x // vector for x rate, can be null, i.e, SmartPetscObj<Vec>()
63 * @param delta2_x // vector for x second rate, i.e. acceleration
64 * @param time // time
65 * @param delta_t // time increment
66 * @param cache_ptr // finite element data cache, can be null
67 * @return SmartPetscObj<Vec>
68 */
69 SmartPetscObj<Vec> assembleVec(SmartPetscObj<DM> dm, std::string fe_name,
70 boost::shared_ptr<FEMethod> pipeline,
72 SmartPetscObj<Vec> delta_x,
73 SmartPetscObj<Vec> delta2_x, double time,
74 double delta_t, CacheTupleWeakPtr cache_ptr);
75
76 /**
77 * @brief Assemble the left hand side vector
78 *
79 * @param dm
80 * @param fe_name // fe name
81 * @param pipeline // pipeline, i.e. fe instance
82 * @param x // problem (dm) vector
83 * @param delta_x // vector for x rate, can be null, i.e, SmartPetscObj<Vec>()
84 * @param delta2_x // vector for x second rate, i.e. acceleration
85 * @param time // time
86 * @param delta_t // time increment
87 * @param cache_ptr // finite element data cache, can be null
88 * @return SmartPetscObj<Vec>
89 */
90 SmartPetscObj<Mat> assembleMat(SmartPetscObj<DM> dm, std::string fe_name,
91 boost::shared_ptr<FEMethod> pipeline,
93 SmartPetscObj<Vec> delta_x,
94 SmartPetscObj<Vec> delta2_x, double time,
95 double delta_t, CacheTupleWeakPtr cache_ptr);
96
97 /**
98 * @brief Calculate directional directive using finite difference
99 *
100 * @param dm
101 * @param fe_name
102 * @param pipeline
103 * @param x
104 * @param delta_x
105 * @param delta2_x
106 * @param diff_x // direction of derivative
107 * @param time
108 * @param delta_t
109 * @param eps
110 * @param cache_ptr
111 * @return SmartPetscObj<Vec>
112 */
114 SmartPetscObj<DM> dm, std::string fe_name,
115 boost::shared_ptr<FEMethod> pipeline, SmartPetscObj<Vec> x,
116 SmartPetscObj<Vec> delta_x, SmartPetscObj<Vec> delta2_x,
117 SmartPetscObj<Vec> diff_x, double time, double delta_t, double eps,
119
120 /**
121 * @brief Check consistency between directional derivative with matrix
122 *
123 * @param dm
124 * @param fe_name
125 * @param pipeline_rhs
126 * @param pipeline_lhs
127 * @param x
128 * @param delta_x
129 * @param delta2_x
130 * @param diff_x
131 * @param time
132 * @param delta_t
133 * @param eps
134 * @param cache_ptr
135 * @return SmartPetscObj<Vec>
136 */
138 SmartPetscObj<DM> dm, std::string fe_name,
139 boost::shared_ptr<FEMethod> pipeline_rhs,
140 boost::shared_ptr<FEMethod> pipeline_lhs, SmartPetscObj<Vec> x,
141 SmartPetscObj<Vec> delta_x, SmartPetscObj<Vec> delta2_x,
142 SmartPetscObj<Vec> diff_x, double time, double delta_t, double eps,
144
145private:
147
148 /**
149 * @brief Set vectors, x, x_t, and x_tt to finite element instance
150 *
151 * Finite element instance is a pipeline. x_t and x_tt are evaluated for given
152 * delta_x, delta2_x and delta_t.
153 *
154 * @param pipeline
155 * @param x
156 * @param delta_x
157 * @param delta2_x
158 * @param delta_t
159 * @return std::pair<SmartPetscObj<Vec>, SmartPetscObj<Vec>>
160 */
161 std::pair<SmartPetscObj<Vec>, SmartPetscObj<Vec>>
162 setPipelineX(boost::shared_ptr<FEMethod> pipeline, SmartPetscObj<Vec> x,
163 SmartPetscObj<Vec> delta_x, SmartPetscObj<Vec> delta2_x,
164 double delta_t);
165};
166
167} // namespace MoFEM
168
169#endif //__OPERATORS_TESTER_HPP__
static const double eps
RowColData
RowColData.
@ COL
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
boost::shared_ptr< CacheTuple > CacheTupleSharedPtr
boost::weak_ptr< CacheTuple > CacheTupleWeakPtr
Core (interface) class.
Definition Core.hpp:82
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative...
SmartPetscObj< Mat > assembleMat(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double time, double delta_t, CacheTupleWeakPtr cache_ptr)
Assemble the left hand side vector.
SmartPetscObj< Vec > checkCentralFiniteDifference(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline_rhs, boost::shared_ptr< FEMethod > pipeline_lhs, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, SmartPetscObj< Vec > diff_x, double time, double delta_t, double eps, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Check consistency between directional derivative with matrix.
std::pair< std::string, std::array< double, 2 > > RandomFieldData
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
virtual ~OperatorsTester()=default
SmartPetscObj< Vec > assembleVec(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double time, double delta_t, CacheTupleWeakPtr cache_ptr)
Assemble the right hand side vector.
SmartPetscObj< Vec > setRandomFields(SmartPetscObj< DM > dm, std::vector< RandomFieldData > random_fields, boost::shared_ptr< Range > ents=nullptr, RowColData r=RowColData::COL)
Generate random fields.
std::pair< SmartPetscObj< Vec >, SmartPetscObj< Vec > > setPipelineX(boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double delta_t)
Set vectors, x, x_t, and x_tt to finite element instance.
SmartPetscObj< Vec > directionalCentralFiniteDifference(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, SmartPetscObj< Vec > diff_x, double time, double delta_t, double eps, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Calculate directional directive using finite difference.
intrusive_ptr for managing petsc objects
base class for all interface classes