Skip to content
Snippets Groups Projects
Commit 5bb84d31 authored by Gareth Tribello's avatar Gareth Tribello
Browse files

Fixed small bug in moments vessel - this would not work if you were...

Fixed small bug in moments vessel - this would not work if you were calculating MOMENTS and MEAN simultaneously
parent 9fabace4
No related branches found
No related tags found
No related merge requests found
......@@ -105,25 +105,25 @@ void Moments::finish( const std::vector<double>& buffer ){
double pfactor, min, max; Tools::convert(str_min,min); Tools::convert(str_max,max);
pfactor = 2*pi / ( max-min ); myvalue.setDomain( str_min, str_max );
double sinsum=0, cossum=0, val;
for(unsigned i=0;i<nvals;++i){ val=pfactor*( buffer[i*nspace*vecsize+nspace] - min ); sinsum+=sin(val); cossum+=cos(val); }
for(unsigned i=0;i<nvals;++i){ val=pfactor*( buffer[bufstart + i*nspace*vecsize+nspace] - min ); sinsum+=sin(val); cossum+=cos(val); }
mean = 0.5 + atan2( sinsum / static_cast<double>( nvals ) , cossum / static_cast<double>( nvals ) ) / (2*pi);
mean = min + (max-min)*mean;
} else {
for(unsigned i=0;i<nvals;++i) mean+=buffer[i*nspace*vecsize+nspace];
for(unsigned i=0;i<nvals;++i) mean+=buffer[bufstart + i*nspace*vecsize+nspace];
mean/=static_cast<double>( nvals ); myvalue.setNotPeriodic();
}
for(unsigned npow=0;npow<powers.size();++npow){
double dev1=0;
if( value_out[0]->getNumberOfDerivatives()>0 ){
for(unsigned i=0;i<nvals;++i) dev1+=pow( myvalue.difference( mean, buffer[i*nspace*vecsize+nspace] ), powers[npow] - 1 );
for(unsigned i=0;i<nvals;++i) dev1+=pow( myvalue.difference( mean, buffer[bufstart + i*nspace*vecsize+nspace] ), powers[npow] - 1 );
dev1/=static_cast<double>( nvals );
}
double moment=0;
MultiValue myvals( getNumberOfComponents(), getAction()->getNumberOfDerivatives() ); myvals.clearAll();
for(unsigned i=0;i<nvals;++i){
double tmp=myvalue.difference( mean, buffer[i*nspace*vecsize+nspace] );
double tmp=myvalue.difference( mean, buffer[bufstart + i*nspace*vecsize+nspace] );
moment+=pow( tmp, powers[npow] );
if( value_out[npow]->getNumberOfDerivatives() ){
double pref=pow( tmp, powers[npow] - 1 ) - dev1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment