1
1
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2
2
// -----------------------------------------------------------------------------
3
- // Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3
+ // Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4
4
// See the top-level COPYRIGHT file for details.
5
5
// SPDX-License-Identifier: Apache-2.0
6
6
// -----------------------------------------------------------------------------
7
7
/* ---------------------------------------------------------------------------*/
8
- /* RunCommandMaterialEnumerate.h (C) 2000-2023 */
8
+ /* RunCommandMaterialEnumerate.h (C) 2000-2024 */
9
9
/* */
10
10
/* Helpers et macros pour exécuter une boucle sur une liste d'envcell */
11
11
/* ---------------------------------------------------------------------------*/
@@ -150,6 +150,71 @@ class EnvCellRunCommand
150
150
Container m_items;
151
151
};
152
152
153
+ /* ---------------------------------------------------------------------------*/
154
+ /* ---------------------------------------------------------------------------*/
155
+ /* !
156
+ * \brief Commande pour itérer sur les MatCell.
157
+ */
158
+ class MatCellRunCommand
159
+ {
160
+ public:
161
+
162
+ using MatCellVectorView = Arcane::Materials::MatCellVectorView;
163
+ using ComponentItemVectorView = Arcane::Materials::ComponentItemVectorView;
164
+ using IMeshMaterial = Arcane::Materials::IMeshMaterial;
165
+ using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
166
+ using MatVarIndex = Arcane::Materials::MatVarIndex;
167
+
168
+ public:
169
+
170
+ /* !
171
+ * \brief Conteneur contenant les informations nécessaires pour la commande.
172
+ */
173
+ class Container
174
+ : public impl::MatCommandContainerBase
175
+ {
176
+ public:
177
+
178
+ explicit Container (IMeshMaterial* mat)
179
+ : impl::MatCommandContainerBase(mat->matView ())
180
+ {
181
+ }
182
+ explicit Container (MatCellVectorView view)
183
+ : impl::MatCommandContainerBase(view)
184
+ {
185
+ }
186
+
187
+ public:
188
+
189
+ MatCellRunCommand createCommand (RunCommand& run_command) const
190
+ {
191
+ return MatCellRunCommand (run_command, *this );
192
+ }
193
+
194
+ public:
195
+
196
+ // ! Accesseur pour le i-ème élément de la liste
197
+ constexpr ARCCORE_HOST_DEVICE ComponentItemLocalId operator [](Int32 i) const
198
+ {
199
+ return { ComponentItemLocalId (m_matvar_indexes[i]) };
200
+ }
201
+ };
202
+
203
+ private:
204
+
205
+ // Uniquement appelable depuis 'Container'
206
+ explicit MatCellRunCommand (RunCommand& command, const Container& items)
207
+ : m_command(command)
208
+ , m_items(items)
209
+ {
210
+ }
211
+
212
+ public:
213
+
214
+ RunCommand& m_command;
215
+ Container m_items;
216
+ };
217
+
153
218
/* ---------------------------------------------------------------------------*/
154
219
/* ---------------------------------------------------------------------------*/
155
220
/* !
@@ -268,6 +333,124 @@ class EnvAndGlobalCellRunCommand
268
333
Container m_items;
269
334
};
270
335
336
+ /* ---------------------------------------------------------------------------*/
337
+ /* ---------------------------------------------------------------------------*/
338
+ /* !
339
+ * \brief Commande pour itérer sur les MatCell et récupérer aussi l'information
340
+ * sur la maille globale associée.
341
+ */
342
+ class MatAndGlobalCellRunCommand
343
+ {
344
+ public:
345
+
346
+ using MatCellVectorView = Arcane::Materials::MatCellVectorView;
347
+ using ComponentItemVectorView = Arcane::Materials::ComponentItemVectorView;
348
+ using IMeshMaterial = Arcane::Materials::IMeshMaterial;
349
+ using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
350
+ using MatVarIndex = Arcane::Materials::MatVarIndex;
351
+
352
+ public:
353
+
354
+ /* !
355
+ * \brief Classe helper pour l'accès au MatVarIndex et au CellLocalId à travers les
356
+ * RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell...
357
+ */
358
+ class Accessor
359
+ {
360
+
361
+ public:
362
+
363
+ // ! Struct interne simple pour éviter l'usage d'un std::tuple pour l'opérateur()
364
+ struct Data
365
+ {
366
+ ComponentItemLocalId m_mvi;
367
+ CellLocalId m_cid;
368
+ };
369
+
370
+ public:
371
+
372
+ constexpr ARCCORE_HOST_DEVICE Accessor (ComponentItemLocalId mvi, CellLocalId cid)
373
+ : m_internal_data{ mvi, cid }
374
+ {
375
+ }
376
+
377
+ /* !
378
+ * \brief Cet opérateur permet de renvoyer le couple [MatVarIndex, LocalCellId].
379
+ *
380
+ * L'utilisation classique est :
381
+ *
382
+ * \code
383
+ * cmd << RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell, evi, envcellsv) {
384
+ * auto [mvi, cid] = evi();
385
+ * }
386
+ * \endcode
387
+ *
388
+ * où evi est le type de cette classe
389
+ */
390
+ ARCCORE_HOST_DEVICE Data operator ()()
391
+ {
392
+ return { m_internal_data.m_mvi , m_internal_data.m_cid };
393
+ }
394
+
395
+ // /! Accesseur sur la partie MatVarIndex
396
+ ARCCORE_HOST_DEVICE ComponentItemLocalId varIndex () { return m_internal_data.m_mvi ; };
397
+
398
+ // /! Accesseur sur la partie cell local id
399
+ ARCCORE_HOST_DEVICE CellLocalId globalCellId () { return m_internal_data.m_cid ; }
400
+
401
+ private:
402
+
403
+ Data m_internal_data;
404
+ };
405
+
406
+ /* !
407
+ * \brief Conteneur contenant les informations nécessaires pour la commande.
408
+ */
409
+ class Container
410
+ : public impl::MatCommandContainerBase
411
+ {
412
+ public:
413
+
414
+ explicit Container (IMeshMaterial* env)
415
+ : impl::MatCommandContainerBase(env->matView ())
416
+ {
417
+ }
418
+ explicit Container (MatCellVectorView view)
419
+ : impl::MatCommandContainerBase(view)
420
+ {
421
+ }
422
+
423
+ public:
424
+
425
+ MatAndGlobalCellRunCommand createCommand (RunCommand& run_command) const
426
+ {
427
+ return MatAndGlobalCellRunCommand (run_command, *this );
428
+ }
429
+
430
+ public:
431
+
432
+ // ! Accesseur pour le i-ème élément de la liste
433
+ constexpr ARCCORE_HOST_DEVICE Accessor operator [](Int32 i) const
434
+ {
435
+ return { ComponentItemLocalId (m_matvar_indexes[i]), CellLocalId (m_global_cells_local_id[i]) };
436
+ }
437
+ };
438
+
439
+ private:
440
+
441
+ // Uniquement appelable depuis 'Container'
442
+ explicit MatAndGlobalCellRunCommand (RunCommand& command, const Container& items)
443
+ : m_command(command)
444
+ , m_items(items)
445
+ {
446
+ }
447
+
448
+ public:
449
+
450
+ RunCommand& m_command;
451
+ Container m_items;
452
+ };
453
+
271
454
/* ---------------------------------------------------------------------------*/
272
455
/* ---------------------------------------------------------------------------*/
273
456
@@ -295,6 +478,30 @@ class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::EnvAndGlobalCell>
295
478
/* ---------------------------------------------------------------------------*/
296
479
/* ---------------------------------------------------------------------------*/
297
480
481
+ // ! Spécialisation pour une vue sur un matériau et la maille globale associée
482
+ template <>
483
+ class RunCommandMatItemEnumeratorTraitsT <Arcane::Materials::MatAndGlobalCell>
484
+ {
485
+ public:
486
+
487
+ using EnumeratorType = MatAndGlobalCellRunCommand::Accessor;
488
+ using ContainerType = MatAndGlobalCellRunCommand::Container;
489
+
490
+ public:
491
+
492
+ static ContainerType createContainer (const Arcane::Materials::MatCellVectorView& items)
493
+ {
494
+ return ContainerType{ items };
495
+ }
496
+ static ContainerType createContainer (Arcane::Materials::IMeshMaterial* env)
497
+ {
498
+ return ContainerType{ env };
499
+ }
500
+ };
501
+
502
+ /* ---------------------------------------------------------------------------*/
503
+ /* ---------------------------------------------------------------------------*/
504
+
298
505
// ! Spécialisation pour une vue sur un milieu.
299
506
template <>
300
507
class RunCommandMatItemEnumeratorTraitsT <Arcane::Materials::EnvCell>
@@ -319,6 +526,30 @@ class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::EnvCell>
319
526
/* ---------------------------------------------------------------------------*/
320
527
/* ---------------------------------------------------------------------------*/
321
528
529
+ // ! Spécialisation pour une vue sur un matériau
530
+ template <>
531
+ class RunCommandMatItemEnumeratorTraitsT <Arcane::Materials::MatCell>
532
+ {
533
+ public:
534
+
535
+ using EnumeratorType = Arcane::Materials::ComponentItemLocalId;
536
+ using ContainerType = MatCellRunCommand::Container;
537
+
538
+ public:
539
+
540
+ static ContainerType createContainer (const Arcane::Materials::MatCellVectorView& items)
541
+ {
542
+ return ContainerType{ items };
543
+ }
544
+ static ContainerType createContainer (Arcane::Materials::IMeshMaterial* mat)
545
+ {
546
+ return ContainerType{ mat };
547
+ }
548
+ };
549
+
550
+ /* ---------------------------------------------------------------------------*/
551
+ /* ---------------------------------------------------------------------------*/
552
+
322
553
} // namespace Arcane::Accelerator
323
554
324
555
/* ---------------------------------------------------------------------------*/
@@ -351,9 +582,13 @@ doMatContainerGPULambda(ContainerType items, Lambda func)
351
582
/* ---------------------------------------------------------------------------*/
352
583
/* ---------------------------------------------------------------------------*/
353
584
/* !
354
- * \brief Applique l'enumération \a func sur la liste d'entité \a items.
585
+ * \brief Applique l'énumération \a func sur la liste d'entité \a items.
355
586
*
356
- * Le container peut être issu de EnvAndGlobalCellRunCommand ou 'EnvCellRunCommand.
587
+ * Le conteneur peut être issu de:
588
+ * - EnvAndGlobalCellRunCommand
589
+ * - EnvCellRunCommand
590
+ * - MatAndGlobalCellRunCommand
591
+ * - MatCellRunCommand
357
592
*/
358
593
template <typename ContainerType, typename Lambda> void
359
594
_applyEnvCells (RunCommand& command, ContainerType items, const Lambda& func)
@@ -406,6 +641,21 @@ namespace Arcane::Accelerator
406
641
/* ---------------------------------------------------------------------------*/
407
642
/* ---------------------------------------------------------------------------*/
408
643
644
+ inline MatAndGlobalCellRunCommand
645
+ operator <<(RunCommand& command, const MatAndGlobalCellRunCommand::Container& view)
646
+ {
647
+ return view.createCommand (command);
648
+ }
649
+
650
+ template <typename Lambda>
651
+ void operator <<(MatAndGlobalCellRunCommand&& nr, const Lambda& func)
652
+ {
653
+ impl::_applyEnvCells (nr.m_command , nr.m_items , func);
654
+ }
655
+
656
+ /* ---------------------------------------------------------------------------*/
657
+ /* ---------------------------------------------------------------------------*/
658
+
409
659
inline EnvAndGlobalCellRunCommand
410
660
operator <<(RunCommand& command, const EnvAndGlobalCellRunCommand::Container& view)
411
661
{
@@ -436,6 +686,21 @@ void operator<<(EnvCellRunCommand&& nr, const Lambda& func)
436
686
/* ---------------------------------------------------------------------------*/
437
687
/* ---------------------------------------------------------------------------*/
438
688
689
+ inline MatCellRunCommand
690
+ operator <<(RunCommand& command, const MatCellRunCommand::Container& view)
691
+ {
692
+ return view.createCommand (command);
693
+ }
694
+
695
+ template <typename Lambda>
696
+ void operator <<(MatCellRunCommand&& nr, const Lambda& func)
697
+ {
698
+ impl::_applyEnvCells (nr.m_command , nr.m_items , func);
699
+ }
700
+
701
+ /* ---------------------------------------------------------------------------*/
702
+ /* ---------------------------------------------------------------------------*/
703
+
439
704
} // End namespace Arcane::Accelerator
440
705
441
706
/* ---------------------------------------------------------------------------*/
0 commit comments