SheafSystem  0.0.0.0
print_property_dofs_action.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/print_property_dofs_action.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/block.h"
25 #include "SheafSystem/error_message.h"
26 #include "SheafSystem/sec_vd.h"
27 #include "SheafSystem/std_iomanip.h"
28 
29 using namespace fields; // Workaround for MS C++ bug.
30 
31 // #define DIAGNOSTIC_OUTPUT 1
32 
33 
34 // ===========================================================
35 // PRINT_PROPERTY_DOFS_ACTION FACET
36 // ===========================================================
37 
38 // PUBLIC MEMBER FUNCTIONS
39 
43  bool xzero_specified)
44  : _property(xproperty),
45  _seq_id_space(&xproperty.schema().discretization_id_space())
46 {
47  // Preconditions:
48 
49  require(xproperty.state_is_read_accessible());
50 
51  // Body:
52 
53  _dof_function = xfcn;
54 
55  _zero_specified = xzero_specified;
56 
58 
59  int ldf = xproperty.schema().df();
60 
61  _dofs.reserve(ldf);
62  _dofs.set_ct(ldf);
63 
64  _specified_dofs.reserve(ldf);
65  _specified_dofs.set_ct(ldf);
66 
67  // Postconditions:
68 
69  // Exit:
70 
71  return;
72 }
73 
76 {
77  // Preconditions:
78 
79  // Body:
80 
81  // Nothing to do.
82 
83  // Postconditions:
84 
85  // Exit:
86 
87  return;
88 }
89 
90 
91 void
94 {
95  // Preconditions:
96 
97  require(property().state_is_read_accessible());
98  require(xdisc_id.in_scope());
99 
100  // Body:
101 
102  using namespace std;
103 
104  // Print the discretization poset and seq id.
105 
106  scoped_index lseq_id(*_seq_id_space, xdisc_id);
107 
108  cout << "id: " << setw(5) << xdisc_id.hub_id() << setw(5) << lseq_id;
109 
110  // Print the coordinates.
111 
112  cout << " coordinates: ";
113  for(int i=0; i<xcoords.ct(); ++i)
114  {
115  cout << " " << setw(16) << xcoords[i];
116  }
117 
118  // Get the property dofs.
119 
120  property().get_fiber(lseq_id.pod(), _dofs.base(),
121  _dofs.ct()*sizeof(sec_vd_value_type));
122 
123  // Print the property.
124 
125  bool is_zero = true;
126  cout << " property: ";
127  for(int i=0; i<_dofs.ct(); ++i)
128  {
129  is_zero = is_zero && (_dofs[i] == 0.0);
130  cout << " " << setw(16) << _dofs[i];
131  }
132 
133  if(_dof_function != 0)
134  {
135 
136  if(is_zero && _zero_specified)
137  {
138  // Property is zero and client has requested
139  // it be treated as specified value.
140 
141  for(int i=0; i<_dofs.ct(); ++i)
142  {
143  _specified_dofs[i] = 0.0;
144  }
145  }
146  else
147  {
148  // Evaluate the property dof function at
149  // the global coordinates of the discretization member.
150 
151  _dof_function(xcoords, _specified_dofs);
152  }
153 
154  // Print the values specified by the property dof funtion.
155 
156  cout << " specified: ";
157  for(int i=0; i<_dofs.ct(); ++i)
158  {
159  cout << " " << setw(16) << _specified_dofs[i];
160  }
161 
162  // Print the difference.
163 
164  cout << " difference: ";
165  for(int i=0; i<_dofs.ct(); ++i)
166  {
167  cout << " " << setw(16) << (_specified_dofs[i] - _dofs[i]);
168  }
169  }
170 
171  cout << endl;
172 
173  // Postconditions:
174 
175 
176  // Exit:
177 
178  return;
179 }
180 
184 {
185  // Preconditions:
186 
187 
188  // Body:
189 
190  sec_vd& result = _property;
191 
192  // Postconditions:
193 
194 
195  // Exit:
196 
197  return result;
198 }
199 
203 {
205 
206  // Preconditions:
207 
208  // Body:
209 
210  result = _dof_function;
211 
212  // Postconditions:
213 
214  ensure(result != 0);
215 
216  // Exit:
217 
218  return result;
219 }
220 
221 
222 // ===========================================================
223 // NON-MEMBER FUNCTIONS
224 // ===========================================================
print_property_dofs_action(sec_vd &xproperty, property_dof_function_type xfcn, bool xzero_specified=false)
Creates an instance using global coordinates xdomain_coords and pullback map xmap.
size_type ct() const
The number of items currently in use.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
Namespace for fields component of sheaf system.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void get_fiber(pod_index_type xdisc_id, vd_lite &xfiber) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
Definition: sec_vd.cc:1087
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
property_dof_function_type dof_function()
The function for computing the property dofs at given global coordinates.
void set_ct(size_type xct)
Sets ct() == xct.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
void(* property_dof_function_type)(block< sec_vd_value_type > &xglobal_coords, block< sec_vd_dof_type > &xproperty_dofs)
The type of the function for computing the property dofs at given global coordinates.
Definition: fields.h:64
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
scoped_index hub_id() const
This mapped to the hub id space.
Definition: scoped_index.h:358
virtual void operator()(const scoped_index &xdisc_id, block< sec_vd_value_type > &xglobal_coords)
The push action.
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
sec_vd & property()
The property section being acted on.
int df() const
The dimension of the fiber space component.
vd_value_type sec_vd_value_type
The type of component in the value of a section at a point.
Definition: fiber_bundle.h:73