OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
coupling.h
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#ifndef COUPLING_H
24#define COUPLING_H
25
26#include <string>
27#include <vector>
28
29// Abstract base class for coupling adapters
31private:
32 int groupNodeId_; // the group node ID for this adapter.
33 int surfaceId_; // the surface ID for this adapter, not used yet
34
35public:
36 virtual ~CouplingAdapter() = default;
37
38 // Configuration
39 virtual bool configure(const std::string& configFile) = 0;
40 virtual void setNodes(const std::vector<int>& nodeIds) = 0;
41
42 // Initialization
43 virtual bool initialize(const double* coordinates, int totalNodes, int mpiRank, int mpiSize) = 0;
44
45 // Data exchange
46 virtual void writeData(const double* values, int totalNodes, double dt, int dataType) = 0;
47 virtual void readData(double* values, int totalNodes, double dt, int dataType) = 0;
48
49 // Simulation control
50 virtual void advance(double& dt) = 0;
51 virtual bool isCouplingOngoing() const = 0;
52 virtual bool requiresWritingCheckpoint() const {return false; };
53 virtual bool requiresReadingCheckpoint() const {return false; };
54
55 // Finalization
56 virtual void finalize() = 0;
57
58 // Getters
59 virtual bool isActive() const = 0;
60 virtual double getMaxTimeStepSize() const = 0;
61 virtual int getNumberOfCouplingNodes() const = 0;
62 int getGroupNodeId() const { return groupNodeId_; }
63 void setGroupNodeId(int id) { groupNodeId_ = id; }
64 int getSurfaceId() const { return surfaceId_; }
65 void setSurfaceId(int id) { surfaceId_ = id; }
66 virtual int getCommunicator() const { return 0; }
67
68 // Data types that can be exchanged during the coupling process
69 enum class DataType {
72 FORCES = 2,
74 DATA_COUNT = 4 // Total number of data types
75 };
76
77 // What to do with the received data
78 enum class Mode {
79 SKIP = 0,
80 REPLACE = 1, // For positions, replace the existing data
81 ADD = 2 // For forces, we add to the existing data
82 };
83
84 // Helper functions to convert between strings and DataType enums
85 static DataType stringToDataType(const std::string& str) {
86 if (str == "DISPLACEMENTS") return DataType::DISPLACEMENTS;
87 if (str == "FORCES") return DataType::FORCES;
88 if (str == "POSITIONS") return DataType::POSITIONS;
89 return DataType::NOTHING;
90 }
91
92 static std::string dataTypeToString(DataType type) {
93 switch (type) {
94 case DataType::DISPLACEMENTS: return "DISPLACEMENTS";
95 case DataType::FORCES: return "FORCES";
96 case DataType::POSITIONS: return "POSITIONS";
97 case DataType::NOTHING: return "NOTHING";
98 case DataType::DATA_COUNT: break; // Don't convert this
99 }
100 return "NOTHING";
101 }
102};
103
104#endif
virtual bool configure(const std::string &configFile)=0
virtual void setNodes(const std::vector< int > &nodeIds)=0
virtual double getMaxTimeStepSize() const =0
virtual void readData(double *values, int totalNodes, double dt, int dataType)=0
virtual void advance(double &dt)=0
virtual bool isCouplingOngoing() const =0
virtual void finalize()=0
virtual bool initialize(const double *coordinates, int totalNodes, int mpiRank, int mpiSize)=0
virtual void writeData(const double *values, int totalNodes, double dt, int dataType)=0
virtual int getNumberOfCouplingNodes() const =0
static std::string dataTypeToString(DataType type)
Definition coupling.h:92
virtual bool isActive() const =0
virtual bool requiresReadingCheckpoint() const
Definition coupling.h:53
virtual ~CouplingAdapter()=default
virtual int getCommunicator() const
Definition coupling.h:66
void setSurfaceId(int id)
Definition coupling.h:65
int getGroupNodeId() const
Definition coupling.h:62
virtual bool requiresWritingCheckpoint() const
Definition coupling.h:52
int getSurfaceId() const
Definition coupling.h:64
void setGroupNodeId(int id)
Definition coupling.h:63
static DataType stringToDataType(const std::string &str)
Definition coupling.h:85
initmumps id