# Cross Sections

Small example on mapping cross sections expansions on beam elements.

This example contains just 6 beams and we want the to be expanded into the cross section BAR. A BAR beam is defined by the following parameters:

- OffsetY
- OffsetZ
- Height
- WidthTop
- WidthBottom

We want the bars to be differently shaped and create 4 different cross sections of type BAR with different parameter values and directions. We also change the eccentricities on the two last elements.

        //--------------------------------------------------------------------------
        // Create the VTFx file
        // -------------------------------------------------------------------------
        cee::PtrRef<cee::vtfx::File> file = new cee::vtfx::File;

        // Create VTFx file settings struct
        cee::vtfx::FileSettings fileSettings;
        fileSettings.applicationName = "VTFx: VTFxCrossSections";
        fileSettings.vendorName = "My Company AS";

        // Let the API create the VTFx file
        const cee::Str fileName = "ExampleCrossSections.vtfx";
        if (!file->create(fileName, fileSettings))
        {
            return EXIT_FAILURE;
        }

        // Create a single database (could have many)
        cee::PtrRef<cee::vtfx::Database> database = new cee::vtfx::Database(file.get(), "Only Database", 1, cee::vtfx::Database::SIMULATION_TYPE_STRUCTURAL, cee::vtfx::Database::SOLUTION_TYPE_TRANSIENT, "Database description"); // database id 1

        // Create a single case (could have many)
        cee::PtrRef<cee::vtfx::Case> singleCase = new cee::vtfx::Case(file.get(), "Only Case", 1, 1); // case id 1 using database with id 1

        //--------------------------------------------------------------------------
        // Add nodes
        // -------------------------------------------------------------------------

        // Create the node block
        cee::PtrRef<cee::vtfx::NodeBlock> nodeBlock = new cee::vtfx::NodeBlock(1, false); // node block id 1, not using node ids

        // Set the node data (Note: The VTFx component expects interleaved node coordinates (xyzxyzxyz...))
        std::vector<float> nodesPart = {  0.0f, 0.0f, 0.0f,  0.0f, 0.0f, 10.0f,
                                          4.0f, 0.0f, 0.0f,  4.0f, 0.0f, 10.0f,
                                          8.0f, 0.0f, 0.0f,  8.0f, 0.0f, 10.0f,
                                          0.0f, 5.0f, 0.0f,  0.0f, 5.0f, 10.0f,
                                          4.0f, 5.0f, 0.0f,  4.0f, 5.0f, 10.0f,
                                          8.0f, 5.0f, 0.0f,  8.0f, 5.0f, 10.0f };

        if (!nodeBlock->setNodes(nodesPart))
        {
            return EXIT_FAILURE;
        }

        // Write the block
        if (!database->writeBlock(nodeBlock.get()))
        {
            return EXIT_FAILURE;
        }

        //--------------------------------------------------------------------------
        // Add elements
        // -------------------------------------------------------------------------

        // Create the element block
        cee::PtrRef<cee::vtfx::ElementBlock> elementBlock = new cee::vtfx::ElementBlock(1, false, false); // element block id 1, not using element ids, referring nodes by index
        elementBlock->setNodeBlockId(1); // Use node block with id = 1
        elementBlock->setCrossSectionsBlockId(11); // Use cross sections block with id = 11

        // Set the element data
        // 6 BEAMS
        std::vector<int> elementNodes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
        std::vector<int> crossSectionsMapping = { 0, 1, 2, 3, 3, 3 }; // One mapping per element
        std::vector<cee::Vec3f> directions = { cee::Vec3f(0.0f,  1.0f, 0.0f),
                                               cee::Vec3f(0.0f, -1.0f, 0.0f),
                                               cee::Vec3f(0.0f,  1.0f, 0.0f),
                                               cee::Vec3f(0.0f,  1.0f, 0.0f),
                                               cee::Vec3f(0.0f, -1.0f, 0.0f),
                                               cee::Vec3f(1.0f,  0.0f, 0.0f) }; // One direction per element

        std::vector<cee::Vec3f> eccentricities = { cee::Vec3f(0.0f, 0.0f, 0.0f), cee::Vec3f(0.0f, 0.0f, 0.0f),
                                                   cee::Vec3f(0.0f, 0.0f, 0.0f), cee::Vec3f(0.0f, 0.0f, 0.0f),
                                                   cee::Vec3f(0.0f, 0.0f, 0.0f), cee::Vec3f(0.0f, 0.0f, 0.0f),
                                                   cee::Vec3f(0.0f, 0.0f, 0.0f), cee::Vec3f(0.0f, 0.0f, 0.0f),
                                                   cee::Vec3f(0.0f, 1.0f, 0.0f), cee::Vec3f(0.0f, 1.0f, 3.0f),
                                                   cee::Vec3f(0.0f, 1.0f, 0.0f), cee::Vec3f(0.0f, 2.0f, -3.0f) };
                                                   // One eccentricity per element node

        if (!elementBlock->addElementsWithCrossSections(cee::vtfx::ElementBlock::BEAMS, elementNodes, crossSectionsMapping, directions, eccentricities))
        {
            return EXIT_FAILURE;
        }

        // Write the element block
        if (!database->writeBlock(elementBlock.get()))
        {
            return EXIT_FAILURE;
        }

        //--------------------------------------------------------------------------
        // Add cross sections
        // -------------------------------------------------------------------------

        // Create cross sections block
        cee::PtrRef<cee::vtfx::CrossSectionsBlock> csBlock = new cee::vtfx::CrossSectionsBlock(11);

        csBlock->addCrossSection(cee::vtfx::CrossSectionsBlock::BEAM_BAR,
            { "OffsetY", "OffsetZ", "Height", "WidthTop", "WidthBottom" },
            { 0.0f,      0.0f,      2.0f,     2.0f,       1.0f });

        csBlock->addCrossSection(cee::vtfx::CrossSectionsBlock::BEAM_BAR,
            { "OffsetY", "OffsetZ", "Height", "WidthTop", "WidthBottom" },
            { 0.0f,      0.0f,      2.5f,     2.0f,       0.5f });

        csBlock->addCrossSection(cee::vtfx::CrossSectionsBlock::BEAM_BAR,
            { "OffsetY", "OffsetZ", "Height", "WidthTop", "WidthBottom" },
            { 0.0f,      0.0f,      2.0f,     2.0f,       2.0f });

        csBlock->addCrossSection(cee::vtfx::CrossSectionsBlock::BEAM_BAR,
            { "OffsetY", "OffsetZ", "Height", "WidthTop", "WidthBottom" },
            { 0.0f,      0.0f,      2.0f,     2.0f,       1.0f });

        // Write the cross sections block
        if (!database->writeBlock(csBlock.get()))
        {
            return EXIT_FAILURE;
        }

        //--------------------------------------------------------------------------
        // Add geometry
        // -------------------------------------------------------------------------

        // Create geometry block
        cee::PtrRef<cee::vtfx::GeometryBlock> geoBlock = new cee::vtfx::GeometryBlock(1); // Only one geometry per state

        size_t geoIndex = 0;
        int partId = 1;

        // Set to use element block with id 1
        if (!geoBlock->addElementBlock(geoIndex, 1, partId)) // Element block with id = 1
        {
            return EXIT_FAILURE;
        }

        // Write the geometry block
        if (!database->writeBlock(geoBlock.get()))
        {
            return EXIT_FAILURE;
        }

        // Create geometry info block
        cee::PtrRef<cee::vtfx::GeometryInfoBlock> infoBlock = new cee::vtfx::GeometryInfoBlock(1); // Only one geometry per state
        infoBlock->addPartInfo(geoIndex, partId, cee::Str("Only part"));

        // Write the geometry info block
        if (!database->writeBlock(infoBlock.get()))
        {
            return EXIT_FAILURE;
        }

        //--------------------------------------------------------------------------
        // Add one state
        // -------------------------------------------------------------------------

        // Create state info block
        cee::PtrRef<cee::vtfx::StateInfoBlock> stepInfo = new cee::vtfx::StateInfoBlock;
        if (!stepInfo->addStateInfo(1, "Only step", 42.0f, cee::vtfx::StateInfoBlock::TIME))
        {
            return EXIT_FAILURE;
        }

        // Write the state info block
        if (!database->writeBlock(stepInfo.get()))
        {
            return EXIT_FAILURE;
        }

        // Finally close the file
        if (!file->close())
        {
            return EXIT_FAILURE;
        }

        std::cout << "Exported successfully to file: " << fileName.toStdString() << std::endl;
        std::cout << std::endl << "Press enter to exit..." << std::endl;
        std::cin.ignore();

        return EXIT_SUCCESS;

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your multilingual generative AI assistant for documentation. Ask me anything about HOOPS Envision for Desktop in your own language, or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...