- Thank you received: 0
Sine Wave Geometry with Exact Amplitude
3 years 8 months ago - 3 years 8 months ago #3617
by ugzhaw
Sine Wave Geometry with Exact Amplitude was created by ugzhaw
Hello,
I'm currently trying to create a geometry resembling a sine wave. So far I have an example where the geometry satisfies more or less my expectations, but the amplitude can not be specified precisely. In this approach, I'm using 5 points to create a single sine wave. The corresponding code can be found at the very bottom of this post.
I tried to multiply the amplitude to "stretch" the sine wave, but the results are confusing me, since I can't figure out the pattern it's following. Below the output of the program with the values 1, 2 and 4 for the amplitude. (The height of the geometry at the right-hand border is 2.)
Obviously, there are downsides to my current approach. For example the sine wave for amplitude = 4 isn't that well-formed...
I suppose, my problem can be explained through this statement from the documentation:
Thus, my question: how can I define a sine wave geometry, where I can define exactly the amplitude?
Edit: I'm also thankful for any further explications on how the spline geometries are working. Like how the curve is calculated between three points.
Code for the generation of the examples in this post:
I'm currently trying to create a geometry resembling a sine wave. So far I have an example where the geometry satisfies more or less my expectations, but the amplitude can not be specified precisely. In this approach, I'm using 5 points to create a single sine wave. The corresponding code can be found at the very bottom of this post.
I tried to multiply the amplitude to "stretch" the sine wave, but the results are confusing me, since I can't figure out the pattern it's following. Below the output of the program with the values 1, 2 and 4 for the amplitude. (The height of the geometry at the right-hand border is 2.)
Obviously, there are downsides to my current approach. For example the sine wave for amplitude = 4 isn't that well-formed...
I suppose, my problem can be explained through this statement from the documentation:
The curve and its tangential direction coincides with the control polygon at the start and the end-point.
Thus, my question: how can I define a sine wave geometry, where I can define exactly the amplitude?
Edit: I'm also thankful for any further explications on how the spline geometries are working. Like how the curve is calculated between three points.
Code for the generation of the examples in this post:
Code:
from netgen import geom2d
from ngsolve import *
from ngsolve.webgui import Draw
from math import pi, sin, cos
# small function to create a sinusidial form
pts = []
amplitude = 1
wavelength = 2 # the length to perform a complete sinus cycle
# create points for a single sinus iteration
pts.append([0, 0])
pts.append([wavelength*0.25, amplitude])
pts.append([wavelength*0.5, 0])
pts.append([wavelength*0.75, -1*amplitude])
pts.append([wavelength, 0])
# auxilliary points
pts.append([wavelength, -2])
pts.append([0, -2])
# init geometry object
geo = geom2d.SplineGeometry()
geoPtsIdxs = []
for p in pts:
geoPtsIdxs.append(geo.AddPoint(*p))
# define sinusiodal geometry
geo.Append(["spline3", geoPtsIdxs[0], geoPtsIdxs[1], geoPtsIdxs[2]], leftdomain=0, rightdomain=1, bc='intern')
geo.Append(["spline3", geoPtsIdxs[2], geoPtsIdxs[3], geoPtsIdxs[4]], leftdomain=0, rightdomain=1, bc='intern')
# close the geometry
geo.Append(["line", geoPtsIdxs[4], geoPtsIdxs[5]], leftdomain=0, rightdomain=1, bc='intern')
geo.Append(["line", geoPtsIdxs[5], geoPtsIdxs[6]], leftdomain=0, rightdomain=1, bc='intern')
geo.Append(["line", geoPtsIdxs[6], geoPtsIdxs[0]], leftdomain=0, rightdomain=1, bc='intern')
geo.SetMaterial(1, "testregion1")
ngmesh=geo.GenerateMesh(maxh=0.5) #0.05
mesh = Mesh(ngmesh)
mesh.Curve(3)
Draw(mesh)
Last edit: 3 years 8 months ago by ugzhaw. Reason: Precise
Time to create page: 0.103 seconds