Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / matrices / lduMatrix / lduAddressing / lduInterface / processorLduInterfaceTemplates.C
bloba49753a1a92537db6115d6a10c942d2ecd612977
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "processorLduInterface.H"
28 #include "IPstream.H"
29 #include "OPstream.H"
31 // * * * * * * * * * * * * * * * Member Functions * * *  * * * * * * * * * * //
33 template<class Type>
34 void Foam::processorLduInterface::send
36     const Pstream::commsTypes commsType,
37     const UList<Type>& f
38 ) const
40     if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
41     {
42         OPstream::write
43         (
44             commsType,
45             neighbProcNo(),
46             reinterpret_cast<const char*>(f.begin()),
47             f.byteSize()
48         );
49     }
50     else if (commsType == Pstream::nonBlocking)
51     {
52         resizeBuf(receiveBuf_, f.size()*sizeof(Type));
54         IPstream::read
55         (
56             commsType,
57             neighbProcNo(),
58             receiveBuf_.begin(),
59             receiveBuf_.size()
60         );
62         resizeBuf(sendBuf_, f.byteSize());
63         memcpy(sendBuf_.begin(), f.begin(), f.byteSize());
65         OPstream::write
66         (
67             commsType,
68             neighbProcNo(),
69             sendBuf_.begin(),
70             f.byteSize()
71         );
72     }
73     else
74     {
75         FatalErrorIn("processorLduInterface::send")
76             << "Unsupported communications type " << commsType
77             << exit(FatalError);
78     }
82 template<class Type>
83 void Foam::processorLduInterface::receive
85     const Pstream::commsTypes commsType,
86     UList<Type>& f
87 ) const
89     if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
90     {
91         IPstream::read
92         (
93             commsType,
94             neighbProcNo(),
95             reinterpret_cast<char*>(f.begin()),
96             f.byteSize()
97         );
98     }
99     else if (commsType == Pstream::nonBlocking)
100     {
101         memcpy(f.begin(), receiveBuf_.begin(), f.byteSize());
102     }
103     else
104     {
105         FatalErrorIn("processorLduInterface::receive")
106             << "Unsupported communications type " << commsType
107             << exit(FatalError);
108     }
112 template<class Type>
113 Foam::tmp<Foam::Field<Type> > Foam::processorLduInterface::receive
115     const Pstream::commsTypes commsType,
116     const label size
117 ) const
119     tmp<Field<Type> > tf(new Field<Type>(size));
120     receive(commsType, tf());
121     return tf;
125 template<class Type>
126 void Foam::processorLduInterface::compressedSend
128     const Pstream::commsTypes commsType,
129     const UList<Type>& f
130 ) const
132     if (sizeof(scalar) != sizeof(float) && Pstream::floatTransfer && f.size())
133     {
134         static const label nCmpts = sizeof(Type)/sizeof(scalar);
135         label nm1 = (f.size() - 1)*nCmpts;
136         label nlast = sizeof(Type)/sizeof(float);
137         label nFloats = nm1 + nlast;
138         label nBytes = nFloats*sizeof(float);
140         const scalar *sArray = reinterpret_cast<const scalar*>(f.begin());
141         const scalar *slast = &sArray[nm1];
142         resizeBuf(sendBuf_, nBytes);
143         float *fArray = reinterpret_cast<float*>(sendBuf_.begin());
145         for (register label i=0; i<nm1; i++)
146         {
147             fArray[i] = sArray[i] - slast[i%nCmpts];
148         }
150         reinterpret_cast<Type&>(fArray[nm1]) = f[f.size() - 1];
152         if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
153         {
154             OPstream::write
155             (
156                 commsType,
157                 neighbProcNo(),
158                 sendBuf_.begin(),
159                 nBytes
160             );
161         }
162         else if (commsType == Pstream::nonBlocking)
163         {
164             resizeBuf(receiveBuf_, nBytes);
166             IPstream::read
167             (
168                 commsType,
169                 neighbProcNo(),
170                 receiveBuf_.begin(),
171                 receiveBuf_.size()
172             );
174             OPstream::write
175             (
176                 commsType,
177                 neighbProcNo(),
178                 sendBuf_.begin(),
179                 nBytes
180             );
181         }
182         else
183         {
184             FatalErrorIn("processorLduInterface::compressedSend")
185                 << "Unsupported communications type " << commsType
186                 << exit(FatalError);
187         }
188     }
189     else
190     {
191         this->send(commsType, f);
192     }
195 template<class Type>
196 void Foam::processorLduInterface::compressedReceive
198     const Pstream::commsTypes commsType,
199     UList<Type>& f
200 ) const
202     if (sizeof(scalar) != sizeof(float) && Pstream::floatTransfer && f.size())
203     {
204         static const label nCmpts = sizeof(Type)/sizeof(scalar);
205         label nm1 = (f.size() - 1)*nCmpts;
206         label nlast = sizeof(Type)/sizeof(float);
207         label nFloats = nm1 + nlast;
208         label nBytes = nFloats*sizeof(float);
210         if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
211         {
212             resizeBuf(receiveBuf_, nBytes);
214             IPstream::read
215             (
216                 commsType,
217                 neighbProcNo(),
218                 receiveBuf_.begin(),
219                 nBytes
220             );
221         }
222         else if (commsType != Pstream::nonBlocking)
223         {
224             FatalErrorIn("processorLduInterface::compressedReceive")
225                 << "Unsupported communications type " << commsType
226                 << exit(FatalError);
227         }
229         const float *fArray =
230             reinterpret_cast<const float*>(receiveBuf_.begin());
231         f[f.size() - 1] = reinterpret_cast<const Type&>(fArray[nm1]);
232         scalar *sArray = reinterpret_cast<scalar*>(f.begin());
233         const scalar *slast = &sArray[nm1];
235         for (register label i=0; i<nm1; i++)
236         {
237             sArray[i] = fArray[i] + slast[i%nCmpts];
238         }
239     }
240     else
241     {
242         this->receive<Type>(commsType, f);
243     }
246 template<class Type>
247 Foam::tmp<Foam::Field<Type> > Foam::processorLduInterface::compressedReceive
249     const Pstream::commsTypes commsType,
250     const label size
251 ) const
253     tmp<Field<Type> > tf(new Field<Type>(size));
254     compressedReceive(commsType, tf());
255     return tf;
259 // ************************************************************************* //