Arcane  v3.14.11.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
case1c.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7void case1c()
8{
9 IAlgebraicMng *alg_mng = createAlgebraicMng(m_parallel_mng);
10
11 // Not the perfect way to create space
12 IndexedSpace space = alg_mng->createSpace("Nom",
13 index_manager->global_size());
14
15 Vector v_b(space);
16 Vector v_x(space);
17 Matrix m_a(space,space);
18
19 // Fill matrix m_a
20 {
21 // C: Try to use 2 parallelMng for filling-in.
22
23 IParallelMng* areaU_pm = m_parallel_mng->
24 createSubParallelMng(owners(areaU));
25 IParallelMng* areaU_pm = m_parallel_mng->
26 createSubParallelMng(owners(areaP));
27
28 MatrixEditor edit_aU(m_a, index_manager, areaU_pm);
29 MatrixEditor edit_aP(m_a, index_manager, areaP_pm);
30 // edit_a is a "copy (CoW ?)" of m_a data.
31 // m_a contents is thus always valid !
32 // C: areaU_pm is the parallel mng where edit_a is defined.
33
34 if (areaU_pm->commRank() >= 0) { // areaU is defined there.
35 ENUMERATE_CELL(icell, areaU.own()) {
36 edit_aU(icell,icell) = fij(icell, icell);
37 ENUMERATE_SUB_ITEM(Cell, isubcell, icell) {
38 edit_aU(icell, isubcell) += fij(icell, isubcell);
39 }
40 }
41 }
42 if (areaP_pm->commRank() >= 0) { // areaP is defined there.
43 ENUMERATE_NODE(inode, areaP.own()) {
44 ENUMERATE_SUB_ITEM(Cell, isubcell, inode) {
45 edit_aP(inode, isubcell) += fij(inode, isubcell);
46 }
47 }
48 }
49
50 // C: How to avoid inter-locking?
51 m_a.add_contrib(edit_aU);
52 m_a.add_contrib(edit_aP);
53 }
54
55 // Fill vector v_b
56 {
57 VectorEditor ve_b (v_b, index_manager);
58
59 ENUMERATE_CELL(icell, areaU.own()) {
60 ve_b(icell) = var_cell[icell];
61 }
62 ENUMERATE_NODE(inode, areaP.own()) {
63 ve_b(inode) = var_node[inode];
64 }
65 v_b.replace(ve_b);
66 }
67
68 Solver solver = solverMng->createSolver(alg_mng, options);
69 v_x = solver.solve(m_a, v_b);
70
71 if (!solver.failed()) {
72 Fatal("Unable to solve Ax=b");
73 }
74
75 // res is automatically in the good space.
76 Vector v_residual = v_b - m_a*v_x;
77
78 info() << "Residual norm_2 = " << norm2(v_residual);
79}
#define ENUMERATE_CELL(name, group)
Enumérateur générique d'un groupe de mailles.
#define ENUMERATE_SUB_ITEM(_item_type, _name, _parent_item)
Enumérateur sur sous-élément d'un ItemPairGroup.
#define ENUMERATE_NODE(name, group)
Enumérateur générique d'un groupe de noeuds.