-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,728 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
| ||
/* | ||
* Gmsh.GH | ||
* Copyright 2023 Tom Svilans | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using Rhino; | ||
using Rhino.Geometry; | ||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Data; | ||
using Grasshopper.Kernel.Types; | ||
using Grasshopper; | ||
|
||
using GmshCommon; | ||
|
||
namespace GmshCommon.GH | ||
{ | ||
|
||
public class Cmpt_Mesh2D : GH_Component | ||
{ | ||
public Cmpt_Mesh2D() | ||
: base("Gmsh2D", "Gmsh2D", | ||
"Mesh 2D entities.", | ||
"Gmsh", "Meshing") | ||
{ | ||
} | ||
|
||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddGenericParameter("Mesh", "M", "Mesh to remesh.", GH_ParamAccess.item); | ||
pManager.AddNumberParameter("SizeMin", "Min", "Minimum mesh size.", GH_ParamAccess.item, 10.0); | ||
pManager.AddNumberParameter("SizeMax", "Max", "Maximum mesh size.", GH_ParamAccess.item, 100.0); | ||
pManager.AddBooleanParameter("Remesh", "R", "Remesh mesh geometry.", GH_ParamAccess.item, false); | ||
|
||
pManager[1].Optional = true; | ||
pManager[2].Optional = true; | ||
pManager[3].Optional = true; | ||
} | ||
|
||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddMeshParameter("Mesh", "M", "Meshed object.", GH_ParamAccess.list); | ||
|
||
pManager.AddIntegerParameter("Node IDs", "NI", "Node IDs.", GH_ParamAccess.list); | ||
pManager.AddPointParameter("Node Positions", "NP", "Node positions.", GH_ParamAccess.list); | ||
pManager.AddIntegerParameter("Element IDs", "EI", "Element IDs.", GH_ParamAccess.list); | ||
pManager.AddIntegerParameter("Element Nodes", "EN", "Element node IDs.", GH_ParamAccess.tree); | ||
} | ||
|
||
protected override void SolveInstance(IGH_DataAccess DA) | ||
{ | ||
double size_min = 10.0, size_max = 100.0; | ||
bool create_geometry = false; | ||
|
||
DA.GetData("SizeMin", ref size_min); | ||
DA.GetData("SizeMax", ref size_max); | ||
DA.GetData("Remesh", ref create_geometry); | ||
|
||
Mesh mesh = null; | ||
|
||
DA.GetData("Mesh", ref mesh); | ||
|
||
if (mesh == null) return; | ||
|
||
Gmsh.InitializeGmsh(); | ||
Gmsh.Clear(); | ||
Gmsh.Logger.Start(); | ||
|
||
var mesh_id = -1; | ||
|
||
// Add mesh data | ||
try | ||
{ | ||
mesh_id = GmshCommon.GeometryExtensions.TransferMesh(mesh, create_geometry); | ||
} | ||
catch (Exception e) | ||
{ | ||
string msg = Gmsh.Logger.GetLastError(); | ||
|
||
var log = Gmsh.Logger.Get(); | ||
foreach (string l in log) | ||
msg += String.Format("\n {0}", log); | ||
|
||
throw new Exception(msg); | ||
} | ||
|
||
if (mesh_id < 0) return; | ||
|
||
|
||
// Get 2D entities (the mesh we just transferred) | ||
Tuple<int, int>[] surfaceTags; | ||
Gmsh.GetEntities(out surfaceTags, 2); | ||
//Message = String.Format("{0} : {1}", mesh_id, surfaceTags[0].Item2); | ||
|
||
var loop = Gmsh.Geo.AddSurfaceLoop(surfaceTags.Select(x => x.Item2).ToArray()); | ||
|
||
//var loop = Gmsh.Geo.AddSurfaceLoop(new int[] { mesh_id }); | ||
var vol = Gmsh.Geo.AddVolume(new int[] { loop }); | ||
|
||
Gmsh.Geo.Synchronize(); | ||
|
||
// Set mesh sizes | ||
int element_order = 1; | ||
Gmsh.SetNumber("Mesh.MeshSizeMin", size_min); | ||
Gmsh.SetNumber("Mesh.MeshSizeMax", size_max); | ||
|
||
Gmsh.SetNumber("Mesh.SaveAll", 0); | ||
Gmsh.SetNumber("Mesh.SaveGroupsOfElements", -1001); | ||
Gmsh.SetNumber("Mesh.SaveGroupsOfNodes", 2); | ||
Gmsh.SetNumber("Mesh.ElementOrder", element_order); | ||
|
||
// Generate mesh | ||
Gmsh.Generate(3); | ||
|
||
mesh = GmshCommon.GeometryExtensions.GetMesh(); | ||
|
||
mesh.Compact(); | ||
List<Mesh> meshes = new List<Mesh>(); | ||
|
||
meshes.Add(mesh); | ||
|
||
DA.SetDataList(0, meshes); | ||
|
||
Gmsh.FinalizeGmsh(); | ||
} | ||
|
||
protected override System.Drawing.Bitmap Icon | ||
{ | ||
get | ||
{ | ||
return null; | ||
// return Properties.Resources.GridSample_01; | ||
} | ||
} | ||
|
||
public override Guid ComponentGuid | ||
{ | ||
/* | ||
0fe48fc4-68ff-484a-949c-37bae7f882c1 | ||
45094c4f-ef59-4a0a-b30a-6a3fcc21a024 | ||
*/ | ||
get { return new Guid("242113a3-bccd-476b-89b1-306c18d4e930"); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<TargetExt>.gha</TargetExt> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{A38DAD71-C6D5-4835-A6FD-8C7F50352532}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Gmsh.GH</RootNamespace> | ||
<AssemblyName>Gmsh.GH</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>$(SolutionDir)..\bin\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<LangVersion>7.3</LangVersion> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
<OutputPath>$(SolutionDir)..\bin\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<LangVersion>7.3</LangVersion> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Eto, Version=2.7.0.0, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\RhinoCommon.7.23.22282.13001\lib\net48\Eto.dll</HintPath> | ||
</Reference> | ||
<Reference Include="GH_IO, Version=7.23.22282.13001, Culture=neutral, PublicKeyToken=6a29997d2e6b4f97, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Grasshopper.7.23.22282.13001\lib\net48\GH_IO.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Grasshopper, Version=7.23.22282.13001, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Grasshopper.7.23.22282.13001\lib\net48\Grasshopper.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rhino.UI, Version=7.23.22282.13001, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\RhinoCommon.7.23.22282.13001\lib\net48\Rhino.UI.dll</HintPath> | ||
</Reference> | ||
<Reference Include="RhinoCommon, Version=7.23.22282.13001, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\RhinoCommon.7.23.22282.13001\lib\net48\RhinoCommon.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Cmpt_Mesh2D.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Utility.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\GmshCommon\GmshCommon.vcxproj"> | ||
<Project>{2089cd1f-e51f-4fe7-9bc0-20d7f22ddf10}</Project> | ||
<Name>GmshCommon</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="..\packages\RhinoCommon.7.23.22282.13001\build\net48\RhinoCommon.targets" Condition="Exists('..\packages\RhinoCommon.7.23.22282.13001\build\net48\RhinoCommon.targets')" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\RhinoCommon.7.23.22282.13001\build\net48\RhinoCommon.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\RhinoCommon.7.23.22282.13001\build\net48\RhinoCommon.targets'))" /> | ||
<Error Condition="!Exists('..\packages\Grasshopper.7.23.22282.13001\build\net48\Grasshopper.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grasshopper.7.23.22282.13001\build\net48\Grasshopper.targets'))" /> | ||
</Target> | ||
<Import Project="..\packages\Grasshopper.7.23.22282.13001\build\net48\Grasshopper.targets" Condition="Exists('..\packages\Grasshopper.7.23.22282.13001\build\net48\Grasshopper.targets')" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Gmsh.GH")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("KADK")] | ||
[assembly: AssemblyProduct("Gmsh.GH")] | ||
[assembly: AssemblyCopyright("Copyright © KADK 2023")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("a38dad71-c6d5-4835-a6fd-8c7f50352532")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.