2023-10-23 03:18:20 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University
|
|
|
|
Copyright Equnior ASA
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-05-26 11:42:51 -05:00
|
|
|
#ifndef Analysis_H_INC
|
|
|
|
#define Analysis_H_INC
|
2015-04-28 10:34:57 -05:00
|
|
|
|
|
|
|
#include "common/Array.h"
|
|
|
|
#include "common/Communication.h"
|
|
|
|
|
2015-07-16 21:08:43 -05:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-08-25 13:32:36 -05:00
|
|
|
// Define types to use for blob ids
|
|
|
|
typedef int32_t BlobIDType;
|
|
|
|
typedef Array<BlobIDType> BlobIDArray;
|
|
|
|
|
2015-04-28 10:34:57 -05:00
|
|
|
/*!
|
|
|
|
* @brief Compute the blob
|
|
|
|
* @details Compute the blob (F>vf|S>vs) starting from (i,j,k) - oil blob
|
|
|
|
* @return Returns the number of cubes in the blob
|
|
|
|
* @param[in] Phase Phase
|
|
|
|
* @param[in] SignDist SignDist
|
|
|
|
* @param[in] vF vF
|
|
|
|
* @param[in] vS vS
|
|
|
|
* @param[out] LocalBlobID The ids of the blobs
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] periodic Optional value
|
2015-04-28 10:34:57 -05:00
|
|
|
* @return Returns the number of blobs
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
int ComputeLocalBlobIDs(const DoubleArray &Phase, const DoubleArray &SignDist,
|
|
|
|
double vF, double vS, BlobIDArray &LocalBlobID,
|
|
|
|
bool periodic = true);
|
2015-04-28 10:34:57 -05:00
|
|
|
|
2015-07-11 21:24:43 -05:00
|
|
|
/*!
|
|
|
|
* @brief Compute blob of an arbitrary phase
|
|
|
|
* @details Compute the connected components for Phase(i,j,k)=VALUE
|
|
|
|
* @return the number of connected components of the phase
|
|
|
|
* @param[in] PhaseID
|
|
|
|
* @param[in] VALUE
|
|
|
|
* @param[out] ComponentLabel
|
|
|
|
* @param[in] periodic
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
int ComputeLocalPhaseComponent(const IntArray &PhaseID, int &VALUE,
|
|
|
|
IntArray &ComponentLabel, bool periodic);
|
2015-07-16 21:08:43 -05:00
|
|
|
|
2015-04-28 10:34:57 -05:00
|
|
|
/*!
|
|
|
|
* @brief Compute the blob
|
|
|
|
* @details Compute the blob (F>vf|S>vs) starting from (i,j,k) - oil blob
|
|
|
|
* @return Returns the number of cubes in the blob
|
|
|
|
* @param[in] nx Number of elements in the x-direction
|
|
|
|
* @param[in] ny Number of elements in the y-direction
|
|
|
|
* @param[in] nz Number of elements in the z-direction
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] rank_info MPI communication info
|
2015-04-28 10:34:57 -05:00
|
|
|
* @param[in] Phase Phase
|
|
|
|
* @param[in] SignDist SignDist
|
|
|
|
* @param[in] vF vF
|
|
|
|
* @param[in] vS vS
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[out] GlobalBlobID The ids of the blobs
|
|
|
|
* @param[in] comm MPI communicator
|
2015-04-28 10:34:57 -05:00
|
|
|
* @return Returns the number of blobs
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
int ComputeGlobalBlobIDs(int nx, int ny, int nz,
|
|
|
|
const RankInfoStruct &rank_info,
|
|
|
|
const DoubleArray &Phase, const DoubleArray &SignDist,
|
|
|
|
double vF, double vS, BlobIDArray &GlobalBlobID,
|
|
|
|
const Utilities::MPI &comm);
|
2015-07-16 21:08:43 -05:00
|
|
|
|
2015-07-13 07:18:03 -05:00
|
|
|
/*!
|
|
|
|
* @brief Compute component of the specified phase
|
|
|
|
* @details Compute component of specified phase PhaseID=VALUE
|
2015-07-16 21:08:43 -05:00
|
|
|
* @return Returns the number of cubes in the blob
|
2015-07-13 07:18:03 -05:00
|
|
|
* @param[in] nx Number of elements in the x-direction
|
|
|
|
* @param[in] ny Number of elements in the y-direction
|
|
|
|
* @param[in] nz Number of elements in the z-direction
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] rank_info MPI communication info
|
2015-07-13 07:18:03 -05:00
|
|
|
* @param[in] PhaseID Array that identifies the phases
|
|
|
|
* @param[in] VALUE Identifier for the phase to decompose
|
|
|
|
* @param[out] GlobalBlobID The ids of the blobs for the phase
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] comm The communicator to use
|
2015-07-13 07:18:03 -05:00
|
|
|
* @return Return the number of components in the specified phase
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
int ComputeGlobalPhaseComponent(int nx, int ny, int nz,
|
|
|
|
const RankInfoStruct &rank_info,
|
|
|
|
const IntArray &PhaseID, int &VALUE,
|
|
|
|
BlobIDArray &GlobalBlobID,
|
|
|
|
const Utilities::MPI &comm);
|
2015-07-16 21:08:43 -05:00
|
|
|
|
2015-04-28 10:34:57 -05:00
|
|
|
/*!
|
|
|
|
* @brief Reorder the blobs
|
|
|
|
* @details Reorder the blobs based on the number of cells they contain
|
|
|
|
* largest first.
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in,out] ID The ids of the blobs
|
|
|
|
* @param[in] comm MPI communicator
|
2015-04-28 10:34:57 -05:00
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
void ReorderBlobIDs(BlobIDArray &ID, const Utilities::MPI &comm);
|
2015-04-28 10:34:57 -05:00
|
|
|
|
2021-11-08 15:58:37 -06:00
|
|
|
typedef std::pair<BlobIDType, std::vector<BlobIDType>> BlobIDSplitStruct;
|
|
|
|
typedef std::pair<std::vector<BlobIDType>, BlobIDType> BlobIDMergeStruct;
|
|
|
|
typedef std::pair<std::vector<BlobIDType>, std::vector<BlobIDType>>
|
|
|
|
BlobIDMergeSplitStruct;
|
|
|
|
typedef std::pair<BlobIDType, BlobIDType> OverlapID;
|
2015-07-16 21:08:43 -05:00
|
|
|
struct ID_map_struct {
|
2021-11-08 15:58:37 -06:00
|
|
|
std::vector<BlobIDType> created; // list of new blobs that were created
|
|
|
|
std::vector<BlobIDType> destroyed; // list of blobs that disappeared
|
|
|
|
std::vector<std::pair<BlobIDType, BlobIDType>>
|
|
|
|
src_dst; // one-one mapping of blobs (first,second timestep id)
|
|
|
|
std::vector<BlobIDSplitStruct> split; // list of blobs that split
|
|
|
|
std::vector<BlobIDMergeStruct> merge; // list of blobs that merged
|
|
|
|
std::vector<BlobIDMergeSplitStruct>
|
|
|
|
merge_split; // list of blobs that both merged and split
|
|
|
|
std::map<OverlapID, int64_t>
|
|
|
|
overlap; // for ids that are not a 1-1 mapping, this is a list of the overlaps <src,dst>
|
2015-08-25 13:32:36 -05:00
|
|
|
//! Empty constructor
|
|
|
|
ID_map_struct() {}
|
|
|
|
//! Create initial map from N blobs (ordered 1:N-1)
|
2021-11-08 15:58:37 -06:00
|
|
|
ID_map_struct(int N) {
|
2015-08-25 13:32:36 -05:00
|
|
|
created.resize(N);
|
2021-11-08 15:58:37 -06:00
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
created[i] = i;
|
|
|
|
}
|
2015-08-25 13:32:36 -05:00
|
|
|
}
|
2015-07-16 21:08:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Get the mapping of blob ids between iterations
|
|
|
|
* @details This functions computes the map of blob ids between iterations
|
|
|
|
* @return Returns the map of the blob ids. Each final blob may have no source
|
|
|
|
* ids, one parent, or multiple parents. Each src id may be a parent for multiple blobs.
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] nx Number of elements in the x-direction
|
|
|
|
* @param[in] ny Number of elements in the y-direction
|
|
|
|
* @param[in] nz Number of elements in the z-direction
|
2015-07-16 21:08:43 -05:00
|
|
|
* @param[in] ID1 The blob ids at the first timestep
|
|
|
|
* @param[in] ID2 The blob ids at the second timestep
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in] comm The communicator to use
|
2015-07-16 21:08:43 -05:00
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
ID_map_struct computeIDMap(int nx, int ny, int nz, const BlobIDArray &ID1,
|
|
|
|
const BlobIDArray &ID2, const Utilities::MPI &comm);
|
2015-08-25 13:32:36 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Compute the new global ids based on the map
|
|
|
|
* @details This functions computes the time-consistent global ids for the
|
|
|
|
* current global id index
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in,out] map The timestep mapping for the ids
|
2015-08-25 13:32:36 -05:00
|
|
|
* @param[in] id_max The globally largest id used previously
|
|
|
|
* @param[out] new_ids The newly renumbered blob ids (0:ids.max())
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
void getNewIDs(ID_map_struct &map, BlobIDType &id_max,
|
|
|
|
std::vector<BlobIDType> &new_ids);
|
2015-08-25 13:32:36 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Update the blob ids based on mapping
|
|
|
|
* @details This functions computes the map of blob ids between iterations.
|
|
|
|
* Note: we also update the map to reflect the new ids
|
|
|
|
* @param[out] new_ids The newly renumbered blob ids (0:ids.max())
|
2021-09-13 10:51:21 -05:00
|
|
|
* @param[in,out] IDs The blob ids to renumber
|
2015-08-25 13:32:36 -05:00
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
void renumberIDs(const std::vector<BlobIDType> &new_ids, BlobIDArray &IDs);
|
2015-08-25 13:32:36 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Write the ID map
|
|
|
|
* @details This functions writes the id map fo an iteration.
|
|
|
|
* If no ids changed, then nothing will be written
|
|
|
|
* Note: only rank 0 writes, and the file is created on timestep 0.
|
|
|
|
* @param[in] map The timestep mapping for the ids
|
|
|
|
* @param[in] timestep The current timestep (timestep 0 creates the file)
|
|
|
|
* @param[in] filename The filename to write/append
|
|
|
|
*/
|
2021-11-08 15:58:37 -06:00
|
|
|
void writeIDMap(const ID_map_struct &map, long long int timestep,
|
|
|
|
const std::string &filename);
|
2015-04-28 10:34:57 -05:00
|
|
|
|
|
|
|
#endif
|