(in-package :clf)

(defun test-cv-constant (&key (cells-nx 20) (cells-ny 1) (output-dir #P"~/prog/clfpv/test-cv-constant/"))
  "Тест на постоянном поле"
  (ensure-directories-exist output-dir)
  (let ((*DEFAULT-PATHNAME-DEFAULTS* output-dir))
    (let ((grid (make-instance 'grid2d-cv
			       :cells-amount-x cells-nx
			       :cells-amount-y cells-ny
			       :left-boundary-condition 'zeroe
			       :right-boundary-condition 'zeroe
			       :bottom-boundary-condition 'zeroe
			       :top-boundary-condition 'zeroe)))
      (init-grid grid
		 :left-border-coord 0
		 :right-border-coord 1
		 :top-border-line (constant-function 1)
		 :bottom-border-line (constant-function 0)
		 :thickening-coef-x 1
		 :thickening-coef-y 1)
      (set-constant-field-2d grid
			     (make-instance 'conservative-variables
					    :phi 0.999999
					    :P 100000.0
					    :ug 25.0
					    :ul 25.0))
      (update-boundary-cells grid)
      (march grid :finish-step -1)
      grid
      )))

(defun test-cv-mono (&key (cells-nx 20) (cells-ny 1) (output-dir #P"~/prog/clfpv/test-cv-mono/"))
  "Тест на монотонном поле, для отладки задания сетки"
  (let ((*DEFAULT-PATHNAME-DEFAULTS* output-dir))
    (let ((grid (make-instance 'grid2d-cv
			       :cells-amount-x cells-nx
			       :cells-amount-y cells-ny
			       :left-boundary-condition 'zeroe
			       :right-boundary-condition 'zeroe
			       :bottom-boundary-condition 'zeroe
			       :top-boundary-condition 'zeroe)))
      (init-grid grid
		 :left-border-coord 0
		 :right-border-coord 1
		 :top-border-line (constant-function 1)
		 :bottom-border-line (constant-function 0)
		 :thickening-coef-x 1
		 :thickening-coef-y 1)
      (let* ((left-vars (make-instance 'primitive-variables
				       :phi 0.999999
				       :rg 1.0
				       :ug 400.0
				       :ul 400.0))
	     (right-vars (make-instance 'primitive-variables
					:phi (phi left-vars)
					:ug (/ (* *sos* *sos*)
					       (* *kappa* (ug left-vars)))
					:ul (/ (* *sos* *sos*)
					       (* *kappa* (ul left-vars)))
					:rg (/ (* (rg left-vars) (ug left-vars))
					       ;; на ug справа
					       (/ (* *sos* *sos*)
						  (* *kappa* (ug left-vars)))))))
	(set-monotonous-field-2d-x grid
				   :left-vars left-vars
				   :right-vars right-vars))
      (update-boundary-cells grid)
      grid
      )))

(defun test-cv-split-1 (&key (cells-nx 20) (cells-ny 1) (output-dir #P"~/prog/clfpv/test-cv-split-1/"))
  "Тест на скачке"
  (ensure-directories-exist output-dir)
  (let ((*DEFAULT-PATHNAME-DEFAULTS* output-dir))
    (let ((grid (make-instance 'grid2d-cv
			       :cells-amount-x cells-nx
			       :cells-amount-y cells-ny
			       :left-boundary-condition 'zeroe
			       :right-boundary-condition 'zeroe
			       :bottom-boundary-condition 'zeroe
			       :top-boundary-condition 'zeroe)))
      (init-grid grid
		 :left-border-coord 0
		 :right-border-coord 1
		 :top-border-line (constant-function 1)
		 :bottom-border-line (constant-function 0)
		 :thickening-coef-x 1
		 :thickening-coef-y 1)
      (let* ((left-vars (make-instance 'primitive-variables
				       :phi 0.999999
				       :rg 1.0
				       :ug 400.0
				       :ul 400.0))
	     (right-vars (make-instance 'primitive-variables
					:phi (phi left-vars)
					:ug (/ (* *sos* *sos*)
					       (* *kappa* (ug left-vars)))
					:ul (/ (* *sos* *sos*)
					       (* *kappa* (ul left-vars)))
					:rg (/ (* (rg left-vars) (ug left-vars))
					       ;; на ug справа
					       (/ (* *sos* *sos*)
						  (* *kappa* (ug left-vars)))))))
	(set-splitted-field-2d-x grid
				 :left-vars left-vars
				 :right-vars right-vars))
      (update-boundary-cells grid)
      (march grid :finish-step -1)
      grid
      )))