[G+smo]gsBasis和gsMultiBasis

gsMultiBasis类

构造:gsMultiPatch<> * patches = NULL;
    if ( fn.empty() )
   patches= gsReadFile<>("../xml/straight_unit_beam.xml");
gsMultiBasis<> bases(*patches);

gsBasis类

gsBasisEvalTest2.cpp

gsBasis是gismo中所有基函数的基础类型。其他类,例如gsSplineBasis, gsBSplineBasis, gsHTensorBasis都从该类派生。

gsRationalBasis派生于gsBasis.


1. 生成gsBasis;
gsBasis 类只有无参数默认构造函数,赋值构造函数;
gsBasis 作为gsGeometry的内部变量,使用时不需要单独定义;
    gsGeometry<>          geo  ;
    gsBasis<>              &space = geo.basis ();

2. 从文件读入

    gsFileData<> fileData(input);
    
    gsBasis<>* pBasis = NULL;
    if (fileData.has< gsBasis<> >())
    {
        pBasis = fileData.getFirst< gsBasis<> >();
    }

gsBasis读入文件定义格式为:

<?xml version="1.0" encoding="UTF-8"?>
<xml>
   <Basis type="TensorBSplineBasis2" parDim="2">
    <Basis type="BSplineBasis" index="0">
     <KnotVector degree="2">0 0 0 0.25 0.5 0.75 1 1 1</KnotVector>
    </Basis>
    <Basis type="BSplineBasis" index="1">
     <KnotVector degree="3">0 0 0 0 0.25 0.5 0.75 1 1 1 1</KnotVector>
    </Basis>
   </Basis>
</xml>

3. 输出基本信息

std::cout << "The file contains: \n" << *pBasis << std::endl;
            
输出为:
The file contains:
TensorBSplineBasis: dim=2, size=42.
  Direction 0: [ 0 0 0 0.25 0.5 0.75 1 1 1 ] (deg=2, size=9, minSpan=0.25, maxSp
an=0.25)
  Direction 1: [ 0 0 0 0 0.25 0.5 0.75 1 1 1 1 ] (deg=3, size=11, minSpan=0.25,
maxSpan=0.25)
    
    // printing some properties of the basis
    std::cout << "Dimension of the parameter space: " << pBasis->dim() << "\n"
              << "Number of basis functions: " << pBasis->size() << "\n"
              << "Number of elements: " << pBasis->numElements() << "\n"
              << "Degree of the basis: " << pBasis->degree() << "\n"
              << std::endl;
输出为:
Dimension of the parameter space: 2
Number of basis functions: 42
Number of elements: 16
Degree of the basis: 2

gsMatrix<> support = pBasis->support();
    std::cout << "Support: \n"
              << support << "\n" << std::endl;

Support:
0 1
0 1

4 计算参数点的值

    gsMatrix<> u = 0.3 * support.col(0) + 0.7 * support.col(1);
    std::cout << "u " << size(u) << ": \n" << u << "\n" << std::endl;
    
    // indices of active (nonzero) functions at parameter u
    gsMatrix<unsigned> active = pBasis->active(u);
    std::cout << "Active functions at u " << size(active) << ": \n" 
                   << active << "\n" << std::endl;    

    // values of all active functions at u
    gsMatrix<> values = pBasis->eval(u);
    std::cout << "Values at u " << size(values) << ": \n"
                   << values << "\n" << std::endl;
    
    // values of single basis functions
    for (index_t i = 0; i != active.rows(); i++)
    {
        gsMatrix<> val = pBasis->evalSingle(active(i), u);
        
        std::cout << "basis fun. index:  " << active(i) 
                  << "   value: " << val(0, 0) << "\n";
    }
    std::cout << std::endl;

Values at u (12 x 1):
2.66667e-005
     0.00088
 0.000426667
  0.00565333
     0.18656
   0.0904533
     0.01176
     0.38808
     0.18816
     0.00256
     0.08448
     0.04096


basis fun. index:  14   value: 2.66667e-005
。。。。。

5. 计算参数点的导数
 gsMatrix<> derivs = pBasis->deriv(u);
    std::cout << "Derivatives at u " << size(derivs) << ": \n"
              << derivs << "\n" << std::endl;
    


    // derivatives of single basis function
    for (index_t i = 0; i != active.rows(); i++)
    {
        gsMatrix<> der = pBasis->derivSingle(active(i), u);
        
        std::cout << "basis fun. index:  " << active(i)
                  << "   value: " << std::setw(15) <<  der(0, 0) << "\n";
        
        for (index_t row = 1; row != der.rows(); row++)
        {
            std::cout << std::setw(46) << der(row, 0) << "\n";
        }
    }
    std::cout << std::endl;

6 计算参数点的二阶导数

    gsMatrix<> derivs2 = pBasis->deriv2(u);
    std::cout << "Second derivatives at u " << size(derivs2) << ": \n"
              << derivs2 << "\n" << std::endl;
    
    for (index_t i = 0; i != active.rows(); i++)
    {
        gsMatrix<> der2 = pBasis->deriv2Single(active(i), u);
        std::cout << "basis fun. index:  " << active(i)
                  << "   value: " << std::setw(15) << der2(0, 0) << "\n";        
        for (index_t row = 1; row != der2.rows(); row++)
        {
            std::cout << std::setw(46) << der2(row, 0) << "\n";
        }
    }
    std::cout << "\nFor more information about evaluation "
              << "(and order of derivatives) look at doxygen documentation." 
              << "\n" << std::endl;
    
7 输出到paraview
    if (output != " ")
    {
        std::cout << "Writing the basis to a paraview file: " << output 
                  << "\n" << std::endl;
        gsWriteParaview(*pBasis, output);
    }

8. anchor points 
Greville abscissae 点
        m_patches.basis(0).anchors_into(ct);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值