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()
50AMRPatchPositionSignatureCut::
51~AMRPatchPositionSignatureCut() =
default;
56CartCoordType AMRPatchPositionSignatureCut::
59 if (sig.size() < MIN_SIZE * 2) {
63 CartCoordType cut_point = -1;
64 CartCoordType mid = sig.size() / 2;
67 for (CartCoordType i = 0; i < sig.size(); ++i) {
77 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
83 UniqueArray<CartCoordType> dsec_sig(sig.size(), 0);
85 CartCoordType
max = -1;
86 for (CartCoordType i = 1; i < dsec_sig.size() - 1; ++i) {
87 dsec_sig[i] = sig[i + 1] - 2 * sig[i] + sig[i - 1];
88 CartCoordType dif = math::abs(dsec_sig[i - 1] - dsec_sig[i]);
93 else if (dif == max && math::abs(cut_point - mid) > math::abs(i - mid)) {
98 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
106 if (cut_point != -1 && cut_point >= MIN_SIZE && sig.size() - cut_point >= MIN_SIZE) {
117std::pair<AMRPatchPositionSignature, AMRPatchPositionSignature> AMRPatchPositionSignatureCut::
120 CartCoordType cut_point_x = _cutDim(sig.sigX());
121 CartCoordType cut_point_y = _cutDim(sig.sigY());
122 CartCoordType cut_point_z = (sig.mesh()->mesh()->dimension() == 2 ? -1 : _cutDim(sig.sigZ()));
124 if (cut_point_x == -1 && cut_point_y == -1 && cut_point_z == -1) {
127 if (cut_point_x != -1) {
128 cut_point_x += sig.patch().minPoint().x;
130 if (cut_point_y != -1) {
131 cut_point_y += sig.patch().minPoint().y;
133 if (cut_point_z != -1) {
134 cut_point_z += sig.patch().minPoint().z;
137 if (cut_point_x != -1 && cut_point_y != -1 && cut_point_z != -1) {
138 Real x_efficacity = 0;
139 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
145 if (fst_x.isValid() && snd_x.isValid()) {
156 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
164 Real y_efficacity = 0;
165 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
171 if (fst_y.isValid() && snd_y.isValid()) {
182 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
190 Real z_efficacity = 0;
191 auto [fst_z, snd_z] = sig.cut(
MD_DirZ, cut_point_z);
197 if (fst_z.isValid() && snd_z.isValid()) {
208 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
216 if (sig.efficacity() > x_efficacity && sig.efficacity() > y_efficacity && sig.efficacity() > z_efficacity) {
220 if (x_efficacity >= y_efficacity && x_efficacity >= z_efficacity && x_efficacity != 0) {
221 return { fst_x, snd_x };
223 if (y_efficacity >= x_efficacity && y_efficacity >= z_efficacity && y_efficacity != 0) {
224 return { fst_y, snd_y };
226 if (z_efficacity == 0) {
229 return { fst_z, snd_z };
232 if (cut_point_x != -1 && cut_point_y != -1) {
233 Real x_efficacity = 0;
234 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
240 if (fst_x.isValid() && snd_x.isValid()) {
251 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
259 Real y_efficacity = 0;
260 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
266 if (fst_y.isValid() && snd_y.isValid()) {
277 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
285 if (sig.efficacity() > x_efficacity && sig.efficacity() > y_efficacity) {
289 if (x_efficacity >= y_efficacity && x_efficacity != 0) {
290 return { fst_x, snd_x };
292 if (y_efficacity == 0) {
295 return { fst_y, snd_y };
298 if (cut_point_x != -1) {
299 Real x_efficacity = 0;
300 auto [fst_x, snd_x] = sig.cut(
MD_DirX, cut_point_x);
306 if (fst_x.isValid() && snd_x.isValid()) {
310 x_efficacity = (fst_x.efficacity() + snd_x.efficacity()) / 2;
316 if (sig.efficacity() > x_efficacity) {
319 return { fst_x, snd_x };
322 if (cut_point_y != -1) {
323 Real y_efficacity = 0;
324 auto [fst_y, snd_y] = sig.cut(
MD_DirY, cut_point_y);
330 if (fst_y.isValid() && snd_y.isValid()) {
334 y_efficacity = (fst_y.efficacity() + snd_y.efficacity()) / 2;
340 if (sig.efficacity() > y_efficacity) {
343 return { fst_y, snd_y };
345 if (cut_point_z != -1) {
346 Real z_efficacity = 0;
347 auto [fst_z, snd_z] = sig.cut(
MD_DirZ, cut_point_z);
353 if (fst_z.isValid() && snd_z.isValid()) {
357 z_efficacity = (fst_z.efficacity() + snd_z.efficacity()) / 2;
363 if (sig.efficacity() > z_efficacity) {
366 return { fst_z, snd_z };
371void AMRPatchPositionSignatureCut::
374 UniqueArray<AMRPatchPositionSignature> sig_array_b;
375 bool a_a_b_b =
false;
376 bool need_cut =
true;
382 UniqueArray<AMRPatchPositionSignature>& array_in = a_a_b_b ? sig_array_a : sig_array_b;
383 UniqueArray<AMRPatchPositionSignature>& array_out = a_a_b_b ? sig_array_b : sig_array_a;
385 for (
Integer i = 0; i < array_in.size(); ++i) {
386 AMRPatchPositionSignature& sig = array_in[i];
389 if (!sig.stopCut()) {
390 if (!sig.isComputed()) {
393 if (sig.canBeCut()) {
394 auto [fst, snd] = cut(sig);
407 sig.setStopCut(
true);
410 sig.setStopCut(
true);
421 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.