tmp<volScalarField> laminar::nuSgs() const
{
    return tmp<volScalarField>
    (
        new volScalarField
        (
            IOobject
            (
                "nuSgs",
                runTime_.timeName(),
                U_.db(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh_,
            dimensionedScalar("nuSgs", nu().dimensions(), 0.0)
        )
    );
}
// Update the coefficients associated with the patch field
void tractionDisplacementCorrectionFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const dictionary& mechanicalProperties = db().lookupObject<IOdictionary>
    (
        "mechanicalProperties"
    );

    dimensionedScalar rho(mechanicalProperties.lookup("rho"));
    dimensionedScalar rhoE(mechanicalProperties.lookup("E"));
    dimensionedScalar nu(mechanicalProperties.lookup("nu"));

    dimensionedScalar E = rhoE/rho;
    dimensionedScalar mu = E/(2.0*(1.0 + nu));
    dimensionedScalar lambda = nu*E/((1.0 + nu)*(1.0 - 2.0*nu));

    Switch planeStress(mechanicalProperties.lookup("planeStress"));

    if (planeStress)
    {
        lambda = nu*E/((1.0 + nu)*(1.0 - nu));
    }

    vectorField n = patch().nf();

    const fvPatchField<symmTensor>& sigmaD =
        patch().lookupPatchField<volSymmTensorField, symmTensor>("sigmaD");

    const fvPatchField<tensor>& sigmaExp = 
        patch().lookupPatchField<volTensorField, tensor>("sigmaExp");

    gradient() =
    (
        (traction_ + pressure_*n)/rho.value() - (n & (sigmaD + sigmaExp))
    )/(2.0*mu + lambda).value();

    fixedGradientFvPatchVectorField::updateCoeffs();
}
void NSNeutronEqResid<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  typedef Intrepid::FunctionSpaceTools FST;

  FST::scalarMultiplyDataData<ScalarT> (flux, NeutronDiff, NGrad);

  FST::integrate<ScalarT>(NResidual, flux, wGradBF, Intrepid::COMP_CPP, false); // "false" overwrites
  
  for (std::size_t cell=0; cell < workset.numCells; ++cell) {
    for (std::size_t qp=0; qp < numQPs; ++qp) {
      abscoeff(cell,qp) = 
	(Absorp(cell,qp) - nu(cell,qp)*Fission(cell,qp)) * Neutron(cell,qp);
      if (haveNeutSource) abscoeff(cell,qp) -= Source(cell,qp);
    }
  }

  FST::integrate<ScalarT>(NResidual, abscoeff, wBF, Intrepid::COMP_CPP, true); // "true" sums into

}
Example #4
0
//---------------------------------------------------------------------------
dimensionedScalar createFields( const TimeHolder& runTime,
                                const fvMeshHolder& mesh,
                                IOdictionaryHolder& transportProperties,
                                volScalarFieldHolder& p,
                                volVectorFieldHolder& U,
                                surfaceScalarFieldHolder& phi,
                                label& pRefCell,
                                scalar& pRefValue )
{
    Info<< "Reading transportProperties\n" << endl;

    transportProperties = IOdictionaryHolder( IOobjectHolder( "transportProperties",
                          runTime->constant(),
                          mesh,
                          IOobject::MUST_READ_IF_MODIFIED,
                          IOobject::NO_WRITE ) );

    dimensionedScalar nu ( transportProperties->lookup("nu") );

    Info << "Reading field p\n" << endl;

    p = volScalarFieldHolder( IOobjectHolder( "p",
                              runTime->timeName(),
                              mesh,
                              IOobject::MUST_READ,
                              IOobject::AUTO_WRITE ), mesh );

    Info<< "Reading field U\n" << endl;
    U = volVectorFieldHolder( IOobjectHolder( "U",
                              runTime->timeName(),
                              mesh,
                              IOobject::MUST_READ,
                              IOobject::AUTO_WRITE ), mesh );


    phi =createPhi( runTime, mesh, U );

    setRefCell( p, mesh->solutionDict().subDict("PISO"), pRefCell, pRefValue);

    return nu;
}
// Update the coefficients associated with the patch field
void tractionDisplacementFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const dictionary& mechanicalProperties =
        db().lookupObject<IOdictionary>("mechanicalProperties");

    dimensionedScalar rho(mechanicalProperties.lookup("rho"));
    dimensionedScalar rhoE(mechanicalProperties.lookup("E"));
    dimensionedScalar nu(mechanicalProperties.lookup("nu"));

    dimensionedScalar E = rhoE/rho;
    dimensionedScalar mu = E/(2.0*(1.0 + nu));
    dimensionedScalar lambda = nu*E/((1.0 + nu)*(1.0 - 2.0*nu));
    dimensionedScalar threeK = E/(1.0 - 2.0*nu);

    Switch planeStress(mechanicalProperties.lookup("planeStress"));

    if (planeStress)
    {
        lambda = nu*E/((1.0 + nu)*(1.0 - nu));
        threeK = E/(1.0 - nu);
    }

    vectorField n = patch().nf();

    const fvPatchField<tensor>& gradU =
        patch().lookupPatchField<volTensorField, tensor>("grad(U)");

    gradient() =
    (
        (traction_ - pressure_*n)/rho.value()
      - (n & (mu.value()*gradU.T() - (mu + lambda).value()*gradU))
      - n*tr(gradU)*lambda.value()
    )/(2.0*mu + lambda).value();

    fixedGradientFvPatchVectorField::updateCoeffs();
}
Example #6
0
typename mtl::vec::dense_vector<typename Collection<Vector>::value_type, parameters<> >
inline householder_s(Vector& y)
{
    vampir_trace<2005> tracer;
    typedef typename  Collection<Vector>::value_type   value_type;
    const value_type  zero= math::zero(y[0]);

    Vector            u(y);
    value_type        nu(sqrt( dot(u, u) )), s;

    if (nu != zero){
	if(u[0] < 0){
		s= -1;
	} else {
		s= 1; 
	}
	u[0]= u[0] + s * nu;
	u/= sqrt( dot(u, u) );
    }

    return u;
}
void PDPS::draw(){

  const Mat & sumlog(m_->suf()->sumlog());
  double nobs(m_->suf()->n());
  Mat Nu(m_->Nu());
  uint d= nrow(Nu);
  for(uint i=0; i<d; ++i){
    Vec sumlog_i(sumlog.row(i));
    Vec nu(Nu.row(i));
    for(uint j=0; j<d; ++j){
      DirichletLogp logp(j, nu, sumlog_i, nobs,
                         phi_row_prior_[i], alpha_row_prior_[i],
                         min_nu_);
      ScalarSliceSampler sam(logp, true);
      sam.set_lower_limit(min_nu_);
      nu[j]= sam.draw(nu[j]);
    }
    Nu.row(i) = nu;
  }

  m_->set_Nu(Nu);
}
void SpalartAllmaras::correct(const tmp<volTensorField>& gradU)
{
    LESModel::correct(gradU);

    if (mesh_.changing())
    {
        y_.correct();
        y_.boundaryField() = max(y_.boundaryField(), VSMALL);
    }

    const volScalarField S(this->S(gradU));
    const volScalarField dTilda(this->dTilda(S));
    const volScalarField STilda(this->STilda(S, dTilda));

    tmp<fvScalarMatrix> nuTildaEqn
    (
        fvm::ddt(nuTilda_)
      + fvm::div(phi(), nuTilda_)
      - fvm::laplacian
        (
            (nuTilda_ + nu())/sigmaNut_,
            nuTilda_,
            "laplacian(DnuTildaEff,nuTilda)"
        )
      - Cb2_/sigmaNut_*magSqr(fvc::grad(nuTilda_))
     ==
        Cb1_*STilda*nuTilda_
      - fvm::Sp(Cw1_*fw(STilda, dTilda)*nuTilda_/sqr(dTilda), nuTilda_)
    );

    nuTildaEqn().relax();
    nuTildaEqn().solve();

    bound(nuTilda_, dimensionedScalar("zero", nuTilda_.dimensions(), 0.0));
    nuTilda_.correctBoundaryConditions();

    updateSubGridScaleFields();
}
Example #9
0
// Bestimmung der dynamischen Viskositaet
Foam::tmp<Foam::volScalarField> Foam::power::mu() const
{
    if (obr_.foundObject<fluidThermo>("thermophysicalProperties"))
    {
        const fluidThermo& thermo =
             obr_.lookupObject<fluidThermo>("thermophysicalProperties");

        return thermo.mu();
    }
    else if
    (
        obr_.foundObject<singlePhaseTransportModel>("transportProperties")
    )
    {
        const transportModel& laminarT =
            obr_.lookupObject<transportModel>
            ("transportProperties");

        return rho()*laminarT.nu();
    }
    else if (obr_.foundObject<dictionary>("transportProperties"))
    {
        const dictionary& transportProperties =
             obr_.lookupObject<dictionary>("transportProperties");

        dimensionedScalar nu(transportProperties.lookup("nu"));

        return rho()*nu;
    }
    else
    {
        FatalErrorIn("power::mu()")
            << "No valid model for dynamic viscosity calculation"
            << exit(FatalError);

        return volScalarField::null();
    }
}
Example #10
0
    void doc_manager::populate(void)
    {
        
        add_class_descriptor(ml::k_base);
        
        add_class_descriptors(ml::k_base, {
            ml::k_classification,
            ml::k_regression
        });
        
        add_class_descriptors(ml::k_regression, {
            ml::k_ann,
            ml::k_linreg,
            ml::k_logreg
        });
        
        add_class_descriptors(ml::k_classification, {
            ml::k_svm,
            ml::k_adaboost,
            ml::k_anbc,
            ml::k_dtw,
            ml::k_hmmc,
            ml::k_softmax,
            ml::k_randforest,
            ml::k_mindist,
            ml::k_knn,
            ml::k_gmm,
            ml::k_dtree
        });
        
        add_class_descriptors(ml::k_feature_extraction, {
            ml::k_peak,
            ml::k_minmax,
            ml::k_zerox
        });
        
        descriptors[ml::k_ann].desc("Artificial Neural Network").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/MLP");
        descriptors[ml::k_linreg].desc("Linear Regression").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/LinearRegression");
        descriptors[ml::k_logreg].desc("Logistic Regression").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/LogisticRegression");
        descriptors[ml::k_peak].desc("Peak Detection").url("").num_outlets(1);
        descriptors[ml::k_minmax].desc("Minimum / Maximum Detection").url("").num_outlets(1);
        descriptors[ml::k_zerox].desc("Zero Crossings Detection").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/ZeroCrossingCounter");
        descriptors[ml::k_svm].desc("Support Vector Machine").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/SVM");
        descriptors[ml::k_adaboost].desc("Adaptive Boosting").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/AdaBoost");
        descriptors[ml::k_anbc].desc("Adaptive Naive Bayes Classifier").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/ANBC");
        descriptors[ml::k_dtw].desc("Dynamic Time Warping").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/DTW");
        descriptors[ml::k_hmmc].desc("Continuous Hidden Markov Model").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/HMM");
        descriptors[ml::k_softmax].desc("Softmax Classifier").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/Softmax");
        descriptors[ml::k_randforest].desc("Random Forests").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/RandomForests");
        descriptors[ml::k_mindist].desc("Minimum Distance").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/MinDist");
        descriptors[ml::k_knn].desc("K Nearest Neighbour").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/KNN");
        descriptors[ml::k_gmm].desc("Gaussian Mixture Model").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/GMMClassifier");
        descriptors[ml::k_dtree].desc("Decision Trees").url("http://www.nickgillian.com/wiki/pmwiki.php/GRT/DecisionTree");
        
        for (auto& desc : {&descriptors[ml::k_hmmc], &descriptors[ml::k_dtw]})
        {
            desc->notes(
                        "add and map messages for time series should be delimited with record messages, e.g. record 1, add 1 40 50, add 1 41 50, record 0"
            );
        }
        
        // base descriptor
        message_descriptor add(
                              "add",
                              "list comprising a class id followed by n features, <class> <feature 1> <feature 2> etc",
                               "1 0.2 0.7 0.3 0.1"
                              );

        
        message_descriptor train(
                                "train",
                                "train the model based on vectors added with 'add'"
                                );
        
        message_descriptor map(
                              "map",
                              "generate the output value(s) for the input feature vector",
                               "0.2 0.7 0.3 0.1"
                              );
        
        message_descriptor write(
                                 "write",
                                 "write training data and / or model, first argument gives path to write file",
                                 "/path/to/my_ml-lib_data"
                                 );
        
        message_descriptor read(
                                "read",
                                "read training data and / or model, first argument gives path to the read file",
                                "/path/to/my_ml-lib_data"
                                );
        
        message_descriptor clear(
                                 "clear",
                                 "clear the stored training data and model"
                                 );
        
        message_descriptor help(
                               "help",
                               "post usage statement to the console"
                               );
        
        valued_message_descriptor<int> scaling(
                                               "scaling",
                                               "sets whether values are automatically scaled",
                                               {0, 1},
                                               1
                                               );
        
        valued_message_descriptor<int> record(
                                              "record",
                                              "start or stop time series recording for a single example of a given class",
                                              {0, 1},
                                              0
                                              );
        
        ranged_message_descriptor<float> training_rate(
                                                       "training_rate",
                                                       "set the learning rate, used to update the weights at each step of learning algorithms such as stochastic gradient descent.",
                                                       0.01,
                                                       1.0,
                                                       0.1
                                                       );
        
        ranged_message_descriptor<float> min_change(
                                                    "min_change",
                                                    "set the minimum change that must be achieved between two training epochs for the training to continue",
                                                    0.0,
                                                    1.0,
                                                    1.0e-5
                                                    );
        
        ranged_message_descriptor<int> max_iterations(
                                                      "max_iterations",
                                                      "set the maximum number of training iterations",
                                                      0,
                                                      1000,
                                                      100
                                                      );
        
        record.insert_before = "add";
        descriptors[ml::k_base].add_message_descriptor(add, write, read, train, clear, map, help, scaling, training_rate, min_change, max_iterations);

        // generic classification descriptor
        valued_message_descriptor<bool> null_rejection(
                                                       "null_rejection",
                                                       "toggle NULL rejection off or on, when 'on' classification results below the NULL-rejection threshold will be discarded",
                                                       {false, true},
                                                       true
                                                       );
        
        ranged_message_descriptor<float> null_rejection_coeff(
                                                              "null_rejection_coeff",
                                                              "set a multiplier for the NULL-rejection threshold ",
                                                              0.1,
                                                              1.0,
                                                              0.9
                                                              );
        
        valued_message_descriptor<int> probs(
                                             "probs",
                                             "determines whether probabilities are sent from the right outlet",
                                             {0, 1},
                                             0
                                             );
        
        descriptors[ml::k_classification].add_message_descriptor(null_rejection_coeff, probs, null_rejection);
        
        // generic feature extraction descriptor
//        descriptors[ml::k_feature_extraction].add_message_descriptor(null_rejection_coeff, null_rejection);

        // generic regression descriptor
       
        
//        descriptors[ml::k_regression].add_message_descriptor(training_rate, min_change, max_iterations);
        
        // Object-specific descriptors
        //-- Regressifiers
        //---- ann
        valued_message_descriptor<ml::data_type> mode("mode",
                                                      "set the mode of the ANN, " + std::to_string(ml::LABELLED_CLASSIFICATION) + " for classification, " + std::to_string(ml::LABELLED_REGRESSION) + " for regression",
                                                      {ml::LABELLED_CLASSIFICATION, ml::LABELLED_REGRESSION, ml::LABELLED_TIME_SERIES_CLASSIFICATION},
                                                      ml::defaults::data_type
                                                      );
        
        
        message_descriptor add_ann(
                              "add",
                              "class id followed by n features, <class> <feature 1> <feature 2> etc when in classification mode or N output values followed by M input values when in regression mode (N = num_outputs)",
                                   "1 0.2 0.7 0.3 0.1"

                              );
      
        ranged_message_descriptor<int> num_outputs(
                                                   "num_outputs",
                                                   "set the number of neurons in the output layer",
                                                   1,
                                                   1000,
                                                   ml::defaults::num_output_dimensions
                                                   );
        
        ranged_message_descriptor<int> num_hidden(
                                                  "num_hidden",
                                                  "set the number of neurons in the hidden layer",
                                                  1,
                                                  1000,
                                                  ml::defaults::num_hidden_neurons
                                                  );
        
        ranged_message_descriptor<int> min_epochs(
                                                  "min_epochs",
                                                  "setting the minimum number of training iterations",
                                                  1,
                                                  1000,
                                                  10
                                                  );
        
        // TODO: check if the "epochs" are still needed or if we can use "iterations" as inherited from ml_regression
        ranged_message_descriptor<int> max_epochs(
                                                  "max_epochs",
                                                  "setting the maximum number of training iterations",
                                                  1,
                                                  10000,
                                                  100
                                                  );

        ranged_message_descriptor<float> momentum(
                                                  "momentum",
                                                  "set the momentum",
                                                  0.0,
                                                  1.0,
                                                  0.5
                                                  );
        
        ranged_message_descriptor<float> gamma(
                                                  "gamma",
                                                  "set the gamma",
                                                  0.0,
                                                  10.0,
                                                  2.0
                                                  );
        
        // TODO: have optional value_labels for value labels
        valued_message_descriptor<int> input_activation_function(
                                                                 "input_activation_function",
                                                                 "set the activation function for the input layer, 0:LINEAR, 1:SIGMOID, 2:BIPOLAR_SIGMOID",
                                                                 {0, 1, 2},
                                                                 0
                                                                 );
        
        valued_message_descriptor<int> hidden_activation_function(
                                                                 "hidden_activation_function",
                                                                 "set the activation function for the hidden layer, 0:LINEAR, 1:SIGMOID, 2:BIPOLAR_SIGMOID",
                                                                 {0, 1, 2},
                                                                 0
                                                                 );
        
        valued_message_descriptor<int> output_activation_function(
                                                                 "output_activation_function",
                                                                 "set the activation function for the output layer, 0:LINEAR, 1:SIGMOID, 2:BIPOLAR_SIGMOID",
                                                                 {0, 1, 2},
                                                                 0
                                                                 );

                                                                 
        ranged_message_descriptor<int> rand_training_iterations(
                                                                 "rand_training_iterations",
                                                                 "set the number of random training iterations",
                                                                 0,
                                                                 1000,
                                                                 10
                                                                 );

        valued_message_descriptor<bool> use_validation_set(
                                                           "use_validation_set",
                                                           "set whether to use a validation training set",
                                                           {false, true},
                                                           true
                                                           );
        
        ranged_message_descriptor<int> validation_set_size(
                                                           "validation_set_size",
                                                           "set the size of the validation set",
                                                           1,
                                                           100,
                                                           20
                                                           );
        
        valued_message_descriptor<bool> randomize_training_order(
                                                           "randomize_training_order",
                                                           "sets whether to randomize the training order",
                                                           {false, true},
                                                           false
                                                           );
        
        
        descriptors[ml::k_ann].add_message_descriptor(add_ann, probs, mode, null_rejection, null_rejection_coeff, num_outputs, num_hidden, min_epochs, max_epochs, momentum, gamma, input_activation_function, hidden_activation_function, output_activation_function, rand_training_iterations, use_validation_set, validation_set_size, randomize_training_order);
        
        
        //-- Classifiers
        //---- ml.svm
        ranged_message_descriptor<int> type(
                                            "type",
                                            "set SVM type,"
                                            " 0:C-SVC (multi-class),"
                                            " 1:nu-SVC (multi-class),"
                                            " 2:one-class SVM,"
                                           // " 3:epsilon-SVR (regression),"
                                           // " 4:nu-SVR (regression)"
                                            ,
                                            0,
                                            2,
                                            0
                                            //        "	0 -- C-SVC		(multi-class classification)\n"
                                            //        "	1 -- nu-SVC		(multi-class classification)\n"
                                            //        "	2 -- one-class SVM\n"
                                            //        "	3 -- epsilon-SVR	(regression)\n"
                                            //        "	4 -- nu-SVR		(regression)\n"

                                            );
        
        ranged_message_descriptor<int> kernel(
                                              "kernel",
                                              "set type of kernel function, "
                                              "0:linear, " // (u'*v),"
                                              "1:polynomial, " // (gamma*u'*v + coef0)^degree,"
                                              "2:radial basis function, " //: exp(-gamma*|u-v|^2),"
                                              "3:sigmoid, " //  tanh(gamma*u'*v + coef0),"
                                              "4:precomputed kernel (kernel values in training_set_file)",
                                              0,
                                              4,
                                              0
                                              //        "	0 -- linear: u'*v\n"
                                              //        "	1 -- polynomial: (gamma*u'*v + coef0)^degree\n"
                                              //        "	2 -- radial basis function: exp(-gamma*|u-v|^2)\n"
                                              //        "	3 -- sigmoid: tanh(gamma*u'*v + coef0)\n"
                                              //        "	4 -- precomputed kernel (kernel values in training_set_file)\n"
                                              );
        
        ranged_message_descriptor<float> degree(
                                              "degree",
                                              "set degree in kernel function",
                                              0,
                                              20,
                                              3
                                              );
        
        ranged_message_descriptor<float> svm_gamma(
                                              "gamma",
                                              "set gamma in kernel function",
                                              0.0,
                                              1.0,
                                              0.5
                                              );
        
        ranged_message_descriptor<float> coef0(
                                               "coef0",
                                               "coef0 in kernel function",
                                               INFINITY * -1.f, INFINITY,
                                               0.0
                                               );
        
        ranged_message_descriptor<float> cost(
                                               "cost",
                                               "set the parameter C of C-SVC, epsilon-SVR, and nu-SVR",
                                               INFINITY * -1.f, INFINITY,
                                               1.0
                                               );
        
        ranged_message_descriptor<float> nu(
                                              "nu",
                                              "set the parameter nu of nu-SVC, one-class SVM, and nu-SVR",
                                              INFINITY * -1.f, INFINITY,
                                              0.5
                                              );
        
        message_descriptor cross_validation(
                                            "cross_validation",
                                            "perform cross validation"
                                            );
        
        ranged_message_descriptor<int> num_folds(
                                                 "num_folds",
                                                 "set the number of folds used for cross validation",
                                                 1, 100,
                                                 10
                                                 );
        
        descriptors[ml::k_svm].add_message_descriptor(cross_validation, num_folds, type, kernel, degree, svm_gamma, coef0, cost, nu);
        
        //---- ml.adaboost        
        ranged_message_descriptor<int> num_boosting_iterations(
                                                                "num_boosting_iterations",
                                                               "set the number of boosting iterations that should be used when training the model",
                                                               0,
                                                               200,
                                                               20
                                                               );
        
        valued_message_descriptor<int> prediction_method(
                                                        "prediction_method",
                                                         "set the Adaboost prediction method, 0:MAX_VALUE, 1:MAX_POSITIVE_VALUE",
                                                         {GRT::AdaBoost::MAX_VALUE, GRT::AdaBoost::MAX_POSITIVE_VALUE},
                                                         GRT::AdaBoost::MAX_VALUE
                                                         
        );
        
        valued_message_descriptor<int> set_weak_classifier(
                                                           "set_weak_classifier",
                                                           "sets the weak classifier to be used by Adaboost, 0:DECISION_STUMP, 1:RADIAL_BASIS_FUNCTION",
                                                           {ml::weak_classifiers::DECISION_STUMP, ml::weak_classifiers::RADIAL_BASIS_FUNCTION},
                                                           ml::weak_classifiers::DECISION_STUMP
                                                           );
        
        valued_message_descriptor<int> add_weak_classifier(
                                                           "add_weak_classifier",
                                                           "add a weak classifier to the list of classifiers used by Adaboost",
                                                           {ml::weak_classifiers::DECISION_STUMP, ml::weak_classifiers::RADIAL_BASIS_FUNCTION},
                                                           ml::weak_classifiers::DECISION_STUMP
                                                           );

        descriptors[ml::k_adaboost].add_message_descriptor(num_boosting_iterations, prediction_method, set_weak_classifier, add_weak_classifier);
        
        //---- ml.anbc
        message_descriptor weights("weights",
                                   "vector of 1 integer and N floating point values where the integer is a class label and the floats are the weights for that class. Sending weights with a vector size of zero clears all weights"
                                   );
        
        descriptors[ml::k_anbc].add_message_descriptor(weights);
        
        //---- ml.dtw
        valued_message_descriptor<int> rejection_mode(
                                                      "rejection_mode",
                                                      "sets the method used for null rejection, 0:TEMPLATE_THRESHOLDS, 1:CLASS_LIKELIHOODS, 2:THRESHOLDS_AND_LIKELIHOODS",
                                                      {GRT::DTW::TEMPLATE_THRESHOLDS, GRT::DTW::CLASS_LIKELIHOODS, GRT::DTW::THRESHOLDS_AND_LIKELIHOODS},
                                                      GRT::DTW::TEMPLATE_THRESHOLDS
                                                      );
        
        ranged_message_descriptor<float> warping_radius(
                                                        "warping_radius",
                                                        "sets the radius of the warping path, which is used if the constrain_warping_path is set to 1",
                                                        0.0,
                                                        1.0,
                                                        0.2
                                                        );
        
        valued_message_descriptor<bool> offset_time_series(
                                                           "offset_time_series",
                                                           "set if each timeseries should be offset by the first sample in the time series",
                                                           {false, true},
                                                           false
                                                           );
        
        valued_message_descriptor<bool> constrain_warping_path(
                                                           "constrain_warping_path",
                                                           "sets the warping path should be constrained to within a specific radius from the main diagonal of the cost matrix",
                                                           {false, true},
                                                           true
                                                           );
        
        valued_message_descriptor<bool> enable_z_normalization(
                                                               "enable_z_normalization",
                                                               "turn z-normalization on or off for training and prediction",
                                                               {false, true},
                                                               false
                                                               );
        
        valued_message_descriptor<bool> enable_trim_training_data(
                                                               "enable_trim_training_data",
                                                               "enabling data trimming prior to training",
                                                               {false, true},
                                                               false
                                                               );
  
        descriptors[ml::k_dtw].insert_message_descriptor(record);
        descriptors[ml::k_dtw].add_message_descriptor(rejection_mode, warping_radius, offset_time_series, constrain_warping_path, enable_z_normalization, enable_trim_training_data);
        
        //---- ml.hmmc
        valued_message_descriptor<int> model_type(
                                                  "model_type",
                                                  "set the model type used, 0:ERGODIC, 1:LEFTRIGHT",
                                                  {HMM_ERGODIC, HMM_LEFTRIGHT},
                                                  HMM_LEFTRIGHT
                                                  );
        
        ranged_message_descriptor<int> delta(
                                             "delta",
                                             "control how many states a model can transition to if the LEFTRIGHT model type is used",
                                             1,
                                             100,
                                             11
                                             );
        
        ranged_message_descriptor<int> max_num_iterations(
                                                          "max_num_iterations",
                                                          "set the maximum number of training iterations",
                                                          1,
                                                          1000,
                                                          100
                                                          );
        
        ranged_message_descriptor<int> committee_size(
                                                      "committee_size",
                                                      "set the committee size for the number of votes combined to make a prediction",
                                                      1,
                                                      1000,
                                                      5
                                                      );
        
        ranged_message_descriptor<int> downsample_factor(
                                                      "downsample_factor",
                                                         "set the downsample factor for the resampling of each training time series. A factor of 5 will result in each time series being resized (smaller) by a factor of 5",
                                                      1,
                                                      1000,
                                                      5
                                                      );
        
        descriptors[ml::k_hmmc].insert_message_descriptor(record);
        descriptors[ml::k_hmmc].add_message_descriptor(model_type, delta, max_num_iterations, committee_size, downsample_factor);
        
        //---- ml.softmax
        
        //---- ml.randforest
        ranged_message_descriptor<int> num_random_splits(
                                                         "num_random_splits",
                                                         "set the number of steps that will be used to search for the best spliting value for each node",
                                                         1,
                                                         1000,
                                                         100
                                                         );
        
        ranged_message_descriptor<int> min_samples_per_node2(
                                                            "min_samples_per_node",
                                                            "set the minimum number of samples that are allowed per node",
                                                            1,
                                                            100,
                                                            5
                                                            );
        
        ranged_message_descriptor<int> max_depth(
                                                 "max_depth",
                                                 "sets the maximum depth of the tree, any node that reaches this depth will automatically become a leaf node",
                                                 1,
                                                 100,
                                                 10
                                                 );

        descriptors[ml::k_randforest].add_message_descriptor(num_random_splits, min_samples_per_node2, max_depth);
        
        //----ml.mindist
        ranged_message_descriptor<int> num_clusters(
                                                    "num_clusters",
                                                    "set how many clusters each model will try to find during the training phase",
                                                    1,
                                                    100,
                                                    10
                                                    );

        descriptors[ml::k_mindist].add_message_descriptor(num_clusters);
                
        //---- ml.knn
//        "best_k_value_search:\tbool (0 or 1) set whether k value search is enabled or not (default 0)\n";

        ranged_message_descriptor<int> k(
                                         "k",
                                         "sets the K nearest neighbours that will be searched for by the algorithm during prediction",
                                         1,
                                         500,
                                         10
                                         );
        
        ranged_message_descriptor<int> min_k_search_value(
                                         "min_k_search_value",
                                         "set the minimum K value to use when searching for the best K value",
                                         1,
                                         500,
                                         1
                                         );
        
        ranged_message_descriptor<int> max_k_search_value(
                                                          "max_k_search_value",
                                                          "set the maximum K value to use when searching for the best K value",
                                                          1,
                                                          500,
                                                          10
                                                          );
        
        valued_message_descriptor<bool> best_k_value_search(
                                                            "best_k_value_search",
                                                            "set whether k value search is enabled or not",
                                                            {false, true},
                                                            false
                                                            );
        
        descriptors[ml::k_knn].add_message_descriptor(k, min_k_search_value, max_k_search_value, best_k_value_search);
        
        //---- ml.gmm
        ranged_message_descriptor<int> num_mixture_models(
                                                          "num_mixture_models",
                                                          "sets the number of mixture models used for class",
                                                          1,
                                                          20,
                                                          2
                                                          );

        descriptors[ml::k_gmm].add_message_descriptor(num_mixture_models);

        //---- ml.dtree
        valued_message_descriptor<bool> training_mode(
                                                      "training_mode",
                                                      "set the training mode",
                                                      {GRT::Tree::BEST_ITERATIVE_SPILT, GRT::Tree::BEST_RANDOM_SPLIT},
                                                      GRT::Tree::BEST_ITERATIVE_SPILT
                                                      );
        
        ranged_message_descriptor<int> num_splitting_steps(
                                                          "num_splitting_steps",
                                                          "set the number of steps that will be used to search for the best spliting value for each node",
                                                          1,
                                                          500,
                                                          100
                                                          );
        
        ranged_message_descriptor<int> min_samples_per_node(
                                                          "min_samples_per_node",
                                                          "sets the minimum number of samples that are allowed per node, if the number of samples at a node is below this value then the node will automatically become a leaf node",
                                                          1,
                                                          100,
                                                          5
                                                          );
        
        ranged_message_descriptor<int> dtree_max_depth(
                                                 "max_depth",
                                                 "sets the maximum depth of the tree, any node that reaches this depth will automatically become a leaf node",
                                                 1,
                                                 100,
                                                 10
                                                 );
        
        valued_message_descriptor<bool> remove_features_at_each_split(
                                                               "remove_features_at_each_split",
                                                               "set if a feature is removed at each spilt so it can not be used again",
                                                               {false, true},
                                                               false
                                                               );
        descriptors[ml::k_dtree].add_message_descriptor(training_mode, num_splitting_steps, min_samples_per_node, dtree_max_depth, remove_features_at_each_split);

        //-- Feature extraction
        
        //---- ml.peak
        ranged_message_descriptor<int> search_window_size(
                                                          "search_window_size",
                                                          "set the search window size in values",
                                                          1,
                                                          500,
                                                          5
                                                          );
        
        ranged_message_descriptor<float> peak(
                                              "float",
                                              "set the current value of the peak detector, a bang will be output when a peak is detected",
                                              INFINITY * -1.f, INFINITY,
                                              1
                                              );
        
        message_descriptor reset(
                                "reset",
                                "reset the peak detector"
                                );
        
        message_descriptor peak_help(
                                 "help",
                                 "post usage statement to the console"
                                 );


        descriptors[ml::k_peak].add_message_descriptor(peak, reset, search_window_size, peak_help);
        
        //---- ml.minmax
        
        message_descriptor input(
                                 "list",
                                 "list of float values in which to find minima and maxima",
                                 "0.1 0.5 -0.3 0.1 0.2 -0.1 0.7 0.1 0.3"
                                 );
        
        ranged_message_descriptor<float> minmax_delta(
                                                      "delta",
                                                      "setting the minmax delta. Input values will be considered to be peaks if they are greater than the previous and next value by at least the delta value",
                                                      0,
                                                      1,
                                                      0.1
                                                      );
        
        descriptors[ml::k_minmax].add_message_descriptor(input, minmax_delta);
        
        //---- ml.zerox
        
        valued_message_descriptor<float> zerox_map(
                                                   "map",
                                                   "a stream of input values in which to detect zero crossings",
                                                   0.5
                                                   );
        
        ranged_message_descriptor<float> dead_zone_threshold(
                                                             "dead_zone_threshold",
                                                             "set the dead zone threshold",
                                                             0.f,
                                                             1.f,
                                                             0.01f
                                                             );
        
        ranged_message_descriptor<int> zerox_search_window_size(
                                                          "search_window_size",
                                                          "set the search window size in values",
                                                          1,
                                                          500,
                                                          20
                                                          );
        
        descriptors[ml::k_zerox].add_message_descriptor(zerox_map, dead_zone_threshold, zerox_search_window_size);
    }
Example #11
0
Matrix Stoichiometry()
{
    Matrix nu(28, 61, 0.0);

   nu(0,0) = -1;
   nu(1,0) = -1;
   nu(2,0) = 1;

   nu(0,1) = 1;
   nu(1,1) = 1;
   nu(2,1) = -1;

   nu(0,2) = -1;
   nu(3,2) = -1;
   nu(4,2) = 1;

   nu(0,3) = 1;
   nu(3,3) = 1;
   nu(4,3) = -1;

   nu(0,4) = -1;
   nu(5,4) = -1;
   nu(6,4) = 1;

   nu(0,5) = 1;
   nu(5,5) = 1;
   nu(6,5) = -1;

   nu(3,6) = -1;
   nu(13,6) = -1;
   nu(14,6) = 1;

   nu(3,7) = 1;
   nu(13,7) = 1;
   nu(14,7) = -1;

   nu(13,8) = -1;
   nu(15,8) = -1;
   nu(16,8) = 1;

   nu(13,9) = 1;
   nu(15,9) = 1;
   nu(16,9) = -1;

   nu(2,10) = -1;
   nu(5,10) = -1;
   nu(7,10) = 1;

   nu(2,11) = 1;
   nu(5,11) = 1;
   nu(7,11) = -1;

   nu(4,12) = -1;
   nu(5,12) = -1;
   nu(8,12) = 1;

   nu(4,13) = 1;
   nu(5,13) = 1;
   nu(8,13) = -1;

   nu(2,14) = -1;
   nu(9,14) = -1;
   nu(11,14) = 1;

   nu(2,15) = 1;
   nu(9,15) = 1;
   nu(11,15) = -1;

   nu(4,16) = -1;
   nu(10,16) = -1;
   nu(12,16) = 1;

   nu(4,17) = 1;
   nu(10,17) = 1;
   nu(12,17) = -1;

   nu(14,18) = -1;
   nu(17,18) = -1;
   nu(18,18) = 1;

   nu(14,19) = 1;
   nu(17,19) = 1;
   nu(18,19) = -1;

   nu(21,20) = 1;

   nu(21,21) = -1;

   nu(13,22) = 1;

   nu(13,23) = -1;

   nu(15,24) = 1;
   nu(16,24) = -1;

   nu(3,25) = 1;
   nu(14,25) = -1;

   nu(3,26) = 1;
   nu(17,26) = 1;
   nu(18,26) = -1;

   nu(3,27) = 1;
   nu(26,27) = 1;
   nu(27,27) = -1;

   nu(22,28) = 1;

   nu(22,29) = -1;

   nu(17,30) = 1;

   nu(17,31) = -1;

   nu(14,32) = 1;
   nu(18,32) = -1;

   nu(24,33) = 1;

   nu(24,34) = -1;

   nu(3,35) = 1;

   nu(3,36) = -1;

   nu(13,37) = 1;
   nu(17,37) = 1;
   nu(18,37) = -1;

   nu(19,38) = 1;
   nu(20,38) = -1;

   nu(13,39) = 1;
   nu(26,39) = 1;
   nu(27,39) = -1;

   nu(23,40) = 1;

   nu(23,41) = -1;

   nu(19,42) = 1;

   nu(19,43) = -1;

   nu(3,44) = 1;
   nu(20,44) = -1;

   nu(3,45) = -1;
   nu(19,45) = -1;
   nu(20,45) = 1;

   nu(3,46) = 1;
   nu(19,46) = 1;
   nu(20,46) = -1;

   nu(25,47) = 1;

   nu(25,48) = -1;

   nu(26,49) = 1;

   nu(26,50) = -1;

   nu(14,51) = 1;
   nu(27,51) = -1;

   nu(14,52) = -1;
   nu(26,52) = -1;
   nu(27,52) = 1;

   nu(14,53) = 1;
   nu(26,53) = 1;
   nu(27,53) = -1;

   nu(0,54) = 1;
   nu(4,54) = -1;

   nu(0,55) = 1;
   nu(10,55) = 1;
   nu(12,55) = -1;

   nu(6,56) = 1;
   nu(8,56) = -1;

   nu(13,57) = 1;
   nu(14,57) = -1;

   nu(13,58) = 1;
   nu(17,58) = 1;
   nu(18,58) = -1;

   nu(13,59) = 1;
   nu(26,59) = 1;
   nu(27,59) = -1;

   nu(19,60) = 1;
   nu(20,60) = -1;

   return nu;
}
GenSGSStress::GenSGSStress
(
    const volVectorField& U,
    const surfaceScalarField& phi,
    transportModel& transport
)
:
    LESModel(word("GenSGSStress"), U, phi, transport),

    ce_
    (
        dimensioned<scalar>::lookupOrAddToDict
        (
            "ce",
            coeffDict_,
            1.048
        )
    ),

    couplingFactor_
    (
        dimensioned<scalar>::lookupOrAddToDict
        (
            "couplingFactor",
            coeffDict_,
            0.0
        )
    ),

    B_
    (
        IOobject
        (
            "B",
            runTime_.timeName(),
            U_.db(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_
    ),

    nuSgs_
    (
        IOobject
        (
            "nuSgs",
            runTime_.timeName(),
            U_.db(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        nu(),
        B_.boundaryField().types()
    )
{
    if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
    {
        FatalErrorIn
        (
            "GenSGSStress::GenSGSStress"
            "(const volVectorField& U, const surfaceScalarField& phi,"
            "transportModel& lamTransportModel)"
        )   << "couplingFactor = " << couplingFactor_
            << " is not in range 0 - 1" << nl
            << exit(FatalError);
    }
}
Example #13
0
 Real VarianceGammaProcess::omega(Time t, Real x) const {
     Real sigma = diffusion(t, x);
     return  1 / nu() * std::log(1 - theta() * nu() - sigma * sigma * nu() * 0.5);
 }
Example #14
0
int
main(int argc, char** argv)
{
  // DEFINE A MODEL FOR THE AUV

  double cog[3] = {0.0, 0.0, 0.01};
  double addedmass[6] = {-1, -16, -16, 0, 0, 0};
  double inertia[3] = {0.04, 2.1, 2.1};
  double lindrag[10] = {-2.4, -23.0, -23.0, -0.3, -9.7, -9.7, 11.5, -11.5, 3.1, -3.1};
  double quadrag[10] = {-2.4, -80.0, -80.0, -0.0006, -9.1, -9.1, 0.3, -0.3, 1.5, -1.5};
  double liftcoef[8] = {-20.6, -20.6, -1.53, -1.53, 3.84, -3.84, -6, 6};
  // double liftcoef[8] = {0.0, 0.0, -1.53, -1.53, 0.0, 0.0, -6, 6};
  double fincoef[5] = {9.6, -9.6, 1.82, -3.84, -3.84};

  DUNE::Control::ModelParameters prmtrs;
  prmtrs.mass = 18.0;
  prmtrs.density = 1020;
  prmtrs.volume = 0.0177;
  prmtrs.motor_friction = 0.06;
  prmtrs.max_thrust = 1.0;
  prmtrs.cog = Matrix(cog, 3, 1);
  prmtrs.addedmass = Matrix(addedmass, 6, 1);
  prmtrs.inertia = Matrix(inertia, 3, 1);
  prmtrs.linear_drag = Matrix(lindrag, 10, 1);
  prmtrs.quadratic_drag = Matrix(quadrag, 10, 1);
  prmtrs.lift = Matrix(liftcoef, 8, 1);
  prmtrs.fin_lift = Matrix(fincoef, 5, 1);

  AUVModel* a = new AUVModel(prmtrs);

  // Initial conditions
  double elements_nu[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
  double elements_eta[6] = {10.0, 10.0, 0.0, 0.0, 0.0, 1.5};
  Matrix nu(elements_nu, 6, 1);
  Matrix eta(elements_eta, 6, 1);

  // DEFINE A DYN SM CONTROLLER
  Matrix Lambda = Matrix(3, 3, 0.0);
  Lambda(0, 0) = 0.5;
  // Lambda(1,1) = 20;
  // Lambda(2,2) = 4;
  Lambda(1, 1) = 0.5;
  Lambda(2, 2) = 0.5;

  Matrix Kd = Matrix(3, 3, 0.0);
  Kd(0, 0) = 0.1;
  Kd(1, 1) = 1;
  Kd(2, 2) = 1;

  // Matrix Ksigma = Matrix(3)*0.5;
  Matrix Ksigma = Matrix(3) * 0.0;
  Ksigma(0, 0) = 0.0;
  float sigma = 0.2;

  Matrix T = Matrix(3) * 0.4;

  DSC* d = new DSC(Lambda, Kd, Ksigma, sigma, T, *a);
  d->setOutputLimits(-45 * Math::c_pi / 180, 45 * Math::c_pi / 180);

  // open file to save data in
  std::ofstream log("Data_log.txt");

  // file format: timestamp x y z roll pitch yaw
  log << "timestamp" << " | "
      << "x" << " | "
      << "y" << " | "
      << "z" << " | "
      << "phi" << " | "
      << "theta" << " | "
      << "psi" << " | "
      << "u" << " | "
      << "v" << " | "
      << "w" << " | "
      << "p" << " | "
      << "q" << " | "
      << "r" << " | "
      << "X" << " | "
      << "Y" << " | "
      << "Z" << " | "
      << "K" << " | "
      << "M" << " | "
      << "N" << " | "
      << "s1_phi" << " | "
      << "s1_theta" << " | "
      << "s1_psi" << " | "
      << "s2_p" << " | "
      << "s2_q" << " | "
      << "s2_r" << " | "
      << std::endl;

  double timestamp = 0.0;
  double timestep = 0.1;
  unsigned maxsteps = 2000;

  // initial tau if necessary
  double elements_tau[6] = {5.0, 0.0, 0.0, 0.0, 0.0, 0.0};
  Matrix tau(elements_tau, 6, 1);

  // body fixed acceleration
  Matrix nu_dot(6, 1, 0.0);

  // Begin the simulation
  for (unsigned i = 0; i < maxsteps; i++)
  {
    if (0)
    {
      std::cout << "------------" << std::endl;
      std::cout << "Step " << i << std::endl;
      std::cout << "------------" << std::endl;
    }

    timestamp += timestep;

    // nu_dot = a->step_inv(tau, nu, eta);
    nu_dot = a->stepInv(tau.get(0, 2, 0, 0), tau.get(3, 5, 0, 0), nu, eta);

    Matrix control = d->step(DSC::StepParam(eta, nu, nu_dot, 0.0, 0.0, 0.0, timestep));

    tau.set(3, 5, 0, 0, control);

    Matrix s1 = d->getControlSurfaces();

    nu += nu_dot * timestep;

    eta += MatrixJ(eta(3), eta(4), eta(5)) * nu * timestep;
    eta(5) = Angles::normalizeRadian(eta(5));

    log << timestamp << ", "
        << eta(0) << ", "
        << eta(1) << ", "
        << eta(2) << ", "
        << eta(3) << ", "
        << eta(4) << ", "
        << eta(5) << ", "
        << nu(0) << ", "
        << nu(1) << ", "
        << nu(2) << ", "
        << nu(3) << ", "
        << nu(4) << ", "
        << nu(5) << ", "
        << tau(0) << ", "
        << tau(1) << ", "
        << tau(2) << ", "
        << tau(3) << ", "
        << tau(4) << ", "
        << tau(5) << ", "
        << s1(0) << ", "
        << s1(1) << ", "
        << s1(2) << ", "
        << s1(3) << ", "
        << s1(4) << ", "
        << s1(5) << ", "
        << std::endl;
  }

  log.close();

  if (d)
    delete d;

  if (a)
    delete a;

  return 0;
}
Example #15
0
 double MVT::pdf(const Vector &x, bool logscale) const {
   return dmvt(x, mu(), siginv(), nu(), ldsi(), logscale);
 }
Example #16
0
 SpdMatrix WishartModel::simdat(){ return rWish(nu(), sumsq()); }
tmp<volScalarField> LaunderSharmaKE::fMu() const
{
    return exp(-3.4/sqr(scalar(1) + sqr(k_)/(nu()*epsilonTilda_)/50.0));
}
tmp<volSymmTensorField> laminar::devBeff() const
{
    return -nu()*dev(twoSymm(fvc::grad(U())));
}
	unsigned int AtomicCompositionTable::CorrectStoichiometry(Reaction& reaction)
	{
		Eigen::VectorXd reactant_side(element_weights_list_.size());
		Eigen::VectorXd product_side(element_weights_list_.size());
		reactant_side.setZero();
		product_side.setZero();
		for (unsigned int i = 0; i<reaction.reactant_nu_indices().size(); i++)
		for (int j = 0; j<reactant_side.size(); j++)
			reactant_side(j) += element_coefficients_list_(reaction.reactant_nu_indices()[i], j)*reaction.reactant_nu()[i];
		for (unsigned int i = 0; i<reaction.product_nu_indices().size(); i++)
		for (int j = 0; j<product_side.size(); j++)
			product_side(j) += element_coefficients_list_(reaction.product_nu_indices()[i], j)*reaction.product_nu()[i];

		// Propose correction
		{
			// List of available elements
			std::vector<unsigned int>	indices_available_elements;
			for (int k = 0; k<reactant_side.size(); k++)
			if (reactant_side(k) > 0.)
				indices_available_elements.push_back(k);

			unsigned int m = indices_available_elements.size();
			unsigned int n = reaction.product_nu_indices().size();

			if (m <= n)
			{
				Eigen::VectorXd	beta(m);
				for (unsigned int k = 0; k < m; k++)
				{
					unsigned int j = indices_available_elements[k];
					beta(k) = reactant_side(j) - product_side(j);
				}

				Eigen::MatrixXd nu(m, n);
				for (unsigned int i = 0; i<reaction.product_nu_indices().size(); i++)
				for (unsigned int k = 0; k < m; k++)
				{
					unsigned int j = indices_available_elements[k];
					nu(k, i) = element_coefficients_list_(reaction.product_nu_indices()[i], j);
				}

				Eigen::VectorXd delta(n);
				if (m == n)
					delta = nu.fullPivLu().solve(beta);
				else
					delta = nu.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(beta);

				for (unsigned int i = 0; i < reaction.product_nu_indices().size(); i++)
				{
					const double new_coefficient = reaction.product_nu()[i] + delta(i);
					reaction.set_product_nu(i, new_coefficient);
				}

				return 1;
			}
			else
			{
				return 0;
			}
		}
	}
Foam::tmp<Foam::scalarField>
Foam::incompressibleTurbulenceModel::mu(const label patchi) const
{
    return nu(patchi);
}
Foam::tmp<Foam::volScalarField>
Foam::incompressibleTurbulenceModel::mu() const
{
    return nu();
}
Example #22
0
// Berechnung des Extraspannungstensors
Foam::tmp<Foam::volSymmTensorField> Foam::power::devRhoReff() const
{
    if (obr_.foundObject<compressible::RASModel>("RASProperties"))
    {
        const compressible::RASModel& ras
            = obr_.lookupObject<compressible::RASModel>("RASProperties");

        return ras.devRhoReff();
    }
    else if (obr_.foundObject<incompressible::RASModel>("RASProperties"))
    {
        const incompressible::RASModel& ras
            = obr_.lookupObject<incompressible::RASModel>("RASProperties");

        return rho()*ras.devReff();
        Info << "XXXXXXXXXXXXX"<< nl;
    }
    else if (obr_.foundObject<compressible::LESModel>("LESProperties"))
    {
        const compressible::LESModel& les =
        obr_.lookupObject<compressible::LESModel>("LESProperties");

        return les.devRhoReff();
    }
    else if (obr_.foundObject<incompressible::LESModel>("LESProperties"))
    {
        const incompressible::LESModel& les
            = obr_.lookupObject<incompressible::LESModel>("LESProperties");

        return rho()*les.devReff();
    }
    else if (obr_.foundObject<fluidThermo>("thermophysicalProperties"))
    {
        const fluidThermo& thermo =
             obr_.lookupObject<fluidThermo>("thermophysicalProperties");

        const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);

        return -thermo.mu()*dev(twoSymm(fvc::grad(U)));
    }
    else if
    (
        obr_.foundObject<transportModel>("transportProperties")
    )
    {
        const transportModel& laminarT =
            obr_.lookupObject<transportModel>("transportProperties");

        const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);

        return -rho()*laminarT.nu()*dev(twoSymm(fvc::grad(U)));
    }
    else if (obr_.foundObject<dictionary>("transportProperties"))
    {
        const dictionary& transportProperties =
             obr_.lookupObject<dictionary>("transportProperties");

        dimensionedScalar nu(transportProperties.lookup("nu"));

        const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);

        return -rho()*nu*dev(twoSymm(fvc::grad(U)));
    }
    else
    {
        FatalErrorIn("power::devRhoReff()")
            << "No valid model for viscous stress calculation"
            << exit(FatalError);

        return volSymmTensorField::null();
    }
}
Example #23
0
 double WishartModel::logp(const SpdMatrix &W) const{
   return dWish(W, sumsq(), nu(), true); }
tmp<volScalarField> LaunderSharmaKE::f2() const
{
    return
        scalar(1)
      - 0.3*exp(-min(sqr(sqr(k_)/(nu()*epsilonTilda_)), scalar(50.0)));
}
Example #25
0
 void WishartModel::initialize_params(){
   SpdMatrix mean(suf()->sumW());
   mean/= suf()->n();
   set_nu(2*mean.nrow()); // out of thin air
   set_sumsq((mean/nu()).inv());
 };
CRGB blend( const CRGB& p1, const CRGB& p2, fract8 amountOfP2 )
{
    CRGB nu(p1);
    nblend( nu, p2, amountOfP2);
    return nu;
}
Example #27
0
int main(int argc, char *argv[])
{
#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"

    Info << "perturbU: generalised velocity perturbation implementation for "
         << "the initialisation of ducted well-resolved LES flows." << endl;
    
    // Xdir -> Ubar - streamwise
    // Ydir -> wallReflection vectors
    // Zdir -> cross product Xdir^Ydir
    
    // Ubar and Retau should be set in transportProperties
    // The choice of Retau is not critical as long as it is 
    // approximately the right order of magnitude
    
    // A laminar background velocity profile is assumed
    // with maximum U at h = max(wall distance)
    // A laminar initial profile is essential since wall normal motion
    // of a mean turbulent profile without resolved turbulence will
    // diffuse the perturbations, preventing transition in some cases
    
    
    wallDist yw(mesh);
    const scalar h = max(yw.internalField());
    
    // local yDir
    wallDistReflection reflexVec(mesh);
    
    const volVectorField yDir = reflexVec.n();


    IOobject Uheader
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );
    Info << "Reading U" << endl;
    volVectorField U(Uheader, mesh);

    IOdictionary transportProperties
    (
        IOobject
        (
            "transportProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

    dimensionedScalar nu
    (
        transportProperties.lookup("nu")
    );
    dimensionedVector Ubar
    (
        transportProperties.lookup("Ubar")
    );
    dimensionedScalar Retau
    (
        transportProperties.lookup("Retau")
    );
    scalar sigma
    (
        transportProperties.lookupOrDefault<scalar>("sigma", 0.00055)
    );
    Info << " sigma = " << sigma << endl;
    scalar duplusC
    (
        transportProperties.lookupOrDefault<scalar>("duplusC", 0.25)
    );
    Info << " duplusC = " << duplusC << endl;
    scalar epsilonC
    (
        transportProperties.lookupOrDefault<scalar>("epsilonC", 0.05)
    );
    Info << " epsilonC = " << epsilonC << endl;
    scalar deviationC
    (
        transportProperties.lookupOrDefault<scalar>("deviationC", 0.2)
    );
    Info << " deviationC = " << deviationC << endl;
    
    vector xDir = Ubar.value() / mag(Ubar.value());


    Info << "Re(tau) = " << Retau << endl;
    const scalar utau = Retau.value() * nu.value() / h;
    Info << " u(tau) = " << utau << endl;

    // wall normal circulation
    const scalar duplus = Ubar.value().x() * duplusC / utau;
    // spanwise wavenumber: spacing z+ = 200
    const scalar betaPlus = 2.0 * 3.14 *(1.0 / 200.0);
    // streamwise wave number: spacing x+ = 500
    const scalar alphaPlus = 2.0 * 3.14 * (1.0 / 500.0);
    const scalar epsilon = Ubar.value().x() * epsilonC;

    const vectorField& centres(mesh.C());

    Random perturbation(1234567);

    forAll(centres, celli)
    {
        // add a small random component to enhance symmetry breaking
        scalar deviation = 1.0 + deviationC * perturbation.GaussNormal();
        const vector& cCentre = centres[celli];

        vector zDir = xDir^yDir[celli];
        zDir /= mag(zDir);

        scalar zplus = (cCentre & zDir) * Retau.value() / h;
        scalar yplus = yw[celli] * Retau.value() / h;
        scalar xplus = (cCentre & xDir) * Retau.value() / h;

        // ML: it seems that this profile (or coefficient before Ubar)
        //     is correct for rectangular shape, for body of
        //     revolution it is (should be?) different
        // laminar parabolic profile
        U[celli] = 3.0 * Ubar.value() * (yw[celli] / h - 0.5 * sqr(yw[celli] / h));

        // streak streamwise velocity
        U[celli] +=
            xDir * (utau * duplus / 2.0) * (yplus / 40.0)
            * Foam::exp(-sigma * Foam::sqr(yplus) + 0.5)
            * Foam::cos(betaPlus * zplus) * deviation;

        // streak spanwise perturbation
        U[celli] +=
            zDir * epsilon
          * Foam::sin(alphaPlus * xplus)
          * yplus
          * Foam::exp(-sigma * Foam::sqr(yplus))
          * deviation;

    }
tmp<volScalarField> laminar::epsilon() const
{
    return 2*nu()*magSqr(symm(fvc::grad(U())));
}
Example #29
0
 MvRegData * MVTR::simdat(const Vec &x)const{
   Vec Y = rmvt(predict(x), Sigma(), nu());
   return new MvRegData(Y,x);
 }
void LaunderSharmaKE::correct()
{
    // Bound in case of topological change
    // HJ, 22/Aug/2007
    if (mesh_.changing())
    {
        bound(k_, k0_);
        bound(epsilonTilda_, epsilon0_);
    }

    RASModel::correct();

    if (!turbulence_)
    {
        return;
    }

    volScalarField S2 = 2*magSqr(symm(fvc::grad(U_)));

    volScalarField G("RASModel::G", nut_*S2);

    volScalarField E = 2.0*nu()*nut_*fvc::magSqrGradGrad(U_);
    volScalarField D = 2.0*nu()*magSqr(fvc::grad(sqrt(k_)));


    // Dissipation rate equation

    tmp<fvScalarMatrix> epsEqn
    (
        fvm::ddt(epsilonTilda_)
      + fvm::div(phi_, epsilonTilda_)
      + fvm::SuSp(-fvc::div(phi_), epsilonTilda_)
      - fvm::laplacian(DepsilonEff(), epsilonTilda_)
     ==
        C1_*G*epsilonTilda_/k_
      - fvm::Sp(C2_*f2()*epsilonTilda_/k_, epsilonTilda_)
      + E
    );

    epsEqn().relax();
    solve(epsEqn);
    bound(epsilonTilda_, epsilon0_);


    // Turbulent kinetic energy equation

    tmp<fvScalarMatrix> kEqn
    (
        fvm::ddt(k_)
      + fvm::div(phi_, k_)
      + fvm::SuSp(-fvc::div(phi_), k_)
      - fvm::laplacian(DkEff(), k_)
     ==
        G - fvm::Sp((epsilonTilda_ + D)/k_, k_)
    );

    kEqn().relax();
    solve(kEqn);
    bound(k_, k0_);


    // Re-calculate viscosity
    nut_ == Cmu_*fMu()*sqr(k_)/epsilonTilda_;
}