Skip to content

Commit 802ff57

Browse files
Merge pull request #289 from arcaneframework/dev/mab-hex-quad-support-elastodynamics
Dev/mab hex quad support elastodynamics
2 parents a4c019e + 00c19a0 commit 802ff57

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

modules/elastodynamics/FemModule.cc

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ _getParameters()
155155

156156
//--------- material parameter ---------//
157157
E = options()->E(); // Youngs modulus 𝐸
158-
nu = options()->nu(); // Poission ratio ν
158+
nu = options()->nu(); // Poisson ratio ν
159159
rho = options()->rho(); // Density ρ
160160

161161
mu = E / (2 * (1 + nu)); // lame parameter μ
@@ -392,23 +392,28 @@ _assembleBilinearOperatorTetra4Gpu()
392392
}
393393

394394
/*---------------------------------------------------------------------------*/
395+
/**
396+
* @brief Assembles the FEM bilinear operator for 2D problems.
397+
*
398+
* This method assembles the FEM stiffness matrix by iterating over each cell,
399+
* computing the element stiffness matrix using the provided function, and
400+
* populating the global stiffness matrix accordingly.
401+
*
402+
* @tparam N The number of nodes per element (e.g., 3 for triangles, 4 for quadrilaterals).
403+
* @param compute_element_matrix A function that computes the element stiffness matrix for a given cell.
404+
*/
395405
/*---------------------------------------------------------------------------*/
396406

407+
template <int N>
397408
void FemModule::
398-
_assembleBilinearOperatorTria3()
409+
_assembleBilinearOperator2d(const std::function<RealMatrix<N, N>(const Cell&)>& compute_element_matrix)
399410
{
400411
auto node_dof(m_dofs_on_nodes.nodeDoFConnectivityView());
401412

402413
ENUMERATE_ (Cell, icell, allCells()) {
403414
Cell cell = *icell;
404415

405-
auto K_e = _computeElementMatrixTria3(cell); // element stiffness matrix
406-
// assemble elementary matrix into the global one elementary terms are
407-
// positioned into K according to the rank of associated node in the
408-
// mesh.nodes list and according the dof number. Here for each node
409-
// two dofs exists [u1,u2]. For each TRIA3 there are 3 nodes hence the
410-
// elementary stiffness matrix size is (3*2 x 3*2)=(6x6). We will fill
411-
// this below in 4 at a time.
416+
auto K_e = compute_element_matrix(cell);
412417
Int32 n1_index = 0;
413418
for (Node node1 : cell.nodes()) {
414419
Int32 n2_index = 0;
@@ -417,13 +422,13 @@ _assembleBilinearOperatorTria3()
417422
Real v2 = K_e(2 * n1_index, 2 * n2_index + 1);
418423
Real v3 = K_e(2 * n1_index + 1, 2 * n2_index);
419424
Real v4 = K_e(2 * n1_index + 1, 2 * n2_index + 1);
420-
// m_k_matrix(node1.localId(), node2.localId()) += v;
425+
421426
if (node1.isOwn()) {
422427
DoFLocalId node1_dof1 = node_dof.dofId(node1, 0);
423428
DoFLocalId node1_dof2 = node_dof.dofId(node1, 1);
424429
DoFLocalId node2_dof1 = node_dof.dofId(node2, 0);
425430
DoFLocalId node2_dof2 = node_dof.dofId(node2, 1);
426-
// m_linear_system.matrixAddValue(node_dof.dofId(node1, 0), node_dof.dofId(node2, 0), v);
431+
427432
m_linear_system.matrixAddValue(node1_dof1, node2_dof1, v1);
428433
m_linear_system.matrixAddValue(node1_dof1, node2_dof2, v2);
429434
m_linear_system.matrixAddValue(node1_dof2, node2_dof1, v3);
@@ -437,17 +442,28 @@ _assembleBilinearOperatorTria3()
437442
}
438443

439444
/*---------------------------------------------------------------------------*/
445+
/**
446+
* @brief Assembles the FEM bilinear operator for 3D problems.
447+
*
448+
* This method assembles the FEM stiffness matrix by iterating over each cell,
449+
* computing the element stiffness matrix using the provided function, and
450+
* populating the global stiffness matrix accordingly.
451+
*
452+
* @tparam N The number of nodes per element (e.g., 4 for tetrahedra, 8 for hexahedra).
453+
* @param compute_element_matrix A function that computes the element stiffness matrix for a given cell.
454+
*/
440455
/*---------------------------------------------------------------------------*/
441456

457+
template <int N>
442458
void FemModule::
443-
_assembleBilinearOperatorTetra4()
459+
_assembleBilinearOperator3d(const std::function<RealMatrix<N, N>(const Cell&)>& compute_element_matrix)
444460
{
445461
auto node_dof(m_dofs_on_nodes.nodeDoFConnectivityView());
446462

447463
ENUMERATE_ (Cell, icell, allCells()) {
448464
Cell cell = *icell;
449465

450-
auto K_e = _computeElementMatrixTetra4(cell);
466+
auto K_e = compute_element_matrix(cell);
451467
Int32 n1_index = 0;
452468
for (Node node1 : cell.nodes()) {
453469
Int32 n2_index = 0;
@@ -500,16 +516,25 @@ _assembleBilinearOperator()
500516
Real elapsedTime = platform::getRealTime();
501517

502518
if (t <= dt) {
503-
if (mesh()->dimension() == 2)
504-
if(m_matrix_format == "BSR" || m_matrix_format == "AF-BSR")
519+
if (m_matrix_format == "DOK") {
520+
if (mesh()->dimension() == 2) {
521+
_assembleBilinearOperator2d<6>([this](const Cell& cell) { return _computeElementMatrixTria3(cell); });
522+
}
523+
if (mesh()->dimension() == 3) {
524+
_assembleBilinearOperator3d<12>([this](const Cell& cell) { return _computeElementMatrixTetra4(cell); });
525+
}
526+
}
527+
else if (m_matrix_format == "BSR" || m_matrix_format == "AF-BSR") {
528+
if (mesh()->dimension() == 2) {
505529
_assembleBilinearOperatorTria3Gpu();
506-
else
507-
_assembleBilinearOperatorTria3();
508-
else
509-
if(m_matrix_format == "BSR" || m_matrix_format == "AF-BSR")
530+
}
531+
if (mesh()->dimension() == 3) {
510532
_assembleBilinearOperatorTetra4Gpu();
511-
else
512-
_assembleBilinearOperatorTetra4();
533+
}
534+
}
535+
else {
536+
ARCANE_FATAL("Unsupported matrix type, only DOK| BSR | AF-BSR is supported.");
537+
}
513538
}
514539

515540
elapsedTime = platform::getRealTime() - elapsedTime;

modules/elastodynamics/FemModule.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ class FemModule
141141
void _validateResults();
142142
void _readCaseTables();
143143
void _assembleBilinearOperator();
144-
void _assembleBilinearOperatorTria3();
145-
void _assembleBilinearOperatorTetra4();
146144

147145
inline void _applyTraction(VariableDoFReal& rhs_values, const IndexedNodeDoFConnectivityView& node_dof);
148146
inline void _applyDirichlet(VariableDoFReal& rhs_values, const IndexedNodeDoFConnectivityView& node_dof);
@@ -151,6 +149,11 @@ class FemModule
151149
RealMatrix<6, 6> _computeElementMatrixTria3(Cell cell);
152150
RealMatrix<12, 12> _computeElementMatrixTetra4(Cell cell);
153151

152+
template <int N>
153+
void _assembleBilinearOperator2d(const std::function<RealMatrix<N, N>(const Cell&)>& compute_element_matrix);
154+
155+
template <int N>
156+
void _assembleBilinearOperator3d(const std::function<RealMatrix<N, N>(const Cell&)>& compute_element_matrix);
154157
};
155158

156159
#endif

0 commit comments

Comments
 (0)