Navigation

    CFD中文网

    CFD中文网

    • Login
    • Search
    • 最新

    UList使用

    OpenFOAM
    2
    3
    500
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Samuel-Tu last edited by

      发现UList似乎可以建立动态的数组。例如

      labelUList Marks(0,50);
      

      就初始化了类labelUList,相当于一个有50个数的一位整数数组,且里面每一个数都为0。但是当我想

      Info<<Marks[3]<<endl;
      Marks[5]=55;
      

      就会报错。我看了一下[]已经被重载了,按理说可以读取这个数组的第2个数,不知道为什么会报错。。而且还不能赋值。。不知道咋解决。。报错信息如下

      #0  Foam::error::printStack(Foam::Ostream&) at ??:?
      #1  Foam::sigSegv::sigHandler(int) at ??:?
      #2  ? in /lib/x86_64-linux-gnu/libc.so.6
      #3  ? in ~/OpenFOAM/saumuel-v1806/platforms/linux64GccDPInt64Opt/bin/IBIcoFoamFD
      #4  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
      #5  ? in ~/OpenFOAM/saumuel-v1806/platforms/linux64GccDPInt64Opt/bin/IBIcoFoamFD
      Segmentation fault (core dumped)
      
      1 Reply Last reply Reply Quote
      • 李东岳
        李东岳 管理员 last edited by

        labelUList Marks(0,50);
        Info<<&Marks[3]<<endl;
        

        UList里面的成员是指针,需要用&

        class UList
        {
            // Private Data
        
                //- Number of elements in UList
                label size_;
        
                //- Vector of values of type T
                T* __restrict__ v_;
        

        你用scalarList就好了?

        CFD高性能服务器 http://dyfluid.com/servers.html

        S 1 Reply Last reply Reply Quote
        • S
          Samuel-Tu @李东岳 last edited by

          @东岳 对,我后来是用List<type>解决的。最后用List来初始化UList

          List<label> IBMarks(50,(label)1);
          labelUList affectedList(IBMarks);
          Info << affectedList<<endl;
          Info << affectedList[25]<<endl;
          

          结果如下

          50{1}
          1
          

          v_感觉是类似数组头的指针,运算符[]可能被重载了,可以直接取值,就像我上面的affectedList[25],输出为1。
          另外我原来

          1 Reply Last reply Reply Quote
          • First post
            Last post

          CFD中文网 | 东岳流体 | 京ICP备15017992号-2
          论坛登录问题反馈可联系 li.dy@dyfluid.com