A tool set to manage variables or curves with multi-layer dependence

1. Objective

   A variable, such as Young's modulus of a elastic media, or a curve, such as stress-strain relations may depends upon various variables as temperature, mass densities of purities etc. This tool provides function of reading and fetching relevant data as independent variables are given.

2. Algorithm

    A tree structure with its node composed by a std::vector<double> is adopted.

3. Functions

1) Read data in tabular form as below
  • Each line of input data must be
---------------------------------------------------------------------------------------------------
    Dependent data1, Dependent data2, ..., independent data1, independent data2, ...
---------------------------------------------------------------------------------------------------
The number of dependents and independents is not limited but constrained by the limit of layer of recursive functions of the compiler used. By the way, data in a line may separated by common or space.
  • Independent data must be inputted in increasing sequences, i.e, input minor value at first and max at last. No sort function here.
  • To define multi-layer dependents, define independent data j while independent j+1 keep constant.

An example,
1.0  3.3  5.0  10.
3.0  4.3  6.0  10.
2.0  5.3  7.0  10.
4.0  6.3  8.0  10.
1.0  3.5  4.0  20.
3.0  4.5  6.0  20.
5.0  5.5  8.0  20.
2.0  6.5  10.0  20.

In this table, the first two column are dependent data while the other two are independent data. Here, when independent data2=10, independent data1 changes from 5.0 to 8.0. When independent data2=20, independent data1 changes from 4.0 to 10.0.

  I think the above format is same with format using by ABAQUS in its field variable dependence definition of material data.

  To read the data and construct our tree structure, just call
------------------------------------------------------------------------
      XYLIB::CVectorTree a(int ncomp, std::ifstream& file)
------------------------------------------------------------------------
where ncomp is the number of dependent data.

2)  Data fetch. Two types interface provides,
---------------------------------------------------------------------
bool GetValue(ValueType& idata,ValueType& odata )
bool GetGrad(ValueType& idata,ValueType& odata)
---------------------------------------------------------------------
Here, we provide independent data into idata and get value needed in odata. When using GetValue, eg., we can get the Young's modulus and Poisson's ratio at temperature T. When using GetGrad, eg., we can get the derivative of the stress-strain curve at temperature T and strain E etc. And, all the data are obtained by linear interpolation. If the independent variables run out the range of the table data defined, we try to find the nearest one (min or max value defined in table).

4. Usages

 1) Download the source code from: https://github.com/hillyuan/FEComponent/blob/master/include/misc/VectTree.h
2)  Just include the header file VectorTree.h

Example:

#include <iostream>
#include "VectTree.h"

int main()
{
    std::ifstream ifs( "input.txt" );
    if( ifs.fail() ) {
        std::cerr << "File do not exist.\n";
        exit(0);
    }
    XYLIB::CVectorTree a(2,ifs);
    a.Show(a.GetRoot());
    std::vector<double_t> idata, odata, odata1;
    idata.push_back(7.5);
    idata.push_back(15.0);
    if(  a.GetValue(idata, odata) ) {
        std::cerr << "Fails to get value.\n";
        exit(0);
    }
    std::cout << "result:"<<odata.size()<< "  "<<odata[0] <<"  "<<odata[1] << std::endl;
    if( a.GetGrad(idata, odata1) ) {
        std::cerr << "Fails to get gradient.\n";
        exit(0);
    }
    std::cout << "result:"<<odata1.size()<< "  "<<odata1[0] << "  "<<odata[1];
    return 0;
}

The example of context of input.txt here:
1.0 3.3 5.0 10.
3.0 4.3 6.0 10.
2.0 5.3 7.0 10.
4.0 6.3 8.0 10.
1.0 3.5 4.0 20.
3.0 4.5 6.0 20.
5.0 5.5 8.0 20.
2.0 6.5 10.0 20.

没有评论:

发表评论

VS Code下cmake, c++编译,调试环境的构成步骤

1   下载必须extension      按[Ctrl+Shift+X]打开extension窗口,选择安装"C/C++", "CMake", "CMake Tools" 2   在VSCode下打开作业目录 ...