-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve apply_support at location defined by decimal value #20404
Comments
Does: M, R = symbols('M_{0.2}, R_{0.2}') work? It is possible SymPy will not support decimals in symbol names. |
Yes, with the proposed fix it works with decimal too, but without curly brackets. I used this code to update def apply_support_fix(self, loc, type="fixed"):
loc = sympify(loc)
self._applied_supports.append((loc, type))
strloc = str(loc).rstrip('0') if loc > 0 else str(loc)
if type == "pin" or type == "roller":
reaction_load = Symbol('R_'+strloc)
print(reaction_load)
self.apply_load(reaction_load, loc, -1)
self.bc_deflection.append((loc, 0))
else:
reaction_load = Symbol('R_'+strloc)
print(reaction_load)
reaction_moment = Symbol('M_'+strloc)
self.apply_load(reaction_load, loc, -1)
self.apply_load(reaction_moment, loc, -2)
self.bc_deflection.append((loc, 0))
self.bc_slope.append((loc, 0))
self._support_as_loads.append((reaction_moment, loc, -2, None))
self._support_as_loads.append((reaction_load, loc, -1, None))
Beam.apply_support = apply_support_fix # adds method to Beam class |
The arguments to Beam() should be sympifiable objects. If a symbol |
Current code does not work with curly brackets regardless of decimal point. That is: ...
b.apply_support(0, 'fixed') # fixed, pin, roller
...
M, R = symbols('M_{0}, R_{0}')
... does not work either, giving |
I understand now. This line: |
I agree. M, R = symbols('M, R')
b.apply_support([M,R], 0, 'fixed') would be syntactic sugar for M, R = symbols('M, R')
b.apply_load(M, 0, -2)
b.apply_load(R, 0, -1) The purpose of The following code would do the job: def apply_support(self, syms, loc, type="fixed"):
try:
reaction_load,reaction_moment = syms
except:
try:
reaction_load, = syms
except:
reaction_load = syms
loc = sympify(loc)
self._applied_supports.append((loc, type))
if type == "pin" or type == "roller":
self.apply_load(reaction_load, loc, -1)
self.bc_deflection.append((loc, 0))
else:
self.apply_load(reaction_load, loc, -1)
self.apply_load(reaction_moment, loc, -2)
self.bc_deflection.append((loc, 0))
self.bc_slope.append((loc, 0))
self._support_as_loads.append((reaction_moment, loc, -2, None))
self._support_as_loads.append((reaction_load, loc, -1, None)) If you agree on the redesign I can make a pull request. Should specific tests be added in addition to doctests? |
Currently if you add a support to a beam at a location defined by decimal value, such as
and you try to catch the symbols created by the method with
the code fails because method
apply_support
, when converting numerical value of location to a string in order to create symbols, maintains the trailing zeros. In order to make the code work the user should write something likewhich is clearly counter-intuitive if not incorrect.
Trailing zeros are present because
loc
variable is converted to string afterThis behaviour could be fixed either by:
loc
to string beforesympify
sympify
functionThe second way could be obtained by replacing
str(loc)
withThe following MWE, currently not working, would run correctly with the above fix:
The text was updated successfully, but these errors were encountered: