|
33 | 33 |
|
34 | 34 | #include <map> |
35 | 35 |
|
| 36 | +namespace RifVtkFieldNames |
| 37 | +{ |
| 38 | +constexpr const char* separator = "__"; |
| 39 | + |
| 40 | +constexpr const char* S = "S_VTK"; |
| 41 | +constexpr const char* S11 = "S11"; |
| 42 | +constexpr const char* S22 = "S22"; |
| 43 | +constexpr const char* S33 = "S33"; |
| 44 | +constexpr const char* S12 = "S12"; |
| 45 | +constexpr const char* S13 = "S13"; |
| 46 | +constexpr const char* S23 = "S23"; |
| 47 | + |
| 48 | +constexpr const char* E = "E_VTK"; |
| 49 | +constexpr const char* E11 = "E11"; |
| 50 | +constexpr const char* E22 = "E22"; |
| 51 | +constexpr const char* E33 = "E33"; |
| 52 | +constexpr const char* E12 = "E12"; |
| 53 | +constexpr const char* E13 = "E13"; |
| 54 | +constexpr const char* E23 = "E23"; |
| 55 | +} // namespace RifVtkFieldNames |
| 56 | + |
36 | 57 | //-------------------------------------------------------------------------------------------------- |
37 | 58 | /// |
38 | 59 | //-------------------------------------------------------------------------------------------------- |
@@ -391,11 +412,29 @@ std::map<std::string, std::vector<std::string>> RifVtkReader::scalarNodeFieldAnd |
391 | 412 | //-------------------------------------------------------------------------------------------------- |
392 | 413 | std::map<std::string, std::vector<std::string>> RifVtkReader::scalarElementFieldAndComponentNames() |
393 | 414 | { |
| 415 | + using namespace RifVtkFieldNames; |
| 416 | + |
394 | 417 | std::map<std::string, std::vector<std::string>> retVal; |
395 | 418 |
|
396 | 419 | for ( auto& entry : m_propertyPartDataElements ) |
397 | 420 | { |
398 | | - retVal[entry.first] = {}; |
| 421 | + // Skip internal S/E component keys (stored as "S_VTK__S11", "E_VTK__E11", etc.) |
| 422 | + const std::string& key = entry.first; |
| 423 | + if ( key.starts_with( std::string( S ) + separator ) || key.starts_with( std::string( E ) + separator ) ) continue; |
| 424 | + |
| 425 | + retVal[key] = {}; |
| 426 | + } |
| 427 | + |
| 428 | + // Add S field with components if any S component data was loaded |
| 429 | + if ( m_propertyPartDataElements.count( std::string( S ) + separator + S11 ) > 0 ) |
| 430 | + { |
| 431 | + retVal[S] = { S11, S22, S33, S12, S13, S23 }; |
| 432 | + } |
| 433 | + |
| 434 | + // Add E field with components if any E component data was loaded |
| 435 | + if ( m_propertyPartDataElements.count( std::string( E ) + separator + E11 ) > 0 ) |
| 436 | + { |
| 437 | + retVal[E] = { E11, E22, E33, E12, E13, E23 }; |
399 | 438 | } |
400 | 439 |
|
401 | 440 | return retVal; |
@@ -507,6 +546,23 @@ void RifVtkReader::readElementField( const std::string& fieldName |
507 | 546 | int frameIndex, |
508 | 547 | std::vector<std::vector<float>*>* resultValues ) |
509 | 548 | { |
| 549 | + // S and E fields have 6 components stored as individual internal keys with a separator |
| 550 | + if ( fieldName == RifVtkFieldNames::S || fieldName == RifVtkFieldNames::E ) |
| 551 | + { |
| 552 | + using namespace RifVtkFieldNames; |
| 553 | + static const std::vector<std::string> sComponents = { S11, S22, S33, S12, S13, S23 }; |
| 554 | + static const std::vector<std::string> eComponents = { E11, E22, E33, E12, E13, E23 }; |
| 555 | + const auto& components = ( fieldName == RifVtkFieldNames::S ) ? sComponents : eComponents; |
| 556 | + size_t count = std::min( components.size(), resultValues->size() ); |
| 557 | + for ( size_t i = 0; i < count; i++ ) |
| 558 | + { |
| 559 | + std::string internalKey = fieldName + separator + components[i]; |
| 560 | + std::vector<std::vector<float>*> singleComp = { ( *resultValues )[i] }; |
| 561 | + readField( RigFemResultPosEnum::RIG_ELEMENT, internalKey, partIndex, stepIndex, &singleComp ); |
| 562 | + } |
| 563 | + return; |
| 564 | + } |
| 565 | + |
510 | 566 | readField( RigFemResultPosEnum::RIG_ELEMENT, fieldName, partIndex, stepIndex, resultValues ); |
511 | 567 | } |
512 | 568 |
|
@@ -593,6 +649,58 @@ void RifVtkReader::readScalarData( RigFemPartCollection* |
593 | 649 | ( *map )[propertyName][stepId][partId] = valuesAsDouble; |
594 | 650 | } |
595 | 651 | } |
| 652 | + else if ( values.size() == 3 * numElements ) |
| 653 | + { |
| 654 | + auto map = propertyDataMap( RigFemResultPosEnum::RIG_ELEMENT ); |
| 655 | + if ( map == nullptr ) continue; |
| 656 | + |
| 657 | + // Multi-component element results: stress[0/1] -> S_VTK, strain[0/1] -> E_VTK |
| 658 | + // Each VTK array contains 3 components per element. |
| 659 | + // Mapping: |
| 660 | + // stress[0]: S_VTK.S11 (index 0), S_VTK.S22 (index 1), S_VTK.S33 (index 2) |
| 661 | + // stress[1]: S_VTK.S12 (index 0), S_VTK.S13 (index 1), S_VTK.S23 (index 2) |
| 662 | + // strain[0]: E_VTK.E11 (index 0), E_VTK.E22 (index 1), E_VTK.E33 (index 2) |
| 663 | + // strain[1]: E_VTK.E12 (index 0), E_VTK.E13 (index 1), E_VTK.E23 (index 2) |
| 664 | + |
| 665 | + struct StressStrainMapping |
| 666 | + { |
| 667 | + std::string vtkName; |
| 668 | + std::string fieldName; |
| 669 | + std::array<std::string, 3> componentNames; |
| 670 | + }; |
| 671 | + |
| 672 | + using namespace RifVtkFieldNames; |
| 673 | + static const std::vector<StressStrainMapping> mappings = { |
| 674 | + { "stress[0]", S, { S11, S22, S33 } }, |
| 675 | + { "stress[1]", S, { S12, S13, S23 } }, |
| 676 | + { "strain[0]", E, { E11, E22, E33 } }, |
| 677 | + { "strain[1]", E, { E12, E13, E23 } }, |
| 678 | + }; |
| 679 | + |
| 680 | + for ( const auto& mapping : mappings ) |
| 681 | + { |
| 682 | + if ( propertyName != mapping.vtkName ) continue; |
| 683 | + |
| 684 | + for ( int compIdx = 0; compIdx < 3; compIdx++ ) |
| 685 | + { |
| 686 | + std::string internalKey = mapping.fieldName + separator + mapping.componentNames[compIdx]; |
| 687 | + |
| 688 | + if ( map->count( internalKey ) == 0 ) ( *map )[internalKey] = {}; |
| 689 | + if ( ( *map )[internalKey].count( stepId ) == 0 ) ( *map )[internalKey][stepId] = {}; |
| 690 | + |
| 691 | + for ( int partIdx = 0; partIdx < femParts->partCount(); partIdx++ ) |
| 692 | + { |
| 693 | + size_t dataSize = femParts->part( partIdx )->elementCount(); |
| 694 | + std::vector<double> compValues( dataSize, 0.0 ); |
| 695 | + for ( size_t i = 0; i < dataSize; i++ ) |
| 696 | + { |
| 697 | + compValues[i] = values[i * 3 + compIdx]; |
| 698 | + } |
| 699 | + ( *map )[internalKey][stepId][partIdx] = compValues; |
| 700 | + } |
| 701 | + } |
| 702 | + } |
| 703 | + } |
596 | 704 | } |
597 | 705 | stepId++; |
598 | 706 | } |
|
0 commit comments