Example #1
0
 /// <summary>
 /// Create interpolator based on <paramref name="sourceMesh"/>
 /// </summary>
 public MeshInterpolator2D(SMeshData sourceMesh, MeshValueType sourceType)
 {
     _smesh      = sourceMesh;
     _sourceType = sourceType;
     _ssearcher  = new SMeshSearcher(_smesh);
     _ssearcher.SetupElementSearch();
     Init();
 }
Example #2
0
        /// <summary>
        /// Set a target being all elements of the <paramref name="targetMesh"/>
        /// </summary>
        public void SetTarget(MeshData targetMesh, MeshValueType targetType)
        {
            if (targetType == MeshValueType.Elements)
            {
                SetTargetSize(targetMesh.NumberOfElements);
                for (int i = 0; i < targetMesh.NumberOfElements; i++)
                {
                    MeshElement targetMeshElement = targetMesh.Elements[i];
                    AddTarget(targetMeshElement.XCenter, targetMeshElement.YCenter);
                }
            }
            else
            {
                SetTargetSize(targetMesh.NumberOfNodes);

                for (int i = 0; i < targetMesh.NumberOfNodes; i++)
                {
                    MeshNode targetMeshNode = targetMesh.Nodes[i];
                    AddTarget(targetMeshNode.X, targetMeshNode.Y);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Set a target being all elements of the <paramref name="targetMesh"/>
        /// </summary>
        public void SetTarget(SMeshData targetMesh, MeshValueType targetType)
        {
            if (targetType == MeshValueType.Elements)
            {
                if (targetMesh.ElementXCenter == null)
                {
                    targetMesh.CalcElementCenters();
                }

                SetTargetSize(targetMesh.NumberOfElements);
                for (int i = 0; i < targetMesh.NumberOfElements; i++)
                {
                    AddTarget(targetMesh.ElementXCenter[i], targetMesh.ElementYCenter[i]);
                }
            }
            else
            {
                SetTargetSize(targetMesh.NumberOfNodes);
                for (int i = 0; i < targetMesh.NumberOfNodes; i++)
                {
                    AddTarget(targetMesh.X[i], targetMesh.Y[i]);
                }
            }
        }
Example #4
0
        public void InterpolateToXYExample(bool nodeInterp)
        {
            // Source mesh
            string    triMesh  = UnitTestHelper.TestDataDir + "small.mesh";
            MeshFile  meshFile = MeshFile.ReadMesh(triMesh);
            SMeshData mesh     = meshFile.ToSMeshData();

            // Build derived data, required for the interpolation routines
            mesh.BuildDerivedData();

            // Create element center Z values array
            double[] elmtZ = new double[meshFile.NumberOfElements];
            Array.Copy(mesh.ElementZCenter, elmtZ, mesh.NumberOfElements);
            // Make a strong peak at element 5 - in the center of the mesh
            elmtZ[4] = -6;

            // Set up so source can be both element values and node values
            MeshValueType sourceType = MeshValueType.Elements | MeshValueType.Nodes;

            // Mesh interpolator
            MeshInterpolator2D interpolator = new MeshInterpolator2D(mesh, sourceType);

            if (nodeInterp)
            {
                // Simpler interpolation type
                interpolator.ElementValueInterpolationType = MeshInterpolator2D.ElmtValueInterpolationType.NodeValues;
            }

            // Interpolate elmtZ to nodeZ
            double[] nodeZInterp = new double[mesh.NumberOfNodes];
            interpolator.SetupElmtToNodeInterpolation();
            interpolator.NodeInterpolator.Interpolate(elmtZ, nodeZInterp);

            // Interpolation of values one-by-one, no storing of interpolation weights
            Assert.AreEqual(-5.999, interpolator.InterpolateElmtToXY(0.7833, 0.531, elmtZ, nodeZInterp), 1e-3);
            Assert.AreEqual(-3.543, interpolator.InterpolateNodeToXY(0.7833, 0.531, nodeZInterp), 1e-3);

            // Add targets, to store interpolation weights
            interpolator.SetTargetSize(mesh.NumberOfElements + 1);
            interpolator.AddTarget(0.7833, 0.531); // Target at (almost) center of element 5
            for (int i = 0; i < mesh.NumberOfElements; i++)
            {
                interpolator.AddTarget(mesh.ElementXCenter[i], mesh.ElementYCenter[i]);
            }

            // Array to interpolate values to
            double[] targetValues = new double[mesh.NumberOfElements + 1];
            // Interpolate to all target points
            interpolator.InterpolateElmtToTarget(elmtZ, targetValues);

            if (!nodeInterp)
            {
                // When element+node values are used, close to peak value of 6
                Assert.AreEqual(-5.999, targetValues[0], 1e-3);
                Assert.AreEqual(-3.8225, targetValues[1], 1e-3);
                for (int i = 0; i < mesh.NumberOfElements; i++)
                {
                    Assert.AreEqual(elmtZ[i], targetValues[i + 1]);
                }
            }
            else // Using only node interpolation, the value is cut off
            {
                Assert.AreEqual(-3.543, targetValues[0], 1e-3);
                Assert.AreEqual(-3.649, targetValues[1], 1e-3);
            }

            // Interpolating in node Z values, matching to box center value of element.
            interpolator.InterpolateNodeToTarget(mesh.Z, targetValues);
            Assert.AreEqual(-4.376, targetValues[0], 1e-3);
            Assert.AreEqual(-4.376, mesh.ElementZCenter[4], 1e-3);
        }