![]() |
v0.16.3 |
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative. More...
#include "src/interfaces/OperatorsTester.hpp"
Public Types | |
| using | RandomFieldData = std::pair< std::string, std::array< double, 2 > > |
| using | ScalarFunction = std::function< MoFEMErrorCode(Vec, PetscReal &)> |
| using | VectorFunction = std::function< MoFEMErrorCode(Vec, Vec)> |
| using | DirectionFunction = std::function< double(const NumeredDofEntity &dof, const std::array< double, 3 > &xyz)> |
| Value of a test direction for one DOF. | |
Public Member Functions | |
| MoFEMErrorCode | query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const |
| OperatorsTester (const MoFEM::Core &core) | |
| virtual | ~OperatorsTester ()=default |
| SmartPetscObj< Vec > | setRandomFields (SmartPetscObj< DM > dm, std::vector< RandomFieldData > random_fields, boost::shared_ptr< Range > ents=nullptr, RowColData r=RowColData::COL) |
| Generate random fields. | |
| SmartPetscObj< Vec > | setDirectionFromFunction (SmartPetscObj< DM > dm, const std::vector< std::string > &fields, DirectionFunction function, boost::shared_ptr< Range > ents=nullptr, RowColData r=RowColData::COL) |
| Set a direction vector from a function of the DOF and position. | |
| 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< 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 > | 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. | |
| 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. | |
| MoFEMErrorCode | checkScalarCentralFiniteDifference (Vec x, Vec direction, Vec gradient, double eps, const ScalarFunction &evaluate, PetscReal &finite_difference, PetscReal &assembled_derivative) |
| MoFEMErrorCode | checkVectorCentralFiniteDifference (Vec x, Vec direction, Vec function_layout, Mat jacobian, double eps, const VectorFunction &evaluate, Vec error) |
Public Member Functions inherited from MoFEM::UnknownInterface | |
| template<class IFACE > | |
| MoFEMErrorCode | registerInterface (bool error_if_registration_failed=true) |
| Register interface. | |
| template<class IFACE > | |
| MoFEMErrorCode | getInterface (IFACE *&iface) const |
| Get interface reference to pointer of interface. | |
| template<class IFACE > | |
| MoFEMErrorCode | getInterface (IFACE **const iface) const |
| Get interface pointer to pointer of interface. | |
| template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0> | |
| IFACE | getInterface () const |
| Get interface pointer to pointer of interface. | |
| template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0> | |
| IFACE | getInterface () const |
| Get reference to interface. | |
| template<class IFACE > | |
| IFACE * | getInterface () const |
| Function returning pointer to interface. | |
| virtual | ~UnknownInterface ()=default |
Private Member Functions | |
| 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. | |
Private Attributes | |
| MoFEM::Core & | cOre |
Additional Inherited Members | |
Static Public Member Functions inherited from MoFEM::UnknownInterface | |
| static MoFEMErrorCode | getLibVersion (Version &version) |
| Get library version. | |
| static MoFEMErrorCode | getFileVersion (moab::Interface &moab, Version &version) |
| Get database major version. | |
| static MoFEMErrorCode | setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD)) |
| Get database major version. | |
| static MoFEMErrorCode | getInterfaceVersion (Version &version) |
| Get database major version. | |
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative.
Definition at line 21 of file OperatorsTester.hpp.
| using MoFEM::OperatorsTester::DirectionFunction = std::function<double( const NumeredDofEntity &dof, const std::array<double, 3> &xyz)> |
Value of a test direction for one DOF.
The DOF gives the entity, field, coefficient index and order; xyz is the centroid of the entity's corner vertices (zero for meshsets).
Definition at line 64 of file OperatorsTester.hpp.
| using MoFEM::OperatorsTester::RandomFieldData = std::pair<std::string, std::array<double, 2> > |
Definition at line 29 of file OperatorsTester.hpp.
| using MoFEM::OperatorsTester::ScalarFunction = std::function<MoFEMErrorCode(Vec, PetscReal &)> |
Definition at line 30 of file OperatorsTester.hpp.
| using MoFEM::OperatorsTester::VectorFunction = std::function<MoFEMErrorCode(Vec, Vec)> |
Definition at line 32 of file OperatorsTester.hpp.
| MoFEM::OperatorsTester::OperatorsTester | ( | const MoFEM::Core & | core | ) |
Definition at line 13 of file OperatorsTester.cpp.
|
virtualdefault |
| SmartPetscObj< Mat > MoFEM::OperatorsTester::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.
| dm | |
| fe_name | // fe name |
| pipeline | // pipeline, i.e. fe instance |
| x | // problem (dm) vector |
| delta_x | // vector for x rate, can be null, i.e, SmartPetscObj<Vec>() |
| delta2_x | // vector for x second rate, i.e. acceleration |
| time | // time |
| delta_t | // time increment |
| cache_ptr | // finite element data cache, can be null |
Definition at line 237 of file OperatorsTester.cpp.
| SmartPetscObj< Vec > MoFEM::OperatorsTester::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.
| dm | |
| fe_name | // fe name |
| pipeline | // pipeline, i.e. fe instance |
| x | // problem (dm) vector |
| delta_x | // vector for x rate, can be null, i.e, SmartPetscObj<Vec>() |
| delta2_x | // vector for x second rate, i.e. acceleration |
| time | // time |
| delta_t | // time increment |
| cache_ptr | // finite element data cache, can be null |
Definition at line 187 of file OperatorsTester.cpp.
| SmartPetscObj< Vec > MoFEM::OperatorsTester::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.
| dm | |
| fe_name | |
| pipeline_rhs | |
| pipeline_lhs | |
| x | |
| delta_x | |
| delta2_x | |
| diff_x | |
| time | |
| delta_t | |
| eps | |
| cache_ptr |
Definition at line 340 of file OperatorsTester.cpp.
| MoFEMErrorCode MoFEM::OperatorsTester::checkScalarCentralFiniteDifference | ( | Vec | x, |
| Vec | direction, | ||
| Vec | gradient, | ||
| double | eps, | ||
| const ScalarFunction & | evaluate, | ||
| PetscReal & | finite_difference, | ||
| PetscReal & | assembled_derivative | ||
| ) |
Check a scalar function derivative against gradient dot direction.
Definition at line 362 of file OperatorsTester.cpp.
| MoFEMErrorCode MoFEM::OperatorsTester::checkVectorCentralFiniteDifference | ( | Vec | x, |
| Vec | direction, | ||
| Vec | function_layout, | ||
| Mat | jacobian, | ||
| double | eps, | ||
| const VectorFunction & | evaluate, | ||
| Vec | error | ||
| ) |
Check a vector function derivative against Jacobian times direction. The returned error is written into a vector with the function layout.
Definition at line 390 of file OperatorsTester.cpp.
| SmartPetscObj< Vec > MoFEM::OperatorsTester::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.
| dm | |
| fe_name | |
| pipeline | |
| x | |
| delta_x | |
| delta2_x | |
| diff_x | // direction of derivative |
| time | |
| delta_t | |
| eps | |
| cache_ptr |
Definition at line 283 of file OperatorsTester.cpp.
|
virtual |
Implements MoFEM::UnknownInterface.
Definition at line 17 of file OperatorsTester.cpp.
| SmartPetscObj< Vec > MoFEM::OperatorsTester::setDirectionFromFunction | ( | SmartPetscObj< DM > | dm, |
| const std::vector< std::string > & | fields, | ||
| DirectionFunction | function, | ||
| boost::shared_ptr< Range > | ents = nullptr, |
||
| RowColData | r = RowColData::COL |
||
| ) |
Set a direction vector from a function of the DOF and position.
Unlike setRandomFields, which draws values in local DOF order, the value of each DOF depends only on the function, the DOF and the mesh. The vector is therefore the same for any number of ranks and any DOF numbering, so derivative checks on one and several ranks test the same direction. DOFs of other fields, or outside ents when given, are zero.
| dm | |
| fields | fields set by the function |
| function | value for each DOF, see DirectionFunction |
| ents | restrict the direction to these entities, null for all |
| r | row or column layout |
Definition at line 98 of file OperatorsTester.cpp.
|
private |
Set vectors, x, x_t, and x_tt to finite element instance.
Finite element instance is a pipeline. x_t and x_tt are evaluated for given delta_x, delta2_x and delta_t.
| pipeline | |
| x | |
| delta_x | |
| delta2_x | |
| delta_t |
Definition at line 420 of file OperatorsTester.cpp.
| SmartPetscObj< Vec > MoFEM::OperatorsTester::setRandomFields | ( | SmartPetscObj< DM > | dm, |
| std::vector< RandomFieldData > | random_fields, | ||
| boost::shared_ptr< Range > | ents = nullptr, |
||
| RowColData | r = RowColData::COL |
||
| ) |
Generate random fields.
Example: generate random vector for DM (problem) from simple interface, where FIELD random values of DOFs are in range from -1 to 1, and FIELD2 random values are in range from 0 to 1.
TODO: Set random field to specific entities, and potentially order for testing proposes to dissect error in tangent matrix.
| dm | |
| random_fields | look at definition RandomFieldData |
Definition at line 23 of file OperatorsTester.cpp.
|
private |
Definition at line 202 of file OperatorsTester.hpp.