pointConstraintsTemplates.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) 2013-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "pointConstraints.H"
29 #include "pointFields.H"
30 #include "valuePointPatchFields.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 template<class Type, class CombineOp>
36 (
37  const polyMesh& mesh,
38  List<Type>& pointData,
39  const CombineOp& cop
40 )
41 {
42  // Transfer onto coupled patch
43  const globalMeshData& gmd = mesh.globalData();
44  const indirectPrimitivePatch& cpp = gmd.coupledPatch();
45  const labelList& meshPoints = cpp.meshPoints();
46 
47  const mapDistribute& slavesMap = gmd.globalCoPointSlavesMap();
48  const labelListList& slaves = gmd.globalCoPointSlaves();
49 
50  List<Type> elems(slavesMap.constructSize());
51  forAll(meshPoints, i)
52  {
53  elems[i] = pointData[meshPoints[i]];
54  }
55 
56  // Pull slave data onto master. No need to update transformed slots.
57  slavesMap.distribute(elems, false);
58 
59  // Combine master data with slave data
60  forAll(slaves, i)
61  {
62  Type& elem = elems[i];
63 
64  const labelList& slavePoints = slaves[i];
65 
66  // Combine master with untransformed slave data
67  forAll(slavePoints, j)
68  {
69  cop(elem, elems[slavePoints[j]]);
70  }
71 
72  // Copy result back to slave slots
73  forAll(slavePoints, j)
74  {
75  elems[slavePoints[j]] = elem;
76  }
77  }
78 
79  // Push slave-slot data back to slaves
80  slavesMap.reverseDistribute(elems.size(), elems, false);
81 
82  // Extract back onto mesh
83  forAll(meshPoints, i)
84  {
85  pointData[meshPoints[i]] = elems[i];
86  }
87 }
88 
89 
90 template<class Type>
92 (
93  GeometricField<Type, pointPatchField, pointMesh>& pf
94 )
95 {
96  typename GeometricField<Type, pointPatchField, pointMesh>::
97  Boundary& pfbf = pf.boundaryFieldRef();
98 
99  forAll(pfbf, patchi)
100  {
101  pointPatchField<Type>& ppf = pfbf[patchi];
102 
103  if (isA<valuePointPatchField<Type>>(ppf))
104  {
105  refCast<valuePointPatchField<Type>>(ppf) =
106  ppf.patchInternalField();
107  }
108  }
109 }
110 
111 
112 template<class Type>
114 (
115  GeometricField<Type, pointPatchField, pointMesh>& pf
116 ) const
117 {
118  forAll(patchPatchPointConstraintPoints_, pointi)
119  {
120  pf[patchPatchPointConstraintPoints_[pointi]] = transform
121  (
122  patchPatchPointConstraintTensors_[pointi],
123  pf[patchPatchPointConstraintPoints_[pointi]]
124  );
125  }
126 }
127 
128 
129 template<class Type>
131 (
132  GeometricField<Type, pointPatchField, pointMesh>& pf,
133  const bool overrideFixedValue
134 ) const
135 {
136  // Override constrained pointPatchField types with the constraint value.
137  // This relies on only constrained pointPatchField implementing the evaluate
138  // function
139  pf.correctBoundaryConditions();
140 
141  // Sync any dangling points
142  syncUntransformedData
143  (
144  mesh()(),
145  pf.primitiveFieldRef(),
146  maxMagSqrEqOp<Type>()
147  );
148 
149  // Apply multiple constraints on edge/corner points
150  constrainCorners(pf);
151 
152  if (overrideFixedValue)
153  {
154  setPatchFields(pf);
155  }
156 }
157 
158 
159 // ************************************************************************* //
const mapDistribute & globalCoPointSlavesMap() const
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
label constructSize() const noexcept
Constructed data size.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
A list of faces which address into the list of points.
const globalMeshData & globalData() const
Return parallel info (demand-driven)
Definition: pointMesh.H:146
dynamicFvMesh & mesh
const pointMesh & mesh() const noexcept
Reference to the mesh.
Definition: MeshObject.H:157
static void syncUntransformedData(const polyMesh &mesh, List< Type > &pointData, const CombineOp &cop)
Helper: sync data on collocated points only.
void constrainCorners(GeometricField< Type, pointPatchField, pointMesh > &pf) const
Apply patch-patch constraints only.
static void setPatchFields(GeometricField< Type, pointPatchField, pointMesh > &)
Helper: set patchField values from internal values (on.
void reverseDistribute(const label constructSize, List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
Class containing processor-to-processor mapping information.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const Type * isA(const U &obj)
Check if dynamic_cast to Type is possible.
Definition: typeInfo.H:88
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
const labelListList & globalCoPointSlaves() const