COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-fieldmanager.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 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for cf3::mesh::FieldManager"
9 
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/list_of.hpp>
12 #include <boost/foreach.hpp>
13 
14 #include "common/Log.hpp"
15 #include "common/OptionList.hpp"
16 #include "common/Environment.hpp"
17 #include "common/Core.hpp"
18 
19 #include "math/VariableManager.hpp"
21 
22 #include "mesh/Mesh.hpp"
23 #include "mesh/Region.hpp"
24 #include "mesh/Elements.hpp"
25 #include "mesh/FieldManager.hpp"
26 #include "mesh/Field.hpp"
28 #include "mesh/Space.hpp"
29 #include "mesh/Faces.hpp"
30 #include "mesh/Cells.hpp"
31 #include "mesh/Dictionary.hpp"
32 
34 
35 using namespace boost;
36 using namespace cf3;
37 using namespace cf3::mesh;
38 using namespace cf3::common;
39 using namespace cf3::math;
40 
42 
43 BOOST_AUTO_TEST_SUITE( FieldManagerSuite )
44 
45 
47 BOOST_AUTO_TEST_CASE( test_FieldManager )
48 {
49  Core::instance().environment().options().set("exception_aborts",false);
50  Core::instance().environment().options().set("exception_backtrace",false);
51  Core::instance().environment().options().set("exception_outputs",false);
52  Component& root = Core::instance().root();
53 
54  // tag to use (normally supplied by the solver)
55  const std::string tag = "solution";
56 
57  Handle<VariableManager> var_manager = root.create_component<VariableManager>("varmanager");
58  var_manager->create_descriptor(tag, "a, b[v], c[t]").options().set(common::Tags::dimension(), 2u);
59 
60  // Test mesh
61  Mesh& mesh = *root.create_component<Mesh>("mesh");
62  Tools::MeshGeneration::create_rectangle(mesh, 1., 1., 10, 10);
63 
64  // FieldManager
65  FieldManager& field_manager = *root.create_component<FieldManager>("fieldmanager");
66  field_manager.options().set("variable_manager", var_manager);
67 
68  // Do this twice, to ensure the second run does nothing
69  field_manager.create_field(tag, mesh.geometry_fields());
70  field_manager.create_field(tag, mesh.geometry_fields());
71 
72  BOOST_CHECK(is_not_null(mesh.geometry_fields().get_child(tag)));
73  Field& field = mesh.geometry_fields().field(tag);
74  BOOST_CHECK(field.has_variable("a"));
75  BOOST_CHECK(field.row_size() == 7);
76 
77  // Now change the descriptor and ensure there is an error
78  var_manager->get_child(tag)->remove_tag(tag);
79  var_manager->create_descriptor(tag, "a, b[v], c[t]").options().set(common::Tags::dimension(), 3u);
80  BOOST_CHECK_THROW(field_manager.create_field(tag, mesh.geometry_fields()), SetupError);
81 }
82 
84 
85 BOOST_AUTO_TEST_SUITE_END()
86 
87 
VariablesDescriptor & create_descriptor(const std::string &name, const std::string &description)
bool has_variable(const std::string &vname) const
True if the field contains a variable with the given name.
Definition: Field.cpp:62
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
external boost library namespace
Basic Classes for Mathematical applications used by COOLFluiD.
BOOST_AUTO_TEST_CASE(test_FieldManager)
tuple root
Definition: coolfluid.py:24
void create_rectangle(Mesh &mesh, const Real x_len, const Real y_len, const Uint x_segments, const Uint y_segments)
Create a rectangular, 2D, quad-only mesh. No buffer for creation.
Field & field(const std::string &name)
Definition: Dictionary.cpp:367
Basic Classes for Mesh applications used by COOLFluiD.
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Uint row_size(Uint i=0) const
Definition: Table.hpp:133
void create_field(const std::string &tag, cf3::mesh::Dictionary &dict)
Create fields. Looks up the VariablesDescriptor with the given tag, and creates a field with the same...
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
Base class for defining CF components.
Definition: Component.hpp:82
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
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
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
Send comments to:
COOLFluiD Web Admin