I'm trying to construct a toy problem for feedback control; in this problem, a 2D cantilevered beam undergoes a static force downwards on one end. I'd like a control force to push the system back up proportional to the maximum deflection of the beam. I don't necessarily care about the application or how good the controller is, I just want to be able to take outputs from ElmerSolver, send them to a UDF, and have the UDF calculate a restoring force.
In my sif file I extract the minimum and maximum deflection of the beam:
Code: Select all
Solver 2
Equation = SaveScalars
Operator 1 = max
Variable 1 = Displacement 2
Procedure = "SaveData" "SaveScalars"
Target Variable 1 = String dispmax
Exec Solver=Always
End
Solver 3
Equation = SaveScalars2
Operator 1 = min
Variable 1 = Displacement 2
Procedure = "SaveData" "SaveScalars"
Target Variable 1 = String dispmin
Exec Solver=Always
End
Code: Select all
Boundary Condition 3
Target Boundaries = 3
Force 2 = Variable Time
Real Procedure "PID" "doPID"
End
Code: Select all
FUNCTION doPID( Model, n, x ) RESULT( f)
USE Types
USE DefUtils
TYPE(Model_t) :: Model
INTEGER :: n
TYPE(Variable_t), POINTER :: dMinP, dMaxP !pointers pointing to displacement
REAL(KIND=dp):: x
REAL(KIND=dp) :: t, p, dMin, dMax, f
LOGICAL GotMin, GotMax
p= 1000 !proportional control
!extract the max/min displacements from the pointers
dMaxP= VariableGet(Model % Variables, 'dispmax',GotMax)
dMax=dMaxP%Values(1)
dMinP= VariableGet(Model % Variables, 'dispmin',GotMin)
dMin=dMinP%Values(1)
!success?
print *, GotMax
print *, GotMin
!return control force
f=-p*dMin
END FUNCTION doPID
How do I do operations on a user defined global variables like 'dispmax' and 'dispmin' without an error?
Thanks for any help!