IFEM  90A354
MPC.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _MPC_H
15 #define _MPC_H
16 
17 #include <map>
18 #include <vector>
19 #include <iostream>
20 
21 
51 class MPC
52 {
53 public:
54 
59  struct DOF
60  {
62  DOF() : node(0), dof(0), coeff(Real(0)), nextc(nullptr) {}
63 
68  DOF(int n, int d, Real c) : node(n), dof(d), coeff(c), nextc(nullptr) {}
69 
71  friend std::ostream& operator<<(std::ostream& s, const DOF& dof)
72  {
73  int ivar = (dof.dof-1) / 3;
74  int idof = (dof.dof+2) % 3;
75  return s << (ivar < 1 ? 'u' : char('q'+ivar)) << '_'
76  << char('x'+idof) <<" in node "<< dof.node;
77  }
78 
80  friend bool operator==(const DOF& a, const DOF& b)
81  {
82  return a.node == b.node && a.dof == b.dof;
83  }
84 
85  int node;
86  int dof;
89  };
90 
99  MPC(int n, int d, Real s = Real(0)) : slave(n,d,s) { iceq = -1; }
100 
105  void addMaster(const DOF& dof, Real tol = Real(1.0e-8));
111  void addMaster(int n, int d, Real c = Real(1), Real tol = Real(1.0e-8))
112  {
113  this->addMaster(DOF(n,d,c),tol);
114  }
115 
117  void updateMaster(size_t pos, Real c)
118  {
119  if (pos < master.size())
120  master[pos].coeff = c;
121  }
122 
124  void updateMaster(size_t pos, MPC* m)
125  {
126  if (pos < master.size())
127  master[pos].nextc = m;
128  }
129 
131  void removeMaster(size_t pos)
132  {
133  if (pos < master.size())
134  master.erase(master.begin()+pos);
135  }
136 
138  bool isChained() const
139  {
140  for (const DOF& mdof : master)
141  if (mdof.nextc) return true;
142  return false;
143  }
144 
146  bool merge(const MPC* mpc);
147 
152  int renumberNodes(const std::map<int,int>& old2new, bool msg = false);
153 
155  void shiftNodes(int nshift);
156 
158  void addOffset(Real offset) { slave.coeff += offset; }
159 
161  void setSlaveCoeff(Real c0) { slave.coeff = c0; }
162 
164  const DOF& getSlave() const { return slave; }
166  const DOF& getMaster(size_t i) const { return master[i]; }
167 
169  size_t getNoMaster(bool recursive = false) const;
170 
172  friend std::ostream& operator<<(std::ostream& s, const MPC& mpc);
173 
174 protected:
176  void printMaster(std::ostream& os) const;
177 
178 public:
179  int iceq;
180 
181 private:
183  std::vector<DOF> master;
184 };
185 
186 #endif
#define Real
The floating point type to use.
Definition: ImmersedBoundaries.h:18
A class representing a general multi-point constraint equation.
Definition: MPC.h:52
void updateMaster(size_t pos, Real c)
Updates the coefficient of the pos'th master DOF.
Definition: MPC.h:117
void removeMaster(size_t pos)
Removes the pos'th master DOF from the constraint equation.
Definition: MPC.h:131
void printMaster(std::ostream &os) const
Prints out the master(s) of this constraint equation.
Definition: MPC.C:125
int iceq
Global constraint equation identifier.
Definition: MPC.h:179
std::vector< DOF > master
The master DOFs of this constraint equation.
Definition: MPC.h:183
int renumberNodes(const std::map< int, int > &old2new, bool msg=false)
Renumbers all node numbers in the constraint equation.
Definition: MPC.C:106
void setSlaveCoeff(Real c0)
Assigns a new c0 coefficient to the constraint equation.
Definition: MPC.h:161
MPC(int n, int d, Real s=Real(0))
Constructor creating a constraint for a specified slave DOF.
Definition: MPC.h:99
const DOF & getSlave() const
Returns a reference to the slave DOF.
Definition: MPC.h:164
void addMaster(int n, int d, Real c=Real(1), Real tol=Real(1.0e-8))
Adds a master DOF to the constraint equation.
Definition: MPC.h:111
DOF slave
The slave DOF of this constraint equation.
Definition: MPC.h:182
void updateMaster(size_t pos, MPC *m)
Updates the next chain element of the pos'th master DOF.
Definition: MPC.h:124
const DOF & getMaster(size_t i) const
Returns a reference to the i'th master DOF.
Definition: MPC.h:166
void addOffset(Real offset)
Increments the c0 coefficient by a given offset.
Definition: MPC.h:158
friend std::ostream & operator<<(std::ostream &s, const MPC &mpc)
Global stream operator printing a constraint equation.
Definition: MPC.C:158
void addMaster(const DOF &dof, Real tol=Real(1.0e-8))
Adds a master DOF to the constraint equation.
Definition: MPC.C:74
void shiftNodes(int nshift)
Increments node numbers in the constraint equation by nshift.
Definition: MPC.C:117
bool isChained() const
Returns true if this MPC is chained.
Definition: MPC.h:138
size_t getNoMaster(bool recursive=false) const
Returns the number of master DOFs.
Definition: MPC.C:61
bool merge(const MPC *mpc)
Merges the given MPC equation into this one.
Definition: MPC.C:86
A struct representing one term in a multi-point constraint equation.
Definition: MPC.h:60
DOF(int n, int d, Real c)
Convenience constructor creating a valid DOF object.
Definition: MPC.h:68
int node
Node number identifying this DOF.
Definition: MPC.h:85
MPC * nextc
Points to another MPC object in case of chained constraints.
Definition: MPC.h:88
DOF()
Default constructor.
Definition: MPC.h:62
friend bool operator==(const DOF &a, const DOF &b)
Global equality operator.
Definition: MPC.h:80
Real coeff
The constrained value, or master DOF scaling coefficient.
Definition: MPC.h:87
int dof
Local DOF number within node.
Definition: MPC.h:86
friend std::ostream & operator<<(std::ostream &s, const DOF &dof)
Global stream operator printing a DOF instance.
Definition: MPC.h:71