/[escript]/trunk/escript/test/python/test_linearPDEs.py
ViewVC logotype

Diff of /trunk/escript/test/python/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2455 by jfenwick, Wed Jun 3 03:29:07 2009 UTC revision 2470 by gross, Thu Jun 11 08:32:32 2009 UTC
# Line 46  __author__="Lutz Gross, l.gross@uq.edu.a Line 46  __author__="Lutz Gross, l.gross@uq.edu.a
46    
47  from esys.escript.util import Lsup,kronecker,interpolate,whereZero, outer, swap_axes  from esys.escript.util import Lsup,kronecker,interpolate,whereZero, outer, swap_axes
48  from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor  from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor
49  from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz, LameEquation  from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz, LameEquation, SolverOptions
50  import numpy  import numpy
51  import unittest  import unittest
52    
# Line 640  class Test_Poisson(Test_linearPDEs): Line 640  class Test_Poisson(Test_linearPDEs):
640    
641  class Test_LinearPDE_noLumping(Test_linearPDEs):  class Test_LinearPDE_noLumping(Test_linearPDEs):
642      N=4      N=4
643        def test_SolverOptions(self):
644            so=SolverOptions()
645    
646            self.failUnless(so.getLevelMax() == 10, "initial  LevelMax is wrong.")
647            self.failUnlessRaises(ValueError,so.setLevelMax,-1)
648            so.setLevelMax(3)
649            self.failUnless(so.getLevelMax() == 3, "LevelMax is wrong.")
650    
651            self.failUnless(so.getCoarseningThreshold() == 0.05, "initial  CoarseningThreshold is wrong.")
652            self.failUnlessRaises(ValueError,so.setCoarseningThreshold,-1)
653            so.setCoarseningThreshold(0.1)
654            self.failUnless(so.getCoarseningThreshold() == 0.1, "CoarseningThreshold is wrong.")
655    
656            self.failUnless(so.getNumSweeps() == 2, "initial  Sweeps is wrong.")
657            self.failUnlessRaises(ValueError,so.setNumSweeps,-1)
658            so.setNumSweeps(3)
659            self.failUnless(so.getNumSweeps() == 3, "Sweeps is wrong.")
660    
661            self.failUnless(so.getNumPreSweeps() == 2, "initial  PreSweeps is wrong.")
662            self.failUnlessRaises(ValueError,so.setNumPreSweeps,-1)
663            so.setNumPreSweeps(4)
664            self.failUnless(so.getNumPreSweeps() == 4, "PreSweeps is wrong.")
665    
666            self.failUnless(so.getNumPostSweeps() == 2, "initial  PreSweeps is wrong.")
667            self.failUnlessRaises(ValueError,so.setNumPostSweeps,-1)
668            so.setNumPostSweeps(5)
669            self.failUnless(so.getNumPostSweeps() == 5, "PreSweeps is wrong.")
670    
671            self.failUnless(so.getTolerance() == 1.e-8, "initial Tolerance is wrong.")
672            self.failUnlessRaises(ValueError,so.setTolerance,-1)
673            so.setTolerance(0.2)
674            self.failUnless(so.getTolerance() == 0.2, "Tolerance is wrong.")
675    
676            self.failUnless(so.getAbsoluteTolerance() == 0., "initial  AbsoluteTolerance is wrong.")
677            self.failUnlessRaises(ValueError,so.setAbsoluteTolerance,-1)
678            so.setAbsoluteTolerance(0.3)
679            self.failUnless(so.getAbsoluteTolerance() == 0.3, "AbsoluteTolerance is wrong.")
680    
681            self.failUnless(so.getInnerTolerance() == 0.9, "initial InnerTolerance is wrong.")
682            self.failUnlessRaises(ValueError,so.setInnerTolerance,-1)
683            so.setInnerTolerance(0.4)
684            self.failUnless(so.getInnerTolerance() == 0.4, "InnerTolerance is wrong.")
685    
686            self.failUnless(so.getDropTolerance() == 0.01, "initial DropTolerance is wrong.")
687            self.failUnlessRaises(ValueError,so.setDropTolerance,-1)
688            so.setDropTolerance(0.5)
689            self.failUnless(so.getDropTolerance() == 0.5, "DropDropTolerance is wrong.")
690    
691            self.failUnless(so.getDropStorage() == 2., "initial DropStorage is wrong.")
692            self.failUnlessRaises(ValueError,so.setDropStorage,-1)
693            so.setDropStorage(10)
694            self.failUnless(so.getDropStorage() == 10, "DropStorage is wrong.")
695            
696            self.failUnless(so.getRelaxationFactor() == 0.3, "initial RelaxationFactor is wrong.")
697            self.failUnlessRaises(ValueError,so.setRelaxationFactor,-1)
698            so.setRelaxationFactor(0.1)
699            self.failUnless(so.getRelaxationFactor() == 0.1, "Relaxation is wrong.")
700    
701    
702            self.failUnless(so.getIterMax() == 10000, "initial IterMax is wrong.")
703            self.failUnlessRaises(ValueError,so.setIterMax,0)
704            so.setIterMax(11)
705            self.failUnless(so.getIterMax() == 11, "IterMax is wrong.")
706    
707            self.failUnless(so.getInnerIterMax() == 10, "initial InnerIterMax is wrong.")
708            self.failUnlessRaises(ValueError,so.setInnerIterMax,0)
709            so.setInnerIterMax(12)
710            self.failUnless(so.getInnerIterMax() == 12, "InnerIterMax is wrong.")
711    
712            self.failUnless(so.getTruncation() == 20, "initial Truncation is wrong.")
713            self.failUnlessRaises(ValueError,so.setTruncation,0)
714            so.setTruncation(13)
715            self.failUnless(so.getTruncation() == 13, "Truncation is wrong.")
716    
717            self.failUnless(so.getRestart() == None, "initial Truncation is wrong.")
718            self.failUnlessRaises(ValueError,so.setTruncation,0)
719            so.setRestart(14)
720            self.failUnless(so.getRestart() == 14, "Truncation is wrong.")
721            so.setRestart(None)
722            self.failUnless(so.getRestart() == None, "Truncation is wrong.")
723        
724            self.failUnless(not so.isSymmetric(), "initial symmetry flag is wrong.")
725            so.setSymmetryOn()
726            self.failUnless(so.isSymmetric(), "symmetry (1) flag is wrong.")
727            so.setSymmetryOff()
728            self.failUnless(not so.isSymmetric(), "symmetry (2) flag is wrong.")
729            so.setSymmetry(flag=True)
730            self.failUnless(so.isSymmetric(), "symmetry (3) flag is wrong.")
731            so.setSymmetry(flag=False)
732            self.failUnless(not so.isSymmetric(), "symmetry (4) flag is wrong.")
733    
734            self.failUnless(so.adaptInnerTolerance(), "initial InnerToleranceAdaption flag is wrong.")
735            so.setInnerToleranceAdaptionOn()
736            self.failUnless(so.adaptInnerTolerance(), "InnerToleranceAdaption (1) flag is wrong.")
737            so.setInnerToleranceAdaptionOff()
738            self.failUnless(not so.adaptInnerTolerance(), "InnerToleranceAdaption (2) flag is wrong.")
739            so.setInnerToleranceAdaption(adapt=True)
740            self.failUnless(so.adaptInnerTolerance(), "InnerToleranceAdaption (3) flag is wrong.")
741            so.setInnerToleranceAdaption(adapt=False)
742            self.failUnless(not so.adaptInnerTolerance(), "InnerToleranceAdaption (4) flag is wrong.")
743        
744            self.failUnless(not so.acceptConvergenceFailure(), "initial acceptConvergenceFailure flag is wrong.")
745            so.setAcceptanceConvergenceFailureOn()
746            self.failUnless(so.acceptConvergenceFailure(), "acceptConvergenceFailure (1) flag is wrong.")
747            so.setAcceptanceConvergenceFailureOff()
748            self.failUnless(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (2) flag is wrong.")
749            so.setAcceptanceConvergenceFailure(accept=True)
750            self.failUnless(so.acceptConvergenceFailure(), "acceptConvergenceFailure (3) flag is wrong.")
751            so.setAcceptanceConvergenceFailure(accept=False)
752            self.failUnless(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (4) flag is wrong.")  
753            
754            self.failUnless(so.getReordering() == 30, "initial Reordering is wrong.")
755            self.failUnlessRaises(ValueError,so.setReordering,-1)
756            so.setReordering(so.NO_REORDERING)
757            self.failUnless(so.getReordering() == 17, "NO_REORDERING is not set.")
758            so.setReordering(so.MINIMUM_FILL_IN)
759            self.failUnless(so.getReordering() == 18, "MINIMUM_FILL_IN is not set.")
760            so.setReordering(so.NESTED_DISSECTION)
761            self.failUnless(so.getReordering() == 19, "NESTED_DISSECTION is not set.")
762            so.setReordering(so.DEFAULT_REORDERING)
763            self.failUnless(so.getReordering() == 30, "DEFAULT_REORDERING is not set.")
764            
765            self.failUnless(so.getPackage() == 0, "initial solver package is wrong.")
766            self.failUnlessRaises(ValueError,so.setPackage,-1)
767            so.setPackage(so.PASO)
768            self.failUnless(so.getPackage() == 21, "PASO is not set.")
769            so.setPackage(so.SUPER_LU)
770            self.failUnless(so.getPackage() == 31, "SUPER_LU is not set.")
771            so.setPackage(so.PASTIX)
772            self.failUnless(so.getPackage() == 32, "PASTIX is not set.")
773            so.setPackage(so.MKL)
774            self.failUnless(so.getPackage() == 15, "MKL is not set.")
775            so.setPackage(so.UMFPACK)
776            self.failUnless(so.getPackage() == 16, "UMFPACK is not set.")
777            so.setPackage(so.TRILINOS)
778            self.failUnless(so.getPackage() == 24, "TRILINOS is not set.")
779    
780            self.failUnless(so.getSolverMethod() == 0, "initial SolverMethod is wrong.")
781            self.failUnlessRaises(ValueError,so.setSolverMethod,-1)
782            so.setSolverMethod(so.DIRECT)
783            self.failUnless(so.getSolverMethod() == 1, "DIRECT is not set.")
784            so.setSolverMethod(so.CHOLEVSKY)
785            self.failUnless(so.getSolverMethod() == 2, "CHOLEVSKY is not set.")
786            so.setSolverMethod(so.PCG)
787            self.failUnless(so.getSolverMethod() == 3, "PCG is not set.")
788            so.setSolverMethod(so.CR)
789            self.failUnless(so.getSolverMethod() == 4, "CR is not set.")
790            so.setSolverMethod(so.CGS)
791            self.failUnless(so.getSolverMethod() == 5, "CGS is not set.")
792            so.setSolverMethod(so.BICGSTAB)
793            self.failUnless(so.getSolverMethod() == 6, "BICGSTAB is not set.")
794            so.setSolverMethod(so.SSOR)
795            self.failUnless(so.getSolverMethod() == 7, "SSOR is not set.")
796            so.setSolverMethod(so.GMRES)
797            self.failUnless(so.getSolverMethod() == 11, "GMRES is not set.")
798            so.setSolverMethod(so.PRES20)
799            self.failUnless(so.getSolverMethod() == 12, "PRES20 is not set.")
800            so.setSolverMethod(so.LUMPING)
801            self.failUnless(so.getSolverMethod() == 13, "LUMPING is not set.")
802            so.setSolverMethod(so.ITERATIVE)
803            self.failUnless(so.getSolverMethod() == 20, "ITERATIVE is not set.")
804            so.setSolverMethod(so.AMG)
805            self.failUnless(so.getSolverMethod() == 22, "AMG is not set.")
806            so.setSolverMethod(so.NONLINEAR_GMRES)
807            self.failUnless(so.getSolverMethod() == 25, "NONLINEAR_GMRES is not set.")
808            so.setSolverMethod(so.TFQMR)
809            self.failUnless(so.getSolverMethod() == 26, "TFQMR is not set.")
810            so.setSolverMethod(so.MINRES)
811            self.failUnless(so.getSolverMethod() == 27, "MINRES is not set.")
812            so.setSolverMethod(so.GAUSS_SEIDEL)
813            self.failUnless(so.getSolverMethod() == 28, "GAUSS_SEIDEL is not set.")
814            so.setSolverMethod(so.DEFAULT)
815            self.failUnless(so.getSolverMethod() == 0, "DEFAULT is not set.")
816    
817            self.failUnless(so.getPreconditioner() == 10, "initial Preconditioner is wrong.")
818            self.failUnlessRaises(ValueError,so.setPreconditioner,-1)
819            so.setPreconditioner(so.ILU0)
820            self.failUnless(so.getPreconditioner() == 8, "ILU0 is not set.")
821            so.setPreconditioner(so.SSOR)
822            self.failUnless(so.getPreconditioner() == 7, "SSOR is not set.")
823            so.setPreconditioner(so.ILUT)
824            self.failUnless(so.getPreconditioner() == 9, "ILUT is not set.")
825            so.setPreconditioner(so.JACOBI)
826            self.failUnless(so.getPreconditioner() == 10, "JACOBI is not set.")
827            so.setPreconditioner(so.AMG)
828            self.failUnless(so.getPreconditioner() == 22, "AMG is not set.")
829            so.setPreconditioner(so.REC_ILU)
830            self.failUnless(so.getPreconditioner() == 23, "REC_ILU is not set.")
831            so.setPreconditioner(so.GAUSS_SEIDEL)
832            self.failUnless(so.getPreconditioner() == 28, "GAUSS_SEIDEL is not set.")
833            so.setPreconditioner(so.RILU)
834            self.failUnless(so.getPreconditioner() == 29, "RILU is not set.")
835            so.setPreconditioner(so.NO_PRECONDITIONER)
836            self.failUnless(so.getPreconditioner() == 36, "NO_PRECONDITIONER is not set.")        
837    
838            self.failUnless(so.getCoarsening() == 0, "initial Coarseningr is wrong.")
839            self.failUnlessRaises(ValueError,so.setCoarsening,-1)
840            so.setCoarsening(so.YAIR_SHAPIRA_COARSENING)
841            self.failUnless(so.getCoarsening() == 33, "YAIR_SHAPIRA_COARSENING is not set.")
842            so.setCoarsening(so.RUGE_STUEBEN_COARSENING)
843            self.failUnless(so.getCoarsening() == 34, "RUGE_STUEBEN_COARSENING is not set.")
844            so.setCoarsening(so.AGGREGATION_COARSENING)
845            self.failUnless(so.getCoarsening() == 35, "AGREGATION_COARSENING is not set.")
846            so.setCoarsening(so.DEFAULT)
847            self.failUnless(so.getCoarsening() == 0, "DEFAULT is not set.")
848    
849            self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
850            self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
851            self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
852            self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
853            self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
854            self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
855            self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong.")
856            self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
857            self.failUnless(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
858            self.failUnless(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
859            self.failUnless(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
860    
861            so._updateDiagnostics("num_iter",1)
862            so._updateDiagnostics("num_inner_iter",2)
863            so._updateDiagnostics("time",3)
864            so._updateDiagnostics("set_up_time",4)
865            so._updateDiagnostics("residual_norm",5)
866            so._updateDiagnostics("converged",True)
867    
868            self.failUnless(so.getDiagnostics("num_iter") == 1, "num_iter is wrong.")
869            self.failUnless(so.getDiagnostics("num_inner_iter") == 2, "num_inner_iter is wrong.")
870            self.failUnless(so.getDiagnostics("time") == 3, "time is wrong.")
871            self.failUnless(so.getDiagnostics("set_up_time") == 4, "set_up_time is wrong.")
872            self.failUnless(so.getDiagnostics("residual_norm") == 5, "residual_norm is wrong.")
873            self.failUnless(so.getDiagnostics("converged"), "converged is wrong.")
874            self.failUnless(so.hasConverged(), "convergence flag is wrong.")
875            self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
876            self.failUnless(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
877            self.failUnless(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
878            self.failUnless(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")  
879            
880            so.resetDiagnostics()
881            self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
882            self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
883            self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
884            self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
885            self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
886            self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
887            self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong")      
888            self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
889            self.failUnless(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
890            self.failUnless(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
891            self.failUnless(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")
892    
893            so._updateDiagnostics("num_iter",10)
894            so._updateDiagnostics("num_inner_iter",20)
895            so._updateDiagnostics("time",30)
896            so._updateDiagnostics("set_up_time",40)
897            so._updateDiagnostics("residual_norm",50)
898            so._updateDiagnostics("converged",False)
899    
900            self.failUnless(so.getDiagnostics("num_iter") == 10, "num_iter is wrong.")
901            self.failUnless(so.getDiagnostics("num_inner_iter") == 20, "num_inner_iter is wrong.")
902            self.failUnless(so.getDiagnostics("time") == 30, "time is wrong.")
903            self.failUnless(so.getDiagnostics("set_up_time") == 40, "set_up_time is wrong.")
904            self.failUnless(so.getDiagnostics("residual_norm") == 50, "residual_norm is wrong.")
905            self.failUnless(not so.getDiagnostics("converged"), "converged is wrong.")
906            self.failUnless(not so.hasConverged(), "convergence flag is wrong.")
907            self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 22, "cum_num_inner_iter is wrong.")
908            self.failUnless(so.getDiagnostics("cum_num_iter") == 11, "cum_num_iter is wrong.")
909            self.failUnless(so.getDiagnostics("cum_time") ==33, "cum_time is wrong.")
910            self.failUnless(so.getDiagnostics("cum_set_up_time") == 44, "cum_set_up_time is wrong.")  
911    
912            so.resetDiagnostics(all=True)
913            self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
914            self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
915            self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
916            self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
917            self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
918            self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
919            self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong.")
920            self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
921            self.failUnless(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
922            self.failUnless(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
923            self.failUnless(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
924            
925      def test_setCoefficient_WithIllegalFunctionSpace(self):      def test_setCoefficient_WithIllegalFunctionSpace(self):
926          mypde=LinearPDE(self.domain,debug=self.DEBUG)          mypde=LinearPDE(self.domain,debug=self.DEBUG)
927          self.failUnlessRaises(IllegalCoefficientFunctionSpace,mypde.setValue, C=Vector(0.,FunctionOnBoundary(self.domain)))          self.failUnlessRaises(IllegalCoefficientFunctionSpace,mypde.setValue, C=Vector(0.,FunctionOnBoundary(self.domain)))

Legend:
Removed from v.2455  
changed lines
  Added in v.2470

  ViewVC Help
Powered by ViewVC 1.1.26