Loading...
Searching...
No Matches
volume_mapper.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
27#include "volume_mapper.hpp"
28
29namespace bitpit {
30
69#if BITPIT_ENABLE_MPI
73VolumeMapper::VolumeMapper(const VolumeKernel *referencePatch, const VolumeKernel *mappedPatch, MPI_Comm communicator)
74#else
75VolumeMapper::VolumeMapper(const VolumeKernel *referencePatch, const VolumeKernel *mappedPatch)
76#endif
77 : m_referencePatch(referencePatch), m_mappedPatch(mappedPatch), m_mapping(1)
78#if BITPIT_ENABLE_MPI
79 , m_communicator(MPI_COMM_NULL)
80#endif
81{
82#if BITPIT_ENABLE_MPI
83 initializeCommunicator(communicator);
84#endif
85}
86
95
100{
101 if (!m_mapping.getKernel()) {
102 return;
103 }
104
105 m_mapping.unsetKernel(true);
106}
107
112{
113 if (!m_inverseMapping.getKernel()) {
114 return;
115 }
116
117 m_inverseMapping.unsetKernel(false);
118}
119
129
139
147
155
165void VolumeMapper::initialize(bool fillInverse)
166{
167 clear();
168
169 _mapMeshes(fillInverse);
170}
171
172#if BITPIT_ENABLE_MPI
178void VolumeMapper::initializeCommunicator(MPI_Comm communicator)
179{
180 // Communication can be set just once
181 if (isCommunicatorSet()) {
182 throw std::runtime_error ("VolumeMapper communicator can be set just once");
183 }
184
185 // The communicator has to be valid
186 if (communicator == MPI_COMM_NULL) {
187 throw std::runtime_error ("VolumeMapper communicator is not valid");
188 }
189
190 // Create a copy of the user-specified communicator
191 //
192 // No library routine should use MPI_COMM_WORLD as the communicator;
193 // instead, a duplicate of a user-specified communicator should always
194 // be used.
195 MPI_Comm_dup(communicator, &m_communicator);
196
197 // Initialize parallel information
198 MPI_Comm_size(m_communicator, &m_nProcs);
199 MPI_Comm_rank(m_communicator, &m_rank);
200}
201
208{
209 return m_communicator;
210}
211
219{
220 return (getCommunicator() != MPI_COMM_NULL);
221}
222
227{
228 if (!isCommunicatorSet()) {
229 return;
230 }
231
232 int finalizedCalled;
233 MPI_Finalized(&finalizedCalled);
234 if (finalizedCalled) {
235 return;
236 }
237
238 MPI_Comm_free(&m_communicator);
239}
240#endif
241
242}
Metafunction for generating a pierced storage.
The VolumeKernel class provides an interface for defining volume patches.
VolumeMapper(const VolumeKernel *referencePatch, const VolumeKernel *mappedPatch, MPI_Comm communicator)
const VolumeKernel * getMappedPatch() const
MPI_Comm getCommunicator() const
const VolumeKernel * m_mappedPatch
void initialize(bool fillInv=false)
void initializeCommunicator(MPI_Comm communicator)
PiercedStorage< mapping::Info > m_inverseMapping
PiercedStorage< mapping::Info > m_mapping
const bitpit::PiercedStorage< mapping::Info > & getInverseMapping() const
const bitpit::PiercedStorage< mapping::Info > & getMapping() const
const VolumeKernel * getReferencePatch() const
const VolumeKernel * m_referencePatch
bool isCommunicatorSet() const
--- layout: doxygen_footer ---