Пример #1
0
 /*! Optional: generation of jacobian matrix, uncomment for default behaviour (brute force) */
 void createJacobian( const RVector & model ) {
     RMatrix *J = dynamic_cast < RMatrix * >( jacobian_ );
     if ( jacobian_->rows() != x_.size() || jacobian_->cols() != nc_ ) J->resize( x_.size(), nc_ );
     
     for ( size_t i = 0 ; i < nc_ ; i++ )
         for ( size_t j = 0 ; j < x_.size() ; j++ )
             (*J)[ j ][ i ] = pow( x_[ j ], (double)i );
 }
Пример #2
0
void HarmonicModelling::createJacobian( const RVector & model ) {
    //!! jacobian = transpose( A );
    RMatrix * jacobian = dynamic_cast < RMatrix * > ( jacobian_ );
    
    if ( jacobian->rows() != nt_ || jacobian->cols() != np_ ) {
        jacobian->resize( nt_, np_ );

        for ( size_t i = 0 ; i < np_ ; i++ ){
            for ( size_t j = 0 ; j < nt_ ; j++ ){
                (*jacobian)[ j ][ i ] = A_[ i ][ j ];
            }
        }
    }
}
Пример #3
0
void interpolate(const Mesh & mesh, const RMatrix & vData,
                 const R3Vector & ipos, RMatrix & iData,
                 bool verbose){

    R3Vector pos(ipos);
    
    if (mesh.dim() == 2){
        if ((zVari(pos) || max(abs(z(pos))) > 0.) && 
            (!yVari(pos) && max(abs(y(pos))) < 1e-8)) {
            if (verbose) 
                std::cout << "Warning! swap YZ coordinates for query "
                            "positions to meet mesh dimensions." << std::endl;
            swapYZ(pos);
        }
    }
        
    if (iData.rows() != vData.rows()){
        iData.resize(vData.rows(), pos.size());
    }

    std::vector < Cell * > cells(pos.size());
    size_t count = 0;
    
    Cell * c = 0;
    for (uint i = 0; i < pos.size(); i ++) {
        
        c = mesh.findCell(pos[i], count, false);
//         if (!c) {__MS(pos[i])
//             c = mesh.findCell(pos[i], count, true);
//             if (!c) exit(0);
//         }
        cells[i] = c;
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << pos.size();
//                             << "\t searched: " << count << std::endl;
    }
    if (verbose) std::cout << std::endl;

    for (uint i = 0; i < vData.rows(); i ++) {
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << vData.rows();
        
        RVector data;
        
        if (vData[i].size() != 0){

            if (vData[i].size() == mesh.nodeCount()){
                data = vData[i];
            } else if (vData[i].size() == mesh.cellCount()){
                data = cellDataToPointData(mesh, vData[i]);
            } else {
                throwLengthError(EXIT_VECTOR_SIZE_INVALID,
                                 WHERE_AM_I + 
                                 " data.size not nodeCount and cellCount " + 
                                 toStr(vData[i].size()) + " != " + 
                                 toStr(mesh.nodeCount()) + " != " + 
                                 toStr(mesh.cellCount()));
            }

            for (uint j = 0; j < pos.size(); j ++) {
                if (cells[j]){
                    iData[i][j] = cells[j]->pot(pos[j], data);
                    
//              this check is obsolete if the findCell (from above) is working properly                     
//                     if (cells[j]->shape().isInside(pos[j])){
//                         iData[i][j] = cells[j]->pot(pos[j], data);
//                     } else {
//                         std::cout << WHERE_AM_I << " here is somethng wrong" << std::endl;
//                     }

//                    std::cout << j << " " << iData[i][j] << std::endl;
                    //** return cell data
//                    iData[i][j] = vData[i][cells[j]->id()];
                } else {        
                    iData[i][j] = 0.0;
                    //std::cout << "Cant find cell for " << pos[j]<< std::endl;
//                     for (uint i = 0; i < mesh.cellCount(); i ++){
//                     	if (mesh.cell(i).shape().isInside(pos[j], true)){
//                         	std::cout << mesh.cell(i) << std::endl;
//                         }
//                     }
//                     exit(0);
                }
            }
        } // if vData.size() != 0
    }  // for each in vData
    if (verbose) std::cout << std::endl;
}