public void FirstTest() { double x0 = 0.0; double x1 = 10.0; double x2 = 8.0; double x3 = 2.0; double y0 = 0.0; double y1 = 1.0; double y2 = 8.0; double y3 = 9.0; double z0 = -10.0; double z1 = -7.0; double z2 = -8.0; double z3 = -12.0; double x = 5.0; double y = 5.0; InterpQuadrangle interpolator = new InterpQuadrangle() { DelVal = d }; InterpQuadrangle.Weights weights = InterpQuadrangle.InterpolationWeights(x, y, x0, y0, x1, y1, x2, y2, x3, y3); double value = interpolator.GetValue(weights, z0, z1, z2, z3); Assert.AreEqual(-9.34375, value); }
void DeleteValueTest(bool valOk, double x, double y, double z0, double z1, double z2, double z3, bool sdc = true) { InterpQuadrangle interpolator = new InterpQuadrangle() { DelVal = d, SmoothDeleteChop = sdc }; InterpQuadrangle.Weights weights = InterpQuadrangle.InterpolationWeights(x, y, 0, 0, 10, 0, 10, 10, 0, 10); double val = interpolator.GetValue(weights, z0, z1, z2, z3); if (valOk) { Assert.AreNotEqual(d, val); } else { Assert.AreEqual(d, val); } }
void WeightTest(double x, double y) { InterpQuadrangle.Weights interp = InterpQuadrangle.InterpolationWeights(x, y, 0, 0, 10, 0, 10, 10, 0, 10); Assert.AreEqual(x * 0.1, interp.dx, 1e-12); Assert.AreEqual(y * 0.1, interp.dy, 1e-12); }
/// <summary> /// Create DFS2 file with interpolated values from the 3x3 quadrangles, /// with various delete values applied in each time step. /// </summary> /// <param name="centerOnly">Only use center quadrangle</param> public void DeleteValueVisualDfs2Test(bool centerOnly) { 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, 200, 0, 0.1, 200, 0, 0.1)); 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; if (centerOnly) { dfs2Builder.CreateFile(UnitTestHelper.TestDataDir + "test_InterpQuadCenter.dfs2"); } else { dfs2Builder.CreateFile(UnitTestHelper.TestDataDir + "test_InterpQuad.dfs2"); } Dfs2File dfs2File = dfs2Builder.GetFile(); // Calculate interpolation weights QuadWeights[][] weights = new QuadWeights[200][]; for (int j = 0; j < 200; j++) { double y = 5 + 0.1 * j + 0.05; weights[j] = new QuadWeights[200]; for (int i = 0; i < 200; i++) { double x = 5 + 0.1 * i + 0.05; weights[j][i].Weights = InterpQuadrangle.UndefinedWeights(); for (int jr = 0; jr < 3; jr++) { for (int ir = 0; ir < 3; ir++) { if (centerOnly && (jr != 1 || ir != 1)) { continue; } double x0 = xcoords[ind(ir, jr)]; double x1 = xcoords[ind(ir + 1, jr)]; double x2 = xcoords[ind(ir + 1, jr + 1)]; double x3 = xcoords[ind(ir, jr + 1)]; double y0 = ycoords[ind(ir, jr)]; double y1 = ycoords[ind(ir + 1, jr)]; double y2 = ycoords[ind(ir + 1, jr + 1)]; double y3 = ycoords[ind(ir, jr + 1)]; if (MeshExtensions.IsPointInsideQuadrangle(x, y, x0, y0, x1, y1, x2, y2, x3, y3)) { weights[j][i].IR = ir; weights[j][i].JR = jr; weights[j][i].Weights = InterpQuadrangle.InterpolationWeights(x, y, x0, y0, x1, y1, x2, y2, x3, y3); } } } } } // Original center quadrangle values double z0 = zcoords[ind(1, 1)]; double z1 = zcoords[ind(1 + 1, 1)]; double z2 = zcoords[ind(1 + 1, 1 + 1)]; double z3 = zcoords[ind(1, 1 + 1)]; float[] data = new float[200 * 200]; VisualDfs2Data(weights, data, z0, z1, z2, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, z2, z3, false); dfs2File.WriteItemTimeStepNext(0, data); // One delete value VisualDfs2Data(weights, data, d, z1, z2, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, z2, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, z2, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, z2, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, d, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, d, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, z2, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, z2, d, false); dfs2File.WriteItemTimeStepNext(0, data); // Two adjacent delete values VisualDfs2Data(weights, data, d, d, z2, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, z2, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, d, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, d, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, z1, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, z2, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, z2, d, false); dfs2File.WriteItemTimeStepNext(0, data); // Two diagonal delete values VisualDfs2Data(weights, data, d, z1, d, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, d, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, z2, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, z2, d, false); dfs2File.WriteItemTimeStepNext(0, data); // Three delete values VisualDfs2Data(weights, data, d, d, d, z3, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, d, z3, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, z2, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, z2, d, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, z1, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, z0, d, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); // All delete values VisualDfs2Data(weights, data, d, d, d, d, true); dfs2File.WriteItemTimeStepNext(0, data); VisualDfs2Data(weights, data, d, d, d, d, false); dfs2File.WriteItemTimeStepNext(0, data); dfs2File.Close(); }
/// <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(); }