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"
34 constexpr Integer TARGET_SIZE = 8;
35 constexpr Real TARGET_SIZE_WEIGHT_IN_EFFICACITY = 1;
36 constexpr Integer MAX_NB_CUT = 6;
37 constexpr Real TARGET_EFFICACITY = 1.0;
43AMRPatchPositionSignatureCut::
44AMRPatchPositionSignatureCut()
51AMRPatchPositionSignatureCut::
52~AMRPatchPositionSignatureCut() =
default;
54Integer AMRPatchPositionSignatureCut::
57 if (sig.size() < MIN_SIZE * 2) {
65 for (
Integer i = 0; i < sig.size(); ++i) {
75 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
81 UniqueArray<Integer> dsec_sig(sig.size(), 0);
84 for (
Integer i = 1; i < dsec_sig.size() - 1; ++i) {
85 dsec_sig[i] = sig[i + 1] - 2 * sig[i] + sig[i - 1];
86 Integer dif = math::abs(dsec_sig[i - 1] - dsec_sig[i]);
91 else if (dif == max && math::abs(cut_point - mid) > math::abs(i - mid)) {
96 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
104 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
112std::pair<AMRPatchPositionSignature, AMRPatchPositionSignature> AMRPatchPositionSignatureCut::
115 Integer cut_point_x = _cutDim(sig.sigX());
116 Integer cut_point_y = _cutDim(sig.sigY());
117 Integer cut_point_z = (sig.mesh()->mesh()->dimension() == 2 ? -1 : _cutDim(sig.sigZ()));
119 if (cut_point_x == -1 && cut_point_y == -1 && cut_point_z == -1) {
122 if (cut_point_x != -1) {
123 cut_point_x += sig.patch().minPoint().x;
125 if (cut_point_y != -1) {
126 cut_point_y += sig.patch().minPoint().y;
128 if (cut_point_z != -1) {
129 cut_point_z += sig.patch().minPoint().z;
132 if (cut_point_x != -1 && cut_point_y != -1 && cut_point_z != -1) {
133 Real x_efficacity = 0;
134 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
140 if (fst_x.isValid() && snd_x.isValid()) {
151 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
159 Real y_efficacity = 0;
160 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
166 if (fst_y.isValid() && snd_y.isValid()) {
177 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
185 Real z_efficacity = 0;
186 auto [fst_z, snd_z] = sig.cut(
MD_DirZ, cut_point_z);
192 if (fst_z.isValid() && snd_z.isValid()) {
203 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
211 if (sig.efficacity() > x_efficacity && sig.efficacity() > y_efficacity && sig.efficacity() > z_efficacity) {
215 if (x_efficacity >= y_efficacity && x_efficacity >= z_efficacity && x_efficacity != 0) {
216 return { fst_x, snd_x };
218 if (y_efficacity >= x_efficacity && y_efficacity >= z_efficacity && y_efficacity != 0) {
219 return { fst_y, snd_y };
221 if (z_efficacity == 0) {
224 return { fst_z, snd_z };
227 if (cut_point_x != -1 && cut_point_y != -1) {
228 Real x_efficacity = 0;
229 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
235 if (fst_x.isValid() && snd_x.isValid()) {
246 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
254 Real y_efficacity = 0;
255 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
261 if (fst_y.isValid() && snd_y.isValid()) {
272 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
280 if (sig.efficacity() > x_efficacity && sig.efficacity() > y_efficacity) {
284 if (x_efficacity >= y_efficacity && x_efficacity != 0) {
285 return { fst_x, snd_x };
287 if (y_efficacity == 0) {
290 return { fst_y, snd_y };
293 if (cut_point_x != -1) {
294 Real x_efficacity = 0;
295 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
301 if (fst_x.isValid() && snd_x.isValid()) {
305 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
311 if (sig.efficacity() > x_efficacity) {
314 return { fst_x, snd_x };
317 if (cut_point_y != -1) {
318 Real y_efficacity = 0;
319 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
325 if (fst_y.isValid() && snd_y.isValid()) {
329 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
335 if (sig.efficacity() > y_efficacity) {
338 return { fst_y, snd_y };
340 if (cut_point_z != -1) {
341 Real z_efficacity = 0;
342 auto [fst_z, snd_z] = sig.cut(
MD_DirZ, cut_point_z);
348 if (fst_z.isValid() && snd_z.isValid()) {
352 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
358 if (sig.efficacity() > z_efficacity) {
361 return { fst_z, snd_z };
365void AMRPatchPositionSignatureCut::
368 UniqueArray<AMRPatchPositionSignature> sig_array_b;
369 bool a_a_b_b =
false;
370 bool need_cut =
true;
376 UniqueArray<AMRPatchPositionSignature>& array_in = a_a_b_b ? sig_array_a : sig_array_b;
377 UniqueArray<AMRPatchPositionSignature>& array_out = a_a_b_b ? sig_array_b : sig_array_a;
379 for (
Integer i = 0; i < array_in.size(); ++i) {
380 AMRPatchPositionSignature sig = array_in[i];
383 if (!sig.stopCut()) {
384 if (!sig.isComputed()) {
387 if (sig.canBeCut()) {
388 auto [fst, snd] = cut(sig);
401 sig.setStopCut(
true);
404 sig.setStopCut(
true);
415 sig_array_a = sig_array_b;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue constante d'un tableau de type T.
Vecteur 1D de données avec sémantique par valeur (style STL).
T max(const T &a, const T &b, const T &c)
Retourne le maximum de trois éléments.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.