queso-0.53.0
InstantiateIntersection.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/VectorSpace.h>
26 #include <queso/VectorSubset.h>
27 #include <queso/BoxSubset.h>
28 #include <queso/IntersectionSubset.h>
29 #include <queso/InstantiateIntersection.h>
30 #include <queso/GslVector.h>
31 #include <queso/GslMatrix.h>
32 
33 namespace QUESO {
34 
35 template<class V, class M>
36 VectorSet<V,M>*
37 InstantiateIntersection(const VectorSet<V,M>& domain1, const VectorSet<V,M>& domain2)
38 {
39  VectorSet<V,M>* result = NULL;
40 
41  unsigned int dim1 = domain1.vectorSpace().dimGlobal();
42  unsigned int dim2 = domain2.vectorSpace().dimGlobal();
43 
44  if (result == NULL) {
45  const VectorSpace<V,M>* tmp1 = dynamic_cast<const VectorSpace<V,M>* >(&domain1);
46  const VectorSpace<V,M>* tmp2 = dynamic_cast<const VectorSpace<V,M>* >(&domain2);
47 
48  if ((tmp1 != NULL) && (tmp2 != NULL)) {
49  if (dim1 < dim2) {
50  result = new VectorSpace<V,M>(tmp1->env(),
51  tmp1->prefix().c_str(),
52  tmp1->dimGlobal(),
53  NULL);//tmp1->componentsNames());
54  }
55  else if (dim1 == dim2) {
56  result = new VectorSpace<V,M>(tmp1->env(),
57  tmp1->prefix().c_str(),
58  tmp1->dimGlobal(),
59  NULL);//tmp1->componentsNames());
60  }
61  else {
62  result = new VectorSpace<V,M>(tmp2->env(),
63  tmp2->prefix().c_str(),
64  tmp2->dimGlobal(),
65  NULL);//tmp2->componentsNames());
66  }
67  }
68  }
69 
70  if (result == NULL) {
71  const VectorSubset<V,M>* tmp1 = dynamic_cast<const VectorSubset<V,M>* >(&domain1);
72  const VectorSubset<V,M>* tmp2 = dynamic_cast<const VectorSubset<V,M>* >(&domain2);
73 
74  if ((tmp1 != NULL) && (tmp2 != NULL)) {
75  if (dim1 == dim2) {
76  const BoxSubset<V,M>* box1 = dynamic_cast<const BoxSubset<V,M>* >(&domain1);
77  const BoxSubset<V,M>* box2 = dynamic_cast<const BoxSubset<V,M>* >(&domain2);
78 
79  if ((box1 != NULL) && (box2 != NULL)) {
80  V minV(box1->minValues());
81  V maxV(box1->maxValues());
82  for (unsigned int i = 0; i < dim1; ++i) {
83  minV[i] = std::max(box1->minValues()[i],
84  box2->minValues()[i]);
85  }
86  for (unsigned int i = 0; i < dim1; ++i) {
87  maxV[i] = std::min(box1->maxValues()[i],
88  box2->maxValues()[i]);
89  }
90  result = new BoxSubset<V,M>(box1->prefix().c_str(),
91  box1->vectorSpace(),
92  minV,
93  maxV);
94  }
95  else {
96  result = new IntersectionSubset<V,M>(tmp1->prefix().c_str(),
97  tmp1->vectorSpace(),
98  0., // FIX ME
99  domain1,
100  domain2);
101  }
102  }
103  else {
104  queso_error_msg("situation 001");
105  }
106  }
107  }
108 
109  if (result == NULL) {
110  const VectorSubset<V,M>* tmp1 = dynamic_cast<const VectorSubset<V,M>* >(&domain1);
111  const VectorSpace <V,M>* tmp2 = dynamic_cast<const VectorSpace <V,M>* >(&domain2);
112 
113  if ((tmp1 != NULL) && (tmp2 != NULL)) {
114  if (dim1 == dim2) {
115  const BoxSubset<V,M>* box1 = dynamic_cast<const BoxSubset<V,M>* >(&domain1);
116  if (box1 != NULL) {
117  result = new BoxSubset<V,M>(box1->prefix().c_str(),
118  box1->vectorSpace(),
119  box1->minValues(),
120  box1->maxValues());
121  }
122  else {
123  queso_error_msg("situation 002");
124  }
125  }
126  else {
127  queso_error_msg("situation 003");
128  }
129  }
130  }
131 
132  if (result == NULL) {
133  const VectorSpace <V,M>* tmp1 = dynamic_cast<const VectorSpace <V,M>* >(&domain1);
134  const VectorSubset<V,M>* tmp2 = dynamic_cast<const VectorSubset<V,M>* >(&domain2);
135 
136  if ((tmp1 != NULL) && (tmp2 != NULL)) {
137  if (dim1 == dim2) {
138  const BoxSubset<V,M>* box2 = dynamic_cast<const BoxSubset<V,M>* >(&domain2);
139  if (box2 != NULL) {
140  result = new BoxSubset<V,M>(box2->prefix().c_str(),
141  box2->vectorSpace(),
142  box2->minValues(),
143  box2->maxValues());
144  }
145  else {
146  queso_error_msg("situation 004");
147  }
148  }
149  else {
150  queso_error_msg("situation 005");
151  }
152  }
153  }
154 
155  if (result == NULL) {
156  queso_error_msg("situation 006");
157  }
158 
159  return result;
160 }
161 
162 } // End namespace QUESO
163 
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
A templated class for handling sets.
Definition: VectorSet.h:52
A templated class representing the intersection of two vector sets.
#define queso_error_msg(msg)
Definition: asserts.h:47
unsigned int dimGlobal() const
Definition: VectorSpace.C:176
const BaseEnvironment & env() const
Environment.
Definition: VectorSpace.C:151
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:79
A templated class for handling subsets.
Definition: VectorSubset.h:46
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:73
const VectorSpace< V, M > & vectorSpace() const
Vector space to which this set belongs to. See template specialization.
Definition: VectorSubset.C:68
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
const std::string & prefix() const
Access to private attribute m_prefix.
Definition: VectorSet.C:84
A class representing a vector space.
Definition: VectorSet.h:49
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5