| 1 | /*!\file GaussianVariogram.c
|
|---|
| 2 | * \brief: implementation of the GaussianVariogram object
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #ifdef HAVE_CONFIG_H
|
|---|
| 6 | #include <config.h>
|
|---|
| 7 | #else
|
|---|
| 8 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 9 | #endif
|
|---|
| 10 |
|
|---|
| 11 | #include <stdio.h>
|
|---|
| 12 | #include <string.h>
|
|---|
| 13 | #include "../objects.h"
|
|---|
| 14 | #include "../../EnumDefinitions/EnumDefinitions.h"
|
|---|
| 15 | #include "../../shared/shared.h"
|
|---|
| 16 | #include "../../include/include.h"
|
|---|
| 17 |
|
|---|
| 18 | /*GaussianVariogram constructors and destructor*/
|
|---|
| 19 | /*FUNCTION GaussianVariogram::GaussianVariogram(){{{*/
|
|---|
| 20 | GaussianVariogram::GaussianVariogram(){
|
|---|
| 21 | this->nugget = 0.2;
|
|---|
| 22 | this->sill = 1;
|
|---|
| 23 | this->range = SQRT3;
|
|---|
| 24 | return;
|
|---|
| 25 | }
|
|---|
| 26 | /*}}}*/
|
|---|
| 27 | /*FUNCTION GaussianVariogram::GaussianVariogram(Options* options){{{*/
|
|---|
| 28 | GaussianVariogram::GaussianVariogram(Options* options){
|
|---|
| 29 |
|
|---|
| 30 | /*Defaults*/
|
|---|
| 31 | this->nugget = 0.2;
|
|---|
| 32 | this->sill = 1;
|
|---|
| 33 | this->range = SQRT3;
|
|---|
| 34 |
|
|---|
| 35 | /*Overwrite from options*/
|
|---|
| 36 | if(options->GetOption("nugget")) options->Get(&this->nugget,"nugget");
|
|---|
| 37 | if(options->GetOption("sill")) options->Get(&this->sill,"sill");
|
|---|
| 38 | if(options->GetOption("range")) options->Get(&this->range,"range");
|
|---|
| 39 |
|
|---|
| 40 | /*Checks*/
|
|---|
| 41 | if(nugget==sill) _error2_("nugget and sill cannot be equal (constant semivariogram not allowed)");
|
|---|
| 42 | }
|
|---|
| 43 | /*}}}*/
|
|---|
| 44 | /*FUNCTION GaussianVariogram::~GaussianVariogram(){{{*/
|
|---|
| 45 | GaussianVariogram::~GaussianVariogram(){
|
|---|
| 46 | return;
|
|---|
| 47 | }
|
|---|
| 48 | /*}}}*/
|
|---|
| 49 |
|
|---|
| 50 | /*Object virtual functions definitions:*/
|
|---|
| 51 | /*FUNCTION GaussianVariogram::Echo {{{*/
|
|---|
| 52 | void GaussianVariogram::Echo(void){
|
|---|
| 53 | _printLine_("GaussianVariogram");
|
|---|
| 54 | _printLine_(" nugget: " << this->nugget);
|
|---|
| 55 | _printLine_(" sill : " << this->sill);
|
|---|
| 56 | _printLine_(" range : " << this->range);
|
|---|
| 57 | }
|
|---|
| 58 | /*}}}*/
|
|---|
| 59 |
|
|---|
| 60 | /*Variogram function*/
|
|---|
| 61 | /*FUNCTION GaussianVariogram::Covariance{{{*/
|
|---|
| 62 | double GaussianVariogram::Covariance(double deltax,double deltay){
|
|---|
| 63 | /*The covariance can be deduced from the variogram from the following
|
|---|
| 64 | * relationship:
|
|---|
| 65 | * 2 gamma = C(x,x) + C(y,y) -2 C(x,y)
|
|---|
| 66 | * so
|
|---|
| 67 | * C(h) = sill - gamma */
|
|---|
| 68 | double h2,a,cova;
|
|---|
| 69 |
|
|---|
| 70 | /*Calculate length square*/
|
|---|
| 71 | h2=pow(deltax,2.)+pow(deltay,2.);
|
|---|
| 72 |
|
|---|
| 73 | /*If h is too small, return sill*/
|
|---|
| 74 | if(h2<0.0000001) return sill;
|
|---|
| 75 |
|
|---|
| 76 | /*compute covariance*/
|
|---|
| 77 | a = 1./3.;
|
|---|
| 78 | cova = (sill-nugget)*exp(-h2/(a*range*range));
|
|---|
| 79 |
|
|---|
| 80 | return cova;
|
|---|
| 81 | }
|
|---|
| 82 | /*}}}*/
|
|---|
| 83 | /*FUNCTION GaussianVariogram::SemiVariogram{{{*/
|
|---|
| 84 | double GaussianVariogram::SemiVariogram(double deltax,double deltay){
|
|---|
| 85 | /*http://en.wikipedia.org/wiki/Variogram*/
|
|---|
| 86 | double h2,a,gamma;
|
|---|
| 87 |
|
|---|
| 88 | /*Calculate length square*/
|
|---|
| 89 | h2=pow(deltax,2.)+pow(deltay,2.);
|
|---|
| 90 |
|
|---|
| 91 | /*return semi-variogram*/
|
|---|
| 92 | a = 1./3.;
|
|---|
| 93 | gamma = (sill-nugget)*(1.-exp(-h2/(a*range*range))) + nugget;
|
|---|
| 94 |
|
|---|
| 95 | //if(h2>1000*1000) _printLine_("gamma = " << gamma << " h= " << sqrt(h2));
|
|---|
| 96 | _printLine_("h = " << sqrt(h2) << " gamma = " << gamma);
|
|---|
| 97 | return gamma;
|
|---|
| 98 | }
|
|---|
| 99 | /*}}}*/
|
|---|