Nektar++
CoupledAssemblyMap.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: CoupledAssemblyMap.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Coupled assembly map for linear elasticity solver.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <iomanip>
36 
37 #include <boost/core/ignore_unused.hpp>
38 
42 #include <LocalRegions/SegExp.h>
46 
47 using namespace std;
48 
49 namespace Nektar
50 {
51 
53 
54 /**
55  * @brief Take an existing assembly map and create a coupled version suitable
56  * for use in the linear elasticity solver.
57  *
58  * The linear elasticity solver requires a slight reordering of local and global
59  * coefficients to support problems of the form
60  *
61  * [ A B C ] [ u ] = [ f_u ]
62  * [ D E F ] [ v ] [ f_v ]
63  * [ G H I ] [ w ] [ f_w ]
64  */
65 
66 CoupledAssemblyMap::CoupledAssemblyMap(
70  const Array<OneD, const BoundaryCondShPtr> &boundaryConditions,
72  AssemblyMapCG(pSession)
73 {
74  boost::ignore_unused(graph, boundaryConditions);
75 
76  int nVel = fields[0]->GetCoordim(0);
77 
78  // Multi-level static condensation doesn't work yet.
82  "Multi-level static condensation not supported.");
83 
84  // Copy various coefficient counts, and multiply by the dimension of the
85  // problem to obtain our new values.
86  m_numLocalDirBndCoeffs = cgMap->GetNumLocalDirBndCoeffs() * nVel;
87  m_numLocalBndCoeffs = cgMap->GetNumLocalBndCoeffs() * nVel;
88  m_numLocalCoeffs = cgMap->GetNumLocalCoeffs() * nVel;
89  m_numGlobalBndCoeffs = cgMap->GetNumGlobalBndCoeffs() * nVel;
90  m_numGlobalDirBndCoeffs = cgMap->GetNumGlobalDirBndCoeffs() * nVel;
91  m_numGlobalCoeffs = cgMap->GetNumGlobalCoeffs() * nVel;
92  m_signChange = cgMap->GetSignChange();
93  m_systemSingular = cgMap->GetSingularSystem();
94 
95  // Copy static condensation information. TODO: boundary and interior patches
96  // need to be re-ordered in order to allow for multi-level static
97  // condensation support.
98  m_staticCondLevel = cgMap->GetStaticCondLevel();
99  m_lowestStaticCondLevel = cgMap->GetLowestStaticCondLevel();
100  m_numPatches = cgMap->GetNumPatches();
101  m_numLocalBndCoeffsPerPatch = cgMap->GetNumLocalBndCoeffsPerPatch();
102  m_numLocalIntCoeffsPerPatch = cgMap->GetNumLocalIntCoeffsPerPatch();
103 
104  // Set up local to global and boundary condition maps.
105  const int nLocBndCondDofs = cgMap->
106  GetBndCondCoeffsToGlobalCoeffsMap().num_elements() * nVel;
107 
108  // Allocate storage for local to global maps.
114  Array<OneD, int>(nLocBndCondDofs,-1);
115 
116  // Only require a sign map if we are using modal polynomials in the
117  // expansion and the order is >= 3.
118  if (m_signChange)
119  {
125  Array<OneD, NekDouble>(nLocBndCondDofs,1.0);
126  }
127  else
128  {
132  }
133 
134  const LocalRegions::ExpansionVector &locExpVector
135  = *(fields[0]->GetExp());
136 
137  map<int, int> newGlobalIds;
138  int i, j, n, cnt1, cnt2;
139 
140  // Order local boundary degrees of freedom. These are basically fine; we
141  // reorder storage so that we loop over each element and then each component
142  // of velocity, by applying a mapping l2g -> nVel*l2g + n, for 0 <= n <
143  // nVel. Note that Dirichlet ordering is preserved under this
144  // transformation.
145  cnt1 = cnt2 = 0;
146  for (i = 0; i < locExpVector.size(); ++i)
147  {
148  const int nBndCoeffs = locExpVector[i]->NumBndryCoeffs();
149 
150  for (n = 0; n < nVel; ++n)
151  {
152  for (j = 0; j < nBndCoeffs; ++j, ++cnt1)
153  {
154  const int l2g = cgMap->GetLocalToGlobalBndMap()[cnt2+j];
155  m_localToGlobalBndMap[cnt1] = nVel * l2g + n;
156 
157  if (m_signChange)
158  {
159  m_localToGlobalBndSign[cnt1] =
160  cgMap->GetLocalToGlobalBndSign()[cnt2+j];
161  }
162 
163  if (n == 0)
164  {
165  const int l2gnew = m_localToGlobalBndMap[cnt1];
166  if (newGlobalIds.count(l2g))
167  {
168  ASSERTL1(newGlobalIds[l2g] == l2gnew,
169  "Consistency error");
170  }
171  newGlobalIds[l2g] = l2gnew;
172  }
173  }
174  }
175 
176  cnt2 += nBndCoeffs;
177  }
178 
179  // Grab map of extra Dirichlet degrees of freedom for parallel runs
180  // (particularly in 3D).
181  m_extraDirDofs = cgMap->GetExtraDirDofs();
182 
183  // Counter for remaining interior degrees of freedom.
184  int globalId = m_numGlobalBndCoeffs;
185 
186  // Interior degrees of freedom are a bit more tricky -- global linear system
187  // solve relies on them being in the same order as the BinvD, C and invD
188  // matrices.
189  cnt1 = cnt2 = 0;
190  for (i = 0; i < locExpVector.size(); ++i)
191  {
192  const int nCoeffs = locExpVector[i]->GetNcoeffs();
193  const int nBndCoeffs = locExpVector[i]->NumBndryCoeffs();
194 
195  for (n = 0; n < nVel; ++n)
196  {
197  for (j = 0; j < nBndCoeffs; ++j, ++cnt1, ++cnt2)
198  {
199  const int l2g = m_localToGlobalBndMap[cnt2];
200  m_localToGlobalMap[cnt1] = l2g;
201 
202  if (m_signChange)
203  {
205  }
206  }
207  }
208 
209  for (n = 0; n < nVel; ++n)
210  {
211  for (j = 0; j < nCoeffs - nBndCoeffs; ++j, ++cnt1)
212  {
213  m_localToGlobalMap[cnt1] = globalId++;
214  }
215  }
216  }
217 
218  for (i = 0; i < m_localToGlobalMap.num_elements(); ++i)
219  {
220  ASSERTL1(m_localToGlobalMap[i] != -1, "Consistency error");
221  }
222 
223  ASSERTL1(globalId == m_numGlobalCoeffs, "Consistency error");
224 
225  cnt1 = 0;
226  for (n = 0; n < nVel; ++n)
227  {
228  for (i = 0; i < nLocBndCondDofs/nVel; ++i, ++cnt1)
229  {
230  const int l2g = cgMap->GetBndCondCoeffsToGlobalCoeffsMap()[i];
231  int newId = newGlobalIds[l2g];
232  m_bndCondCoeffsToGlobalCoeffsMap[cnt1] = newId + n;
233 
234  if (m_signChange)
235  {
237  cgMap->GetBndCondCoeffsToGlobalCoeffsSign(i);
238  }
239  }
240  }
241 
242  // Finally, set up global to universal maps.
247 
248  for (i = 0; i < cgMap->GetNumGlobalBndCoeffs(); ++i)
249  {
250  for (n = 0; n < nVel; ++n)
251  {
252  m_globalToUniversalBndMap[i*nVel + n] =
253  cgMap->GetGlobalToUniversalBndMap()[i]*nVel + n;
254  m_globalToUniversalMap[i*nVel + n] =
255  cgMap->GetGlobalToUniversalBndMap()[i]*nVel + n;
256  }
257  }
258 
262  for (unsigned int i = 0; i < m_numGlobalBndCoeffs; ++i)
263  {
264  tmp[i] = m_globalToUniversalBndMap[i];
265  }
266 
267  LibUtilities::CommSharedPtr vCommRow = m_comm->GetRowComm();
268  m_gsh = Gs::Init(tmp, vCommRow);
269  m_bndGsh = Gs::Init(tmp2, vCommRow);
270  Gs::Unique(tmp, vCommRow);
271  for (unsigned int i = 0; i < m_numGlobalCoeffs; ++i)
272  {
273  m_globalToUniversalMapUnique[i] = (tmp[i] >= 0 ? 1 : 0);
274  }
275  for (unsigned int i = 0; i < m_numGlobalBndCoeffs; ++i)
276  {
277  m_globalToUniversalBndMapUnique[i] = (tmp2[i] >= 0 ? 1 : 0);
278  }
279 
280  m_hash = hash_range(
281  m_localToGlobalMap.begin(), m_localToGlobalMap.end());
282 }
283 
284 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::size_t hash_range(Iter first, Iter last)
Definition: HashUtils.hpp:69
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
bool m_systemSingular
Flag indicating if the system is singular or not.
Definition: AssemblyMap.h:321
bool m_signChange
Flag indicating if modes require sign reversal.
Definition: AssemblyMap.h:346
int m_numGlobalBndCoeffs
Total number of global boundary coefficients.
Definition: AssemblyMap.h:315
LibUtilities::CommSharedPtr m_comm
Communicator.
Definition: AssemblyMap.h:307
std::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
Definition: AssemblyMapCG.h:51
static Array< OneD, NekDouble > NullNekDouble1DArray
Array< OneD, int > m_globalToUniversalMapUnique
Integer map of unique process coeffs to universal space (signed)
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
STL namespace.
Array< OneD, int > m_globalToUniversalMap
Integer map of process coeffs to universal space.
int m_numLocalCoeffs
Total number of local coefficients.
Definition: AssemblyMap.h:332
std::map< int, std::vector< ExtraDirDof > > m_extraDirDofs
Map indicating degrees of freedom which are Dirichlet but whose value is stored on another processor...
std::vector< ExpansionSharedPtr > ExpansionVector
Definition: Expansion.h:67
Array< OneD, int > m_localToGlobalMap
Integer map of local coeffs to global space.
static gs_data * Init(const Nektar::Array< OneD, long > pId, const LibUtilities::CommSharedPtr &pComm, bool verbose=true)
Initialise Gather-Scatter map.
Definition: GsLib.hpp:167
size_t m_hash
Hash for map.
Definition: AssemblyMap.h:310
Array< OneD, unsigned int > m_numLocalBndCoeffsPerPatch
The number of bnd dofs per patch.
Definition: AssemblyMap.h:389
GlobalSysSolnType m_solnType
The solution type of the global system.
Definition: AssemblyMap.h:364
Array< OneD, NekDouble > m_bndCondCoeffsToGlobalCoeffsSign
Integer map of bnd cond coeffs to global coefficients.
Definition: AssemblyMap.h:355
int m_numGlobalDirBndCoeffs
Number of Global Dirichlet Boundary Coefficients.
Definition: AssemblyMap.h:319
static void Unique(const Nektar::Array< OneD, long > pId, const LibUtilities::CommSharedPtr &pComm)
Updates pId to negate all-but-one references to each universal ID.
Definition: GsLib.hpp:202
Array< OneD, unsigned int > m_numLocalIntCoeffsPerPatch
The number of int dofs per patch.
Definition: AssemblyMap.h:391
int m_lowestStaticCondLevel
Lowest static condensation level.
Definition: AssemblyMap.h:398
Array< OneD, int > m_localToGlobalBndMap
Integer map of local boundary coeffs to global space.
Definition: AssemblyMap.h:349
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition: Conditions.h:219
const Array< OneD, const int > & GetBndCondCoeffsToGlobalCoeffsMap()
Retrieves the global indices corresponding to the boundary expansion modes.
int m_numLocalDirBndCoeffs
Number of Local Dirichlet Boundary Coefficients.
Definition: AssemblyMap.h:317
Array< OneD, int > m_bndCondCoeffsToGlobalCoeffsMap
Integer map of bnd cond coeffs to global coefficients.
Definition: AssemblyMap.h:353
int m_numLocalBndCoeffs
Number of local boundary coefficients.
Definition: AssemblyMap.h:313
int m_staticCondLevel
The level of recursion in the case of multi-level static condensation.
Definition: AssemblyMap.h:385
Array< OneD, NekDouble > m_localToGlobalBndSign
Integer sign of local boundary coeffs to global space.
Definition: AssemblyMap.h:351
Array< OneD, NekDouble > m_localToGlobalSign
Integer sign of local coeffs to global space.
Array< OneD, int > m_globalToUniversalBndMap
Integer map of process coeffs to universal space.
Definition: AssemblyMap.h:359
Array< OneD, int > m_globalToUniversalBndMapUnique
Integer map of unique process coeffs to universal space (signed)
Definition: AssemblyMap.h:361
Constructs mappings for the C0 scalar continuous Galerkin formulation.
Definition: AssemblyMapCG.h:70
int m_numGlobalCoeffs
Total number of global coefficients.
Definition: AssemblyMap.h:343
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SessionReader > SessionReaderSharedPtr
int m_numPatches
The number of patches (~elements) in the current level.
Definition: AssemblyMap.h:387