diff --git a/src/Triangle/IO/MfemMesh.cs b/src/Triangle/IO/MfemMesh.cs
index 48b6622..3ca8052 100644
--- a/src/Triangle/IO/MfemMesh.cs
+++ b/src/Triangle/IO/MfemMesh.cs
@@ -13,10 +13,13 @@ namespace TriangleNet.IO
///
/// A simple helper class to write a mesh using MFEM mesh format and send it to GLVis.
///
+ ///
+ /// See https://mfem.org/mesh-format-v1.0/ and https://glvis.org/
+ ///
public static class MfemMesh
{
///
- /// Send the to default GLVis socket (127.0.0.1:19916).
+ /// Send the mesh to default GLVis socket (127.0.0.1:19916).
///
/// The mesh to send.
/// The port number (default = 19916).
@@ -26,35 +29,28 @@ public static async Task Send(IMesh mesh, int port = 19916)
}
///
- /// Number the vertices and write them to a .node file.
+ /// Send the mesh to the given GLVis socket.
///
/// The mesh to send.
/// The IP address.
/// The port number.
public static async Task Send(IMesh mesh, IPAddress ip, int port)
{
- var client = new TcpClient();
+ using var client = new TcpClient();
- try
- {
- await client.ConnectAsync(ip, port);
-
- var stream = client.GetStream();
-
- using (var sw = new StreamWriter(stream) { NewLine = "\n" })
- {
- sw.WriteLine("mesh"); // fem2d_gf_data
- sw.WriteLine();
+ await client.ConnectAsync(ip, port);
- Write(mesh, sw);
- }
+ var stream = client.GetStream();
- client.Close();
- }
- catch (Exception e)
+ using (var sw = new StreamWriter(stream) { NewLine = "\n" })
{
- Console.WriteLine(e.Message);
+ sw.WriteLine("mesh");
+ sw.WriteLine();
+
+ Write(mesh, sw);
}
+
+ client.Close();
}
///
@@ -65,7 +61,10 @@ public static async Task Send(IMesh mesh, IPAddress ip, int port)
public static void Write(IMesh mesh, string filename)
{
using var file = File.Open(filename, FileMode.Create);
- using var sw = new StreamWriter(file);
+ using var sw = new StreamWriter(file)
+ {
+ NewLine = "\n"
+ };
Write(mesh, sw);
}
@@ -77,15 +76,16 @@ public static void Write(IMesh mesh, string filename)
/// The target stream.
public static void Write(IMesh mesh, Stream stream)
{
- using var sw = new StreamWriter(stream);
+ using var sw = new StreamWriter(stream)
+ {
+ NewLine = "\n"
+ };
Write(mesh, sw);
}
private static void Write(IMesh mesh, StreamWriter sw)
{
- sw.NewLine = "\n";
-
mesh.Renumber();
// Header