Skip to content

Problem with initializing double[][][] #2024

@stephenmontgomerysmith

Description

@stephenmontgomerysmith

I have in my code a declaration
double data[2][3][3];
Then I want to initialize it in my input.py file:
...data[0] = [[1,2,3],[4,5,6],[7,8,9]]
doesn't initialize it.

Useful if you have an array of moments of inertia.

S_define

/**************************** Trick Header *********************************************************
PURPOSE: (S_define Header)
LIBRARY_DEPENDENCY: ((src/test.cpp))
***********************************/

#include "sim_objects/default_trick_sys.sm"

##include "test.hh"

class TestSimObject : public Trick::SimObject {
    public:
    Stuff stuff;

    TestSimObject() {

        ("initialization") initialize(stuff);
    }
};

TestSimObject test;

test.hh

/**************************** Trick Header *********************************************************
PURPOSE: (S_define Header)
LIBRARY_DEPENDENCY: ((src/test.cpp))
***********************************/

#include "sim_objects/default_trick_sys.sm"

##include "test.hh"

class TestSimObject : public Trick::SimObject {
    public:
    Stuff stuff;

    TestSimObject() {

        ("initialization") initialize(stuff);
    }
};

TestSimObject test;

test.cpp

#include <iostream>

#include "test.hh"

int initialize(Stuff stuff) {


    std::cout << "This doesn't work:" << std::endl;
    for (int i=0; i<3; i++) for (int j=0; j<3; j++) {
        std::cout << stuff.data1[0][i][j] << " ";
    }
    std::cout << std::endl;

    std::cout << "This works:" << std::endl;
    for (int i=0; i<3; i++) for (int j=0; j<3; j++) {
        std::cout << stuff.data2[i][j] << " ";
    }
    std::cout << std::endl;

    std::cout << "This works:" << std::endl;
    for (int i=0; i<3; i++) {
        std::cout << stuff.data3[0][i] << " ";
    }
    std::cout << std::endl;

    std::cout << "This works:" << std::endl;
    for (int i=0; i<3; i++) {
        std::cout << stuff.data1[1][0][i] << " ";
    }
    std::cout << std::endl;

    return 0;

}

input.py

test.stuff.data1[0] = [[1,2,3],[4,5,6],[7,8,9]]
test.stuff.data1[1][0] = [1,2,3]
test.stuff.data2 = [[1,2,3],[4,5,6],[7,8,9]]
test.stuff.data3[0] = [1,2,3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions