public void InterpolateNodeTest() { string triMesh = UnitTestHelper.TestDataDir + "odense_rough.mesh"; string quadMesh = UnitTestHelper.TestDataDir + "odense_rough_quads.mesh"; // Source mesh MeshFile sourcemeshFile = MeshFile.ReadMesh(triMesh); SMeshData sourcemesh = sourcemeshFile.ToSMeshData(); sourcemesh.BuildDerivedData(); // Target mesh MeshFile targetMeshFile = MeshFile.ReadMesh(quadMesh); SMeshData targetmesh = targetMeshFile.ToSMeshData(); targetmesh.BuildDerivedData(); MeshInterpolator2D interpolator = new MeshInterpolator2D(sourcemesh, MeshValueType.Nodes); interpolator.SetTarget(targetmesh, MeshValueType.Nodes); double[] target = new double[targetmesh.NumberOfNodes]; interpolator.InterpolateNodeToTarget(sourcemesh.Z, target); Assert.False(target.Any(vv => vv == interpolator.DeleteValue)); targetMeshFile.Z = target; targetMeshFile.Write(UnitTestHelper.TestDataDir + "test_odense_rough_quads-fromTri.mesh"); }
public void SMeshDataOdenseQuadsTest() { string quadMesh = UnitTestHelper.TestDataDir + "odense_rough_quads.mesh"; MeshFile meshFile = MeshFile.ReadMesh(quadMesh); SMeshData mesh = meshFile.ToSMeshData(); Assert.AreEqual(535, mesh.NumberOfNodes); Assert.AreEqual(5, mesh.NodeIds[4]); Assert.AreEqual(212827.81746849261, mesh.X[4]); Assert.AreEqual(6156804.9152286667, mesh.Y[4]); Assert.AreEqual(-0.42102556956959569, mesh.Z[4]); Assert.AreEqual(1, mesh.Code[5]); Assert.AreEqual(724, mesh.NumberOfElements); Assert.AreEqual(5, mesh.ElementIds[4]); Assert.AreEqual(3, mesh.ElementTable[4].Length); Assert.AreEqual(62, mesh.ElementTable[4][0]); // Remember: Index here is zero based, while mesh file is one-based Assert.AreEqual(367, mesh.ElementTable[4][1]); Assert.AreEqual(358, mesh.ElementTable[4][2]); mesh.BuildNodeElements(); Assert.AreEqual(4, mesh.NodesElmts[4].Count); Assert.AreEqual(33, mesh.NodesElmts[4][0] + 1); Assert.AreEqual(36, mesh.NodesElmts[4][1] + 1); Assert.AreEqual(43, mesh.NodesElmts[4][2] + 1); Assert.AreEqual(58, mesh.NodesElmts[4][3] + 1); //mesh.BuildFaces(true, true, false); //int reverts = FaceRevert(mesh, mesh.Faces); //Console.Out.WriteLine("reverts: " + reverts); //mesh.Faces.Sort(FaceSortComparer); //List<MeshFace> facesOld = mesh.Faces; //mesh.BuildFaces(true, true, true); //reverts = FaceRevert(mesh, mesh.Faces); //Console.Out.WriteLine("reverts: " + reverts); //mesh.Faces.Sort(FaceSortComparer); //List<MeshFace> facesNew = mesh.Faces; //for (int i = 0; i < facesOld.Count; i++) //{ // bool ok = FaceEquals(facesOld[i], facesNew[i]); // Assert.IsTrue(ok, "Face " + i); //} //Assert.AreEqual(1259, mesh.Faces.Count); //Assert.AreEqual(1, mesh.Faces[0].FromNode.Id); //Assert.AreEqual(42, mesh.Faces[0].ToNode.Id); //Assert.AreEqual(1, mesh.Faces[1].FromNode.Id); //Assert.AreEqual(251, mesh.Faces[1].ToNode.Id); //Assert.AreEqual(1, mesh.Faces[2].FromNode.Id); //Assert.AreEqual(309, mesh.Faces[2].ToNode.Id); //int ind = mesh.Faces.FindIndex(mf => mf.FromNode.Id == 68); //Assert.AreEqual(202, ind); //Assert.AreEqual(68, mesh.Faces[ind].FromNode.Id); //Assert.AreEqual(43, mesh.Faces[ind].ToNode.Id); //Assert.AreEqual(1, mesh.Faces[ind].Code); //Assert.AreEqual(366, mesh.Faces[ind].LeftElement.Id); //Assert.AreEqual(null, mesh.Faces[ind].RightElement); }
/// <summary> /// Create <see cref="IMeshDataInfo"/>, depending on <paramref name="smesh"/> flag. /// </summary> public static IMeshDataInfo ToMeshData(this MeshFile file, bool smesh) { if (smesh) { return(file.ToSMeshData()); } return(file.ToMeshData()); }
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); }
/// <summary> /// Create DFS2 file with iterpolated values from the 3x3 quadrangles, /// with various delete values applied in each time step. /// </summary> public void DeleteValueVisualDfs2DoTest() { string meshFileName = UnitTestHelper.TestDataDir + "small.mesh"; MeshFile file = MeshFile.ReadMesh(meshFileName); _meshVisual = file.ToSMeshData(); DfsFactory factory = new DfsFactory(); Dfs2Builder dfs2Builder = new Dfs2Builder(); dfs2Builder.SetDataType(0); dfs2Builder.SetTemporalAxis(factory.CreateTemporalEqTimeAxis(eumUnit.eumUsec, 0, 1)); dfs2Builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUmeter, 80, 0, 0.01, 80, 0, 0.01)); dfs2Builder.SetGeographicalProjection(factory.CreateProjectionUndefined()); dfs2Builder.AddDynamicItem("DeleteValueSmooth", eumQuantity.UnDefined, DfsSimpleType.Float, DataValueType.Instantaneous); dfs2Builder.AddDynamicItem("DeleteValueBox", eumQuantity.UnDefined, DfsSimpleType.Float, DataValueType.Instantaneous); dfs2Builder.DeleteValueFloat = (float)d; dfs2Builder.CreateFile(UnitTestHelper.TestDataDir + "test_InterpTri.dfs2"); Dfs2File dfs2File = dfs2Builder.GetFile(); // Calculate interpolation weights MeshWeights[][] weights = new MeshWeights[80][]; for (int j = 0; j < 80; j++) { double y = 0.2 + 0.01 * j + 0.005; weights[j] = new MeshWeights[80]; for (int i = 0; i < 80; i++) { double x = 0.4 + 0.01 * i + 0.005; weights[j][i].QuadWeights = InterpQuadrangle.UndefinedWeights(); weights[j][i].TriWeights = InterpTriangle.UndefinedWeights(); for (int ielmt = 0; ielmt < _meshVisual.NumberOfElements; ielmt++) { var elmtNodes = _meshVisual.ElementTable[ielmt]; if (elmtNodes.Length == 4) { double x0 = _meshVisual.X[elmtNodes[0]]; double x1 = _meshVisual.X[elmtNodes[1]]; double x2 = _meshVisual.X[elmtNodes[2]]; double x3 = _meshVisual.X[elmtNodes[3]]; double y0 = _meshVisual.Y[elmtNodes[0]]; double y1 = _meshVisual.Y[elmtNodes[1]]; double y2 = _meshVisual.Y[elmtNodes[2]]; double y3 = _meshVisual.Y[elmtNodes[3]]; if (MeshExtensions.IsPointInsideQuadrangle(x, y, x0, y0, x1, y1, x2, y2, x3, y3)) { weights[j][i].ElmtIndex = ielmt; weights[j][i].QuadWeights = InterpQuadrangle.InterpolationWeights(x, y, x0, y0, x1, y1, x2, y2, x3, y3); } } else { double x0 = _meshVisual.X[elmtNodes[0]]; double x1 = _meshVisual.X[elmtNodes[1]]; double x2 = _meshVisual.X[elmtNodes[2]]; double y0 = _meshVisual.Y[elmtNodes[0]]; double y1 = _meshVisual.Y[elmtNodes[1]]; double y2 = _meshVisual.Y[elmtNodes[2]]; if (MeshExtensions.IsPointInsideTriangle(x, y, x0, y0, x1, y1, x2, y2)) { weights[j][i].ElmtIndex = ielmt; weights[j][i].TriWeights = InterpTriangle.InterpolationWeights(x, y, x0, y0, x1, y1, x2, y2); } } } } } // Original center quadrangle values double z4 = _meshVisual.Z[3]; double z6 = _meshVisual.Z[5]; double z8 = _meshVisual.Z[7]; float[] data = new float[80 * 80]; VisualDfs2Data(weights, data, z4, z6, z8, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, z6, z8, false); dfs2File.WriteItemTimeStepNext(0, data); // One delete value VisualDfs2Data(weights, data, d, z6, z8, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z6, z8, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, d, z8, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, d, z8, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, z6, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, z6, d, false); dfs2File.WriteItemTimeStepNext(0, data); // Two adjacent delete values VisualDfs2Data(weights, data, d, d, z8, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, z8, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z4, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z6, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z6, d, false); dfs2File.WriteItemTimeStepNext(0, data); // All delete values VisualDfs2Data(weights, data, d, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); dfs2File.Close(); }