using System; using ccm2math1Lib; using meshtools = ccm2meshtoolsLib; using meshtools1D = ccm2meshtools1dLib; using triamesh = ccm2triameshLib; using quadmesh = ccm2quadmeshLib; namespace example_Csharp { /// /// Very simple C# program to mesh a square with triangles or quadrangles. /// Uses CM2 TriaMesh and CM2 QuadMesh through the COM interface. /// class Class1 { /// /// Main entry. /// [STAThread] static void Main(string[] args) { try { DoubleMat pos = new DoubleMat(); UIntVec indices = new UIntVec(); UIntMat connectB = new UIntMat(); UIntMat connectM = new UIntMat(); meshtools.MeshTools MT = new meshtools.MeshTools(); meshtools1D.MeshTools1D MT1D = new meshtools1D.MeshTools1D(); // The mesh generators. triamesh.mesher mesherT3 = new triamesh.mesher(); quadmesh.mesher mesherQ4 = new quadmesh.mesher(); triamesh.data_type dataT3 = new triamesh.data_type(); quadmesh.data_type dataQ4 = new quadmesh.data_type(); // Registration of the DLLs. mesherT3.registration ("Licensed to DEMO.", "FC5B65DEDF55"); mesherQ4.registration ("Licensed to DEMO.", "7FA4A61046AA"); // Construct the four vertices of the square. pos.push_back2 ( 0.0, 0.0); pos.push_back2 (10.0, 0.0); pos.push_back2 (10.0, 10.0); pos.push_back2 ( 0.0, 10.0); // Mesh the four segments (10 elements on each segment). MT1D.mesh_straight1 (pos, 0, 1, 10, indices); indices.pop_back(); MT1D.mesh_straight1 (pos, 1, 2, 10, indices); indices.pop_back(); MT1D.mesh_straight1 (pos, 2, 3, 10, indices); indices.pop_back(); MT1D.mesh_straight1 (pos, 3, 0, 10, indices); MT1D.indices_to_connectE2 (indices, connectB); // Do the triangle mesh. dataT3.pos = pos; dataT3.connectB = connectB; mesherT3.run (dataT3); if (dataT3.error_code != 0) // Catch errors. { string msg1 = dataT3.msg1; throw new Exception ("CM2 Exception: " + msg1); } pos = dataT3.pos; connectM = dataT3.connectM; dataT3.print_info(); // MEDIT output of the triangle mesh MT.medit_output ("T3.mesh", pos, connectM, meshtools.Celement_type.CM2_FACET3); // Do the quadrangle mesh. dataQ4.pos = pos; dataQ4.connectB = connectB; mesherQ4.run (dataQ4); if (dataQ4.error_code != 0) // Catch errors. { string msg1 = dataQ4.msg1; throw new Exception ("CM2 Exception: " + msg1); } pos = dataQ4.pos; connectM = dataQ4.connectM; dataQ4.print_info(); // MEDIT output of the quadrangle mesh MT.medit_output ("Q4.mesh", pos, connectM, meshtools.Celement_type.CM2_FACEQ4); } catch (Exception ex) { Console.WriteLine (ex.ToString()); } } } }