Discussion Forum

[Solved] -- Geometry Creation using a LOOP

Thread index  |  Previous thread  |  Next thread  |  Start a new discussion

RSS FeedRSS feed   |   Email notificationsTurn on email notifications   |   6 Replies   Last post: April 18, 2011 1:42pm UTC
Markthomas Cutone

Markthomas Cutone

June 4, 2010 2:31pm UTC

[Solved] -- Geometry Creation using a LOOP

I am attempting to create a 2nd order Bezier curve using a Matlab script file. The number of points that I would like to process are extraordinary on the order of 500 - 1000; maybe even more. My data is set up in a text file that I can import into matlab using the load command. I have inserted what code I currently have below. When I run this in comsol it only outputs the last curve: named CO495. How can i get all the curves to be on the same plot? i.e. CO1 to CO495?

Thank you for your help!
Markthomas

%******************Start of M-file***********************
%Load Data
load 'Coord.txt'
x = Coord(:,1);
y = Coord(:,2);

%Initial Conditions
i = 1; j = 2; k = 3;

% Geometry objects
clear s

while k<=length(x)

% Geometry
carr=curve2([x(i), x(j), x(k)],[y(i),y(j),y(k)],[1,0.52,1]);
g4=geomcoerce('curve',carr);

s.objs={g4};
s.name={['CO' num2str(i)]};
s.tags={'g4'};

fem.draw=struct('s',s);
fem.sdim = {'x','y'};
fem.frame = {'ref'};
i = i+2; j = j+2; k = k+2;

end

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

June 5, 2010 12:19pm UTC in response to Markthomas Cutone

Re: Geometry Creation using a LOOP

Hi

Ido not have comsol and matlab here from home, but shouldnt you index these too:

g4=geomcoerce('curve',carr);

s.objs={g4};
s.name={['CO' num2str(i)]};
s.tags={'g4'};


for me I read only 1 item, and if you go through all its only the "last one" remaining.

If you make a complex geoemtry with 2-3 or more items, COSMOL stores g1 g2 g3 g4 ... and the name list contains all names

check it out
Have fun Comsoling
Ivar

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Markthomas Cutone

Markthomas Cutone

June 5, 2010 4:48pm UTC in response to Ivar Kjelberg

Re: Geometry Creation using a LOOP

I tried to index the following as:

g(i)=geomcoerce('curve',carr);

s.objs={g(i)};
s.name={['CO' num2str(i)]};
s.tags={'g(i)'};

but COMSOL doesn't like that... I am not sure of a way to index variable names i.e.

g1...g500

Do you know how to do this?

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

June 5, 2010 4:59pm UTC in response to Markthomas Cutone

Re: Geometry Creation using a LOOP

Hi

not like that (I have no direct access to COMSOL from home), but really make a geometry from the GUI interface and save as a M file or just analyse your history.m file, and compare.
Then check that the naming is the same w.r.t. chr and ' '

Good luck
Ivar

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Markthomas Cutone

Markthomas Cutone

June 7, 2010 12:46pm UTC in response to Ivar Kjelberg

[Solved] -- Geometry Creation using a LOOP

I figured out how to create a geometry using a loop (while loop or for loop) in COMSOL/MATLAB... It finally occurred to me what I had to do... I guess I am a little out of practice! Thank you for your help!

Markthomas

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Richard Springer

Richard Springer

March 25, 2011 3:29pm UTC in response to Markthomas Cutone

Re: [Solved] -- Geometry Creation using a LOOP


I figured out how to create a geometry using a loop ...


So let us know, please!

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Gayathri Sridharan

Gayathri Sridharan

April 18, 2011 1:42pm UTC in response to Markthomas Cutone

Re: [Solved] -- Geometry Creation using a LOOP

Hi,

1) I have an arc that form my 2-D geometry. I also have an array of straight lines(y=constant) that cut my arc splitting into multiple arcs.
2) I need to move my multiple arcs to different positions.
3) So i select the arc to be moved.
4) Now I need to access the index of the array of straight line that is nearest to this arc.
5) So, I need to loop through the existing array and extract the y-coordinate of this straight line from the array.
6) Then retrieve the min y-position of the arc selected for moving.
7) Use if condition to check if y of line exceeds y of the appropriate arc.
8) Based on the above comparison, decide where to place my arc.
9) The displacement through which I take the arc will have the array index that is to be retrieved in 4.

I do not expect an exact solution to the problem but would be glad even if I can get hints on
a) how to access the index of an array of geometric object.
b) how to write if condition
c) how to write for loop

Note: I am flexible to choose between 3.5 and 4.1 or even integrating matlab with comsol if necessary though I have never tried it before.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse


Rules and guidelines