cyclicAMIGAMGInterface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "AMIInterpolation.H"
30 #include "cyclicAMIGAMGInterface.H"
32 #include "Map.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(cyclicAMIGAMGInterface, 0);
40  (
41  GAMGInterface,
42  cyclicAMIGAMGInterface,
43  lduInterface
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
51 (
52  const label index,
53  const lduInterfacePtrsList& coarseInterfaces,
54  const lduInterface& fineInterface,
55  const labelField& localRestrictAddressing,
56  const labelField& neighbourRestrictAddressing,
57  const label fineLevelIndex,
58  const label coarseComm
59 )
60 :
62  (
63  index,
64  coarseInterfaces
65  ),
66  fineCyclicAMIInterface_
67  (
68  refCast<const cyclicAMILduInterface>(fineInterface)
69  )
70 {
71  // Construct face agglomeration from cell agglomeration
72  {
73  // From coarse face to cell
74  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
75 
76  // From face to coarse face
77  DynamicList<label> dynFaceRestrictAddressing
78  (
79  localRestrictAddressing.size()
80  );
81 
82  Map<label> masterToCoarseFace(localRestrictAddressing.size());
83 
84  for (const label curMaster : localRestrictAddressing)
85  {
86  const auto iter = masterToCoarseFace.cfind(curMaster);
87 
88  if (iter.found())
89  {
90  // Already have coarse face
91  dynFaceRestrictAddressing.append(iter.val());
92  }
93  else
94  {
95  // New coarse face
96  const label coarseI = dynFaceCells.size();
97  dynFaceRestrictAddressing.append(coarseI);
98  dynFaceCells.append(curMaster);
99  masterToCoarseFace.insert(curMaster, coarseI);
100  }
101  }
102 
103  faceCells_.transfer(dynFaceCells);
104  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
105  }
106 
107 
108  // On the owner side construct the AMI
109 
110  if (fineCyclicAMIInterface_.owner())
111  {
112  // Construct the neighbour side agglomeration (as the neighbour would
113  // do it so it the exact loop above using neighbourRestrictAddressing
114  // instead of localRestrictAddressing)
115 
116  labelList nbrFaceRestrictAddressing;
117  {
118  // From face to coarse face
119  DynamicList<label> dynNbrFaceRestrictAddressing
120  (
121  neighbourRestrictAddressing.size()
122  );
123 
124  Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
125 
126  for (const label curMaster : neighbourRestrictAddressing)
127  {
128  const auto iter = masterToCoarseFace.cfind(curMaster);
129 
130  if (iter.found())
131  {
132  // Already have coarse face
133  dynNbrFaceRestrictAddressing.append(iter.val());
134  }
135  else
136  {
137  // New coarse face
138  const label coarseI = masterToCoarseFace.size();
139  dynNbrFaceRestrictAddressing.append(coarseI);
140  masterToCoarseFace.insert(curMaster, coarseI);
141  }
142  }
143 
144  nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
145  }
146 
147  amiPtr_.reset
148  (
150  (
151  fineCyclicAMIInterface_.AMI(),
152  faceRestrictAddressing_,
153  nbrFaceRestrictAddressing
154  )
155  );
156  }
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161 
163 {}
164 
165 
166 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 
169 (
170  const Pstream::commsTypes commsType,
171  const labelUList& iF
172 ) const
173 {
174  const cyclicAMIGAMGInterface& nbr =
175  dynamic_cast<const cyclicAMIGAMGInterface&>(neighbPatch());
176  const labelUList& nbrFaceCells = nbr.faceCells();
177 
178  tmp<labelField> tpnf(new labelField(nbrFaceCells.size()));
179  labelField& pnf = tpnf.ref();
180 
181  forAll(pnf, facei)
182  {
183  pnf[facei] = iF[nbrFaceCells[facei]];
184  }
185 
186  return tpnf;
187 }
188 
189 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
Foam::Map< label >
AMIInterpolation.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Map.H
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field< label >
Foam::labelField
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:52
Foam::GAMGInterface::faceCells
virtual const labelUList & faceCells() const
Return faceCell addressing.
Definition: GAMGInterface.H:221
Foam::GAMGInterface
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
cyclicAMIGAMGInterface.H
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::UPtrList< const lduInterface >
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::cyclicAMIGAMGInterface
GAMG agglomerated cyclic AMI interface.
Definition: cyclicAMIGAMGInterface.H:51
Foam::cyclicAMIGAMGInterface::~cyclicAMIGAMGInterface
virtual ~cyclicAMIGAMGInterface()
Destructor.
Definition: cyclicAMIGAMGInterface.C:162
Foam::List< label >
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:79
Foam::UList< label >
Foam::cyclicAMIGAMGInterface::internalFieldTransfer
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
Definition: cyclicAMIGAMGInterface.C:169
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)