OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
cwipi_coupling_adapter.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 CWIPI_COUPLING_ADAPTER_H
24#define CWIPI_COUPLING_ADAPTER_H
25
26#include "coupling.h"
27#include <memory>
28#include <array>
29
30#ifdef WITH_CWIPI
31#include "cwipi.h"
32#include <mpi.h>
33
34class CwipiCouplingAdapter : public CouplingAdapter {
35public:
36 CwipiCouplingAdapter();
37 ~CwipiCouplingAdapter() override;
38
39 // Implement abstract interface
40 bool configure(const std::string& configFile) override;
41 void setNodes(const std::vector<int>& nodeIds) override;
42 void setMesh(const int* elem_node_offsets, const int* elem_node_indices, int num_elements);
43 bool initialize(const double* coordinates, int totalNodes, int mpiRank, int mpiSize) override;
44 void writeData(const double* values, int totalNodes, double dt, int dataType) override;
45 void readData(double* values, int totalNodes, double dt, int dataType) override;
46 void advance(double& dt) override;
47 bool isCouplingOngoing() const override;
48 bool requiresWritingCheckpoint() const override;
49 bool requiresReadingCheckpoint() const override;
50 void finalize() override;
51 bool isActive() const override;
52 double getMaxTimeStepSize() const override;
53 int getNumberOfCouplingNodes() const override;
54
55 struct CouplingData {
56 bool isActive = false; // Whether this data type is active
57 Mode mode = Mode::SKIP; // Mode for this data type
58 std::vector<double> buffer;
59 int sendRequest = -1; // Track async send request
60 int recvRequest = -1; // Track async receive request
61 };
62
63private:
64 // Configuration data
65 bool active_;
66 std::string applicationName_;
67 std::string coupledAppName_;
68 std::string couplingName_;
69 std::string exchangeName_;
70 int dimension_;
71 double tolerance_;
72 int order_;
73
74 std::array<CouplingData, static_cast<size_t>(DataType::DATA_COUNT)> readData_;
75 std::array<CouplingData, static_cast<size_t>(DataType::DATA_COUNT)> writeData_;
76
77 // Coupling data
78 std::vector<int> couplingNodeIds_;
79 double maxTimeStepSize_;
80 bool initialized_;
81
82 // CWIPI specific data
83 MPI_Comm localComm_;
84
85 // Mesh connectivity storage
86 std::vector<int> eltsConnecPointer_;
87 std::vector<int> eltsConnec_;
88 int numElements_;
89
90 // Helper functions
91 void extractNodeData(const double* globalValues, int totalNodes, int dataType);
92 void injectNodeData(double* globalValues, int totalNodes, int dataType);
93 std::string getFieldName(DataType type);
94 int getTag(DataType type);
95 //override getCommuncator to return localComm_
96 int getCommunicator() const override {
97 int FortranComm = MPI_Comm_c2f(localComm_);
98 return FortranComm;
99 }
100};
101
102#endif
103#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
virtual bool isActive() const =0
virtual bool requiresReadingCheckpoint() const
Definition coupling.h:53
virtual int getCommunicator() const
Definition coupling.h:66
virtual bool requiresWritingCheckpoint() const
Definition coupling.h:52
LIBSEQ_INT MPI_Comm
Definition mpi.h:50