queso-0.51.1
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,2009,2010,2011,2012,2013 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  UQ_FATAL_TEST_MACRO(true,
105  domain1.env().worldRank(),
106  "InstantiateIntersection<V,M>()",
107  "situation 001");
108  }
109  }
110  }
111 
112  if (result == NULL) {
113  const VectorSubset<V,M>* tmp1 = dynamic_cast<const VectorSubset<V,M>* >(&domain1);
114  const VectorSpace <V,M>* tmp2 = dynamic_cast<const VectorSpace <V,M>* >(&domain2);
115 
116  if ((tmp1 != NULL) && (tmp2 != NULL)) {
117  if (dim1 == dim2) {
118  const BoxSubset<V,M>* box1 = dynamic_cast<const BoxSubset<V,M>* >(&domain1);
119  if (box1 != NULL) {
120  result = new BoxSubset<V,M>(box1->prefix().c_str(),
121  box1->vectorSpace(),
122  box1->minValues(),
123  box1->maxValues());
124  }
125  else {
126  UQ_FATAL_TEST_MACRO(true,
127  domain1.env().worldRank(),
128  "InstantiateIntersection<V,M>()",
129  "situation 002");
130  }
131  }
132  else {
133  UQ_FATAL_TEST_MACRO(true,
134  domain1.env().worldRank(),
135  "InstantiateIntersection<V,M>()",
136  "situation 003");
137  }
138  }
139  }
140 
141  if (result == NULL) {
142  const VectorSpace <V,M>* tmp1 = dynamic_cast<const VectorSpace <V,M>* >(&domain1);
143  const VectorSubset<V,M>* tmp2 = dynamic_cast<const VectorSubset<V,M>* >(&domain2);
144 
145  if ((tmp1 != NULL) && (tmp2 != NULL)) {
146  if (dim1 == dim2) {
147  const BoxSubset<V,M>* box2 = dynamic_cast<const BoxSubset<V,M>* >(&domain2);
148  if (box2 != NULL) {
149  result = new BoxSubset<V,M>(box2->prefix().c_str(),
150  box2->vectorSpace(),
151  box2->minValues(),
152  box2->maxValues());
153  }
154  else {
155  UQ_FATAL_TEST_MACRO(true,
156  domain1.env().worldRank(),
157  "InstantiateIntersection<V,M>()",
158  "situation 004");
159  }
160  }
161  else {
162  UQ_FATAL_TEST_MACRO(true,
163  domain1.env().worldRank(),
164  "InstantiateIntersection<V,M>()",
165  "situation 005");
166  }
167  }
168  }
169 
170  if (result == NULL) {
171  UQ_FATAL_TEST_MACRO(true,
172  domain1.env().worldRank(),
173  "InstantiateIntersection<V,M>()",
174  "situation 006");
175  }
176 
177  return result;
178 }
179 
180 } // End namespace QUESO
181 
const std::string & prefix() const
Access to private attribute m_prefix.
Definition: VectorSet.C:88
A templated class representing the intersection of two vector sets.
A templated class for handling sets.
Definition: VectorSet.h:49
const BaseEnvironment & env() const
Environment.
Definition: VectorSpace.C:177
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:82
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const VectorSpace< V, M > & vectorSpace() const
Vector space to which this set belongs to. See template specialization.
Definition: VectorSubset.C:80
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:88
A templated class for handling subsets.
Definition: VectorSubset.h:44
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
unsigned int dimGlobal() const
Definition: VectorSpace.C:205
const BaseEnvironment & env() const
Environment. Access to private attribute m_env.
Definition: VectorSet.C:82
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:41
A class representing a vector space.
Definition: VectorSet.h:46
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223

Generated on Thu Apr 23 2015 19:26:14 for queso-0.51.1 by  doxygen 1.8.5