Loading...
Searching...
No Matches
pod_kernel.hpp
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#ifndef __BITPIT_POD_KERNEL_HPP__
26#define __BITPIT_POD_KERNEL_HPP__
27
28#if BITPIT_ENABLE_MPI
29# include <mpi.h>
30#endif
31#include <string>
32#include <vector>
33#include <unordered_map>
34
35#include "pod_common.hpp"
36#include "bitpit_common.hpp"
37#include "bitpit_patchkernel.hpp"
38
39namespace bitpit {
40
41class PODKernel : public VTKBaseStreamer {
42
43 friend class POD;
44
45public:
46# if BITPIT_ENABLE_MPI
47 PODKernel(MPI_Comm comm = MPI_COMM_WORLD);
48# else
49 PODKernel();
50# endif
51
52 virtual ~PODKernel();
53
58 PODKernel(PODKernel&& other) = default;
59
61 void evalCellsVolume();
62 double getCellVolume(long id);
63 double getRawCellVolume(long rawIndex);
65
66 bool isMapperDirty();
67 void computeMapper(const VolumeKernel * mesh, bool fillInv = true);
68 void adaptionPrepare(const std::vector<adaption::Info> & info);
69 void adaptionAlter(const std::vector<adaption::Info> & info, bool fillInv = true);
70 void adaptionCleanUp(const std::vector<adaption::Info> & info);
71
72#if BITPIT_ENABLE_MPI
73 MPI_Comm getCommunicator() const;
74 bool isCommunicatorSet() const;
75#endif
76
77
78protected:
79 std::unique_ptr<VolumeKernel> m_meshPOD;
82#if BITPIT_ENABLE_MPI
83 MPI_Comm m_communicator;
84#endif
85 int m_rank;
88 std::unique_ptr<VolumeMapper> m_meshmap;
92 void clear();
93
94 void setMesh(std::unique_ptr<VolumeKernel> &&mesh);
95
96 std::unique_ptr<VolumeKernel> readMesh(const pod::SnapshotFile &snap);
97 void restoreMesh(const pod::SnapshotFile &snap);
98
99 void clearMapper();
100 void setMapperDirty(bool dirty = true);
101
102 virtual std::unique_ptr<VolumeKernel> createMesh() = 0;
103
104 virtual std::unique_ptr<VolumeMapper> _computeMapper(const VolumeKernel * mesh, bool fillInv) = 0;
105
106 virtual pod::PODField mapPODFieldToPOD(const pod::PODField & field, const std::unordered_set<long> * targetCells) = 0;
107 virtual void mapPODFieldFromPOD(pod::PODField & field, const std::unordered_set<long> * targetCells, const pod::PODField & mappedField) = 0;
108
109 virtual PiercedStorage<double> mapFieldsToPOD(const PiercedStorage<double> & fields, const VolumeKernel * mesh, const std::unordered_set<long> * targetCells,
110 const std::vector<std::size_t> &scalarIds, const std::vector<std::array<std::size_t, 3>> &vectorIds) = 0;
111 virtual void mapFieldsFromPOD(PiercedStorage<double> & fields, const VolumeKernel * mesh, const std::unordered_set<long> * targetCells,
112 const PiercedStorage<double> & mappedFields,
113 const std::vector<std::size_t> &scalarIds, const std::vector<std::array<std::size_t, 3>> &vectorIds) = 0;
114
115 virtual PiercedStorage<bool> mapBoolFieldToPOD(const PiercedStorage<bool> & field, const VolumeKernel * mesh, const std::unordered_set<long> * targetCells) = 0;
116 virtual void mapBoolFieldToPOD(const PiercedStorage<bool> & field, const VolumeKernel * mesh, const std::unordered_set<long> * targetCells, PiercedStorage<bool> & mappedField) = 0;
117
118 virtual std::unordered_set<long> mapCellsToPOD(const std::unordered_set<long> * cells) = 0;
119
120 virtual void adaptMeshToMesh(const VolumeKernel * meshToAdapt, const VolumeKernel * meshReference) = 0;
121
122#if BITPIT_ENABLE_MPI
123 void initializeCommunicator(MPI_Comm communicator);
124 void freeCommunicator();
125#endif
126
127};
128
129}
130
131#endif
The PODKernel class provides an interface to manage the mesh dependent members and functions of a POD...
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)
PODKernel(PODKernel &&other)=default
The POD (Proper Orthogonal Decomposition) class provides an interface for defining POD object.
Definition pod.hpp:41
Metafunction for generating a pierced storage.
The base class to be used to derive VTK streamers form.
Definition VTK.hpp:209
The VolumeKernel class provides an interface for defining volume patches.
The VolumeMapper is the class to map two meshes.
The PODfield structure is used to store the fields inside POD classes.
The SnapFile structure is used to store the file names inside POD classes.
--- layout: doxygen_footer ---