C# DPF API Example

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 472
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭

C# DPF API Example

Tagged:

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 472
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited February 2024

    How to Use this example project

    Windows:

    If DPF was installed as part of a normal Ansys Software installation, the
    required .dll files are available for running the DPF capabilities

    you can create a .bat file to laucnh Visual studio with these lines:

    set AWP_ROOTDV_DEV=C:\Program Files\Ansys Inc\v241
    set PATH=%AWP_ROOTDV_DEV%\aisol\bin\winx64;%PATH%

    start "" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe"

    and then load the dpf_csharp_client.csproj

    dpf_csharp_client.csproj

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <Platforms>AnyCPU;x64</Platforms>
      </PropertyGroup>
    
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <PlatformTarget>x64</PlatformTarget>
        <OutputPath>$(AWP_ROOTDV_DEV)\aisol\bin\winx64\</OutputPath>
        <WarningLevel>0</WarningLevel>
      </PropertyGroup>
    
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
        <PlatformTarget>x64</PlatformTarget>
        <OutputPath>$(AWP_ROOTDV_DEV)\aisol\bin\winx64\</OutputPath>
        <WarningLevel>0</WarningLevel>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
      </PropertyGroup>
    
      <ItemGroup>
        <Reference Include="Ans_Dpf_FEMutils_dll_cs">
          <HintPath>$(AWP_ROOTDV_DEV)\aisol\bin\winx64\Ans_Dpf_FEMutils_dll_cs.dll</HintPath>
        </Reference>
        <Reference Include="Ans_Dpf_Native_dll_cs">
          <HintPath>$(AWP_ROOTDV_DEV)\aisol\bin\winx64\Ans_Dpf_Native_dll_cs.dll</HintPath>
        </Reference>
        <Reference Include="CS_DataProcessing">
          <HintPath>$(AWP_ROOTDV_DEV)\aisol\bin\winx64\CS_DataProcessing.dll</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
    

    Program.cs

    using System;
    using System.IO;
    using Ans.DataProcessing;
    
    namespace dpf_csharp_client
    {
        class Program
        {
            static void Main(string[] args)
            {
                /* this will only work on Windows */
                Environment.CurrentDirectory = Environment.GetEnvironmentVariable("AWP_ROOTDV_DEV");
                DataProcessingCore.InitializationWithContext(1, Environment.CurrentDirectory .ToString()+ "\\dpf\\utilities\\DpfCoreStandalone.xml");
                /* DataProcessingCore.Initialization(); */
    
    
                /* read displacements from an rst file */
                var op = new Ans.DataProcessing.operators.result.displacement();
                op.inputs.data_sources.Connect(new DataSources("C:\\temp\\file.rst"));
                var fields = op.outputs.getfields_container();
    
                var field = fields[0];
    
                /* read a mesh from an rst file */
                var op2 = new Ans.DataProcessing.operators.mesh.mesh_provider();
                op2.inputs.data_sources.Connect(new DataSources("C:\\temp\\file.rst"));
                var mesh = op2.outputs.getmesh();
    
                var nrmop = new Ans.DataProcessing.operators.math.norm_fc(fields);
                fields = nrmop.outputs.getfields_container();
                field = fields[0];
    
    
            }
        }
    }
    

    launchSettings.json

    {
      "profiles": {
        "dpf_csharp_client": {
          "commandName": "Project",
          "workingDirectory": "$(AWP_ROOTDV_DEV)\\aisol\\Bin\\winx64"
        }
      }
    }
    

    Set-up the above mentioned files in the following folder structure: