Esempio n. 1
0
FiniteVolumeEquation<Vector2D> laplacian(const ScalarFiniteVolumeField &gamma,
                                         VectorFiniteVolumeField &phi,
                                         Scalar theta)
{
    FiniteVolumeEquation<Vector2D> eqn(phi);
    const ScalarFiniteVolumeField &gamma0 = gamma.oldField(0);
    const VectorFiniteVolumeField &phi0 = phi.oldField(0);

    for (const Cell &cell: phi.cells())
    {
        for (const InteriorLink &nb: cell.neighbours())
        {
            Scalar coeff = gamma(nb.face()) * dot(nb.rCellVec(), nb.outwardNorm()) / nb.rCellVec().magSqr();
            Scalar coeff0 = gamma0(nb.face()) * dot(nb.rCellVec(), nb.outwardNorm()) / nb.rCellVec().magSqr();
            eqn.add(cell, cell, theta * -coeff);
            eqn.add(cell, nb.cell(), theta * coeff);
            eqn.addSource(cell, (1. - theta) * coeff0 * (phi0(nb.cell()) - phi0(cell)));
        }

        for (const BoundaryLink &bd: cell.boundaries())
        {
            Scalar coeff = gamma(bd.face()) * dot(bd.rFaceVec(), bd.outwardNorm()) / bd.rFaceVec().magSqr();
            Scalar coeff0 = gamma0(bd.face()) * dot(bd.rFaceVec(), bd.outwardNorm()) / bd.rFaceVec().magSqr();

            switch (phi.boundaryType(bd.face()))
            {
            case VectorFiniteVolumeField::FIXED:
                eqn.add(cell, cell, theta * -coeff);
                eqn.addSource(cell, theta * coeff * phi(bd.face()));
                eqn.addSource(cell, (1. - theta) * coeff0 * (phi0(bd.face()) - phi0(cell)));
                break;

            case VectorFiniteVolumeField::NORMAL_GRADIENT:
                break;
            case VectorFiniteVolumeField::SYMMETRY:
            {
                Vector2D tw = bd.outwardNorm().tangentVec().unitVec();

                eqn.add(cell, cell, theta * -coeff);
                eqn.add(cell, cell, theta * coeff * outer(tw, tw));
                eqn.addSource(cell, (1. - theta) * coeff0 * (dot(phi0(cell), tw) * tw - phi0(cell)));
            }
                break;

            default:
                throw Exception("fv", "laplacian<Vector2D>", "unrecognized or unspecified boundary type.");
            }
        }
    }

    return eqn;
}
Esempio n. 2
0
/* set v-node state */
void SetVnSt( v_node *v_nodes, c_node * c_nodes,
        int CodeLength, double *col_one,
        int NumberCodeBits, double *input_decoder_c)
{
    int i, j;
    int c_index;
    
    for (i=0;i<CodeLength;i++) {
        
        *v_nodes[i].initial_value = input_decoder_c[i];
        for (j=0;j< *v_nodes[i].degree;j++) {
            
            v_nodes[i].index[j]=(int) (col_one[i+j*NumberCodeBits]);
            
            for (c_index=0;c_index<*c_nodes[ v_nodes[i].index[j] ].degree;c_index++)
                if ( c_nodes[ v_nodes[i].index[j] ].index[c_index] == i ) {
                v_nodes[i].socket[j] = c_index;
                break;
                }
            
            v_nodes[i].message[j] = phi0( fabs(input_decoder_c[i]) );
            
            if (input_decoder_c[i] < 0)
                v_nodes[i].sign[j] = 1;
            else
                v_nodes[i].sign[j] = 0;
        }
    }  
    
}
Esempio n. 3
0
//Hermite
void Hermite() 
{ 
    float passot=0.0001,tg,tc,cx,cy; 
    int i=1; 
    Derivata_x_rapp_incr();//calcola la derivata in x dei punti
    Derivata_y_rapp_incr();//calcola la derivata in y dei punti
  
    if(mod_der==1)//checkbox spuntato -> modifico il valore della derivata in un punto
    { 
        dx[ip]=val_der_x;
        dy[ip]=val_der_y; 
    } 
  
    for (tg=0;tg<=1;tg=tg+passot) //nell'intervallo [0,1] disegno punti variando 0.0001 ogni volta
    { 
          
        //localizziamo l'intervallo iesimo [t(i),t(i+1)] a cui il valore del parametro tg appartiene 
        //all'inizio i=1,parto quindi dal primo intervallo...ogni volta che supero l'intervallo incremento la i,spostandomi quindi nell'intervallo successivo
		if (tg>t[i+1]) 
            i++; 

        // mappare il punto tg appartenente all'intervallo [t(i),t(i+1)] in un punto tcappello in [0,1] 
        tc=(tg-t[i])/(t[i+1]-t[i]); 

        // valutiamo le coordinate del punto sulla curva con le formule di interpolazione di hermite 
        cx=Punti[i].x*phi0(tc)+
			dx[i]*phi1(tc)*(t[i+1]-t[i])+
			Punti[i+1].x*psi0(tc)+
			dx[i+1]*psi1(tc)*(t[i+1]-t[i]);

        cy=Punti[i].y*phi0(tc)+
			dy[i]*phi1(tc)*(t[i+1]-t[i])+
			Punti[i+1].y*psi0(tc)+
			dy[i+1]*psi1(tc)*(t[i+1]-t[i]);
  
		//disegno il punto ottenuto sullo schermo
        glBegin(GL_POINTS);
            glVertex2f(cx,cy); 
        glEnd(); 
    } 
    glFlush(); 
} 
Esempio n. 4
0
void Disegna_Funzioni_Base() 
{ 
    float fbasephi0[1000],fbasephi1[1000],fbasepsi0[1000],fbasepsi1[1000],tf,vt[1000]; 
    int n_pti_val=900,i=1; 
    float passo=1.0/(n_pti_val-1); 
  
    for(tf=0;tf<=1;tf+=passo) 
    { 
        vt[i]=tf; 
        fbasephi0[i]=phi0(tf); 
        fbasephi1[i]=phi1(tf); 
        fbasepsi0[i]=psi0(tf); 
        fbasepsi1[i]=psi1(tf); 
        i++; 
    } 
    //definiamo le coordinate della finestra reale(sul mondo) 
    glMatrixMode(GL_PROJECTION);   
    glLoadIdentity();   
    gluOrtho2D(0.0, 1.0, -0.8, 1.0); 
  
    //il contenuto della finestra reale prima definita verrà mappato nella viewport sullo schermo che ha origine in (0,500),h 150 e largh 150 
    glViewport(0,500,150,150); 
      
    glColor3f(0.0,0.0,1.0); 
    glBegin(GL_POINTS); 
        for(i=1;i<=n_pti_val;i++) 
            glVertex2f(vt[i],fbasephi0[i]);  
        glEnd(); 
  
    glColor3f(0.0,1.0,1.0); 
    glBegin(GL_POINTS); 
        for(i=1;i<=n_pti_val;i++) 
            glVertex2f(vt[i],fbasephi1[i]);  
        glEnd(); 
  
    glColor3f(0.0,1.0,0.0); 
    glBegin(GL_POINTS); 
    for(i=1;i<=n_pti_val;i++) 
        glVertex2f(vt[i],fbasepsi0[i]);  
    glEnd(); 
  
    glColor3f(1.0,0.0,0.0); 
    glBegin(GL_POINTS); 
    for(i=1;i<=n_pti_val;i++) 
        glVertex2f(vt[i],fbasepsi1[i]);  
    glEnd(); 
    glFlush(); 
  
    glMatrixMode(GL_PROJECTION);   
    glLoadIdentity();   
    gluOrtho2D(0.0, WINH, 0.0, WINH); 
    glViewport(0,0,WINH,WINH); 
} 
Esempio n. 5
0
    model_error_case()
        : acc_(2)
        , model_()
    {
        Eigen::VectorXd phi0(2), veps(2);
        Eigen::MatrixXd phi1(2,2);

        phi0 << 2, 3;
        phi1 << .80, 0, 0, .64;
        veps << 1.0, 0.25;
        model_ = alps::alea::util::var1_model<double>(phi0, phi1, veps);
    }
  Vector7d manipulablityG(const Vector7d& phi, const double m0, const double ks) {
	  const double h = 0.0000001;
	  Vector7d tau;
	  Vector7d phi0;
	  Vector7d phi1;
	  for (unsigned int i = 0; i < 7; i++) {
		  phi0 = phi1 = phi;
		  phi0(i) -= h;
		  phi1(i) += h;
		  tau(i) = (manipulablityV(phi1, m0, ks) - manipulablityV(phi0, m0, ks))/(2.0*h);
	  }
	  return tau;
  }
Esempio n. 7
0
alps::alea::util::var1_model<double> get_test_model()
{
    // Model setup
    Eigen::VectorXd phi0(2), veps(2);
    Eigen::MatrixXd phi1(2,2);
    phi0 << 2, 3;
    phi1 << .5, .25, .25, .3;
    veps << 1.0, 0.25;
    std::cerr << "PHI0=\n" << phi0
              << "\nPHI1=\n" << phi1
              << "\nVEPS=\n" << veps << "\n";
    return alps::alea::util::var1_model<double>(phi0, phi1, veps);
}
Esempio n. 8
0
    Field<dim> lbfgs(
      const Functional& F,
      const Gradient& dF,
      const Field<dim>& phi_start,
      const unsigned int m,
      const double eps
    )
    {
      double cost_old = std::numeric_limits<double>::infinity();
      double cost = F(phi_start);

      Field<dim> phi0(phi_start);
      DualField<dim> df0 = dF(phi_start);
      const auto& discretization = phi0.get_discretization();

      // Create vectors for storing the last few differences of the guesses,
      // differences of the gradients, and the inverses of their inner products
      std::vector<Field<dim>> s(m, Field<dim>(discretization));
      std::vector<DualField<dim>> y(m, DualField<dim>(discretization));
      std::vector<double> rho(m);

      // As an initial guess, we will assume that the Hessian inverse is a
      // multiple of the inverse of the mass matrix
      double gamma = 1.0;

      for (unsigned int k = 0; std::abs(cost_old - cost)/cost > eps; ++k) {
        const Field<dim> p = -lbfgs_two_loop(df0, s, y, rho, gamma);
        const Field<dim> phi1 = line_search(F, phi0, df0, p, eps);
        const DualField<dim> df1 = dF(phi1);

        s[0] = phi1 - phi0;
        y[0] = df1 - df0;

        const double cos_angle = inner_product(y[0], s[0]);
        const double norm_y = norm(y[0]);
        rho[0] = 1.0 / cos_angle;
        gamma = cos_angle / (norm_y * norm_y);

        std::rotate(s.begin(), s.begin() + 1, s.end());
        std::rotate(y.begin(), y.begin() + 1, y.end());
        std::rotate(rho.begin(), rho.begin() + 1, rho.end());

        phi0 = phi1;
        df0 = df1;
        cost_old = cost;
        cost = F(phi0);
      }

      return phi0;
    }
Esempio n. 9
0
TEST(var1_test, autocorr)
{
    Eigen::VectorXd phi0(2), veps(2);
    Eigen::MatrixXd phi1(2,2);
    phi0 << 2, 3;
    phi1 << .80, 0, 0, .64;
    veps << 1.0, 0.25;
    alps::alea::util::var1_model<double> model(phi0, phi1, veps);

    std::cerr << "EXACT MEAN=" << model.mean().transpose() << "\n";
    std::cerr << "EXACT TAU =" << model.ctau().diagonal().transpose() << "\n";

    alps::alea::autocorr_acc<double> acc(2);

    fill(model, acc, 400000);
    alps::alea::autocorr_result<double> res = acc.finalize();
    print_result(std::cerr, res);

    // perform T2 test
    alps::alea::t2_result t2 = alps::alea::test_mean(res, model.mean());
    print_t2(std::cerr, t2);
    ASSERT_GE(t2.pvalue(), 0.01);
}
Esempio n. 10
0
TEST(var1_test, same)
{
    Eigen::VectorXd phi0(2), veps_one(2), veps_two(2);
    Eigen::MatrixXd phi1(2,2);
    phi0 << 2, 3;
    phi1 << .90, 0, 0, .30;
    veps_one << 1.0, 0.25;
    veps_two << 2.0, 3.25;

    alps::alea::util::var1_model<double> model1(phi0, phi1, veps_one);
    alps::alea::util::var1_model<double> model2(phi0, phi1, veps_two);

    std::cerr << "EXACT MEAN=" << model1.mean().transpose() << "\n";

    alps::alea::autocorr_acc<double> acc1(2), acc2(2);
    fill(model1, acc1, 400000);
    fill(model2, acc2, 400000);

    alps::alea::autocorr_result<double> res1 = acc1.finalize();
    print_result(std::cerr, res1);

    alps::alea::autocorr_result<double> res2 = acc2.finalize();
    print_result(std::cerr, res2);

    // perform T2 test manually
    alps::alea::var_result<double> diff = alps::alea::internal::pool_var(res1, res2);
    print_result(std::cerr, diff);
    alps::alea::t2_result t2 = alps::alea::t2_test(diff.mean(), diff.var(),
                                                   diff.observations(), 1, 1e-10);
    print_t2(std::cerr, t2);
    ASSERT_GE(t2.pvalue(), 0.01);

    // Perform T2 test automatically
    t2 = alps::alea::test_mean(res1, res2);
    ASSERT_GE(t2.pvalue(), 0.01);
}
kinematicSingleLayer::kinematicSingleLayer
(
    const word& modelType,
    const fvMesh& mesh,
    const dimensionedVector& g,
    const word& regionType,
    const bool readFields
)
:
    surfaceFilmModel(modelType, mesh, g, regionType),

    momentumPredictor_(solution().subDict("PISO").lookup("momentumPredictor")),
    nOuterCorr_(solution().subDict("PISO").lookupOrDefault("nOuterCorr", 1)),
    nCorr_(readLabel(solution().subDict("PISO").lookup("nCorr"))),
    nNonOrthCorr_
    (
        readLabel(solution().subDict("PISO").lookup("nNonOrthCorr"))
    ),

    cumulativeContErr_(0.0),

    deltaSmall_("deltaSmall", dimLength, SMALL),
    deltaCoLimit_(solution().lookupOrDefault("deltaCoLimit", 1e-4)),

    rho_
    (
        IOobject
        (
            "rhof",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimDensity, 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),
    mu_
    (
        IOobject
        (
            "muf",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimPressure*dimTime, 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),
    sigma_
    (
        IOobject
        (
            "sigmaf",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimMass/sqr(dimTime), 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),

    delta_
    (
        IOobject
        (
            "deltaf",
            time().timeName(),
            regionMesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh()
    ),
    alpha_
    (
        IOobject
        (
            "alpha",
            time().timeName(),
            regionMesh(),
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimless, 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),
    U_
    (
        IOobject
        (
            "Uf",
            time().timeName(),
            regionMesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh()
    ),
    Us_
    (
        IOobject
        (
            "Usf",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        U_,
        zeroGradientFvPatchScalarField::typeName
    ),
    Uw_
    (
        IOobject
        (
            "Uwf",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        U_,
        zeroGradientFvPatchScalarField::typeName
    ),
    deltaRho_
    (
        IOobject
        (
            delta_.name() + "*" + rho_.name(),
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", delta_.dimensions()*rho_.dimensions(), 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),

    phi_
    (
        IOobject
        (
            "phi",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("0", dimLength*dimMass/dimTime, 0.0)
    ),

    primaryMassTrans_
    (
        IOobject
        (
            "primaryMassTrans",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimMass, 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),
    cloudMassTrans_
    (
        IOobject
        (
            "cloudMassTrans",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimMass, 0.0),
        zeroGradientFvPatchScalarField::typeName
    ),
    cloudDiameterTrans_
    (
        IOobject
        (
            "cloudDiameterTrans",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimLength, -1.0),
        zeroGradientFvPatchScalarField::typeName
    ),

    USp_
    (
        IOobject
        (
            "USpf",
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedVector
        (
            "zero", dimMass*dimVelocity/dimArea/dimTime, Zero
        ),
        this->mappedPushedFieldPatchTypes<vector>()
    ),
    pSp_
    (
        IOobject
        (
            "pSpf",
            time_.timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimPressure, 0.0),
        this->mappedPushedFieldPatchTypes<scalar>()
    ),
    rhoSp_
    (
        IOobject
        (
            "rhoSpf",
            time_.timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimMass/dimTime/dimArea, 0.0),
        this->mappedPushedFieldPatchTypes<scalar>()
    ),

    USpPrimary_
    (
        IOobject
        (
            USp_.name(), // must have same name as USp_ to enable mapping
            time().timeName(),
            primaryMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        primaryMesh(),
        dimensionedVector("zero", USp_.dimensions(), Zero)
    ),
    pSpPrimary_
    (
        IOobject
        (
            pSp_.name(), // must have same name as pSp_ to enable mapping
            time().timeName(),
            primaryMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        primaryMesh(),
        dimensionedScalar("zero", pSp_.dimensions(), 0.0)
    ),
    rhoSpPrimary_
    (
        IOobject
        (
            rhoSp_.name(), // must have same name as rhoSp_ to enable mapping
            time().timeName(),
            primaryMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        primaryMesh(),
        dimensionedScalar("zero", rhoSp_.dimensions(), 0.0)
    ),

    UPrimary_
    (
        IOobject
        (
            "U", // must have same name as U to enable mapping
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedVector("zero", dimVelocity, Zero),
        this->mappedFieldAndInternalPatchTypes<vector>()
    ),
    pPrimary_
    (
        IOobject
        (
            "p", // must have same name as p to enable mapping
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimPressure, 0.0),
        this->mappedFieldAndInternalPatchTypes<scalar>()
    ),
    rhoPrimary_
    (
        IOobject
        (
            "rho", // must have same name as rho to enable mapping
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimDensity, 0.0),
        this->mappedFieldAndInternalPatchTypes<scalar>()
    ),
    muPrimary_
    (
        IOobject
        (
            "thermo:mu", // must have same name as mu to enable mapping
            time().timeName(),
            regionMesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        regionMesh(),
        dimensionedScalar("zero", dimPressure*dimTime, 0.0),
        this->mappedFieldAndInternalPatchTypes<scalar>()
    ),

    filmThermo_(filmThermoModel::New(*this, coeffs_)),

    availableMass_(regionMesh().nCells(), 0.0),

    injection_(*this, coeffs_),

    transfer_(*this, coeffs_),

    turbulence_(filmTurbulenceModel::New(*this, coeffs_)),

    forces_(*this, coeffs_),

    addedMassTotal_(0.0)
{
    if (readFields)
    {
        transferPrimaryRegionThermoFields();

        correctAlpha();

        correctThermoFields();

        deltaRho_ == delta_*rho_;

        surfaceScalarField phi0
        (
            IOobject
            (
                "phi",
                time().timeName(),
                regionMesh(),
                IOobject::READ_IF_PRESENT,
                IOobject::AUTO_WRITE,
                false
            ),
            fvc::flux(deltaRho_*U_)
        );

        phi_ == phi0;
    }
}