Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/examples/Adjoint_CostRegSolver/Valid_CostRegSolver3.sif
3204 views
!################################################
!# Validation test case for Adjoint_CostRegSolver
!#  Test regularisation penalising 
!#  first spatial derivatives
!#   same as 1 but executing the solvers on the bottom surface
!################################################
! PARAMETERS:
$name="CostReg3"
!###############################################
Header
  Mesh DB "." "mesh2D"
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Simulation
  Coordinate System  = Cartesian 3D 
  Simulation Type = Steady State
 
  ! Internal extrusion 
  Extruded Mesh Levels=5

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


  max output level = 4
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Body 1
  Equation = 1
  Body Force = 1
  Initial Condition = 1
End
Body 2
  Equation = 2
  Initial Condition = 1
  Body Force = 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 "sqrt(2.0)*tx(0)^2+sqrt(2)*tx(1)*tx(1)/2"
 !=> V = a x^2 + b y^2
 !=> J = (a^2 * 2/3 + b^2 * 2/3)

 ! perturbation variable
 VarP = REAL MATC "0.1*rand(1,1)"
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Body Force 1
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"
  Gradient Variable Name = String "DJDp"

  Result File = File "Validation_$name$.dat"
 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Equation 1
  Active Solvers (1) = 1
End
Equation 2
  Active Solvers (2) = 2 3
End
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Boundary Condition 1
  Target Boundaries = 1
End

Boundary Condition 2
  Body Id = 2
End

Boundary Condition 3

End