-
Notifications
You must be signed in to change notification settings - Fork 1
/
gsPreCICEFunction.h
197 lines (165 loc) · 6.29 KB
/
gsPreCICEFunction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/** @file gsPreCICEFunction.h
@brief Provides declaration of ConstantFunction class.
This file is part of the G+Smo library.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Author(s): H.M. Verhelst (TU Delft, 2019-2024), J.Li (TU Delft, 2023 - ...)
*/
#pragma once
#include <gsCore/gsLinearAlgebra.h>
#include <gsCore/gsGeometry.h>
#include <gsPreCICE/gsPreCICE.h>
namespace gismo
{
/**
* @brief Class defining a gsFunction that reads from the precice::SolverInterface
* @details The gsPreCICEFunction enables efficient data lookups based on spatial coordinates. When given a set of points and corresponding
* @tparam T Number format
*/
template <class T>
class gsPreCICEFunction : public gsFunction<T>
{
public:
typedef gsGeometry<T> Base;
/// Shared pointer for gsPreCICEFunction
typedef memory::shared_ptr< gsPreCICEFunction > Ptr;
/// Unique pointer for gsPreCICEFunction
typedef memory::unique_ptr< gsPreCICEFunction > uPtr;
/// Default constructor
gsPreCICEFunction() { }
/**
* @brief Constructs a new instance of the gsPreCICEFunction
*
* @param interface The precice::SolverInterface (see \a gsPreCICE)
* @param[in] meshName The ID of the mesh on which the data is located
* @param[in] dataName The ID of the data
* @param[in] patches The geometry
* @param[in] parametric Specifies whether the data is defined on the parametric domain or not
*/
gsPreCICEFunction( gsPreCICE<T> * interface,
const std::string & meshName,
const std::string & dataName,
const gsMultiPatch<T> & patches,
const index_t & targetDim,
const bool parametric = false)
:
m_interface(interface),
m_meshName(meshName),
m_dataName(dataName),
m_patches(patches),
m_parametric(parametric),
m_patchID(0),
m_domainDim(m_patches.domainDim()),
m_targetDim(targetDim)
{
}
/**
* @brief Constructs a new instance of the gsPreCICEFunction
*
* @param interface The precice::SolverInterface (see \a gsPreCICE)
* @param[in] meshName The ID of the mesh on which the data is located
* @param[in] dataName The ID of the data
* @param[in] patches The geometry
* @param[in] parametric Specifies whether the data is defined on the parametric domain or not
*/
gsPreCICEFunction( gsPreCICE<T> * interface,
const std::string & meshName,
const std::string & dataName,
const gsMultiPatch<T> & patches,
const index_t & domainDim,
const index_t & targetDim,
const bool parametric = false)
:
m_interface(interface),
m_meshName(meshName),
m_dataName(dataName),
m_patches(patches),
m_parametric(parametric),
m_patchID(0),
m_domainDim(domainDim),
m_targetDim(targetDim)
{
}
/// Constructs a function pointer
static uPtr make( const gsPreCICE<T> * interface,
const std::string & meshName,
const std::string & dataName,
const gsMultiPatch<T> & patches,
const index_t & targetDim,
const bool parametric = false)
{ return uPtr(new gsPreCICEFunction(interface, meshName, dataName, patches, targetDim, parametric)); }
GISMO_CLONE_FUNCTION(gsPreCICEFunction)
/// Access a piece
const gsPreCICEFunction<T> & piece(const index_t) const
{
return *this;
}
/// See \a gsFunction
virtual short_t domainDim() const
{ return m_domainDim; }
/// Gives the targetDomain, currently only scalar functions (todo)
virtual short_t targetDim() const
{ return m_targetDim; }
/// See \a gsFunction
virtual void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
{
gsMatrix<T> coords;
this->_getCoords(u,coords);
m_interface->readData(m_meshName,m_dataName,coords,result);
}
/// See \a gsFunction
virtual void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
{
// This would be nice to have with higher-order (IGA) coupling of precice
GISMO_NO_IMPLEMENTATION;
}
/// See \a gsFunction
virtual void deriv2_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
{
// This would be nice to have with higher-order (IGA) coupling of precice
GISMO_NO_IMPLEMENTATION;
}
/// See \a gsFunction
void evalAllDers_into(const gsMatrix<T> & u, int n,
std::vector<gsMatrix<T> > & result) const
{
result.resize(1);
// This would be nice to have with higher-order (IGA) coupling of precice
gsMatrix<T> tmp;
this->eval_into(u,tmp);
result[0]= tmp;
}
/// See \a gsFunction
virtual std::ostream &print(std::ostream &os) const
{
os << "gsPreCICEFunction, defined using gsPreCICE (precice::SolverInterface):\n";
os << m_interface;
return os;
}
protected:
void _getCoords(const gsMatrix<T>& u, gsMatrix<T>& result) const
{
GISMO_ASSERT(u.rows() == m_domainDim, "Wrong domain dimension "<< u.rows()
<< ", expected "<< m_domainDim);
// Does not work
// if (m_parametric)
// m_interface->readBlockScalarData(m_meshName,m_dataName,m_patches.patch(m_patchID).eval(u),result);
// if (m_parametric)
// m_interface->readBlockScalarData(m_meshName,m_dataName,u,result);
result.resize(m_patches.targetDim(),u.cols());
if (m_parametric)
m_patches.patch(m_patchID).eval_into(u,result);
else
result = u;
}
protected:
gsPreCICE<T> * m_interface;
std::string m_meshName;
std::string m_dataName;
gsMultiPatch<T> m_patches;
bool m_parametric;
index_t m_patchID;
index_t m_domainDim, m_targetDim;
};
}