AjayMenon

60 Reputation

4 Badges

2 years, 134 days
Ajay is a research student working in the fields of ocean engineering, renewable offshore energy, and wave-structure interactions. Majoring in Ocean Engineering and Naval Architecture, his interest mainly lies in the intersection of technology and theoretical engineering. Using tools such as Maple, Matlab, Python, Solidworks, Ansys, and AutoCAD, Ajay looks to harness powerful computational platforms to improve simulation accuracy and efficiency while better understanding the concepts that drive these tools.

MaplePrimes Activity


These are questions asked by AjayMenon

Hi there!

I have developed a component in Modelica to import values from a Matlab struct into MapleSim and use it with other components. This data is saved in a ".mat" file and the struct was constructed as follows:

% Matlab command window
% Struct name is "bemData" saved in a v7 format to be read in by Modelica
>> bemData.m33 = 100;
>> bemData.Ainf33 = 100;
>> bemData.Khs33 = 20000;
>> bemData.ss_rad33.A = [1 1;0 1];
>> bemData.ss_rad33.B = [1;0];
>> bemData.ss_rad33.C = [1 1];
>> bemData.ss_rad33.D = 0;
>> save -v7 bemData.mat

And the Modelica code I am using to try import this into MapleSim is as follows:

Modelica.SIunits.Mass M = scalar(Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.m33",1,1));

Modelica.SIunits.Mass Ainf = scalar(Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.Ainf33",1,1));

Modelica.SIunits.TranslationalSpringConstant C = scalar(Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.Khs33",1,1));
    
Real A[2,2] = Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.ss_rad33.A",2,2);

Real B[1,2] = transpose(Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.ss_rad33.B",2,1));

Real C[1,2] = Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.ss_rad33.C",1,2);

Real D = scalar(Modelica.Utilities.Streams.readRealMatrix("bemData.mat","bemData.ss_rad33.D",1,1));

I then use these imported variables to solve ODEs, and the result is incorrect. I have narrowed it down to the fact that MapleSim/Modelica imports a value of 0 in place of the original data in the struct. Moreover, there is no way to attach a probe to any of the imported variables in MapleSim (I need to force all model variables to be displayed in the Simulation results tab).

I would appreciate help in pointing out where I might be making a mistake. My primary concern is why a value of 0 is being imported in place of the actual Matlab struct data. When I use Matlab's command window to check the contents of the struct, they appear to be in order.

Also, I have saved the struct file in the same folder in which my custom component is stored (the Modelica file where I have written the code to import the data). Should I be saving this file elsewhere?

Thank you!

Hi there!

I'm attempting to develop a custom library in MapleSim (a Modelica solver engine) that can use convolution integrals to model the hydrodynamic behaviour of floating bodies. The convolution integral is mathematically represented as follows:

a general form of a convolution integral, spanning from negative to positive infinity in time

And the equation I'm particularly interested in solving is as follows:

Cummins equation to determine the motion of a floating body in waves

I'm trying to solve this convolution integral in Modelica using a model that can be imported to MapleSim. So far, I've had no luck in implementing this convolution for continuous functions symbolically. I have used a numerical approach on 2 arrays using the following approach in Modelica:

// Modelica function
function convIntegral
  input Real simTime;  // Simulation time
  input Real f[:];     // Kernel function array
  input Real g[:];     // Second function array

  output Real h[(2*simTime) - 1];    // Output the convolution integral in the form of an array
  
  // Define the algorithm to numerically compute the convolution integral of 2 arrays
  algorithm
    // Initialize the output array with zeroes
    for i in 1:((2*simTime) - 1) loop
      h[i] := 0;
    end for;
    
    // Iterate over the simulation time
    // Recursively increment the convolution array with the pointwise product of the 2 functions
    for i in 1:simTime loop
      for j in 1:simTime loop
        h[i+j-1] := (f[i] * g[j]) + h[i+j-1];
      end for;
    end for;
end convIntegral;
// End of function to compute the convolution integral

This works perfectly for discrete samples and I have verified it with output from Matlab's inbuilt function

conv(A,B)  % For 2 arrays A and B

However, I would like to implement this on 2 continuous functions and this numerical approach does not work since MapleSim does not support conversion between discrete and continuous signals.

I understand that convolution is essentially an operation between two functions, where we time-flip one of the functions (kernel) and then slide it across the other function while measuring the bounded area and outputting that as the result of the convolution. I include this image from Wikipedia that sums up convolution: (Not including links as they mark questions as spam)

I've tried implementing this in Modelica using the following code:

// Model to perform convolution on 2 continuous functions
model ConvolutionalIntegral

  extends Modelica.Blocks.Icons.Block;

  // Define model variables
  Real kernelFunction = (e ^ (-0.5 * time)) * cos(0.5 * time);  // I've taken an example of a function I might use
  Real kernelFunctionFlipped = (e ^ (-0.5 * (T_sim - time))) * cos(0.5 * (T_sim - time));  // I've flipped the kernel function about the vertical axis by converting the (time) variable to (T_sim - time) where (T_sim) is a variable storing the simulation duration
  Real secondFunction;  // The other function for the convolution
  Real convolutionIntegralOutput;  // Function to store the output
  
  equation
    // Convolution implementation
    der(convolutionIntegralOutput) = kernelFunctionFlipped * secondFunction;

    // Final equation to solve
    der(secondFunction) + convolutionIntegralOutput = 0;
    // An example of a differential equation I'd like to solve involving the convolution integral
    
end ConvolutionIntegral;

I had hoped that this would yield the output of the convolution since I'm essentially multiplying the time-flipped kernel and the other function and then integrating them over time. However, the output does not provide the expected result and it appears that Modelica interprets my code to mean that I'm integrating the pointwise product of these 2 functions over time instead of sliding the kernel over the other function.

I'd appreciate it if you could take a look at my code and my approach to solving the convolution integral symbolically, and point out where I'm making a mistake and what a possible fix might be.

Thank you!

Hi there!

I'm working on implementing a custom Modelica Library in MapleSim 2021. I have Maple 2021 installed and my software is up to date. The library I have developed is in a single file (extension ".mo") which I developed on an IDE for Modelica i.e., I did not create the library using MapleSim. During the import into MapleSim, no errors appear in the system logs. All my components and models have been imported except for an "expandable connector". It appears that the problem is with the term "expandable".

Since this expandable connector does not appear among my library components, I attempted to create a custom component using the Modelica code editor in MapleSim. However, the file cannot be saved while I prefix the term "expandable" to "connector". The software allows me to save the file with the new code after dropping the "expandable" term.

I know that expandable connectors are used by Modelica. Here are the references I used during development:

https://mbe.modelica.university/components/architectures/expandable/

Working with Expandable Connectors - Claytex

However, there does not seem to be any information on expandable connectors in MapleSim. I'd appreciate it if any of you could throw some light on why I'm not able to import this component into MapleSim and fixes/suggestions on what I might be doing wrong. If any further information on my question is required, please do let me know.

Page 1 of 1