161 |
self.target = target |
self.target = target |
162 |
self.attribute = None |
self.attribute = None |
163 |
self.setAttributeName(attribute) |
self.setAttributeName(attribute) |
164 |
|
|
165 |
|
def getAttributeName(self): |
166 |
|
""" |
167 |
|
returns the name of the attribute the link is pointing to |
168 |
|
""" |
169 |
|
return self.attribute |
170 |
|
|
171 |
def setAttributeName(self,attribute): |
def setAttributeName(self,attribute): |
172 |
""" |
""" |
403 |
self.declareParameters(parameters) |
self.declareParameters(parameters) |
404 |
|
|
405 |
def __repr__(self): |
def __repr__(self): |
406 |
return "<%s %r>" % (self.__class__.__name__, |
return "<%s %d>"%(self.__class__.__name__,id(self)) |
|
[(p, getattr(self, p, None)) for p in self.parameters]) |
|
407 |
|
|
408 |
def declareParameter(self,**parameters): |
def declareParameter(self,**parameters): |
409 |
""" |
""" |
626 |
finalizing condition is fullfilled. At each time step an iterative |
finalizing condition is fullfilled. At each time step an iterative |
627 |
process can be performed and the time step size can be controlled. A |
process can be performed and the time step size can be controlled. A |
628 |
Model has the following work flow:: |
Model has the following work flow:: |
629 |
|
|
630 |
doInitialization() |
doInitialization() |
631 |
|
while not terminateInitialIteration(): doInitializationiStep() |
632 |
|
doInitialPostprocessing() |
633 |
while not finalize(): |
while not finalize(): |
634 |
dt=getSafeTimeStepSize(dt) |
dt=getSafeTimeStepSize(dt) |
635 |
doStepPreprocessing(dt) |
doStepPreprocessing(dt) |
655 |
ParameterSet.__init__(self, parameters=parameters,**kwarg) |
ParameterSet.__init__(self, parameters=parameters,**kwarg) |
656 |
|
|
657 |
def __str__(self): |
def __str__(self): |
658 |
return "<%s %d>"%(self.__class__,id(self)) |
return "<%s %d>"%(self.__class__.__name__,id(self)) |
659 |
|
|
660 |
def toDom(self, document, node): |
def toDom(self, document, node): |
661 |
""" |
""" |
675 |
This function may be overwritten. |
This function may be overwritten. |
676 |
""" |
""" |
677 |
pass |
pass |
678 |
|
def doInitialStep(self): |
679 |
|
""" |
680 |
|
performs an iteration step in the initialization phase |
681 |
|
|
682 |
|
This function may be overwritten. |
683 |
|
""" |
684 |
|
pass |
685 |
|
|
686 |
|
def terminateInitialIteration(self): |
687 |
|
""" |
688 |
|
Returns True if iteration at the inital phase is terminated. |
689 |
|
""" |
690 |
|
return True |
691 |
|
|
692 |
|
def doInitialPostprocessing(self): |
693 |
|
""" |
694 |
|
finalises the initialization iteration process |
695 |
|
|
696 |
|
This function may be overwritten. |
697 |
|
""" |
698 |
|
pass |
699 |
|
|
700 |
def getSafeTimeStepSize(self,dt): |
def getSafeTimeStepSize(self,dt): |
701 |
""" |
""" |
746 |
Returns True if iteration on a time step is terminated. |
Returns True if iteration on a time step is terminated. |
747 |
""" |
""" |
748 |
return True |
return True |
749 |
|
|
750 |
|
|
751 |
def doStepPostprocessing(self,dt): |
def doStepPostprocessing(self,dt): |
752 |
""" |
""" |
753 |
Finalalizes the time step. |
finalises the time step. |
754 |
|
|
755 |
dt is the currently used time step size. |
dt is the currently used time step size. |
756 |
|
|
869 |
This is the minimum over the time step sizes of all models. |
This is the minimum over the time step sizes of all models. |
870 |
""" |
""" |
871 |
out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()]) |
out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()]) |
|
#print "%s: safe step size is %e."%(str(self),out) |
|
872 |
return out |
return out |
873 |
|
|
874 |
def doInitialization(self): |
def doInitialization(self): |
878 |
self.n=0 |
self.n=0 |
879 |
self.tn=0. |
self.tn=0. |
880 |
for o in self.iterModels(): |
for o in self.iterModels(): |
881 |
o.doInitialization() |
o.doInitialization() |
882 |
|
def doInitialStep(self): |
883 |
|
""" |
884 |
|
performs an iteration step in the initialization step for all models |
885 |
|
""" |
886 |
|
iter=0 |
887 |
|
while not self.terminateInitialIteration(): |
888 |
|
if iter==0: self.trace("iteration for initialization starts") |
889 |
|
iter+=1 |
890 |
|
self.trace("iteration step %d"%(iter)) |
891 |
|
for o in self.iterModels(): |
892 |
|
o.doInitialStep() |
893 |
|
if iter>self.MAX_ITER_STEPS: |
894 |
|
raise IterationDivergenceError("initial iteration did not converge after %s steps."%iter) |
895 |
|
self.trace("Initialization finalized after %s iteration steps."%iter) |
896 |
|
|
897 |
|
def doInitialPostprocessing(self): |
898 |
|
""" |
899 |
|
finalises the initialization iteration process for all models. |
900 |
|
""" |
901 |
|
for o in self.iterModels(): |
902 |
|
o.doInitialPostprocessing() |
903 |
def finalize(self): |
def finalize(self): |
904 |
""" |
""" |
905 |
Returns True if any of the models is to be finalized. |
Returns True if any of the models is to be finalized. |
908 |
|
|
909 |
def doFinalization(self): |
def doFinalization(self): |
910 |
""" |
""" |
911 |
Finalalizes the time stepping for all models. |
finalises the time stepping for all models. |
912 |
""" |
""" |
913 |
for i in self.iterModels(): i.doFinalization() |
for i in self.iterModels(): i.doFinalization() |
914 |
self.trace("end of time integation.") |
self.trace("end of time integation.") |
926 |
""" |
""" |
927 |
out=all([o.terminateIteration() for o in self.iterModels()]) |
out=all([o.terminateIteration() for o in self.iterModels()]) |
928 |
return out |
return out |
929 |
|
|
930 |
|
def terminateInitialIteration(self): |
931 |
|
""" |
932 |
|
Returns True if all initial iterations for all models are terminated. |
933 |
|
""" |
934 |
|
out=all([o.terminateInitialIteration() for o in self.iterModels()]) |
935 |
|
return out |
936 |
|
|
937 |
def doStepPostprocessing(self,dt): |
def doStepPostprocessing(self,dt): |
938 |
""" |
""" |
939 |
Finalalizes the iteration process for all models. |
finalises the iteration process for all models. |
940 |
""" |
""" |
941 |
for o in self.iterModels(): |
for o in self.iterModels(): |
942 |
o.doStepPostprocessing(dt) |
o.doStepPostprocessing(dt) |
967 |
Run the simulation by performing essentially:: |
Run the simulation by performing essentially:: |
968 |
|
|
969 |
self.doInitialization() |
self.doInitialization() |
970 |
|
while not self.terminateInitialIteration(): self.doInitialStep() |
971 |
|
self.doInitialPostprocessing() |
972 |
while not self.finalize(): |
while not self.finalize(): |
973 |
dt=self.getSafeTimeStepSize() |
dt=self.getSafeTimeStepSize() |
974 |
self.doStep(dt) |
self.doStep(dt) |
986 |
In both cases the time integration is given up after |
In both cases the time integration is given up after |
987 |
C{Simulation.FAILED_TIME_STEPS_MAX} attempts. |
C{Simulation.FAILED_TIME_STEPS_MAX} attempts. |
988 |
""" |
""" |
|
dt=self.UNDEF_DT |
|
989 |
self.doInitialization() |
self.doInitialization() |
990 |
|
self.doInitialStep() |
991 |
|
self.doInitialPostprocessing() |
992 |
|
dt=self.UNDEF_DT |
993 |
while not self.finalize(): |
while not self.finalize(): |
994 |
step_fail_counter=0 |
step_fail_counter=0 |
995 |
iteration_fail_counter=0 |
iteration_fail_counter=0 |