Ejemplo n.º 1
0
        static public void Simulate(CMshTriangleMesherDouble 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();
        }
Ejemplo n.º 2
0
        private void Simulate(CMshTriangleMesherDouble 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, 0.0);
                }

                T.setValue(i, 1.0);
            }

            double rho = 1.0;   // density
            double Cp  = 1.0;   // specific heat
            double k   = 1.0;   // conductivity

            double time  = 0.1;
            int    nIter = 10;
            double dt    = time / nIter;

            // Unsteady conduction in a plate
            for (int i = 0; i < nIter; ++i)
            {
                Debug.WriteLine("Time = " + dt * (i + 1));

                var aTransientTerm = new CSleSystemDouble();
                aTransientTerm = ENigMA.ddt(T);
                aTransientTerm.Multiply(rho * Cp / dt);

                var aDiffusionTerm = new CSleSystemDouble();
                aDiffusionTerm = ENigMA.laplacian(T);
                aDiffusionTerm.Multiply(k);

                var aSystem = new CSleSystemDouble();
                aSystem = aTransientTerm;
                aSystem.Plus(aDiffusionTerm);

                var aPdeEquation = new CPdeEquationDouble(aSystem);

                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 aControlVolumeId = T.mesh().nodeId(i);

                sScalars.SetTuple1(aControlVolumeId, 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 MeshActor = vtkActor.New();

            aRenderer.AddActor(MeshActor);

            var MeshMapper = vtkDataSetMapper.New();

            MeshMapper.SetInput(anUnstructuredGrid);

            MeshActor.SetMapper(aBandedMapper);
        }
Ejemplo n.º 3
0
        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();
        }