Last active
July 2, 2021 06:20
-
-
Save Balaje/ec17ea229483669a1b04bb4e944a97b3 to your computer and use it in GitHub Desktop.
SymbolicUtils Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ModelingToolkit | |
using SymbolicUtils | |
@syms w x y z | |
# Rule using exp | |
rexp=@rule exp(~~xs) => ~~xs | |
A=rexp(exp(10*sin(w)+exp(z))) # Returns 10*sin(w)+exp(z) | |
# Rule using Differential | |
rdiff=@rule Differential(x)(~~xs*Differential(x)(w)) => ~~xs | |
B=rdiff(Differential(x)(sin(x)*sin(y)*Differential(x)(w))) # I expect sin(x)*sin(y), but I get nothing. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ModelingToolkit | |
using SymbolicUtils | |
using SymbolicUtils.Rewriters | |
@syms w x y z | |
# Function to determine if the input is a Differential | |
isDiff = T -> T isa Differential | |
# The IBP rule for single PD. | |
getargDiff = @rule (~x::isDiff)((~~w)) => ((~~w))*(~x); | |
#Function to do the IBP on all terms | |
function IBP(T, testFunc) | |
opsum=0; | |
if(length(SymbolicUtils.arguments(T))==1) | |
opsum=getargDiff(T).outer*getargDiff(T).inner(testFunc); | |
return opsum[1]; | |
else | |
for X=SymbolicUtils.arguments(T) | |
op=getargDiff(X).outer*getargDiff(X).inner(testFunc); | |
opsum+=op[1]; | |
end | |
return opsum; | |
end | |
end | |
# Define the LHS of the Poisson Equation | |
Dx=Differential(x); | |
Dy=Differential(y); | |
DxkDx=Dx((sin(x)+exp(y))*Dx(w)); | |
DykDy=Dy(Dy(w)); | |
DD=DxkDx + DykDy; | |
@show DD # The Poisson equation | |
# Do the IBP | |
term1=IBP(DD, z) # The weak form of the LHS | |
@show term1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment