inline void testMultistateFieldWroteCorrectlyToRestart(const std::string &restartFilename,
        const double time,
        const std::string &fieldName,
        const double stateNp1Value,
        const double stateNValue)
{
    MPI_Comm communicator = MPI_COMM_WORLD;
    stk::io::StkMeshIoBroker stkIo(communicator);
    size_t index = stkIo.add_mesh_database(restartFilename, stk::io::READ_RESTART);
    stkIo.set_active_mesh(index);
    stkIo.create_input_mesh();

    stk::mesh::MetaData &restartedMetaData = stkIo.meta_data();
    stk::mesh::FieldBase *triStateField =
            declareTriStateNodalField(restartedMetaData, fieldName);

    stkIo.add_input_field(stk::io::MeshField(*triStateField));
    stkIo.populate_bulk_data();
    stkIo.read_defined_input_fields(time);

    stk::mesh::FieldBase *statedFieldNp1 =
            triStateField->field_state(stk::mesh::StateNP1);
    testDataOnField(stkIo.bulk_data(), stateNp1Value, *statedFieldNp1);
    stk::mesh::FieldBase *statedFieldN =
            triStateField->field_state(stk::mesh::StateN);
    testDataOnField(stkIo.bulk_data(), stateNValue, *statedFieldN);
}
inline void testMultistateFieldWroteCorrectly(const std::string &resultsFilename,
        const double time,
        const std::string &np1Name,
        const std::string &nName,
        const std::string &nm1Name,
        const double stateNp1Value,
        const double stateNValue,
        const double stateNm1Value)
{
    MPI_Comm communicator = MPI_COMM_WORLD;
    stk::io::StkMeshIoBroker stkIo(communicator);
    size_t index = stkIo.add_mesh_database(resultsFilename, stk::io::READ_RESTART);
    stkIo.set_active_mesh(index);
    stkIo.create_input_mesh();

    stk::mesh::MetaData &resultsedMetaData = stkIo.meta_data();
    stk::mesh::FieldBase *FieldNp1 = declareNodalField(resultsedMetaData, np1Name, 1);
    stk::mesh::FieldBase *FieldN   = declareNodalField(resultsedMetaData, nName, 1);
    stk::mesh::FieldBase *FieldNm1 = declareNodalField(resultsedMetaData, nm1Name, 1);

    stkIo.add_input_field(stk::io::MeshField(*FieldNp1, np1Name));
    stkIo.add_input_field(stk::io::MeshField(*FieldN,   nName));
    stkIo.add_input_field(stk::io::MeshField(*FieldNm1, nm1Name));

    stkIo.populate_bulk_data();
    stkIo.read_defined_input_fields(time);

    testDataOnField(stkIo.bulk_data(), stateNp1Value, *FieldNp1);
    testDataOnField(stkIo.bulk_data(), stateNValue,   *FieldN);
    testDataOnField(stkIo.bulk_data(), stateNm1Value, *FieldNm1);
}
Exemple #3
0
void GameofLife::write_mesh()
{
    m_bulkData.modification_begin();

    stk::mesh::EntityVector elements;
    stk::mesh::get_entities(m_bulkData, stk::topology::ELEM_RANK, elements);
    for(stk::mesh::Entity element : elements)
    {
        if ( *stk::mesh::field_data(m_lifeField, element) != 1)
        {
            stk::mesh::EntityVector nodes(m_bulkData.begin_nodes(element), m_bulkData.end_nodes(element));
            m_bulkData.destroy_entity(element);
            for(unsigned j=0; j<nodes.size(); j++)
                m_bulkData.destroy_entity(nodes[j]);
        }
    }

    put_all_nodes_in_nodeset();

    m_bulkData.modification_end();

    stk::io::StkMeshIoBroker stkIo(m_bulkData.parallel());
    stkIo.set_bulk_data(m_bulkData);
    size_t fh = stkIo.create_output_mesh("pic.g", stk::io::WRITE_RESULTS);
    stkIo.begin_output_step(fh, 0);
    stkIo.write_defined_output_fields(fh);
    stkIo.end_output_step(fh);
}
Exemple #4
0
void MeshBuilder::write_mesh()
{
    std::string timeStep = std::to_string(m_time);
    while (timeStep.size() < 8)
        timeStep = "0" + timeStep;

    stk::io::StkMeshIoBroker stkIo(m_bulkData.parallel());
    stkIo.set_bulk_data(m_bulkData);
    size_t fh = stkIo.create_output_mesh(m_name + timeStep + ".e", stk::io::WRITE_RESULTS);
    stkIo.write_output_mesh(fh);

    stkIo.begin_output_step(fh, m_time++);
    stkIo.end_output_step(fh);
}