13#include "arcane/aleph/tests/AlephTest.h"
24using namespace Arcane;
37, m_aleph_factory(new
AlephFactory(subDomain()->application(), traceMng()))
42, m_get_solution_idx(0)
43, m_fake_nb_iteration(0)
45 debug() <<
"\33[37m[AlephTestModule::AlephTestModule] Loading AlephTestModule\33[0m";
51 delete m_aleph_kernel;
52 delete m_aleph_params;
53 delete m_aleph_factory;
62 ItacFunction(AlephTestModule);
63 m_aleph_mat.resize(
options()->alephNumberOfSolvers);
64 m_aleph_rhs.resize(
options()->alephNumberOfSolvers);
65 m_aleph_sol.resize(
options()->alephNumberOfSolvers);
68 m_local_nb_cell = MESH_OWN_ACTIVE_CELLS(
mesh()).size();
70 debug() <<
"\33[37m[AlephTestModule::init] m_total_nb_cell=" << m_total_nb_cell
71 <<
", local=" << m_local_nb_cell <<
"\33[0m";
80 m_face_temperature[iFace] =
options()->initTemperature();
84 m_sub_domain_id[icell] =
subDomain()->subDomainId();
86 m_unique_id[icell] = icell->uniqueId().asInteger();
95 initAmrRefineMesh((
Integer)(
mesh()->cellFamily()->allItems().own().size() *
options()->initAmr()));
96 mesh()->checkValidMeshFull();
105void AlephTestModule::
108 const Integer nb_row_size = m_total_nb_cell;
109 const Integer nb_row_rank = m_local_nb_cell;
112 Int32 underlying_solver = options()->alephUnderlyingSolver;
114 info() <<
"[AlephTestModule::initAlgebra] ALEPH init, " << nb_row_size
115 <<
" lines in total, " << nb_row_rank <<
" for me";
116 info() <<
"[AlephTestModule::initAlgebra] alephUnderlyingSolver="
117 << underlying_solver;
118 info() <<
"[AlephTestModule::initAlgebra] alephNumberOfCores="
119 << options()->alephNumberOfCores;
121 delete m_aleph_factory;
122 m_aleph_factory =
new AlephFactory(subDomain()->application(), traceMng());
126 delete m_aleph_kernel;
132 options()->alephNumberOfCores,
133 options()->alephCellOrdering);
137 const bool use_is_even = (subDomain()->parallelMng()->commSize() % 2) == 0;
138 const bool use_petsc_args = (underlying_solver == AlephKernel::SOLVER_PETSC && use_is_even);
139 if (use_petsc_args) {
141 slist1.add(
"-trmalloc");
142 slist1.add(
"-log_trace");
145 m_aleph_kernel->solverInitializeArgs().setCommandLineArguments(args);
147 m_aleph_kernel->initialize(nb_row_size, nb_row_rank);
149 delete m_aleph_params;
153 TypesSolver::DIAGONAL,
165 "SolveErrorAlephMatrix.dbg",
174 TypesSolver::SymHybGSJ_smoother,
175 TypesSolver::ParallelRugeStuben,
176 TypesSolver::CG_coarse_solver,
183 m_cell_matrix_idx.fill(-1);
187 m_vector_indexs.resize(0);
188 m_vector_zeroes.resize(0);
189 m_vector_lhs.resize(0);
190 const AlephInt row_offset = m_aleph_kernel->topology()->part()[m_aleph_kernel->rank()];
192 m_cell_matrix_idx[iCell] = row_offset + idx;
193 m_vector_indexs.add(m_cell_matrix_idx[iCell] = row_offset + idx);
194 m_vector_zeroes.add(0.0);
195 m_vector_lhs.add(0.0);
199 m_cell_matrix_idx.synchronize();
204 m_rows_nb_element.resize(nb_row_rank);
206 options()->schema()->preFetchNumElementsForEachRow(m_rows_nb_element,
207 m_aleph_kernel->topology()->part()[m_aleph_kernel->rank()]);
208 debug() <<
"\33[37m[AlephTestModule::initAlgebra] done\33[0m";
214void AlephTestModule::
219 Real residual_norm[4];
220 debug() <<
"\33[37m[AlephTestModule::compute]\33[0m";
221 const Integer rank_offset = m_aleph_kernel->topology()->part()[m_aleph_kernel->rank()];
222 ItacFunction(AlephTestModule);
224 for (
int i = 0; i < options()->alephNumberOfSolvers; i += 1)
228 for (
int i = options()->alephNumberOfSolvers - 1; i >= 0; i -= 1) {
229 debug() <<
"\33[37m[AlephTestModule::compute] Getting solution #" << i <<
"\33[0m";
230 AlephVector* solution = m_aleph_kernel->syncSolver(i, nb_iteration, &residual_norm[0]);
232 info() <<
"\33[37mSolved in \33[7m" << nb_iteration <<
"\33[m iterations,"
233 <<
"residuals=[\33[1m" << residual_norm[0] <<
"\33[m," << residual_norm[3] <<
"]";
234 debug() <<
"\33[37m[AlephTestModule::compute] Applying solution #" << m_get_solution_idx <<
"\33[0m";
235 solution->getLocalComponents(m_vector_indexs.size(), m_vector_indexs.view(), m_vector_lhs.view());
236 m_get_solution_idx += 1;
238 m_get_solution_idx %= options()->alephNumberOfSolvers;
259 if (options()->alephDeleteKernel() ==
true) {
260 debug() <<
"\33[37m[AlephTestModule::compute] DELETE the KERNEL between each iteration"
266 debug() <<
"\33[37m[AlephTestModule::compute] Now get our results"
269 m_cell_temperature[iCell] = m_vector_lhs[m_cell_matrix_idx[iCell] - rank_offset];
273 if (subDomain()->commonVariables().globalIteration() >= options()->iterations + delta_amr)
274 subDomain()->timeLoopMng()->stopComputeLoop(
true);
276 debug() <<
"\33[37m[AlephTestModule::compute] done"
283void AlephTestModule::
286 ItacFunction(AlephTestModule);
287 debug() <<
"\33[37m[AlephTestModule::postSolver] #" << i <<
"\33[0m";
288 const Integer rank_offset = m_aleph_kernel->topology()->part()[m_aleph_kernel->rank()];
291 debug() <<
"\33[37m[AlephTestModule::postSolver] Filling the right-hand side"
293 m_vector_rhs.resize(0);
295 m_vector_rhs.add(m_cell_temperature[iCell]);
298 debug() <<
"\33[37m[AlephTestModule::postSolver] ENUMERATE_FACE"
301 if (!iFace->cell(0).isOwn())
303 m_vector_rhs[m_cell_matrix_idx[iFace->cell(0)] - rank_offset] +=
304 options()->deltaT * (m_face_temperature[iFace]) / geoFaceSurface(*iFace, nodesCoordinates());
308 m_aleph_mat.setAt(i, m_aleph_kernel->createSolverMatrix());
309 m_aleph_rhs.setAt(i, m_aleph_kernel->createSolverVector());
310 m_aleph_sol.setAt(i, m_aleph_kernel->createSolverVector());
313 m_aleph_mat.at(i)->create();
314 m_aleph_rhs.at(i)->create();
315 m_aleph_sol.at(i)->create();
318 options()->schema()->setValues(options()->deltaT, m_aleph_mat.at(i));
319 m_aleph_mat.at(i)->assemble();
321 debug() <<
"\33[37m[AlephTestModule::postSolver] setLocalComponents"
323 m_aleph_rhs.at(i)->setLocalComponents(m_vector_indexs.size(), m_vector_indexs.view(), m_vector_rhs.view());
324 m_aleph_rhs.at(i)->assemble();
326 m_aleph_sol.at(i)->setLocalComponents(m_vector_indexs.size(), m_vector_indexs.view(), m_vector_zeroes.view());
327 m_aleph_sol.at(i)->assemble();
330 debug() <<
"\33[37m[AlephTestModule::postSolver] Now solve with Aleph"
332 m_aleph_mat.at(i)->solve(m_aleph_sol.at(i),
335 &m_fake_residual_norm[0],
343Real AlephTestModule::
347 const Real3 xyz0 = nodes_coords[face.
node(0)];
348 const Real3 xyz1 = nodes_coords[face.
node(1)];
349 const Real3 xyz3 = nodes_coords[face.
node(3)];
350 return (xyz0 - xyz1).normL2() * (xyz0 - xyz3).normL2();
353 const Real3 xyz0 = nodes_coords[face.
node(0)];
354 const Real3 xyz1 = nodes_coords[face.
node(1)];
355 return (xyz0 - xyz1).squareNormL2();
363void AlephTestModule::
364initAmrRefineMesh(
Integer nb_to_refine)
366 ItacFunction(AlephTestModule);
367 if (nb_to_refine == 0)
370 info() <<
"Refining nb_to_refine=" << nb_to_refine;
375 if ((cell.
type() == IT_Hexaedron8) || (cell.
type() == IT_Quad4)) {
376 if (nb_to_refine-- <= 0)
378 info(5) <<
"\t[amrRefineMesh] refine cell.uid=" << cell.
uniqueId();
384 info() <<
"now refine";
385 mesh()->modifier()->flagCellToRefine(cells_local_id);
386 mesh()->modifier()->adapt();
393 for (
Integer i = 0, is = cells_local_id.
size(); i < is; ++i) {
394 Int32 lid = cells_local_id[i];
395 Cell cell = cells[lid];
397 for (
Integer j = 0, js = CELL_NB_H_CHILDREN(cell); j < js; ++j) {
399 m_cell_temperature[cells[CELL_H_CHILD(cell, j).localId()]] = m_cell_temperature[cells[lid]];
400 auto faces = allCells().view()[CELL_H_CHILD(cell, j).localId()].toCell().faces();
402 for (
Face face : faces) {
405 m_face_temperature[face] = m_face_temperature[cell.
face(index)];
409 m_face_temperature[face] = 0;
420ARCANE_DEFINE_STANDARD_MODULE(AlephTestModule, AlephTest);
Generation de la classe de base du Module.
CaseOptionsAlephTestModule * options() const
Options du jeu de données du module.
Arcane::VariableCellReal m_cell_temperature
Variables du module.
Integer size() const
Number of elements in the vector.
ISubDomain * subDomain() const override
Sub-domain associated with the module.
Parameters of a linear system.
Vector of a linear system.
void add(ConstReferenceType val)
Adds element val to the end of the array.
View of cell information.
Face face(Int32 i) const
i-th face of the cell
VariableScalarReal m_global_deltat
Global Delta T.
bool isSubDomainBoundary() const
Indicates if the face is on the subdomain boundary (i.e nbCell()==1).
Exception when a fatal error has occurred.
Node node(Int32 i) const
i-th node of the entity
Int32 nbNode() const
Number of nodes of the entity.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Int16 type() const
Entity type.
CellGroup allCells() const
Returns the group containing all cells.
FaceGroup allFaces() const
Returns the group containing all faces.
Information for building a module.
Class managing a 3-dimensional real vector.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
ItemVariableScalarRefT< Real3 > VariableItemReal3
3D coordinate type quantity
@ ReduceSum
Sum of values.
Int32 Integer
Type representing an integer.
List< String > StringList
Unicode string list.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
int AlephInt
Default type for indexing rows and columns of matrices and vectors.
std::int32_t Int32
Signed integer type of 32 bits.