Skip to content

Commit 83eadd8

Browse files
committed
Implement column model builder
This commit unifies the column model builder so that a unified unit operation interface is exposed while internally unit operations can have both different or unified implementations. Makes input field `SPATIAL_METHOD` mandatory.
1 parent ca4b9b5 commit 83eadd8

10 files changed

+268
-385
lines changed

src/libcadet/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ set(LIBCADET_SOURCES
146146
${CMAKE_SOURCE_DIR}/src/libcadet/model/OutletModel.cpp
147147
${CMAKE_SOURCE_DIR}/src/libcadet/model/StirredTankModel.cpp
148148
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithoutPores.cpp
149-
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithoutPoresBuilder.cpp
150149
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores.cpp
151-
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPoresBuilder.cpp
152150
${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel.cpp
153-
${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModelBuilder.cpp
151+
${CMAKE_SOURCE_DIR}/src/libcadet/model/ColumnModelBuilder.cpp
154152
${CMAKE_SOURCE_DIR}/src/libcadet/model/ParameterMultiplexing.cpp
155153
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/ConvectionDispersionOperator.cpp
156154
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/AxialConvectionDispersionKernel.cpp
@@ -200,7 +198,6 @@ if (ENABLE_2D_MODELS)
200198
${CMAKE_SOURCE_DIR}/src/libcadet/model/MultiChannelTransportModel.cpp
201199
${CMAKE_SOURCE_DIR}/src/libcadet/model/MultiChannelTransportModel-LinearSolver.cpp
202200
${CMAKE_SOURCE_DIR}/src/libcadet/model/MultiChannelTransportModel-InitialConditions.cpp
203-
${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel2DBuilder.cpp
204201
)
205202

206203
if (NOT SUPERLU_FOUND)

src/libcadet/ModelBuilderImpl.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ namespace cadet
3232
{
3333
void registerInletModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
3434
void registerOutletModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
35-
36-
void registerColumnModel1D(std::unordered_map<std::string, std::function<IUnitOperation* (UnitOpIdx, IParameterProvider&)>>& models);
37-
void registerGeneralRateModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
38-
void registerLumpedRateModelWithPores(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
39-
void registerLumpedRateModelWithoutPores(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
35+
void registerColumnModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
4036
void registerCSTRModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
4137
#ifdef ENABLE_2D_MODELS
42-
void registerGeneralRateModel2D(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
4338
void registerMultiChannelTransportModel(std::unordered_map<std::string, std::function<IUnitOperation*(UnitOpIdx, IParameterProvider&)>>& models);
44-
void registerColumnModel2D(std::unordered_map<std::string, std::function<IUnitOperation* (UnitOpIdx, IParameterProvider&)>>& models);
4539
#endif
4640

4741
namespace inlet
@@ -61,16 +55,10 @@ namespace cadet
6155
// Register all available models
6256
model::registerInletModel(_modelCreators);
6357
model::registerOutletModel(_modelCreators);
64-
model::registerGeneralRateModel(_modelCreators);
65-
model::registerLumpedRateModelWithPores(_modelCreators);
66-
model::registerLumpedRateModelWithoutPores(_modelCreators);
6758
model::registerCSTRModel(_modelCreators);
68-
model::registerColumnModel1D(_modelCreators);
69-
59+
model::registerColumnModel(_modelCreators);
7060
#ifdef ENABLE_2D_MODELS
71-
model::registerGeneralRateModel2D(_modelCreators);
7261
model::registerMultiChannelTransportModel(_modelCreators);
73-
model::registerColumnModel2D(_modelCreators);
7462
#endif
7563

7664
// Register all available inlet profiles
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#include "model/ColumnModel1D.hpp"
2+
#ifdef ENABLE_2D_MODELS
3+
#include "model/ColumnModel2D.hpp"
4+
#include "model/GeneralRateModel2D.hpp"
5+
#endif
6+
#include "model/GeneralRateModel.hpp"
7+
#include "model/LumpedRateModelWithoutPores.hpp"
8+
#include "model/LumpedRateModelWithoutPoresDG.hpp"
9+
#include "model/LumpedRateModelWithPores.hpp"
10+
#include "CompileTimeConfig.hpp"
11+
#include "LoggingUtils.hpp"
12+
#include "Logging.hpp"
13+
14+
15+
namespace cadet
16+
{
17+
namespace model
18+
{
19+
20+
IUnitOperation* selectAxialFlowColumnUnitOperation(UnitOpIdx uoId, IParameterProvider& paramProvider)
21+
{
22+
IUnitOperation* model = nullptr;
23+
24+
std::string uoType = paramProvider.getString("UNIT_TYPE");
25+
26+
if (uoType == "COLUMN_MODEL_1D")
27+
{
28+
if (paramProvider.exists("particle_type_000"))
29+
{
30+
paramProvider.pushScope("discretization");
31+
const std::string discName = paramProvider.getString("SPATIAL_METHOD");
32+
paramProvider.popScope();
33+
34+
paramProvider.pushScope("particle_type_000");
35+
36+
if(paramProvider.getString("PARTICLE_TYPE") == "EQUILIBRIUM_PARTICLE")
37+
{
38+
if (discName == "DG")
39+
model = new LumpedRateModelWithoutPoresDG(uoId);
40+
else if (discName == "FV")
41+
model = createAxialFVLRM(uoId);
42+
else
43+
LOG(Error) << "Unknown bulk discretization type " << discName << " for unit " << uoId;
44+
}
45+
else if (discName == "FV")
46+
{
47+
if(paramProvider.getString("PARTICLE_TYPE") == "HOMOGENEOUS_PARTICLE")
48+
model = createAxialFVLRMP(uoId);
49+
else if (paramProvider.getString("PARTICLE_TYPE") == "GENERAL_RATE_PARTICLE")
50+
model = createAxialFVGRM(uoId);
51+
}
52+
else
53+
model = new ColumnModel1D(uoId);
54+
55+
paramProvider.popScope();
56+
}
57+
else
58+
model = new ColumnModel1D(uoId);
59+
}
60+
#ifdef ENABLE_2D_MODELS
61+
else if (uoType.find("_2D") != std::string::npos)
62+
{
63+
paramProvider.pushScope("discretization");
64+
const std::string discName = paramProvider.getString("SPATIAL_METHOD");
65+
paramProvider.popScope();
66+
67+
if (discName == "DG")
68+
model = new ColumnModel2D(uoId);
69+
else if (discName == "FV")
70+
{
71+
if (uoType != "GENERAL_RATE_MODEL_2D")
72+
LOG(Error) << uoType + " has no FV implementation for the bulk phase, but was specified as such for unit " << uoId;
73+
else
74+
model = new GeneralRateModel2D(uoId);
75+
}
76+
else
77+
LOG(Error) << "Unknown bulk discretization type " << discName << " for unit " << uoId;
78+
}
79+
#endif
80+
else
81+
{
82+
paramProvider.pushScope("discretization");
83+
const std::string discName = paramProvider.getString("SPATIAL_METHOD");
84+
paramProvider.popScope();
85+
86+
if (discName == "DG")
87+
{
88+
if (uoType == "LUMPED_RATE_MODEL_WITHOUT_PORES")
89+
model = new LumpedRateModelWithoutPoresDG(uoId);
90+
else if (uoType == "LUMPED_RATE_MODEL_WITH_PORES" || uoType == "GENERAL_RATE_MODEL")
91+
model = new ColumnModel1D(uoId);
92+
}
93+
else if (discName == "FV")
94+
{
95+
if (uoType == "LUMPED_RATE_MODEL_WITHOUT_PORES")
96+
model = createAxialFVLRM(uoId);
97+
else if (uoType == "LUMPED_RATE_MODEL_WITH_PORES")
98+
model = createAxialFVLRMP(uoId);
99+
else if (uoType == "GENERAL_RATE_MODEL")
100+
model = createAxialFVGRM(uoId);
101+
}
102+
else
103+
LOG(Error) << "Unknown bulk discretization type " << discName << " for unit " << uoId;
104+
}
105+
106+
return model;
107+
}
108+
109+
IUnitOperation* selectRadialFlowColumnUnitOperation(UnitOpIdx uoId, IParameterProvider& paramProvider)
110+
{
111+
IUnitOperation* model = nullptr;
112+
113+
std::string uoType = paramProvider.getString("UNIT_TYPE");
114+
115+
if (uoType == "COLUMN_MODEL_1D")
116+
{
117+
if (paramProvider.exists("particle_type_000"))
118+
{
119+
paramProvider.pushScope("discretization");
120+
const std::string discName = paramProvider.getString("SPATIAL_METHOD");
121+
paramProvider.popScope();
122+
123+
if (discName == "DG")
124+
LOG(Error) << "Radial flow not implemented for DG discretization yet, was called for unit " << uoId;
125+
else if (discName != "FV")
126+
LOG(Error) << "Unknown bulk discretization type " << discName << " for unit " << uoId;
127+
128+
paramProvider.pushScope("particle_type_000");
129+
130+
if (paramProvider.getString("PARTICLE_TYPE") == "EQUILIBRIUM_PARTICLE")
131+
model = createRadialFVLRM(uoId);
132+
if (paramProvider.getString("PARTICLE_TYPE") == "HOMOGENEOUS_PARTICLE")
133+
model = createRadialFVLRMP(uoId);
134+
else if (paramProvider.getString("PARTICLE_TYPE") == "GENERAL_RATE_PARTICLE")
135+
model = createRadialFVGRM(uoId);
136+
137+
paramProvider.popScope();
138+
}
139+
else
140+
model = createRadialFVLRM(uoId); // LRM used for npartype = 0
141+
}
142+
else
143+
{
144+
paramProvider.pushScope("discretization");
145+
const std::string discName = paramProvider.getString("SPATIAL_METHOD");
146+
147+
if (discName == "DG")
148+
LOG(Error) << "Radial flow not implemented for DG discretization yet, was called for unit " << uoId;
149+
else if (discName == "FV")
150+
{
151+
if (uoType == "RADIAL_LUMPED_RATE_MODEL_WITHOUT_PORES")
152+
model = createRadialFVLRM(uoId);
153+
else if (uoType == "RADIAL_LUMPED_RATE_MODEL_WITH_PORES")
154+
model = createRadialFVLRMP(uoId);
155+
else if (uoType == "RADIAL_GENERAL_RATE_MODEL")
156+
model = createRadialFVGRM(uoId);
157+
}
158+
else
159+
LOG(Error) << "Unknown bulk discretization type " << discName << " for unit " << uoId;
160+
161+
paramProvider.popScope();
162+
}
163+
164+
return model;
165+
}
166+
167+
void registerColumnModel(std::unordered_map<std::string, std::function<IUnitOperation* (UnitOpIdx, IParameterProvider&)>>& models)
168+
{
169+
models[ColumnModel1D::identifier()] = selectAxialFlowColumnUnitOperation;
170+
models["COLUMN_MODEL_1D"] = selectAxialFlowColumnUnitOperation;
171+
172+
models[ColumnModel2D::identifier()] = selectAxialFlowColumnUnitOperation;
173+
models["COLUMN_MODEL_2D"] = selectAxialFlowColumnUnitOperation;
174+
175+
models[LumpedRateModelWithoutPoresDG::identifier()] = selectAxialFlowColumnUnitOperation;
176+
models["LRM_DG"] = selectAxialFlowColumnUnitOperation;
177+
178+
typedef GeneralRateModel<parts::AxialConvectionDispersionOperator> AxialGRM;
179+
typedef GeneralRateModel<parts::RadialConvectionDispersionOperator> RadialGRM;
180+
181+
models[AxialGRM::identifier()] = selectAxialFlowColumnUnitOperation;
182+
models["GRM"] = selectAxialFlowColumnUnitOperation;
183+
184+
models[RadialGRM::identifier()] = selectRadialFlowColumnUnitOperation;
185+
models["RGRM"] = selectRadialFlowColumnUnitOperation;
186+
187+
models[GeneralRateModel2D::identifier()] = selectAxialFlowColumnUnitOperation;
188+
models["GRM2D"] = selectAxialFlowColumnUnitOperation;
189+
190+
typedef LumpedRateModelWithPores<parts::AxialConvectionDispersionOperator> AxialLRMP;
191+
typedef LumpedRateModelWithPores<parts::RadialConvectionDispersionOperator> RadialLRMP;
192+
193+
models[AxialLRMP::identifier()] = selectAxialFlowColumnUnitOperation;
194+
models["LRMP"] = selectAxialFlowColumnUnitOperation;
195+
196+
models[RadialLRMP::identifier()] = selectRadialFlowColumnUnitOperation;
197+
models["RLRMP"] = selectRadialFlowColumnUnitOperation;
198+
199+
typedef LumpedRateModelWithoutPores<parts::AxialConvectionDispersionOperatorBase> AxialLRM;
200+
typedef LumpedRateModelWithoutPores<parts::RadialConvectionDispersionOperatorBase> RadialLRM;
201+
202+
models[AxialLRM::identifier()] = selectAxialFlowColumnUnitOperation;
203+
models["LRM"] = selectAxialFlowColumnUnitOperation;
204+
models["DPFR"] = selectAxialFlowColumnUnitOperation;
205+
206+
models[RadialLRM::identifier()] = selectRadialFlowColumnUnitOperation;
207+
models["RLRM"] = selectRadialFlowColumnUnitOperation;
208+
}
209+
210+
} // namespace model
211+
212+
} // namespace cadet

src/libcadet/model/GeneralRateModel2DBuilder.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)