|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "FoamPostprocessorBCBase.h" |
| 4 | +#include <UPstream.H> |
| 5 | + |
| 6 | +class FoamMappedInletBCBase : public FoamPostprocessorBCBase |
| 7 | +{ |
| 8 | +public: |
| 9 | + static InputParameters validParams(); |
| 10 | + |
| 11 | + FoamMappedInletBCBase(const InputParameters & params); |
| 12 | + |
| 13 | + virtual ~FoamMappedInletBCBase() { destroyCommunicator(_foam_comm); } |
| 14 | + |
| 15 | +protected: |
| 16 | + Foam::vector _offset; |
| 17 | + |
| 18 | + std::map<int, std::vector<int>> _send_map; |
| 19 | + |
| 20 | + std::map<int, std::vector<int>> _recv_map; |
| 21 | + |
| 22 | + Foam::label _foam_comm; |
| 23 | + |
| 24 | + MPI_Comm _mpi_comm; |
| 25 | + |
| 26 | + // create send and receive information for mapping |
| 27 | + void createPatchProcMap(); |
| 28 | + |
| 29 | + // get array from mapped plane on the inlet processes |
| 30 | + template <typename T> |
| 31 | + Foam::Field<T> getMappedArray(const Foam::word & name); |
| 32 | + |
| 33 | + // check if bounding box intersects with rank |
| 34 | + bool intersectMapPlane(const Foam::fvMesh & mesh, Real cart_bbox[6]); |
| 35 | + |
| 36 | + // create/assign communicators for the transfers between map and inlet planes |
| 37 | + void createMapComm(const Foam::fvMesh & mesh, |
| 38 | + Foam::vectorField face_centres, |
| 39 | + std::vector<int> & send_process, |
| 40 | + std::vector<int> & recv_process); |
| 41 | + |
| 42 | + // find index of cell containing point or raise error if not found |
| 43 | + int findIndex(const Foam::point & location, const MPI_Comm & comm); |
| 44 | + |
| 45 | + // handle creation of new communicators in parallel or serial |
| 46 | + Foam::label |
| 47 | + createCommunicator(const Foam::label parent_comm, std::vector<int> procs, MPI_Comm & new_comm) |
| 48 | + { |
| 49 | + Foam::label foam_comm; |
| 50 | + if (Foam::UPstream::parRun()) |
| 51 | + { |
| 52 | + Foam::labelList foam_procs(procs.begin(), procs.end()); |
| 53 | + foam_comm = Foam::UPstream::allocateCommunicator(parent_comm, foam_procs, true); |
| 54 | + new_comm = Foam::PstreamGlobals::MPICommunicators_[foam_comm]; |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + foam_comm = Foam::UPstream::worldComm; |
| 59 | + new_comm = MPI_COMM_WORLD; |
| 60 | + } |
| 61 | + return foam_comm; |
| 62 | + } |
| 63 | + |
| 64 | + // free communicators if parallel run |
| 65 | + void destroyCommunicator(Foam::label comm) |
| 66 | + { |
| 67 | + if (Foam::UPstream::parRun()) |
| 68 | + Foam::UPstream::freeCommunicator(comm); |
| 69 | + } |
| 70 | +}; |
0 commit comments