Commit 8c1ad88b authored by jouke's avatar jouke
Browse files

Fixes for module testing

- added a better testing procedure with more informative error reporting
based on quantitative comparision of files
- Updated SimpleCropModel results as they are a bit different. A 10%
differences is caused by:

- line 300 simuladerivative.hpp

Neither the old nor the new are ideal, but reverting to the old,
will introduce warnings again. The real solution is not to depend
on finite differences, which would be a lot more work to implement.
parent 98ce69f4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -297,6 +297,8 @@ public:
			var*=0.01;//pure guess
			return;
		}
		//todo this change is a bit faster, but gives a slightly different result. 
		// these approximations are not really good and should be avoided. 
		Time t2 = t;//t1 + 2 * d1;
		Time rt = SimulaTimeDriven::getWallTime(t2);
		if (t2 > rt) {
+0 −24
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"? -->
<!-- Copyright © 2016 Forschungszentrum Jülich GmbH All rights reserved. 
	Redistribution and use in source and binary forms, with or without modification, 
	are permitted under the GNU General Public License v3 and provided that the 
	following conditions are met: 1. Redistributions of source code must retain 
	the above copyright notice, this list of conditions and the following disclaimer. 
	2. Redistributions in binary form must reproduce the above copyright notice, 
	this list of conditions and the following disclaimer in the documentation 
	and/or other materials provided with the distribution. 3. Neither the name 
	of the copyright holder nor the names of its contributors may be used to 
	endorse or promote products derived from this software without specific prior 
	written permission. Disclaimer THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
	HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
	FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
	HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
	OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
	ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
	OF SUCH DAMAGE. You should have received the GNU GENERAL PUBLIC LICENSE v3 
	with this file in license.txt but can also be found at http://www.gnu.org/licenses/gpl-3.0.en.html -->

<!--This XML constructs a simple, rue based crop model. Roots and stems are 
	only presented as Carbon (dry weight) pools Leaf dry weight is converted 
	to leaf area based on SLA Leaf area is converted to light interception using 
+3 −3
Original line number Diff line number Diff line
@@ -226,7 +226,7 @@ The force exerted by the spring is linear dependent on u , the length spring is
		</SimulaDerivative>
	</SimulaBase-->

	<SimulaBase name="Fehlberg">
	<!--SimulaBase name="Fehlberg">
		<SimulaDerivative
			name="a"
			unit="cm/day"
@@ -288,7 +288,7 @@ The force exerted by the spring is linear dependent on u , the length spring is
				type="string"> (analyticSolution-u)/(-g*mass/stiff)
			</SimulaConstant>
		</SimulaDerivative>
	</SimulaBase>
	</SimulaBase-->


	<SimulaBase name="simulationControls">
+120 −0
Original line number Diff line number Diff line
#!/usr/bin/Rscript


#get list of command line arguments
args <- commandArgs(TRUE)

#define function to set values based on commandline arguments
getArgument<-function(argn,defaultsetting){
  n= 1+c(1:length(args))[args==argn]
  if(length(n)){
    args[n]
  }else{
    defaultsetting
  }
}

#print help and exit
printhelp<-function(){
  cat(
    "\
R script for comparing OpenSimRoot data. Example usage:\
\
./compareTabledOuput.R OutputFolder1 OutputFolder2

\
additional arguments behind plotting command:\
  -h -help --help   this help\
\
"
  )
}

#print help
h=sum(args=="-h")+sum(args=="--help")+sum(args=="-help")+!length(args)==2
if(h){
  printhelp()
  quit('no')
}


folder1=args[1]
folder2=args[2]
extension=args[3]
if(!length(extension) | !is.character(extension) | is.na(extension)) extension="tab"
wdStart=getwd()
if(folder1[length(folder1)]!='/') folder1=paste0(folder1,'/')
if(folder2[length(folder2)]!='/') folder2=paste0(folder2,'/')

#find tabled_output.tab
setwd(folder1)
#change dir so files1 does not contain folder1 in the path
lscom = paste0("ls *.",extension)
files1=system(command = lscom,intern = T)
setwd(wdStart)
setwd(folder2)
files2=system(command = lscom,intern = T)
setwd(wdStart)

errocode=0

# match them 
filesInCommon=files1[files1%in%files2]
filesMissingIn1=files1[!files1%in%files2]
filesMissingIn2=files2[!files2%in%files1]
for(f in filesMissingIn1){
  print(paste0("File ",f," is missing in folder ",folder2))
  errocode=errocode+1
 }
for(f in filesMissingIn2){
  print(paste0("File ",f," is missing in folder ",folder1))
  errocode=errocode+1
}

# process the 
for(f in filesInCommon){
  print(paste0('----Processing file ',f,'----'))
  # read files
  d1=read.table(paste0(folder1,f),header=T)
  d2=read.table(paste0(folder2,f),header=T)
  # check their length
  if(sum(dim(d1)-dim(d2))){
    print(paste0("Files for ",f," do not have same length"))
    errocode=errocode+1
  }
  # match unique rows
  d1$du=paste(d1[,1],'(',d1[,5],') in ',d1[,6],' at time ',d1[,2],' days',sep='')
  d2$du=paste(d2[,1],'(',d2[,5],') in ',d2[,6],' at time ',d2[,2],' days',sep='')
  d1c=d1[d1$du%in%d2$du,]
  d2c=d2[d2$du%in%d1$du,]
  # compare data
  dd12=abs(d1c[,3]-d2c[,3])
  rd12=abs(dd12/d1c[,3])
  if(!length(dd12)) {
    print(paste0("Files for ",f," share no common data. Did the path change?"))
    errocode=errocode+1
    next;
  }
  # report
  errSel=which(d1c[3]>1e-15 & rd12>0.1)
  errPath=unique(d2c[errSel,7])
  if(length(errPath)>10){
    d1c$dup=paste(d1c[,1],'(',d1c[,5],') in ',d1c[,6],sep='')
    errPath2=aggregate(rd12[errSel],by=list(pf=as.factor(d1c$dup[errSel])),max)
    print(paste('Large differences found in',f,". Check:"))
    print(paste("   ",errPath2$pf,'has an all-time max relative error of',errPath2$x*100,'%.'))
    errocode=errocode+1
  }else if(length(errPath)>0){
    print(paste('Small differences found in',f,". Check:"))
    print(paste('   ', errPath,'in',f,'more than 10% of'))
    errocode=errocode+1
  }else{
    maxError=max(rd12[d1c[3]>1e-15])
    print(paste("Files past test, largest relative deviation is",maxError*100,"%"))
  }
  # 
  print("------------------------------------------")
}

# quit passing the errorcode, note that Rscript needs errorcode to be 2 or greater to fail
q(status=errocode)
+1926 −1926

File changed.

Preview size limit exceeded, changes collapsed.

Loading