MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
MacroscopicProblem.C
1 /*
2 
3  ooo ooooo oooooooooo. ooooo ooo
4  `88. .888' `888' `Y8b `888b. `8'
5  888b d'888 .ooooo. 888 888 .ooooo. 8 `88b. 8 .oooo.
6  8 Y88. .P 888 d88' `88b 888 888 d88' `88b 8 `88b. 8 `P )88b
7  8 `888' 888 888 888 888 888 888ooo888 8 `88b.8 .oP"888
8  8 Y 888 888 888 888 d88' 888 .o 8 `888 d8( 888
9  o8o o888o `Y8bod8P' o888bood8P' `Y8bod8P' o8o `8 `Y888""8o
10 
11 Copyright
12  2014-2016 MoDeNa Consortium, All rights reserved.
13 
14 License
15  This file is part of Modena.
16 
17  Modena is free software; you can redistribute it and/or modify it under
18  the terms of the GNU General Public License as published by the Free
19  Software Foundation, either version 3 of the License, or (at your option)
20  any later version.
21 
22  Modena is distributed in the hope that it will be useful, but WITHOUT ANY
23  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
25  details.
26 
27  You should have received a copy of the GNU General Public License along
28  with Modena. If not, see <http://www.gnu.org/licenses/>.
29 
30 Description
31  Solving the two tank problem the MoDeNa way.
32 
33  A prototypical macros-scopic code embeds a micro-scale model (flowRate)
34  through the MoDeNa interface library.
35 
36 Authors
37  Jonas Mairhofer
38 
39 Contributors
40 */
41 
42 #include <stdio.h>
43 #include <iostream>
44 #include "modena.h"
45 
46 using namespace std;
47 
48 int
49 main(int argc, char *argv[])
50 {
51  double T = 200;
52  double Tend = 220.0;
53 
54  // Instantiate index set
55  //modena_index_set_t *indexSet = modena_index_set_new("species");
56 
57 
58  // Instantiate a model
59  modena_model_t *model = modena_model_new("Solubility[A=CO2,B=HEXANE]");
60  if(modena_error_occurred())
61  {
62  return modena_error();
63  }
64 
65  // Allocate memory and fetch arg positions
66  modena_inputs_t *inputs = modena_inputs_new(model);
67  modena_outputs_t *outputs = modena_outputs_new(model);
68 
69 
70  size_t Tpos = modena_model_inputs_argPos(model, "T");
71 
73 
74 
75  while(T < Tend)
76  {
77  // Set input vector
78  modena_inputs_set(inputs, Tpos, T);
79 
80  // Call the model
81  int ret = modena_model_call(model, inputs, outputs);
82 
83  // Terminate, if requested
84  if(modena_error_occurred())
85  {
86  modena_inputs_destroy(inputs);
87  modena_outputs_destroy(outputs);
88  modena_model_destroy(model);
89 
90  return modena_error();
91  }
92 
93  // Fetch result
94  double H = modena_outputs_get(outputs, 0);
95 
96  cout << "T = " << T;
97 
98 
99  T = T + 10.0;
100  }
101 
102 
103  modena_inputs_destroy(inputs);
104  modena_outputs_destroy(outputs);
105  modena_model_destroy(model);
106 
107  return 0;
108 }
size_t modena_model_inputs_argPos(const modena_model_t *self, const char *name)
Function determining position of an argument in the input vector.
Definition: model.c:366
modena_model_t * modena_model_new(const char *modelId)
Function fetching a surrogate model from MongoDB.
Definition: model.c:281
int modena_model_call(modena_model_t *self, modena_inputs_t *inputs, modena_outputs_t *outputs)
Function calling the surrogate model and checking for errors.
Definition: model.c:553
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23
stores a surrogate model
Definition: model.h:94
void modena_model_destroy(modena_model_t *self)
Function deallocating the memory allocated for the surrogate model.
Definition: model.c:665
Definition: model.f90:7
void modena_model_argPos_check(const modena_model_t *self)
Function checking that the user has queried all input positions.
Definition: model.c:408