Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/examples/Adjoint_CostRegSolver/Valid_CostRegSolver2.sif
3204 views
!################################################
!# Validation test case for Adjoint_CostRegSolver
!#  Test regularisation penalising 
!#  first spatial derivatives
!#   Same as 1 but testing nodal value prescribed in body forces and change of variable
!################################################
! PARAMETERS:
$name="CostReg2"
!###############################################
Header
  Mesh DB "." "mesh2D"
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Simulation
  Coordinate System  = Cartesian 2D 
  Simulation Type = Steady State


  Output Intervals = 1

  Steady State Max Iterations = 20
  Steady State Min Iterations = 20

  !Post File = "case.vtu"

  max output level = 4
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Body 1
  Equation = 1
  Body Force = 1
  Initial Condition = 1
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Initial Condition 1
 ! initial value for var
 ! Cost function is int 0.5 [ (dV/dx)^2 + (dV/dy)^2]
 Var = Variable Coordinate 1, Coordinate 2
  Real  MATC "log(sqrt(2.0)*tx(0)^2+sqrt(2)*tx(1)*tx(1)/2+1)"
 !=> V = a x^2 + b y^2
 !=> J = (a^2 * 2/3 + b^2 * 2/3)

 ! perturbation variable
 VarP = REAL MATC "0.01*log(rand(1,1)+1)"
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Body Force 1
  ! Nodal Value prescribed here
  ! can be useful if we want to make a change of variable
  CostReg Nodal Variable = Variable Var
   Real procedure "ElmerIceUSF" "TenPowerA"
  ! Provide a function that give teh derivative
  ! of the function above with respect to your variable
  ! if you want the derivative of your function with respect to this variable
  CostReg Nodal Variable derivative = Variable Var
   Real procedure "ElmerIceUSF" "TenPowerA_d"
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! dumy just here to declare variables
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Solver 1
 Exec Solver  = never
 Equation = String "UpdateExport"
 procedure = "ElmerIceSolvers" "UpdateExport"

 Exported Variable 1 = -global "CostValue"  
 Exported Variable 2 = Var
 Exported Variable 3 = DJDp
 Exported Variable 4 = VarP
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Compute regularisation cost
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Solver 2
  Equation = String "CostReg"
  procedure = "ElmerIceSolvers" "Adjoint_CostRegSolver"

  !# True if cost function and gradient must be initialised to 0 in this solver
  Reset Cost Value = Logical True

  Cost Filename = File "CostFile_$name$.dat"

  Lambda=Real 1.0

  Cost Variable Name = String "CostValue" 

  Gradient Variable Name = String "DJDp"

  !Optimized Variable Name = String "Var"

  A priori Regularisation = Logical FALSE
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Validation
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Solver 3
  Equation = "GradientValidation"
  procedure = "ElmerIceSolvers" "Adjoint_GradientValidation"

  Cost Variable Name = String "CostValue"
  Optimized Variable Name = String "Var"
  Perturbation Variable Name = String "VarP"
  ! the derivative w.r.t. Var
  Gradient Variable Name = String "DJDp"

  Result File = File "Validation_$name$.dat"
 
end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Equation 1
  Active Solvers (3)= 1 2 3
End