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 <iostream>
18 #include <set>
19 
20 namespace Opm {
21 namespace Elasticity {
22 
24 enum 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 
58 class MPC
59 {
60 public:
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& dof)
79  {
80  return s <<"u_"<< char('w'+dof.dof) <<" in node "<< dof.node;
81  }
82 
83  int node;
84  int dof;
85  double coeff;
86  };
87 
89  class Less {
90  public:
93  bool operator()(const MPC* lhs, const MPC* rhs) const;
96  static bool compareSlaveDofOnly;
97  };
98 
105  MPC(int n, int d, double c = double(0)) : slave(n,d,c) { iceq = -1; }
106 
113  void addMaster(int n, int d, double c = double(1), double tol = double(1.0e-8))
114  {
115  if (c < -tol || c > tol) master.push_back(DOF(n,d,c));
116  }
117 
119  void updateMaster(size_t pos, double c)
120  {
121  if (pos < master.size())
122  master[pos].coeff = c;
123  }
124 
126  void removeMaster(size_t pos)
127  {
128  if (pos < master.size())
129  master.erase(master.begin()+pos);
130  }
131 
133  void addOffset(double offset) { slave.coeff += offset; }
134 
136  void setSlaveCoeff(double c0) { slave.coeff = c0; }
137 
139  const DOF& getSlave() const { return slave; }
141  const DOF& getMaster(size_t i) const { return master[i]; }
142 
144  size_t getNoMaster() const { return master.size(); }
145 
147  friend std::ostream& operator<<(std::ostream& s, const MPC& mpc);
148 
149  int iceq;
150 private:
151  DOF slave;
152  std::vector<DOF> master;
153 };
154 
156 typedef std::set<MPC*,MPC::Less> MPCSet;
157 
159 typedef std::map<int,MPC*> MPCMap;
160 
161 }
162 }
163 
164 #endif
void removeMaster(size_t pos)
Removes the pos'th master DOF from the constraint equation.
Definition: mpc.hh:126
int iceq
Global constraint equation identifier.
Definition: mpc.hh:149
Definition: applier.hpp:18
static bool compareSlaveDofOnly
Indicates whether only the slave dof number should affect sorting.
Definition: mpc.hh:96
const DOF & getSlave() const
Returns a reference to the slave DOF.
Definition: mpc.hh:139
int node
Node number identifying this DOF.
Definition: mpc.hh:83
Definition: mpc.hh:26
friend std::ostream & operator<<(std::ostream &s, const MPC &mpc)
Global stream operator printing a constraint equation.
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:105
A class for representing a general multi-point constraint equation.
Definition: mpc.hh:58
std::map< int, MPC * > MPCMap
A mapping from dof to MPCs.
Definition: mpc.hh:159
const DOF & getMaster(size_t i) const
Returns a reference to the i'th master DOF.
Definition: mpc.hh:141
Definition: mpc.hh:25
Definition: mpc.hh:24
size_t getNoMaster() const
Returns the number of master DOFs.
Definition: mpc.hh:144
Comparison predicate for MPCs.
Definition: mpc.hh:89
friend std::ostream & operator<<(std::ostream &s, const DOF &dof)
Global stream operator printing a DOF instance.
Definition: mpc.hh:78
void updateMaster(size_t pos, double c)
Updates the coefficient of the pos'th master DOF.
Definition: mpc.hh:119
Definition: mpc.hh:24
std::set< MPC *, MPC::Less > MPCSet
A set of MPCs.
Definition: mpc.hh:156
int dof
Local DOF number within node.
Definition: mpc.hh:84
void addOffset(double offset)
Increments the c0 coefficient by a given offset.
Definition: mpc.hh:133
void setSlaveCoeff(double c0)
Assigns a new c0 coefficient to the constraint equation.
Definition: mpc.hh:136
Definition: mpc.hh:24
Direction
An enum for specification of global coordinate directions.
Definition: mpc.hh:24
DOF()
Default constructor.
Definition: mpc.hh:69
A struct for representing one term (DOF number and associated coefficient) in a MPC equation...
Definition: mpc.hh:66
DOF(int n, int d, double c=double(0))
Convenience constructor creating a valid DOF object.
Definition: mpc.hh:75
double coeff
The constrained value, or master DOF scaling coefficient.
Definition: mpc.hh:85
Definition: mpc.hh:24
bool operator()(const MPC *lhs, const MPC *rhs) const
Comparison operator used when inserting an MPC-pointer into a set object...
Definition: mpc.hh:25
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:113
Definition: mpc.hh:25