Loading...
Searching...
No Matches
pod_kernel.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include <cassert>
26#include <sstream>
27#include <typeinfo>
28#include <unordered_map>
29#include <unordered_set>
30
31#if BITPIT_ENABLE_MPI
32# include <mpi.h>
33#endif
34
35#include "bitpit_private_lapacke.hpp"
36#include "bitpit_voloctree.hpp"
37
38#include "pod_kernel.hpp"
39
40namespace bitpit {
41
54# if BITPIT_ENABLE_MPI
59# else
61# endif
62:m_cellsVolume(1)
63{
64
65#if BITPIT_ENABLE_MPI
66 m_communicator = MPI_COMM_NULL;
67#endif
68
69 m_meshPOD = nullptr;
70 m_meshmap = nullptr;
71
72# if BITPIT_ENABLE_MPI
73 initializeCommunicator(comm);
74 MPI_Comm_size(m_communicator, &m_nProcs);
75 MPI_Comm_rank(m_communicator, &m_rank);
76#else
77 m_rank = 0;
78 m_nProcs = 1;
79#endif
80
81 setMapperDirty(true);
82
83}
84
92
97{
99
100# if BITPIT_ENABLE_MPI
102# endif
103}
104
110void PODKernel::setMesh(std::unique_ptr<VolumeKernel> &&mesh)
111{
112 m_meshPOD = std::move(mesh);
113}
114
121{
122 return m_meshPOD.get();
123}
124
130std::unique_ptr<VolumeKernel> PODKernel::readMesh(const pod::SnapshotFile &snap)
131{
132 int dumpBlock = (m_nProcs > 1) ? m_rank : -1;
133 std::string filename = std::string(snap.directory) + "/" + std::string(snap.name) + ".mesh";
134 IBinaryArchive binaryReader(filename, dumpBlock);
135
136 std::unique_ptr<VolumeKernel> mesh = createMesh();
137
138 mesh->restore(binaryReader.getStream());
139
140 binaryReader.close();
141
142 return mesh;
143}
144
151{
152 m_meshPOD = readMesh(snap);
154}
155
160{
163 for (Cell & cell : m_meshPOD->getCells()){
164 long id = cell.getId();
165 m_cellsVolume[id] = m_meshPOD->evalCellVolume(id);
166 }
167}
168
175{
176 return m_cellsVolume[id];
177}
178
184double PODKernel::getRawCellVolume(long rawIndex)
185{
186 return m_cellsVolume.rawAt(rawIndex);
187}
188
194void PODKernel::computeMapper(const VolumeKernel * mesh, bool fillInv)
195{
196 if (m_meshPOD == nullptr)
197 throw std::runtime_error ("PODKernel: no pod mesh set in compute Mapper");
198
199 if (mesh == nullptr)
200 throw std::runtime_error ("PODKernel: no valid input mesh in compute Mapper");
201
202 clearMapper();
203
204 m_meshmap = _computeMapper(mesh, fillInv);
205
206 setMapperDirty(false);
207}
208
214void PODKernel::adaptionPrepare(const std::vector<adaption::Info> & info)
215{
216 m_meshmap->adaptionPrepare(info, false);
217 setMapperDirty(true);
218}
219
226void PODKernel::adaptionAlter(const std::vector<adaption::Info> & info, bool fillInv)
227{
228 m_meshmap->adaptionAlter(info, false, fillInv);
229 setMapperDirty(false);
230}
231
236void PODKernel::adaptionCleanUp(const std::vector<adaption::Info> & info)
237{
238 BITPIT_UNUSED(info);
239 m_meshmap->adaptionCleanup();
240}
241
247{
248 return m_meshmap.get();
249}
250
251
256{
257 m_meshmap.reset();
258 setMapperDirty(true);
259}
260
266{
267 m_dirtymap = dirty;
268}
269
275{
276 return m_dirtymap;
277}
278
279#if BITPIT_ENABLE_MPI
285void PODKernel::initializeCommunicator(MPI_Comm communicator)
286{
287 // Communication can be set just once
288 if (isCommunicatorSet())
289 throw std::runtime_error ("PODKernel communicator can be set just once");
290
291 // The communicator has to be valid
292 if (communicator == MPI_COMM_NULL)
293 throw std::runtime_error ("PODKernel communicator is not valid");
294
295 // Create a copy of the user-specified communicator
296 //
297 // No library routine should use MPI_COMM_WORLD as the communicator;
298 // instead, a duplicate of a user-specified communicator should always
299 // be used.
300 MPI_Comm_dup(communicator, &m_communicator);
301}
302
308{
309 return m_communicator;
310}
311
319{
320
321 return (getCommunicator() != MPI_COMM_NULL);
322}
323
328{
329 if (!isCommunicatorSet())
330 return;
331
332 int finalizedCalled;
333 MPI_Finalized(&finalizedCalled);
334 if (finalizedCalled)
335 return;
336
337 MPI_Comm_free(&m_communicator);
338}
339#endif
340
341}
The Cell class defines the cells.
Definition cell.hpp:42
Input binary archive.
std::istream & getStream()
std::unique_ptr< VolumeKernel > readMesh(const pod::SnapshotFile &snap)
std::unique_ptr< VolumeMapper > m_meshmap
void computeMapper(const VolumeKernel *mesh, bool fillInv=true)
MPI_Comm m_communicator
VolumeMapper * getMapper()
PODKernel(MPI_Comm comm=MPI_COMM_WORLD)
void adaptionPrepare(const std::vector< adaption::Info > &info)
VolumeKernel * getMesh()
void adaptionAlter(const std::vector< adaption::Info > &info, bool fillInv=true)
void adaptionCleanUp(const std::vector< adaption::Info > &info)
void setMesh(std::unique_ptr< VolumeKernel > &&mesh)
double getCellVolume(long id)
void restoreMesh(const pod::SnapshotFile &snap)
bool isCommunicatorSet() const
double getRawCellVolume(long rawIndex)
virtual ~PODKernel()
std::unique_ptr< VolumeKernel > m_meshPOD
PiercedStorage< double > m_cellsVolume
void setMapperDirty(bool dirty=true)
MPI_Comm getCommunicator() const
void initializeCommunicator(MPI_Comm communicator)
void setStaticKernel(const PiercedKernel< id_t > *kernel)
void unsetKernel(bool release=true)
__PS_REFERENCE__ rawAt(std::size_t pos, std::size_t offset=0)
The VolumeKernel class provides an interface for defining volume patches.
The VolumeMapper is the class to map two meshes.
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
The SnapFile structure is used to store the file names inside POD classes.
--- layout: doxygen_footer ---