MAST
kinematic_coupling.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 //MAST includes
24 #include "base/nonlinear_system.h"
26 
27 // libMesh includes
28 #include "libmesh/dof_map.h"
29 
30 
32 MAST::DoFCouplingBase(sys_init),
33 _initialized (false) {
34 
35 }
36 
37 
39 
40  std::map<const libMesh::Node*, const MAST::KinematicCouplingConstraint*>::const_iterator
41  it = _slave_node_constraints.begin(),
42  end = _slave_node_constraints.end();
43 
44  for ( ; it != end; it++)
45  delete it->second;
46 }
47 
48 
49 
50 void
53 (const std::vector<std::pair<const libMesh::Node*, std::set<const libMesh::Node*>>>& couplings,
54  bool constrain_rotations) {
55 
56  for (unsigned int i=0; i<couplings.size(); i++)
57  this->add_master_and_slave(couplings[i].second,
58  *couplings[i].first,
59  constrain_rotations);
60 }
61 
62 
63 void
65 add_master_and_slave(const std::set<const libMesh::Node*>& master,
66  const libMesh::Node& slave,
67  bool constrain_rotations) {
68 
69  libmesh_assert(!_initialized);
70  libmesh_assert(!_slave_node_constraints.count(&slave));
71 
74  slave,
75  master,
76  constrain_rotations);
77 
78  _slave_node_constraints[&slave] = constr;
79 }
80 
81 
82 
83 void
85 
86  libMesh::DofMap
87  &dof_map = _system_init.system().get_dof_map();
88 
89  std::vector<std::tuple<libMesh::dof_id_type, libMesh::DofConstraintRow, Real>>
90  constrs;
91 
92  this->get_constraint_rows(constrs);
93 
94  std::vector<std::tuple<libMesh::dof_id_type, libMesh::DofConstraintRow, Real>>::iterator
95  it = constrs.begin(),
96  end = constrs.end();
97 
98  for ( ; it != end; it++)
99  dof_map.add_constraint_row(std::get<0>(*it), std::get<1>(*it), std::get<2>(*it), true);
100 }
101 
102 
103 void
106 (std::vector<std::tuple<libMesh::dof_id_type, libMesh::DofConstraintRow, Real>>& constrs) {
107 
108  // iterate over all the nodes in the map and initialize their constraints
109  constrs.clear();
110 
111  std::map<const libMesh::Node*, const MAST::KinematicCouplingConstraint*>::const_iterator
112  it = _slave_node_constraints.begin(),
113  end = _slave_node_constraints.end();
114 
115  unsigned int
116  idx = 0;
117 
118  for ( ; it != end; it++)
119  idx += it->second->n_constrain_nodes();
120 
121  constrs.reserve(idx);
122 
123  it = _slave_node_constraints.begin();
124 
125  for ( ; it != end; it++) {
126 
127  std::vector<std::tuple<libMesh::dof_id_type, libMesh::DofConstraintRow, Real>>
128  constraints;
129 
130  it->second->get_dof_constraint_row(constraints);
131 
132  for (unsigned int i=0; i<constraints.size(); i++)
133  constrs.push_back(constraints[i]);
134  }
135 
136  libmesh_assert_equal_to(constrs.size(), idx);
137 
138  // set the flag so that new slave-master sets cannot be added
139  _initialized = true;
140 }
141 
MAST::NonlinearSystem & system()
std::map< const libMesh::Node *, const MAST::KinematicCouplingConstraint * > _slave_node_constraints
void add_dof_constraints_to_dof_map()
initializes the dof constraint rows in the DofMap object associated with the system.
This object stores the information about the coupling of nodes.
void add_master_and_slave(const std::set< const libMesh::Node * > &master, const libMesh::Node &slave, bool constrain_rotations)
Constrain the slave node to the specified set of master nodes.
MAST::SystemInitialization & _system_init
This provides a base class to couple degrees-of-freedom within a single system.
virtual void get_constraint_rows(std::vector< std::tuple< libMesh::dof_id_type, libMesh::DofConstraintRow, Real >> &constrs)
Provides the vector of constraints and right-hand-side value pairs to be added to the system...
KinematicCoupling(MAST::SystemInitialization &sys_init)