< Back to IRCAM Forum

Questions for FEM inside of LUA

Hi Robert !

I am diving into the world of FEM inside of LUA - really phantastic what seems to be possible here! :nerd_face: I am trying to understand the way the example 3D instruments have been made - AND - to see which mlys getinfo/setinfo messages that work with the FEM object.

There are many questions to be answered, please see below. I made the adjoint patch in order to record them. Feel free to answer any of the questions as you like, in any order, maybe one by one?

Have a look to the patch and especially the subpatcher “testing-FEM-messages”.

lua_3D_parametric_HPST.maxpat (76.5 KB)

All the best Hans Peter

Listing questions of FEM inside LUA

LUA script

  • { } what does curly brackets mean in LUA?

  • Why must there be two values returned from the { } function?

  • Can a function definition inside { } include for and while loops?

  • Why does the resolution-loop not work on different function specifications? Is it one index too large?

  • Why does getNodeXY not work? Maybe also a question of wrong indexing?

FEM messages

  • Why does mode-amplitude not work on FEMs?

  • After some time you cant excite the FEM. Why ?

  • How to “slide” an access over FEM-nodes?

  • An error message from a certain getinfo message may persist even if changing to another message. Should be corrected?

Hi Hans Peter!

Thank you so much for your interest and deep diving into mlys.lua and 3D!
I am answering the Lua questions first.

  • { } what does curly brackets mean in LUA?
    Curly brakets are for “tables”. A table is a set of (key,value) pair. For instance a={truc=“bidule”, value=543.3}, so a[“truc”] returns “bidule”. A special case is b={34,“coco”,17}: behind the lua hood the table b={[1]=34,[2]=“koko”,[3]=17} is created, so b[2] returns “coco”. Tables are great to pass explicit (=named) parameters to a function.
  • Why must there be two values returned from the { } function?
    Because this is a 2D parametric curve, so it return (x(t), y(t)).
  • Can a function definition inside { } include for and while loops?
    Yes of course. A function is a variable like any other (inside a table for instance). The function itself can be as complex and long as you want.
  • Why does the resolution-loop not work on different function specifications? Is it one index too large?
    Could you elaborate?.. Not sure what you mean!
  • Why does getNodeXY not work? Maybe also a question of wrong indexing?
    What makes you think it doesn’t work?..

After some time you cant excite the FEM. Why ?
Because your object is attached nowhere (a “boundary” condition (=hold) that is displayed in red in the 3D view). See the other examples. Sometimes it is tricky to pick a node to create a hold.

I can see that your result mesh has issues: it is like there is a double shell or something. I will look into it, and also address the other questions!

Robert

Great Robert! And thank you for the clarifications. Lua start to stand in a brighter light … :slight_smile:

As for the two last Lua question here’s some more explanations:

  • Why does the resolution-loop not work on different function specifications? Is it one index too large?

Have a look to my lua script where I included a revision of your function (method) “ParametricCurve2D:createMeshFromCurve()”. I could not make this function accept my mesh unless I asked it to do a a loop from n=1 to self.resolution-2 (your version does self.resolution-1). So maybe my mesh is bad or the loop should perform safer indexing to accept meshes of various layout or sizes. Both could also be true, of course. I would like such a function to be true class method so each object (mesh) could redefined it as necessary. I am not sure if true methods are be possible in Lua?

  • Why does getNodeXY not work? Maybe also a question of wrong indexing?

I should be more explicit. By “not working” I mean specificly in relation to my mesh. I had to fixate the node used for the hold-mesh (see the “build3Dobject” function in the script). Its a bit the same kind of situation as for the previous question. Either my mesh is bad so getNodeXY can’t find a valid node or the function could be made more general (safe) to be able to work with many different meshes. The last option would be lovely of course. Again I think this would be best solved if Lua would work with proper methods.

Looking forward to your answer(s), all the best Hans Peter

Hi Hans Peter,

There are several issues in your script.

  • Attempting to create a closed sphere by rotation is not the most desirable thing because you get two singularities at both poles::. It is better (mode calculation-wise) to punch the sphere with two little holes. (Also, even if you wanted a closed sphere, the curve from which the surface derives should not be a full circle, but rather half a circle, because of the 360 rotation you apply thereafter…)
    To create ‘holes’, you can for instance modify the parametric curve like this:
local curve=ParametricCurve2D:new{ scale=0.5, resolution=npoints,
									f =	function(t)
											local u = 19*t/20+1/40
											return math.cos(u*math.pi), math.sin(u*math.pi)
										end }
  • Also the rotation axis must be changed:
modalys.extend_mesh{ method="rotation",mesh=M,steps=steps,axis={1,0,0},center={0,0,0},angle=360 }
  • Redefining createMeshFromCurve (originally in tools.lua) is not necessary or desired…
  • For ‘holding’ the object, topY = 10 cannot lead to go result… In fact, the value is a coordinate, so it must be very precise. The line of code local topY = curve:getYmax() you commented works for me.
  • And if you want a closed sphere (correctly meshed with quads), open the example lua_3d_sphere_from_obj_file_view_modes

NB: for upcoming Modalys 3.7, I intend to add support for true parametric surfaces (so with 2 parameters s and t). It’ll be much easier to create interesting surfaces… :wink:

I will respond the remaining questions (messaging) later.

Best,
Robert

Thank you very much, Robert, that was really helpfull.

I see now that the main problem was that my mesh was badly constructed and many issues arose therefrom. Firstly it sort of wrapped twice around itself like you said due to the 360 degrees rotation (which really should have been 180 degrees). This wrapping distorted the mesh with regard to the “ParametricCurve2D:new” function (forcing me to redefine it). It works for me now without modifying any exisiting functions (which I agree is a dangerous enterprise best to avoid). Secondly my holding point was not defined correctly meaning the object would drift unanchored in space. So I could hit it once or twice quickly after instatiation then it would be off to unknown galaxial terrain. Solved, great!

Some follow up questions:

• Could you give a brief explanation of what is meant by “singularities”? I understand it to be a type of undesired mode(s), perhaps of zero frequency and/or a zeroed out modeshape?

• Would there be any method for resetting (forcing) the position of an object who has swayed off?

• Say I had succeeded in creating a closed parametric sphere. Could classic “hole-connections” have been applied to remedy for the holes missing in the mesh construction?

I should maybe add that of course there is a sonic difference between a closed sphere and one punched with holes. But I guess its a natural consequence of such objects modal differences.

Looking forward to hear your explanations, best Hans Peter