COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Action.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/function.hpp>
8 #include <boost/bind.hpp>
9 
10 #include "common/URI.hpp"
11 #include "common/OptionArray.hpp"
13 #include "common/OptionList.hpp"
15 
16 #include "mesh/Region.hpp"
17 #include "mesh/Mesh.hpp"
18 
19 #include "physics/PhysModel.hpp"
20 
21 #include "solver/Time.hpp"
22 #include "solver/Action.hpp"
23 #include "solver/Solver.hpp"
24 #include "solver/Tags.hpp"
25 
26 using namespace cf3::mesh;
27 
28 namespace cf3 {
29 namespace solver {
30 
32 
33 Action::Action ( const std::string& name ) :
34  common::Action(name)
35 {
36  mark_basic();
37 
38  // options
39 
40  options().add(Tags::solver(), m_solver)
41  .description("Link to the solver discretizing the problem")
42  .pretty_name("Solver")
43  .mark_basic()
44  .link_to(&m_solver);
45 
46  options().add(Tags::mesh(), m_mesh)
47  .description("Mesh the Discretization Method will be applied to")
48  .pretty_name("Mesh")
49  .mark_basic()
50  .link_to(&m_mesh);
51 
52  options().add(Tags::physical_model(), m_physical_model)
53  .description("Physical model")
54  .pretty_name("Physical Model")
55  .mark_basic()
56  .link_to(&m_physical_model);
57 
58  std::vector< common::URI > dummy;
59  options().add(Tags::regions(), dummy)
60  .description("Regions this action is applied to")
61  .pretty_name("Regions")
62  .attach_trigger ( boost::bind ( &Action::config_regions, this ) )
63  .mark_basic();
64 
65 }
66 
67 
68 Action::~Action() {}
69 
70 
71 physics::PhysModel& Action::physical_model()
72 {
73  Handle< physics::PhysModel > model = m_physical_model;
74  if( is_null(model) )
76  "Physical Model not yet set for component " + uri().string() );
77  return *model;
78 }
79 
80 
81 
83 {
84  Handle< Mesh > m = m_mesh;
85  if( is_null(m) )
87  "Mesh not yet set for component " + uri().string() );
88  return *m;
89 }
90 
91 
93 {
94  Handle< solver::Solver > s = m_solver;
95  if( is_null(s) )
97  "Solver not yet set for component " + uri().string() );
98  return *s;
99 }
100 
101 
102 const std::vector< Handle<Region> >& Action::regions() const
103 {
104  return m_loop_regions;
105 }
106 
107 
108 void Action::config_regions()
109 {
110 
111  m_loop_regions.clear();
112 
113  const std::string regions_option_name("regions"); // for Intel Composer 2011...
114  boost_foreach(const common::URI region_uri, options().option(regions_option_name).value< std::vector<common::URI> >())
115  {
116  Handle<Component> comp;
117  if (region_uri.is_relative())
118  {
119  if ( is_null(m_mesh) )
120  throw common::SetupError(FromHere(), "First configure the mesh");
121  comp = m_mesh->access_component(region_uri);
122  }
123  else
124  {
125  comp = access_component(region_uri);
126  }
127 
128  if ( is_null(comp) )
129  {
131  "Could not find region with path [" + region_uri.path() +"]" );
132  }
133  Handle< Region > region = comp->handle<Region>();
134  if ( is_not_null(region) )
135  m_loop_regions.push_back( region );
136  else
138  "Component [" + region_uri.path() +"] is not of type Region" );
139  }
140 
141  on_regions_set();
142 }
143 
145 
146 void Action::on_regions_set()
147 {
148 }
149 
150 
152 
153 } // solver
154 } // cf3
std::string name(ComponentWrapper &self)
bool is_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:151
std::string path() const
Definition: URI.cpp:253
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
common::URI uri(ComponentWrapper &self)
bool is_relative() const
Definition: URI.cpp:189
Handle< Component > access_component(const URI &path) const
Definition: Component.cpp:487
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
Basic Classes for Mesh applications used by COOLFluiD.
tuple model
Global confifuration.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Action(const std::string &name)
Definition: Action.cpp:25
Component that executes an action. Implementation of the IAction interface as a component, exposing the execute function as a signal.
Definition: Action.hpp:21
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
#define FromHere()
Send comments to:
COOLFluiD Web Admin