Skip to content

Commit

Permalink
Merge pull request #912 from arcaneframework/dev/gg-begin-cartesianme…
Browse files Browse the repository at this point in the history
…sh-coarsening

Begin development for coarsening of cartesian mesh
  • Loading branch information
grospelliergilles authored Oct 5, 2023
2 parents d7fd724 + 6e90b20 commit 5f9a489
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 6 deletions.
15 changes: 14 additions & 1 deletion arcane/ceapart/src/arcane/cartesianmesh/CartesianMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "arcane/cartesianmesh/ICartesianMesh.h"
#include "arcane/cartesianmesh/CartesianConnectivity.h"
#include "arcane/cartesianmesh/CartesianMeshRenumberingInfo.h"
#include "arcane/cartesianmesh/CartesianMeshCoarsening.h"
#include "arcane/cartesianmesh/internal/CartesianMeshPatch.h"

#include "arcane/cartesianmesh/internal/CartesianMeshUniqueIdRenumbering.h"
Expand Down Expand Up @@ -128,7 +129,9 @@ class CartesianMeshImpl

void checkValid() const override;

private:
Ref<CartesianMeshCoarsening> createCartesianMeshCoarsening() override;

private:

//! Indice dans la numérotation locale de la maille, de la face dans
// la direction X, Y ou Z
Expand Down Expand Up @@ -697,6 +700,16 @@ renumberItemsUniqueId(const CartesianMeshRenumberingInfo& v)
}
}


/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Ref<CartesianMeshCoarsening> CartesianMeshImpl::
createCartesianMeshCoarsening()
{
return makeRef(new CartesianMeshCoarsening(this));
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Expand Down
77 changes: 77 additions & 0 deletions arcane/ceapart/src/arcane/cartesianmesh/CartesianMeshCoarsening.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CartesianMeshCoarsening.cc (C) 2000-2023 */
/* */
/* Déraffinement d'un maillage cartésien. */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/cartesianmesh/CartesianMeshCoarsening.h"

#include "arcane/utils/FatalErrorException.h"

#include "arcane/core/IMesh.h"
#include "arcane/core/IParallelMng.h"

#include "arcane/cartesianmesh/ICartesianMesh.h"
#include "arcane/cartesianmesh/CellDirectionMng.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

namespace Arcane
{

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

CartesianMeshCoarsening::
CartesianMeshCoarsening(ICartesianMesh* m)
: TraceAccessor(m->traceMng())
, m_cartesian_mesh(m)
{
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void CartesianMeshCoarsening::
coarseCartesianMesh()
{
IMesh* mesh = m_cartesian_mesh->mesh();
Integer nb_patch = m_cartesian_mesh->nbPatch();
if (nb_patch != 1)
ARCANE_FATAL("This method is only valid for 1 patch (nb_patch={0})", nb_patch);

// TODO: Supprimer les mailles fantômes puis les reconstruire

Integer nb_dir = mesh->dimension();
if (nb_dir != 2)
ARCANE_FATAL("This method is only valid for 2D mesh");

IParallelMng* pm = mesh->parallelMng();
if (pm->isParallel())
ARCANE_FATAL("This method does not work in parallel");

for (Integer idir = 0; idir < nb_dir; ++idir) {
CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
Int32 nb_own_cell = cdm.ownNbCell();
info() << "NB_OWN_CELL dir=" << idir << " n=" << nb_own_cell;
if ((nb_own_cell % 2) != 0)
ARCANE_FATAL("Invalid number of cells ({0}) for direction {1}. Should be a multiple of 2",
nb_own_cell, idir);
}
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

} // End namespace Arcane

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
83 changes: 83 additions & 0 deletions arcane/ceapart/src/arcane/cartesianmesh/CartesianMeshCoarsening.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CartesianMeshCoarsening.h (C) 2000-2023 */
/* */
/* Déraffinement d'un maillage cartésien. */
/*---------------------------------------------------------------------------*/
#ifndef ARCANE_CARTESIANMESH_CARTESIANMESHCOARSENING_H
#define ARCANE_CARTESIANMESH_CARTESIANMESHCOARSENING_H
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/utils/TraceAccessor.h"

#include "arcane/cartesianmesh/CartesianMeshGlobal.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

namespace Arcane
{

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!
* \ingroup ArcaneCartesianMesh
*
* \brief Déraffine un maillage cartésien par 2.
*
* \warning Cette méthode est expérimentale.
*
* Cette classe permet de déraffiner un maillage cartésien. Les instances
* de cette classe sont créées via ICartesianMesh::createCartesianMeshCoarsening().
*
* Après utilisation, le maillage sera un maillage AMR et le maillage
* initial sera un patch (ICartesianMeshPatch). Les mailles du maillage
* initial seront des mailles de niveau 1.
*
* Le maillage initial doit être cartésien et ne doit pas avoir de patchs.
*
* Le maillage doit être un maillage AMR (IMesh::isAmrActivated()==true).
*
* Le nombre de mailles dans chaque dimension doit être un multiple de 2
* ainsi que le nombre de mailles locales à chaque sous-domaine.
*
*/
class ARCANE_CARTESIANMESH_EXPORT CartesianMeshCoarsening
: public TraceAccessor
{
friend CartesianMeshImpl;

private:

explicit CartesianMeshCoarsening(ICartesianMesh* m);

public:

/*!
* \brief Déraffine le maillage initial par 2.
*
* Cette méthode est collective.
*/
void coarseCartesianMesh();

private:

ICartesianMesh* m_cartesian_mesh = nullptr;
};

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

} // End namespace Arcane

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#endif

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CartesianMeshGlobal.h (C) 2000-2022 */
/* CartesianMeshGlobal.h (C) 2000-2023 */
/* */
/* Déclarations de la composante 'arcane_cartesianmesh'. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -38,6 +38,7 @@ class ICartesianMesh;
class ICartesianMeshPatch;
class CartesianMeshPatch;
class CartesianConnectivity;
class CartesianMeshCoarsening;

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand Down
8 changes: 8 additions & 0 deletions arcane/ceapart/src/arcane/cartesianmesh/ICartesianMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CartesianMeshRenumberingInfo;
class ARCANE_CARTESIANMESH_EXPORT ICartesianMesh
{
public:

virtual ~ICartesianMesh() {} //<! Libère les ressources

/*!
Expand All @@ -49,9 +50,11 @@ class ARCANE_CARTESIANMESH_EXPORT ICartesianMesh
static ICartesianMesh* getReference(const MeshHandleOrMesh& mesh, bool create = true);

public:

virtual void build() = 0;

public:

//! Maillage associé à ce maillage cartésien
virtual IMesh* mesh() const = 0;

Expand Down Expand Up @@ -153,6 +156,11 @@ class ARCANE_CARTESIANMESH_EXPORT ICartesianMesh

//! Effectue des vérifications sur la validité de l'instance.
virtual void checkValid() const = 0;

/*!
* \brief Créé une instance pour gérer le déraffinement du maillage.
*/
virtual Ref<CartesianMeshCoarsening> createCartesianMeshCoarsening() = 0;
};

/*---------------------------------------------------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions arcane/ceapart/src/arcane/cartesianmesh/srcs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set(ARCANE_SOURCES
NodeDirectionMng.h
ICartesianMesh.h
ICartesianMeshPatch.h
CartesianMeshCoarsening.cc
CartesianMeshCoarsening.h
CartesianMeshGlobal.h
internal/CartesianMeshPatch.h
internal/CartesianMeshUniqueIdRenumbering.h
Expand Down
5 changes: 5 additions & 0 deletions arcane/ceapart/src/arcane/tests/CartesianMeshTester.axl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
Indique si on construit les arêtes
</description>
</simple>
<simple name="coarse-cartesian-mesh" type="bool" default="false" >
<description>
Indique si on raffine le maillage cartésien initial
</description>
</simple>
</options>

<entry-points>
Expand Down
15 changes: 11 additions & 4 deletions arcane/ceapart/src/arcane/tests/CartesianMeshTesterModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@

#include "arcane/Connectivity.h"

#include "arcane/cea/ICartesianMesh.h"
#include "arcane/cea/CellDirectionMng.h"
#include "arcane/cea/NodeDirectionMng.h"
#include "arcane/cea/CartesianConnectivity.h"
#include "arcane/cartesianmesh/CartesianMeshCoarsening.h"

#include "arcane/cartesianmesh/ICartesianMesh.h"
#include "arcane/cartesianmesh/CellDirectionMng.h"
#include "arcane/cartesianmesh/NodeDirectionMng.h"
#include "arcane/cartesianmesh/CartesianConnectivity.h"

#include "arcane/tests/ArcaneTestGlobal.h"
#include "arcane/tests/CartesianMeshTester_axl.h"
Expand Down Expand Up @@ -414,6 +416,11 @@ init()
void CartesianMeshTesterModule::
compute()
{
if (options()->coarseCartesianMesh() && m_global_iteration()==1){
Ref<CartesianMeshCoarsening> coarser = m_cartesian_mesh->createCartesianMeshCoarsening();
coarser->coarseCartesianMesh();
}

_compute1();
}

Expand Down
1 change: 1 addition & 0 deletions arcane/ceapart/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ ARCANE_ADD_TEST_PARALLEL(cartesian2D-1_repart testCartesianMesh2D-1.arc 4 "-m 20
if (Lima_FOUND)
ARCANE_ADD_TEST(cartesian2D-lima testCartesianMesh2D-2.arc "-m 20")
endif()
arcane_add_test_sequential(cartesian2D_coarsen1 testCartesianMesh2D-coarsen-1.arc "-m 20")
arcane_add_test_sequential(adiadvection-1 testAdiAdvection-1.arc "-m 20")
arcane_add_accelerator_test_sequential(adiadvection-1 testAdiAdvection-1.arc "-m 20")
arcane_add_test(amr-cartesian2D-1 testAMRCartesianMesh2D-1.arc "-m 20")
Expand Down
49 changes: 49 additions & 0 deletions arcane/ceapart/tests/testCartesianMesh2D-coarsen-1.arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<cas codename="ArcaneTest" xml:lang="fr" codeversion="1.0">
<arcane>
<titre>Test CartesianMesh</titre>

<description>Test des maillages cartesiens 2D</description>

<boucle-en-temps>CartesianMeshTestLoop</boucle-en-temps>

<modules>
<module name="ArcanePostProcessing" active="true" />
</modules>

</arcane>

<arcane-post-traitement>
<periode-sortie>1</periode-sortie>
<depouillement>
<variable>Density</variable>
<variable>NodeDensity</variable>
<groupe>AllCells</groupe>
<groupe>AllNodes</groupe>
<groupe>AllFacesDirection0</groupe>
<groupe>AllFacesDirection1</groupe>
</depouillement>
</arcane-post-traitement>


<maillage>
<meshgenerator>
<cartesian>
<nsd>2 2</nsd>
<origine>0.0 0.0</origine>
<lx nx='2' prx='1.0'>2.0</lx>
<lx nx='3' prx='1.0'>3.0</lx>
<lx nx='3' prx='1.2'>3.0</lx>
<lx nx='4' prx='2.0'>4.0</lx>

<ly ny='2' pry='1.0'>2.0</ly>
<ly ny='3' pry='2.0'>3.0</ly>
<ly ny='3' pry='2.0'>3.0</ly>
</cartesian>
</meshgenerator>
</maillage>

<cartesian-mesh-tester>
<coarse-cartesian-mesh>1</coarse-cartesian-mesh>
</cartesian-mesh-tester>
</cas>

0 comments on commit 5f9a489

Please sign in to comment.