COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
coolfluid-solver.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #include <boost/program_options/errors.hpp>
8 #include <boost/program_options/options_description.hpp>
9 #include <boost/program_options/parsers.hpp>
10 #include <boost/program_options/variables_map.hpp>
11 
12 #include "common/Core.hpp"
13 #include "common/Journal.hpp"
14 #include "common/Log.hpp"
15 #include "common/Table.hpp"
16 
17 #include "common/PE/Manager.hpp"
18 #include "common/PE/Comm.hpp"
20 
21 #include "solver/Plotter.hpp"
22 
23 #include "Tools/solver/CWorker.hpp"
26 
27 using namespace boost;
28 using namespace cf3;
29 using namespace cf3::common;
30 using namespace cf3::common::PE;
31 using namespace cf3::solver;
32 using namespace cf3::Tools::solver;
33 
35 
36 void setup_tree()
37 {
38  Handle< Component > tools = Core::instance().root().get_child("Tools");
39  Plotter & plotter = *tools->create_component< Plotter >("Plotter");
40  Table<Real> & table = *tools->create_component< Table<Real> >("MyTable");
41  tools->create_component< Journal >("Journal");
42 
43  table.set_row_size(8); // reserve 8 columns
44  Table<Real>::Buffer buffer = table.create_buffer(8000);
45 
46  table.mark_basic();
47  plotter.mark_basic();
48  plotter.set_data_set( table.uri() );
49 
50  // fill the table
51  std::vector<Real> row(8);
52 
53  for(Real value = 0.0 ; value != 1000.0 ; value += 1.0 )
54  {
55  row[0] = value / 1000; // x
56  row[1] = 0; // y
57  row[2] = (value / 1000) - 1; // z
58  row[3] = std::sin(4 * row[0]); // u
59  row[4] = 0; // v
60  row[5] = std::cos(4 * row[2]); // w
61  row[6] = 1000; // p
62  row[7] = 278 * row[0]; // t
63 
64  buffer.add_row( row );
65  }
66 
67  buffer.flush();
68 }
69 
71 
72 int main(int argc, char ** argv)
73 {
74  LogForwarder * forwarder;
75  Notifier * notifier;
76  Communicator parent_comm;
77  int rank;
78 
79  // initiate the CF core and MPI environment
80  Core::instance().initiate(argc, argv);
81  Comm::instance().init(argc, argv);
82 
83  parent_comm = Comm::instance().get_parent();
84  rank = Comm::instance().rank();
85 
86  if( parent_comm == MPI_COMM_NULL )
87  {
88  CFerror << "This solver cannot run without a manager. Exiting..." << CFendl;
89  return 1;
90  }
91 
92  setup_tree();
93 
94  // create the PE manager
95  Handle< Manager > mgr = Core::instance().root().get_child("Tools")->
96  create_component<Manager>("PEManager");
97 
98  Core::instance().root().create_component<CWorker>("Worker");
99 
100  // Make sure the python ScriptEngine gets created, if it exists
101  try
102  {
103  build_component("cf3.python.ScriptEngine", "DummyScriptEngine");
104  }
105  catch(...)
106  {
107  }
108 
109  mgr->mark_basic();
110 
111  notifier = new Notifier( mgr );
112 
113  notifier->listen_to_event("tree_updated", true);
114 
115  // set the forwarder, if needed
116  // if( forward == "all" || (forward == "rank0" && Comm::instance().rank() == 0) )
117  {
118  forwarder = new LogForwarder();
119  Logger::instance().getStream(INFO).addStringForwarder(forwarder);
120  }
121 
122  bool rank0 = CFinfo.getFilterRankZero(LogStream::SCREEN);
123 
124  CFinfo.setFilterRankZero(LogStream::SCREEN, false);
125 
126  CFinfo << "Worker[" << rank << "] -> Syncing with the parent..." << CFendl;
127  Comm::instance().barrier();
128  MPI_Barrier( parent_comm );
129  CFinfo << "Worker[" << rank << "] -> Synced with the parent!" << CFendl;
130 
131  CFinfo.setFilterRankZero(LogStream::SCREEN, rank0);
132 
133  mgr->listening_thread()->join();
134 
135  CFinfo << "Worker[" << rank << "] -> " << "C U..." << CFendl;
136 
137  // synchronize with the parent before we finalize the MPI environment
138  MPI_Barrier( parent_comm );
139 
140  // terminate the CF core and MPI environment
141  Comm::instance().finalize();
142  Core::instance().terminate();
143 
144  delete forwarder;
145  delete notifier;
146 
147  return 0;
148 }
#define CFinfo
these are always defined
Definition: Log.hpp:104
boost::thread * listening_thread()
Definition: Manager.cpp:350
boost::shared_ptr< Component > build_component(const std::string &builder_name, const std::string &name, const std::string &factory_type_name)
Definition: Component.cpp:1200
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
external boost library namespace
tuple tools
Definition: coolfluid.py:33
Basic Classes for Solver applications used by CF.
Definition: Action.cpp:29
Buffer create_buffer(const size_t buffersize=16384)
Definition: Table.hpp:102
#define CFendl
Definition: Log.hpp:109
void setup_tree()
Top-level namespace for coolfluid.
Definition: Action.cpp:18
MPI_Comm Communicator
communicator
Definition: types.hpp:41
void set_data_set(const common::URI &uri)
Definition: Plotter.cpp:94
Classes offering a MPI interface for COOLFluiD.
Definition: all_gather.hpp:39
Appends LoggingEvents to the remote client log window.
void listen_to_event(const std::string &name, bool notify_once)
Definition: Notifier.cpp:38
#define CFerror
Definition: Log.hpp:105
Component & mark_basic()
marks this component as basic.
Definition: Component.cpp:1076
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
int main(int argc, char **argv)
Send comments to:
COOLFluiD Web Admin