CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Open Source Meshers: Gmsh, Netgen, CGNS, ...

solving a matrix 2x2 inside the geo file!

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By alexeym

Reply
 
LinkBack Thread Tools Display Modes
Old   June 16, 2017, 01:34
Default solving a matrix 2x2 inside the geo file!
  #1
Member
 
OpenFoam
Join Date: Jun 2016
Posts: 82
Rep Power: 3
CFD-Lover is on a distinguished road
Hello All,

I am working on a small problem in the geo file, which involves solving a matrix 2x2 to fit a polynomial. I was wondering if there is any way to do that. I have created the following code in Matlab and I want to do the same in the geo file

Code:
clear all;clc;close all
R = 0.509515; % m
R1 = 0.559467; % m
R2 = 0.579594; % m
L = 0;
L1 = -0.08568; 
L2 = 0.13974; 
hold on
plot([L L1 L2],[R R1 R2],'k.')

y = [R1-R;R2-R];
x = [L1^2 L1;L2^2 L2];
c = x\y;

x1 = linspace(-0.08568,0.13974,20);
for ii = 1:length(x1)
    y(ii) = c(1)*x1(ii)^2+c(2)*x1(ii)+R;
end
plot(x1,y)
Many thanks,
CFD-Lover is offline   Reply With Quote

Old   June 17, 2017, 02:04
Default
  #2
Member
 
OpenFoam
Join Date: Jun 2016
Posts: 82
Rep Power: 3
CFD-Lover is on a distinguished road
Can I for instance call a Matlab script through the .geo file in order to get the coefficients c1 and c2 that will be used in the geo file?

Thanks,
CFD-Lover is offline   Reply With Quote

Old   June 17, 2017, 06:44
Default
  #3
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,734
Rep Power: 29
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi,

Why you cannot put this simple analytic solution into geo:

\left[\begin{matrix}\left(- R + R_{1}\right) \left(\frac{L_{2}}{L_{1}^{2} \left(L_{1} - L_{2}\right)} + \frac{1}{L_{1}^{2}}\right) - \frac{- R + R_{2}}{L_{2} \left(L_{1} - L_{2}\right)}\\\frac{L_{1} \left(- R + R_{2}\right)}{L_{2} \left(L_{1} - L_{2}\right)} - \frac{L_{2} \left(- R + R_{1}\right)}{L_{1} \left(L_{1} - L_{2}\right)}\end{matrix}\right]

But it you REALLY want to call Matlab, you can use SystemCall function to call Matlab script, and parse output.
CFD-Lover likes this.
alexeym is offline   Reply With Quote

Old   June 17, 2017, 17:27
Thumbs up
  #4
Member
 
OpenFoam
Join Date: Jun 2016
Posts: 82
Rep Power: 3
CFD-Lover is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Hi,

Why you cannot put this simple analytic solution into geo:

\left[\begin{matrix}\left(- R + R_{1}\right) \left(\frac{L_{2}}{L_{1}^{2} \left(L_{1} - L_{2}\right)} + \frac{1}{L_{1}^{2}}\right) - \frac{- R + R_{2}}{L_{2} \left(L_{1} - L_{2}\right)}\\\frac{L_{1} \left(- R + R_{2}\right)}{L_{2} \left(L_{1} - L_{2}\right)} - \frac{L_{2} \left(- R + R_{1}\right)}{L_{1} \left(L_{1} - L_{2}\right)}\end{matrix}\right]

But it you REALLY want to call Matlab, you can use SystemCall function to call Matlab script, and parse output.
Hi Alexeym,

Why not, your formula works perfect. That's what I need for now.

Many thanks for the formula,
CFD-Lover is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
chtMultiRegionSimpleFoam turbulent case Aditya Patil OpenFOAM Running, Solving & CFD 6 April 24, 2017 22:13
Swak4Foam funkyDoCalc with OF2.3 massflow NiFl OpenFOAM 11 November 1, 2016 07:43
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 04:34
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 12:46


All times are GMT -4. The time now is 23:07.