static public void DrawMesh(CMshBasicMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid) { vtkPoints sPoints = vtkPoints.New(); for (int i = 0; i < aMesher.mesh().nbNodes(); ++i) { int aNodeId = aMesher.mesh().nodeId(i); var aNode = aMesher.mesh().node(aNodeId); sPoints.InsertNextPoint(aNode.x(), aNode.y(), aNode.z()); } anUnstructuredGrid.SetPoints(sPoints); for (int i = 0; i < aMesher.mesh().nbElements(); ++i) { int anElementId = aMesher.mesh().elementId(i); var anElement = aMesher.mesh().element(anElementId); if (anElement.elementType() == EElementType.ET_TETRAHEDRON) { var aTetrahedron = vtkTetra.New(); aTetrahedron.GetPointIds().SetId(0, aMesher.mesh().nodeIndex(anElement.nodeId(0))); aTetrahedron.GetPointIds().SetId(1, aMesher.mesh().nodeIndex(anElement.nodeId(1))); aTetrahedron.GetPointIds().SetId(2, aMesher.mesh().nodeIndex(anElement.nodeId(2))); aTetrahedron.GetPointIds().SetId(3, aMesher.mesh().nodeIndex(anElement.nodeId(3))); anUnstructuredGrid.InsertNextCell(aTetrahedron.GetCellType(), aTetrahedron.GetPointIds()); } } }
static public void GenerateMesh(CMshBasicMesherDouble aMesher, vtkRenderer aRenderer) { var aVertex1 = new CGeoCoordinateDouble(+0.00, +0.00, -0.02); var aVertex2 = new CGeoCoordinateDouble(+1.00, +0.00, -0.02); var aVertex3 = new CGeoCoordinateDouble(+1.00, +0.10, -0.02); var aVertex4 = new CGeoCoordinateDouble(+0.00, +0.10, -0.02); var aVertex5 = new CGeoCoordinateDouble(+0.00, +0.00, +0.02); var aVertex6 = new CGeoCoordinateDouble(+1.00, +0.00, +0.02); var aVertex7 = new CGeoCoordinateDouble(+1.00, +0.10, +0.02); var aVertex8 = new CGeoCoordinateDouble(+0.00, +0.10, +0.02); var aHexahedron = new CGeoHexahedronDouble(); aHexahedron.addVertex(aVertex1); aHexahedron.addVertex(aVertex2); aHexahedron.addVertex(aVertex3); aHexahedron.addVertex(aVertex4); aHexahedron.addVertex(aVertex5); aHexahedron.addVertex(aVertex6); aHexahedron.addVertex(aVertex7); aHexahedron.addVertex(aVertex8); aMesher.generate(aHexahedron, 100, 10, 1, false); aMesher.mesh().generateFaces(1E-3); }
static public void GenerateMesh(CMshTetrahedronMesherDouble aMesher, vtkRenderer aRenderer) { var aVertex1 = new CGeoCoordinateDouble(0.0, 0.0, 0.0); var aVertex2 = new CGeoCoordinateDouble(1.0, 0.0, 0.0); var aVertex3 = new CGeoCoordinateDouble(1.0, 1.0, 0.0); var aVertex4 = new CGeoCoordinateDouble(0.0, 1.0, 0.0); var aVertex5 = new CGeoCoordinateDouble(0.0, 0.0, 1.0); var aVertex6 = new CGeoCoordinateDouble(1.0, 0.0, 1.0); var aVertex7 = new CGeoCoordinateDouble(1.0, 1.0, 1.0); var aVertex8 = new CGeoCoordinateDouble(0.0, 1.0, 1.0); var aHexahedron = new CGeoHexahedronDouble(); aHexahedron.addVertex(aVertex1); aHexahedron.addVertex(aVertex2); aHexahedron.addVertex(aVertex3); aHexahedron.addVertex(aVertex4); aHexahedron.addVertex(aVertex5); aHexahedron.addVertex(aVertex6); aHexahedron.addVertex(aVertex7); aHexahedron.addVertex(aVertex8); var aBasicMesher = new CMshBasicMesherDouble(); aBasicMesher.generate(aHexahedron, 10, 10, 10, true); CMshMeshDouble aBoundaryMesh = aBasicMesher.mesh().extractBoundary(1E-6); aBoundaryMesh.generateFaces(1E-4); var aMeshSize = 0.1; aMesher.generate(aBoundaryMesh, 99999, aMeshSize, 0.1, 1E-4); aMesher.mesh().renumber(); }
static public void Simulate(CMshBasicMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid, vtkRenderer aRenderer, RenderWindowControl aRenderControl) { aMesher.mesh().generateFaces(1E-12); aMesher.mesh().calculateFaceCentroid(); aMesher.mesh().calculateElementCentroid(); var aFvmMesh = new CFvmMeshDouble(aMesher.mesh()); double U = 1.0; // Lid velocity double mu = 0.001; // dynamic viscosity double rho = 1.0; // density double nu = mu / rho; // kinematic viscosity var aPisoSolver = new CFvmPisoSolverDouble(aFvmMesh); aPisoSolver.setGravity(0.0, 0.0, 0.0); aPisoSolver.setMaterialProperties(rho, mu); var sFaceIds = new StdVectorInt(); sFaceIds.Clear(); for (int i = 0; i < aFvmMesh.nbFaces(); ++i) { int aFaceId = aFvmMesh.faceId(i); var aFace = aFvmMesh.face(aFaceId); aFace.calculateCentroid(); if (aFace.centroid().y() == 0.0 || aFace.centroid().y() == 0.1) { sFaceIds.Add(aFaceId); } } aPisoSolver.setBoundaryVelocity(sFaceIds, EBoundaryType.BT_WALL_NO_SLIP, 0.0, 0.0, 0.0); aPisoSolver.setBoundaryPressure(sFaceIds, EBoundaryType.BT_WALL_NO_SLIP, 0.0); sFaceIds.Clear(); for (int i = 0; i < aFvmMesh.nbFaces(); ++i) { int aFaceId = aFvmMesh.faceId(i); var aFace = aFvmMesh.face(aFaceId); aFace.calculateCentroid(); if (aFace.centroid().x() == 0.0) { sFaceIds.Add(aFaceId); } } aPisoSolver.setBoundaryVelocity(sFaceIds, EBoundaryType.BT_INLET_FLOW, U, 0.0, 0.0); sFaceIds.Clear(); for (int i = 0; i < aFvmMesh.nbFaces(); ++i) { int aFaceId = aFvmMesh.faceId(i); var aFace = aFvmMesh.face(aFaceId); aFace.calculateCentroid(); if (aFace.centroid().x() == 1.0) { sFaceIds.Add(aFaceId); } } aPisoSolver.setBoundaryVelocity(sFaceIds, EBoundaryType.BT_OUTLET, 0.0, 0.0, 0.0); double dt = U / 100; // Courant < 1 var sScalars = vtkFloatArray.New(); sScalars.SetNumberOfTuples(aFvmMesh.nbControlVolumes()); var aGeometryFilter = vtkGeometryFilter.New(); var aCellDataToPointDataFilter1 = vtkCellDataToPointData.New(); var aBoundedFilter = vtkBandedPolyDataContourFilter.New(); var aLookupTable = vtkLookupTable.New(); aLookupTable.SetNumberOfColors(256); aLookupTable.SetHueRange(0.667, 0.0); aLookupTable.Build(); var aBandedMapper = vtkPolyDataMapper.New(); // add actor to the renderer var aMeshActor = vtkActor.New(); aRenderer.AddActor(aMeshActor); var aScalarBarActor = vtkScalarBarActor.New(); aRenderer.AddActor(aScalarBarActor); int nIter = 40; // Flow in a rectangle for (int ii = 0; ii < nIter; ++ii) { aPisoSolver.iterate(dt); for (int i = 0; i < aFvmMesh.nbControlVolumes(); ++i) { var aControlVolumeId = aFvmMesh.controlVolumeId(i); double u = aPisoSolver.u(aControlVolumeId); double v = aPisoSolver.v(aControlVolumeId); double vel = Math.Sqrt(u * u + v * v); sScalars.SetTuple1(aControlVolumeId, vel); } sScalars.Modified(); anUnstructuredGrid.GetCellData().SetScalars(sScalars); aGeometryFilter.SetInput(anUnstructuredGrid); aGeometryFilter.Update(); aCellDataToPointDataFilter1.SetInputConnection(aGeometryFilter.GetOutputPort()); aCellDataToPointDataFilter1.Update(); aBoundedFilter.SetInput(aCellDataToPointDataFilter1.GetOutput()); aBoundedFilter.GenerateValues(24, sScalars.GetRange()[0], sScalars.GetRange()[1]); aBandedMapper.SetInputConnection(aBoundedFilter.GetOutputPort()); aBandedMapper.SetScalarModeToUsePointData(); aBandedMapper.SetScalarRange(sScalars.GetRange()[0], sScalars.GetRange()[1]); aBandedMapper.SetLookupTable(aLookupTable); aMeshActor.SetMapper(aBandedMapper); aScalarBarActor.SetLookupTable(aLookupTable); aScalarBarActor.SetTitle("Velocity"); aScalarBarActor.SetNumberOfLabels(6); aRenderer.Render(); if (ii == 0) { aRenderer.ResetCamera(); } aRenderControl.Refresh(); } }
static public void Simulate(CMshBasicMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid, vtkRenderer aRenderer) { var T = new CPdeFieldDouble(); aMesher.mesh().generateFaces(1E-12); aMesher.mesh().calculateFaceCentroid(); aMesher.mesh().calculateElementCentroid(); T.setMesh(aMesher.mesh()); T.setDiscretMethod(EDiscretMethod.DM_FVM); T.setDiscretOrder(EDiscretOrder.DO_LINEAR); T.setDiscretLocation(EDiscretLocation.DL_ELEMENT_CENTER); T.setSimulationType(ESimulationType.ST_THERMAL); T.setNbDofs(1); // Set BC and initial conditions T.setSize(T.mesh().nbElements()); for (int i = 0; i < T.mesh().nbFaces(); ++i) { int aFaceId = T.mesh().faceId(i); if (Math.Abs(T.mesh().faceCentroid(aFaceId).x() - 0.0) < 1E-6) { var aFixedTemperature = new CPdeBoundaryConditionDouble(EBoundaryConditionType.BT_GENERIC_FIXED_VALUE); aFixedTemperature.addCondition(EConditionType.CT_GENERIC_FIXED_VALUE, 0.0); T.addBCFace(aFaceId, aFixedTemperature); } if (Math.Abs(T.mesh().faceCentroid(aFaceId).x() - 1.0) < 1E-6) { var aFixedTemperature = new CPdeBoundaryConditionDouble(EBoundaryConditionType.BT_GENERIC_FIXED_VALUE); aFixedTemperature.addCondition(EConditionType.CT_GENERIC_FIXED_VALUE, 0.0); T.addBCFace(aFaceId, aFixedTemperature); } if (Math.Abs(T.mesh().faceCentroid(aFaceId).y() - 0.0) < 1E-6) { var aFixedTemperature = new CPdeBoundaryConditionDouble(EBoundaryConditionType.BT_GENERIC_FIXED_VALUE); aFixedTemperature.addCondition(EConditionType.CT_GENERIC_FIXED_VALUE, 0.0); T.addBCFace(aFaceId, aFixedTemperature); } if (Math.Abs(T.mesh().faceCentroid(aFaceId).y() - 1.0) < 1E-6) { var aFixedTemperature = new CPdeBoundaryConditionDouble(EBoundaryConditionType.BT_GENERIC_FIXED_VALUE); aFixedTemperature.addCondition(EConditionType.CT_GENERIC_FIXED_VALUE, 1.0); T.addBCFace(aFaceId, aFixedTemperature); } } // Steady conduction in a rectangle var aPdeEquation = new CPdeEquationDouble(ENigMA.laplacian(T)); aPdeEquation.solve(T); var sScalars = vtkFloatArray.New(); sScalars.SetNumberOfTuples(T.mesh().nbElements()); for (int i = 0; i < T.mesh().nbElements(); ++i) { int anElementId = T.mesh().elementId(i); sScalars.SetTuple1(anElementId, T.value(i)); } anUnstructuredGrid.GetCellData().SetScalars(sScalars); var aGeometryFilter = vtkGeometryFilter.New(); aGeometryFilter.SetInput(anUnstructuredGrid); aGeometryFilter.Update(); var aCellDataToPointDataFilter1 = vtkCellDataToPointData.New(); aCellDataToPointDataFilter1.SetInputConnection(aGeometryFilter.GetOutputPort()); aCellDataToPointDataFilter1.Update(); var aBoundedFilter = vtkBandedPolyDataContourFilter.New(); aBoundedFilter.SetInput(aCellDataToPointDataFilter1.GetOutput()); aBoundedFilter.GenerateValues(24, sScalars.GetRange()[0], sScalars.GetRange()[1]); var aLookupTable = vtkLookupTable.New(); aLookupTable.SetNumberOfColors(256); aLookupTable.SetHueRange(0.667, 0.0); aLookupTable.Build(); var aBandedMapper = vtkPolyDataMapper.New(); aBandedMapper.SetInputConnection(aBoundedFilter.GetOutputPort()); aBandedMapper.SetScalarModeToUsePointData(); aBandedMapper.SetScalarRange(sScalars.GetRange()[0], sScalars.GetRange()[1]); aBandedMapper.SetLookupTable(aLookupTable); // add actor to the renderer var aMeshActor = vtkActor.New(); aRenderer.AddActor(aMeshActor); aMeshActor.SetMapper(aBandedMapper); var aScalarBarActor = vtkScalarBarActor.New(); aRenderer.AddActor(aScalarBarActor); aScalarBarActor.SetLookupTable(aLookupTable); aScalarBarActor.SetTitle("Temperature"); aScalarBarActor.SetNumberOfLabels(6); aScalarBarActor.Modified(); }
static public void Simulate(CMshBasicMesherDouble aMesher, vtkUnstructuredGrid anUnstructuredGrid, vtkRenderer aRenderer) { var T = new CPdeFieldDouble(); T.setMesh(aMesher.mesh()); T.setDiscretMethod(EDiscretMethod.DM_FEM); T.setDiscretOrder(EDiscretOrder.DO_LINEAR); T.setDiscretLocation(EDiscretLocation.DL_NODE); T.setSimulationType(ESimulationType.ST_THERMAL); T.setNbDofs(1); // Set BC and initial conditions T.setSize(T.mesh().nbNodes()); for (int i = 0; i < T.mesh().nbNodes(); ++i) { int aNodeId = T.mesh().nodeId(i); var aNode = T.mesh().node(aNodeId); if (Math.Abs(aNode.x() + 0.0) < 1E-6) { T.setFixedValue(i, 0.0); } if (Math.Abs(aNode.x() - 1.0) < 1E-6) { T.setFixedValue(i, 0.0); } if (Math.Abs(aNode.y() + 0.0) < 1E-6) { T.setFixedValue(i, 0.0); } if (Math.Abs(aNode.y() - 1.0) < 1E-6) { T.setFixedValue(i, 1.0); } T.setValue(i, 0.0); } // Steady conduction in a rectangle var aPdeEquation = new CPdeEquationDouble(ENigMA.laplacian(T)); aPdeEquation.setElimination(T); aPdeEquation.solve(T); var sScalars = vtkFloatArray.New(); sScalars.SetNumberOfTuples(T.mesh().nbNodes()); for (int i = 0; i < T.mesh().nbNodes(); ++i) { int aNodeId = T.mesh().nodeId(i); sScalars.SetTuple1(aNodeId, T.value(i)); } anUnstructuredGrid.GetPointData().SetScalars(sScalars); var aGeometryFilter = vtkGeometryFilter.New(); aGeometryFilter.SetInput(anUnstructuredGrid); aGeometryFilter.Update(); var aBoundedFilter = vtkBandedPolyDataContourFilter.New(); aBoundedFilter.SetInput(aGeometryFilter.GetOutput()); aBoundedFilter.GenerateValues(24, sScalars.GetRange()[0], sScalars.GetRange()[1]); var aLookupTable = vtkLookupTable.New(); aLookupTable.SetNumberOfColors(256); aLookupTable.SetHueRange(0.667, 0.0); aLookupTable.Build(); var aBandedMapper = vtkPolyDataMapper.New(); aBandedMapper.SetInputConnection(aBoundedFilter.GetOutputPort()); aBandedMapper.SetScalarModeToUsePointData(); aBandedMapper.SetScalarRange(sScalars.GetRange()[0], sScalars.GetRange()[1]); aBandedMapper.SetLookupTable(aLookupTable); // add actor to the renderer var aMeshActor = vtkActor.New(); aRenderer.AddActor(aMeshActor); aMeshActor.SetMapper(aBandedMapper); var aScalarBarActor = vtkScalarBarActor.New(); aRenderer.AddActor(aScalarBarActor); aScalarBarActor.SetLookupTable(aLookupTable); aScalarBarActor.SetTitle("Temperature"); aScalarBarActor.SetNumberOfLabels(6); aScalarBarActor.Modified(); }