14#include "arcane/cartesianmesh/internal/AMRPatchPositionSignatureCut.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/Math.h"
19#include "arcane/core/IMesh.h"
21#include "arcane/cartesianmesh/ICartesianMesh.h"
23#include "arcane/cartesianmesh/internal/AMRPatchPositionSignature.h"
39AMRPatchPositionSignatureCut::
40AMRPatchPositionSignatureCut() =
default;
45AMRPatchPositionSignatureCut::
46~AMRPatchPositionSignatureCut() =
default;
55 if (sig.
size() < MIN_SIZE * 2) {
75 ARCANE_FATAL(
"Call AMRPatchPositionSignature::compress() before");
77 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.
size() - cut_point >= MIN_SIZE) {
90 dsec_sig[i] = sig[i + 1] - 2 * sig[i] + sig[i - 1];
91 CartCoord dif = math::abs(dsec_sig[i - 1] - dsec_sig[i]);
96 else if (dif == max && math::abs(cut_point - mid) > math::abs(i - mid)) {
101 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.
size() - cut_point >= MIN_SIZE) {
111 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.
size() - cut_point >= MIN_SIZE) {
131 if (cut_point_x == -1 && cut_point_y == -1 && cut_point_z == -1) {
136 if (cut_point_x != -1) {
139 if (cut_point_y != -1) {
142 if (cut_point_z != -1) {
147 if (cut_point_x != -1 && cut_point_y != -1 && cut_point_z != -1) {
154 Real x_efficacity = 0;
155 auto [fst_x, snd_x] = sig.
cut(
MD_DirX, cut_point_x);
161 if (fst_x.isValid() && snd_x.isValid()) {
172 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
180 Real y_efficacity = 0;
181 auto [fst_y, snd_y] = sig.
cut(
MD_DirY, cut_point_y);
187 if (fst_y.isValid() && snd_y.isValid()) {
198 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
206 Real z_efficacity = 0;
207 auto [fst_z, snd_z] = sig.
cut(
MD_DirZ, cut_point_z);
213 if (fst_z.isValid() && snd_z.isValid()) {
224 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
235 if (sig_efficacity > x_efficacity && sig_efficacity > y_efficacity && sig_efficacity > z_efficacity) {
241 if (x_efficacity >= y_efficacity && x_efficacity >= z_efficacity && x_efficacity != 0) {
242 return { fst_x, snd_x };
244 if (y_efficacity >= x_efficacity && y_efficacity >= z_efficacity && y_efficacity != 0) {
245 return { fst_y, snd_y };
247 if (z_efficacity == 0) {
250 return { fst_z, snd_z };
254 if (cut_point_x != -1 && cut_point_y != -1) {
255 Real x_efficacity = 0;
256 auto [fst_x, snd_x] = sig.
cut(
MD_DirX, cut_point_x);
262 if (fst_x.isValid() && snd_x.isValid()) {
273 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
281 Real y_efficacity = 0;
282 auto [fst_y, snd_y] = sig.
cut(
MD_DirY, cut_point_y);
288 if (fst_y.isValid() && snd_y.isValid()) {
299 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
308 if (sig_efficacity > x_efficacity && sig_efficacity > y_efficacity) {
313 if (x_efficacity >= y_efficacity && x_efficacity != 0) {
314 return { fst_x, snd_x };
316 if (y_efficacity == 0) {
319 return { fst_y, snd_y };
322 if (cut_point_x != -1) {
323 Real x_efficacity = 0;
324 auto [fst_x, snd_x] = sig.
cut(
MD_DirX, cut_point_x);
330 if (fst_x.isValid() && snd_x.isValid()) {
334 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
343 return { fst_x, snd_x };
346 if (cut_point_y != -1) {
347 Real y_efficacity = 0;
348 auto [fst_y, snd_y] = sig.
cut(
MD_DirY, cut_point_y);
354 if (fst_y.isValid() && snd_y.isValid()) {
358 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
367 return { fst_y, snd_y };
369 if (cut_point_z != -1) {
370 Real z_efficacity = 0;
371 auto [fst_z, snd_z] = sig.
cut(
MD_DirZ, cut_point_z);
377 if (fst_z.isValid() && snd_z.isValid()) {
381 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
390 return { fst_z, snd_z };
400 bool a_a_b_b =
false;
403 bool need_cut =
true;
411 for (
auto& sig : array_in) {
415 if (!sig.stopCut()) {
416 if (!sig.isComputed()) {
419 if (sig.canBeCut()) {
420 auto [fst, snd] =
cut(sig);
434 sig.setStopCut(
true);
439 sig.setStopCut(
true);
455 sig_array_a = sig_array_b;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
static CartCoord _cutDim(ConstArrayView< CartCoord > sig)
Method allowing searching for the best point to perform a cut.
static std::pair< AMRPatchPositionSignature, AMRPatchPositionSignature > cut(const AMRPatchPositionSignature &sig)
Method allowing a patch to be cut into two.
Class for managing patch signatures.
ConstArrayView< CartCoord > sigX() const
Method for retrieving the X signature.
ConstArrayView< CartCoord > sigZ() const
Method for retrieving the Z signature.
Real efficacity() const
Method to determine the patch's efficiency.
std::pair< AMRPatchPositionSignature, AMRPatchPositionSignature > cut(Integer dim, CartCoord cut_point) const
Method for cutting the patch. The patch is not modified.
AMRPatchPosition patch() const
Method for retrieving a copy of the patch.
ConstArrayView< CartCoord > sigY() const
Method for retrieving the Y signature.
CartCoord3 minPoint() const
Method to retrieve the min position of the enclosing box.
Integer size() const
Number of elements in the vector.
void clear()
Removes the elements from the array.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 CartCoord
Represents a coordinate of an element in the Cartesian grid (in X or Y or Z).
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.