-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstraints.h
More file actions
180 lines (138 loc) · 5.64 KB
/
constraints.h
File metadata and controls
180 lines (138 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONSTRAINTS_H
#define CONSTRAINTS_H
#include <QDataStream>
#include <QDebug>
#include <Eigen/Dense>
#include <memory>
#include "global.h"
using Eigen::Matrix3d;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::VectorXi;
using Eigen::ColMajor;
namespace Constraint {
class ConstraintBase
{
public:
ConstraintBase & operator= (ConstraintBase &&) = delete;
ConstraintBase( ConstraintBase &&) = delete;
ConstraintBase (const ConstraintBase & other) = delete;
ConstraintBase & operator= (const ConstraintBase & other) = delete;
protected:
ConstraintBase();
virtual ~ConstraintBase() = default;
static MatrixXd null( const VectorXd &xs );
static MatrixXd Rot_ab( const VectorXd &a,
const VectorXd &b);
public:
enum Status { UNEVAL=0, REQUIRED, OBSOLETE };
virtual void serialize( QDataStream &out) const; // = 0
static std::shared_ptr<ConstraintBase> deserialize( QDataStream &in );
virtual const char *type_name() const = 0;
virtual int dof() const = 0;
virtual int arity() const = 0;
Status status() const { return m_status; } // serialzation
bool enforced() const { return m_enforced; }
bool required() const { return m_status==REQUIRED; }
bool obsolete() const { return m_status==OBSOLETE; }
bool unevaluated() const { return m_status==UNEVAL; }
void setStatus( const Status s) { m_status = s; }
void setEnforced( const bool b) { m_enforced = b; }
virtual MatrixXd Jacobian( const VectorXi &idxx, const VectorXd &l0, const VectorXd &l) const = 0;
virtual VectorXd contradict( const VectorXi &idxx, const VectorXd &l0 ) const = 0;
template<typename T>
bool is() { return ( dynamic_cast<T*>(this) != nullptr); }
virtual std::shared_ptr<ConstraintBase> clone() const = 0; // virtual constructor (copying)
private:
Status m_status; // { UNEVAL=0 | REQUIRED | OBSOLETE };
bool m_enforced;
};
class Copunctual : public ConstraintBase
{
public:
MatrixXd Jacobian( const VectorXi &idxx, const VectorXd &l0, const VectorXd &l) const override;
VectorXd contradict( const VectorXi &idxx, const VectorXd &l0) const override;
int dof() const override {return s_dof;}
int arity() const override {return s_arity;} //!< number of involved entities
protected:
const char* type_name() const override { return "copunctual"; }
private:
std::shared_ptr<ConstraintBase> clone() const override;
Matrix3d cof3( const Matrix3d &MM ) const; //!< 3x3 cofactor matrix
static const int s_dof = 1;
static const int s_arity = 3;
public:
static std::shared_ptr<ConstraintBase> create() {
return std::make_shared<Copunctual>();
}
};
class Parallel : public ConstraintBase
{
public:
MatrixXd Jacobian( const VectorXi &idxx, const VectorXd &l0, const VectorXd &l) const override;
VectorXd contradict( const VectorXi &idxx, const VectorXd &l0) const override;
int dof() const override { return s_dof; }
int arity() const override { return s_arity; }
static std::shared_ptr<ConstraintBase> create() {
return std::make_shared<Parallel>();
}
private:
const char* type_name() const override { return "parallel"; }
std::shared_ptr<ConstraintBase> clone() const override;
static Eigen::Matrix3d S3();
static const int s_dof = 1;
static const int s_arity = 2;
};
class Orthogonal : public ConstraintBase
{
public:
MatrixXd Jacobian( const VectorXi &idxx, const VectorXd &l0, const VectorXd &l) const override;
VectorXd contradict( const VectorXi &idxx, const VectorXd &l0) const override;
int dof() const override { return s_dof; }
int arity() const override { return s_arity; }
static std::shared_ptr<ConstraintBase> create() {
return std::make_shared<Orthogonal>();
}
private:
const char* type_name() const override { return "orthogonal"; }
std::shared_ptr<ConstraintBase> clone() const override;
static Matrix3d CC();
static const int s_dof = 1;
static const int s_arity = 2;
};
class Identical : public ConstraintBase
{
public:
MatrixXd Jacobian( const VectorXi &idxx, const VectorXd &l0, const VectorXd &l) const override;
VectorXd contradict( const VectorXi &idxx, const VectorXd &l0) const override;
int dof() const override {return s_dof;}
int arity() const override {return s_arity;}
private:
const char* type_name() const override {return "identical";}
std::shared_ptr<ConstraintBase> clone() const override;
static const int s_dof = 2;
static const int s_arity = 2;
template <typename T>
inline bool sameSign( T a, T b ) const { return a*b >= 0.; } // for debugging and assertion
template <typename T>
inline int sign(T val) const { return (T(0) < val) - (val < T(0)); }
};
} // namespace Constraint
#endif // CONSTRAINTS_H