Skip to content

Commit

Permalink
Added CBS lid-driven example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaraujo committed Dec 24, 2024
1 parent d7dd0c4 commit 8932121
Show file tree
Hide file tree
Showing 11 changed files with 3,645 additions and 26 deletions.
127 changes: 125 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ MathEval (plugin)
Expression 0: Sqrt(v0^2+v1^2)
```

<details><summary>Code</summary>
<details><summary>Code FVM</summary>
<p>

```python
Expand Down Expand Up @@ -983,7 +983,130 @@ for i in range(0, fvmMesh.nbControlVolumes()):
u.setValue(i * 2 + 1, pisoSolver.v(controlVolumeId))

posGmsh = ENigMA.CPosGmsh()
posGmsh.save(u, "fvm_01.msh", "Flow")
posGmsh.save(u, "fvm_lid_01.msh", "Flow")
```

</p>
</details>

<details><summary>Code FEM</summary>
<p>

```
import math
from ENigMA import ENigMA
edgeMesh = ENigMA.CMshMesh()
node1 = ENigMA.CMshNode(0.0, 0.0, 0.0)
node2 = ENigMA.CMshNode(1.0, 0.0, 0.0)
node3 = ENigMA.CMshNode(1.0, 1.0, 0.0)
node4 = ENigMA.CMshNode(0.0, 1.0, 0.0)
edgeMesh.addNode(1, node1)
edgeMesh.addNode(2, node2)
edgeMesh.addNode(3, node3)
edgeMesh.addNode(4, node4)
element1 = ENigMA.CMshElement(ENigMA.ET_BEAM)
element1.addNodeId(1)
element1.addNodeId(2)
element2 = ENigMA.CMshElement(ENigMA.ET_BEAM)
element2.addNodeId(2)
element2.addNodeId(3)
element3 = ENigMA.CMshElement(ENigMA.ET_BEAM)
element3.addNodeId(3)
element3.addNodeId(4)
element4 = ENigMA.CMshElement(ENigMA.ET_BEAM)
element4.addNodeId(4)
element4.addNodeId(1)
edgeMesh.addElement(1, element1)
edgeMesh.addElement(2, element2)
edgeMesh.addElement(3, element3)
edgeMesh.addElement(4, element4)
triangleMesher = ENigMA.CMshTriangleMesher()
meshSize = 0.03
edgeMesh.generateFaces(1E-3)
triangleMesher.remesh(edgeMesh, meshSize)
interiorPoints = ENigMA.StdVectorCGeoCoordinate()
triangleMesher.generate(edgeMesh, 9999, interiorPoints, meshSize, meshSize, meshSize, 1E-6)
triangleMesher.flipEdges(triangleMesher.mesh())
triangleMesher.relaxNodes(triangleMesher.mesh())
surfaceMesh = triangleMesher.mesh()
U = 1.0 # lid velocity
mu = 0.001 # dynamic viscosity
rho = 1.0 # density
nu = mu / rho # kinematic viscosit
cbsSolver = ENigMA.CFemCbsSolver2(surfaceMesh)
cbsSolver.setGravity(0.0, 0.0);
cbsSolver.setMaterialProperties(rho, mu);
index = 0
for i in range(0, surfaceMesh.nbNodes()):
nodeId = surfaceMesh.nodeId(i)
node = surfaceMesh.node(nodeId)
if (math.fabs(node.x() - 0.0) < 1E-6):
cbsSolver.u().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
cbsSolver.v().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
if (math.fabs(node.x() - 1.0) < 1E-6):
cbsSolver.u().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
cbsSolver.v().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
if (math.fabs(node.y() - 0.0) < 1E-6):
cbsSolver.u().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
cbsSolver.v().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
if (math.fabs(node.y() - 1.0) < 1E-6):
cbsSolver.u().setFixedValue(surfaceMesh.nodeIndex(nodeId), 1.0)
cbsSolver.v().setFixedValue(surfaceMesh.nodeIndex(nodeId), 0.0)
cbsSolver.u().setValue(i, 0.0);
cbsSolver.v().setValue(i, 0.0);
cbsSolver.p().setValue(i, 0.0);
# Courant < 1
dt = 0.01
iter = 20
# Flow in a rectangle
for ii in range(0, iter):
cbsSolver.iterate(dt)
print('Iter = {} of {}'.format(ii + 1, iter))
u = ENigMA.CPdeField()
u.setMesh(surfaceMesh)
u.setSimulationType(ENigMA.ST_FLOW)
u.setDiscretMethod(ENigMA.DM_FEM)
u.setDiscretOrder(ENigMA.DO_LINEAR)
u.setDiscretLocation(ENigMA.DL_NODE)
u.setNbDofs(2)
u.setSize(surfaceMesh.nbNodes() * 2)
for i in range(0, surfaceMesh.nbNodes()):
nodeId = surfaceMesh.nodeId(i)
u.setValue(i * 2 + 0, cbsSolver.u().value(nodeId))
u.setValue(i * 2 + 1, cbsSolver.v().value(nodeId))
posGmsh = ENigMA.CPosGmsh()
posGmsh.save(u, "fem_lid_01.msh", "Flow")
```

</p>
Expand Down
22 changes: 11 additions & 11 deletions trunk/include/ENigMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include "AnaTemperature.hpp"
#include "BemTriangle.hpp"
#include "FdmGrid.hpp"
#include "IntBeam.hpp"
#include "IntHexahedron.hpp"
#include "IntQuadrilateral.hpp"
#include "IntTetrahedron.hpp"
#include "IntTriangle.hpp"
#include "IntTriangularPrism.hpp"
#include "IntGaussIntegration.hpp"
#include "FemBeam.hpp"
#include "FemEdge.hpp"
#include "FemElement.hpp"
Expand Down Expand Up @@ -66,13 +73,6 @@
#include "GeoVertexList.hpp"
#include "GeoVolume.hpp"
#include "GeoAdtree.hpp"
#include "IntBeam.hpp"
#include "IntGaussIntegration.hpp"
#include "IntHexahedron.hpp"
#include "IntQuadrilateral.hpp"
#include "IntTetrahedron.hpp"
#include "IntTriangle.hpp"
#include "IntTriangularPrism.hpp"
#include "LbmLattice.hpp"
#include "LbmSolver.hpp"
#include "MatMaterial.hpp"
Expand All @@ -91,10 +91,10 @@
#include "PdeBoundaryCondition.hpp"
#include "PdeEquation.hpp"
#include "PdeField.hpp"
#include "bem\BemOperators.hpp"
#include "fdm\FdmOperators.hpp"
#include "fem\FemOperators.hpp"
#include "fvm\FvmOperators.hpp"
#include "bem/BemOperators.hpp"
#include "fdm/FdmOperators.hpp"
#include "fem/FemOperators.hpp"
#include "fvm/FvmOperators.hpp"
#include "PosGmsh.hpp"
#include "PosGnuplot.hpp"
#include "PosQuickMesh.hpp"
Expand Down
1 change: 0 additions & 1 deletion trunk/src/integration/IntTriangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace ENigMA
{

namespace integration
{

Expand Down
1 change: 0 additions & 1 deletion trunk/src/solvers/FemCbsSolver_Imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ namespace ENigMA
// Three-dimensional
template <typename Real>
CFemCbsSolver<Real, 3>::CFemCbsSolver(CMshMesh<Real>& aMesh)
: CFemCbsSolver<Real, 2>(aMesh)
{
m_mesh = aMesh;

Expand Down
2 changes: 0 additions & 2 deletions trunk/src/solvers/FvmPisoSolver_Imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

namespace ENigMA
{

namespace fvm
{

template <typename Real>
CFvmPisoSolver<Real>::CFvmPisoSolver(CFvmMesh<Real>& aFvmMesh)
: m_dt(0.0)
Expand Down
3 changes: 0 additions & 3 deletions trunk/tests/TestFemCbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ TEST_F(CTestFemCbs, hydroPressure) {

for (Integer i = 0; i < aBasicMesher.mesh().nbNodes(); ++i)
{

Integer aNodeId = aBasicMesher.mesh().nodeId(i);
CMshNode<Decimal> aNode = aBasicMesher.mesh().node(aNodeId);

Expand All @@ -94,7 +93,6 @@ TEST_F(CTestFemCbs, hydroPressure) {
aCbsSolver.v().setValue(i, 0.0);

aCbsSolver.p().setValue(i, 0.0);

}

Decimal dt = 1E-3;
Expand All @@ -113,6 +111,5 @@ TEST_F(CTestFemCbs, hydroPressure) {
}

EXPECT_NEAR(rho*std::fabs(g), p, 1000);

}

20 changes: 14 additions & 6 deletions trunk/wrappers/swig/ENigMA.i
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ namespace std
#include "PdeField.hpp"
#include "PdeEquation.hpp"
#include "PdeBoundaryCondition.hpp"
#include "IntGaussIntegration.hpp"
#include "FemBeam.hpp"
#include "FemTriangle.hpp"
#include "FemQuadrilateral.hpp"
#include "FemTetrahedron.hpp"
#include "FemTriangularPrism.hpp"
#include "FemHexahedron.hpp"
#include "FemCbsSolver.hpp"
#include "FvmNode.hpp"
#include "FvmFace.hpp"
#include "FvmCell.hpp"
Expand Down Expand Up @@ -662,34 +664,40 @@ namespace std
// FEM Beam
%include "FemBeam.hpp"
%template(CFemBeamDouble211) ENigMA::fem::CFemBeam<double, 2, 1, 1>;
%template(CFemBeam) ENigMA::fem::CFemBeam<double, 2, 1, 1>;
// FEM Triangle
%include "FemTriangle.hpp"
%template(CFemTriangleDouble311) ENigMA::fem::CFemTriangle<double, 3, 1, 1>;
%template(CFemTriangle) ENigMA::fem::CFemTriangle<double, 3, 1, 1>;
// FEM Quadrilateral
%include "FemQuadrilateral.hpp"
%template(CFemQuadrilateralDouble411) ENigMA::fem::CFemQuadrilateral<double, 4, 1, 1>;
%template(CFemQuadrilateral) ENigMA::fem::CFemQuadrilateral<double, 4, 1, 1>;
// FEM Tetrahedron
%include "FemTetrahedron.hpp"
%template(CFemTetrahedronDouble411) ENigMA::fem::CFemTetrahedron<double, 4, 1, 1>;
%template(CFemTetrahedron) ENigMA::fem::CFemTetrahedron<double, 4, 1, 1>;
// FEM Triangular Prism
%include "FemTriangularPrism.hpp"
%template(CFemTriangularPrismDouble611) ENigMA::fem::CFemTriangularPrism<double, 6, 1, 1>;
%template(CFemTriangularPrism) ENigMA::fem::CFemTriangularPrism<double, 6, 1, 1>;
// FEM Hexahedron
%include "FemHexahedron.hpp"
%template(CFemHexahedronDouble811) ENigMA::fem::CFemHexahedron<double, 8, 1, 1>;
%template(CFemHexahedron) ENigMA::fem::CFemHexahedron<double, 8, 1, 1>;
*/

// FEM CBS Solver
%include "FemCbsSolver.hpp"

%template(CFemCbsSolver2) ENigMA::fem::CFemCbsSolver<double, 2>;
%template(CFemCbsSolver3) ENigMA::fem::CFemCbsSolver<double, 3>;

// FVM Node
%include "FvmNode.hpp"

Expand Down
Loading

0 comments on commit 8932121

Please sign in to comment.