mpc.hh
Go to the documentation of this file.
1//==============================================================================
11//==============================================================================
12#ifndef MPC_HH_
13#define MPC_HH_
14
15#include <map>
16#include <vector>
17#include <iosfwd>
18#include <set>
19
20namespace Opm {
21namespace Elasticity {
22
24enum Direction { NONE = 0, X = 1, Y = 2, Z = 4,
25 XY = 1+2, XZ = 1+4, YZ = 2+4,
26 XYZ = 1+2+4 };
27
58class MPC
59{
60public:
61
66 struct DOF
67 {
69 DOF() : node(0), dof(0), coeff(double(0)) {}
70
75 DOF(int n, int d, double c = double(0)) : node(n), dof(d), coeff(c) {}
76
78 friend std::ostream& operator<<(std::ostream& s, const DOF& d);
79
80 int node;
81 int dof;
82 double coeff;
83 };
84
86 class Less {
87 public:
90 bool operator()(const MPC* lhs, const MPC* rhs) const;
94 };
95
102 MPC(int n, int d, double c = double(0)) : slave(n,d,c) { iceq = -1; }
103
110 void addMaster(int n, int d, double c = double(1), double tol = double(1.0e-8))
111 {
112 if (c < -tol || c > tol) master.push_back(DOF(n,d,c));
113 }
114
116 void updateMaster(size_t pos, double c)
117 {
118 if (pos < master.size())
119 master[pos].coeff = c;
120 }
121
123 void removeMaster(size_t pos)
124 {
125 if (pos < master.size())
126 master.erase(master.begin()+pos);
127 }
128
130 void addOffset(double offset) { slave.coeff += offset; }
131
133 void setSlaveCoeff(double c0) { slave.coeff = c0; }
134
136 const DOF& getSlave() const { return slave; }
138 const DOF& getMaster(size_t i) const { return master[i]; }
139
141 size_t getNoMaster() const { return master.size(); }
142
144 friend std::ostream& operator<<(std::ostream& s, const MPC& mpc);
145
146 int iceq;
147private:
148 DOF slave;
149 std::vector<DOF> master;
150};
151
153typedef std::set<MPC*,MPC::Less> MPCSet;
154
156typedef std::map<int,MPC*> MPCMap;
157
158}
159}
160
161#endif
Comparison predicate for MPCs.
Definition: mpc.hh:86
bool operator()(const MPC *lhs, const MPC *rhs) const
Comparison operator used when inserting an MPC-pointer into a set<MPC*,MPC::Less> object.
static bool compareSlaveDofOnly
Indicates whether only the slave dof number should affect sorting.
Definition: mpc.hh:93
A class for representing a general multi-point constraint equation.
Definition: mpc.hh:59
friend std::ostream & operator<<(std::ostream &s, const MPC &mpc)
Global stream operator printing a constraint equation.
size_t getNoMaster() const
Returns the number of master DOFs.
Definition: mpc.hh:141
void setSlaveCoeff(double c0)
Assigns a new c0 coefficient to the constraint equation.
Definition: mpc.hh:133
MPC(int n, int d, double c=double(0))
Constructor creating a constraint for a specified slave DOF with no master DOFs.
Definition: mpc.hh:102
void addMaster(int n, int d, double c=double(1), double tol=double(1.0e-8))
Adds a master DOF to the constraint equation.
Definition: mpc.hh:110
const DOF & getSlave() const
Returns a reference to the slave DOF.
Definition: mpc.hh:136
void addOffset(double offset)
Increments the c0 coefficient by a given offset.
Definition: mpc.hh:130
int iceq
Global constraint equation identifier.
Definition: mpc.hh:146
void removeMaster(size_t pos)
Removes the pos'th master DOF from the constraint equation.
Definition: mpc.hh:123
void updateMaster(size_t pos, double c)
Updates the coefficient of the pos'th master DOF.
Definition: mpc.hh:116
const DOF & getMaster(size_t i) const
Returns a reference to the i'th master DOF.
Definition: mpc.hh:138
Direction
An enum for specification of global coordinate directions.
Definition: mpc.hh:24
@ XZ
Definition: mpc.hh:25
@ Z
Definition: mpc.hh:24
@ XYZ
Definition: mpc.hh:26
@ YZ
Definition: mpc.hh:25
@ NONE
Definition: mpc.hh:24
@ Y
Definition: mpc.hh:24
@ X
Definition: mpc.hh:24
@ XY
Definition: mpc.hh:25
std::set< MPC *, MPC::Less > MPCSet
A set of MPCs.
Definition: mpc.hh:153
std::map< int, MPC * > MPCMap
A mapping from dof to MPCs.
Definition: mpc.hh:156
Definition: ImplicitAssembly.hpp:43
A struct for representing one term (DOF number and associated coefficient) in a MPC equation.
Definition: mpc.hh:67
DOF()
Default constructor.
Definition: mpc.hh:69
DOF(int n, int d, double c=double(0))
Convenience constructor creating a valid DOF object.
Definition: mpc.hh:75
int dof
Local DOF number within node.
Definition: mpc.hh:81
int node
Node number identifying this DOF.
Definition: mpc.hh:80
friend std::ostream & operator<<(std::ostream &s, const DOF &d)
Global stream operator printing a DOF instance.
double coeff
The constrained value, or master DOF scaling coefficient.
Definition: mpc.hh:82