Skip to content
This repository
Browse code

demo a MeshlessInterpolationFunction in miscellaneous_ex8.C

  • Loading branch information...
commit 1e2376890dbabb662bde82f3f1e46ba19e467357 1 parent 1f1068e
Benjamin S. Kirk authored December 19, 2012
2  examples/miscellaneous/miscellaneous_ex8/Makefile.am
... ...
@@ -1,6 +1,6 @@
1 1
 example_name  = miscellaneous_ex8
2 2
 install_dir   = $(examples_install_path)/miscellaneous/ex8
3  
-data          = miscellaneous_ex8.C run.sh unstruct.ucd.gz struct.ucd.gz
  3
+data          = miscellaneous_ex8.C meshless_interpolation_function.h run.sh unstruct.ucd.gz struct.ucd.gz
4 4
 sources       = $(data) run.sh
5 5
 
6 6
 # conditionally enable this test
45  examples/miscellaneous/miscellaneous_ex8/Makefile.in
@@ -108,8 +108,9 @@ CONFIG_CLEAN_VPATH_FILES =
108 108
 @LIBMESH_DEVEL_MODE_TRUE@am__EXEEXT_3 = example-devel$(EXEEXT)
109 109
 @LIBMESH_PROF_MODE_TRUE@am__EXEEXT_4 = example-prof$(EXEEXT)
110 110
 @LIBMESH_OPROF_MODE_TRUE@am__EXEEXT_5 = example-oprof$(EXEEXT)
111  
-am__example_dbg_SOURCES_DIST = miscellaneous_ex8.C run.sh \
112  
-	unstruct.ucd.gz struct.ucd.gz
  111
+am__example_dbg_SOURCES_DIST = miscellaneous_ex8.C \
  112
+	meshless_interpolation_function.h run.sh unstruct.ucd.gz \
  113
+	struct.ucd.gz
113 114
 am__objects_1 = example_dbg-miscellaneous_ex8.$(OBJEXT)
114 115
 am__objects_2 = $(am__objects_1)
115 116
 @LIBMESH_DBG_MODE_TRUE@am_example_dbg_OBJECTS = $(am__objects_2)
@@ -123,8 +124,9 @@ am__v_lt_1 =
123 124
 example_dbg_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
124 125
 	$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(example_dbg_CXXFLAGS) \
125 126
 	$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
126  
-am__example_devel_SOURCES_DIST = miscellaneous_ex8.C run.sh \
127  
-	unstruct.ucd.gz struct.ucd.gz
  127
+am__example_devel_SOURCES_DIST = miscellaneous_ex8.C \
  128
+	meshless_interpolation_function.h run.sh unstruct.ucd.gz \
  129
+	struct.ucd.gz
128 130
 am__objects_3 = example_devel-miscellaneous_ex8.$(OBJEXT)
129 131
 am__objects_4 = $(am__objects_3)
130 132
 @LIBMESH_DEVEL_MODE_TRUE@am_example_devel_OBJECTS = $(am__objects_4)
@@ -135,8 +137,9 @@ example_devel_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
135 137
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
136 138
 	$(example_devel_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
137 139
 	-o $@
138  
-am__example_oprof_SOURCES_DIST = miscellaneous_ex8.C run.sh \
139  
-	unstruct.ucd.gz struct.ucd.gz
  140
+am__example_oprof_SOURCES_DIST = miscellaneous_ex8.C \
  141
+	meshless_interpolation_function.h run.sh unstruct.ucd.gz \
  142
+	struct.ucd.gz
140 143
 am__objects_5 = example_oprof-miscellaneous_ex8.$(OBJEXT)
141 144
 am__objects_6 = $(am__objects_5)
142 145
 @LIBMESH_OPROF_MODE_TRUE@am_example_oprof_OBJECTS = $(am__objects_6)
@@ -147,8 +150,9 @@ example_oprof_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
147 150
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
148 151
 	$(example_oprof_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
149 152
 	-o $@
150  
-am__example_opt_SOURCES_DIST = miscellaneous_ex8.C run.sh \
151  
-	unstruct.ucd.gz struct.ucd.gz
  153
+am__example_opt_SOURCES_DIST = miscellaneous_ex8.C \
  154
+	meshless_interpolation_function.h run.sh unstruct.ucd.gz \
  155
+	struct.ucd.gz
152 156
 am__objects_7 = example_opt-miscellaneous_ex8.$(OBJEXT)
153 157
 am__objects_8 = $(am__objects_7)
154 158
 @LIBMESH_OPT_MODE_TRUE@am_example_opt_OBJECTS = $(am__objects_8)
@@ -158,8 +162,9 @@ example_opt_OBJECTS = $(am_example_opt_OBJECTS)
158 162
 example_opt_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
159 163
 	$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(example_opt_CXXFLAGS) \
160 164
 	$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
161  
-am__example_prof_SOURCES_DIST = miscellaneous_ex8.C run.sh \
162  
-	unstruct.ucd.gz struct.ucd.gz
  165
+am__example_prof_SOURCES_DIST = miscellaneous_ex8.C \
  166
+	meshless_interpolation_function.h run.sh unstruct.ucd.gz \
  167
+	struct.ucd.gz
163 168
 am__objects_9 = example_prof-miscellaneous_ex8.$(OBJEXT)
164 169
 am__objects_10 = $(am__objects_9)
165 170
 @LIBMESH_PROF_MODE_TRUE@am_example_prof_OBJECTS = $(am__objects_10)
@@ -203,6 +208,24 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
203 208
 am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
204 209
 am__v_CXXLD_0 = @echo "  CXXLD   " $@;
205 210
 am__v_CXXLD_1 = 
  211
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
  212
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  213
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
  214
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
  215
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
  216
+	$(AM_CFLAGS) $(CFLAGS)
  217
+AM_V_CC = $(am__v_CC_@AM_V@)
  218
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
  219
+am__v_CC_0 = @echo "  CC      " $@;
  220
+am__v_CC_1 = 
  221
+CCLD = $(CC)
  222
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
  223
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
  224
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
  225
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
  226
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
  227
+am__v_CCLD_0 = @echo "  CCLD    " $@;
  228
+am__v_CCLD_1 = 
206 229
 SOURCES = $(example_dbg_SOURCES) $(example_devel_SOURCES) \
207 230
 	$(example_oprof_SOURCES) $(example_opt_SOURCES) \
208 231
 	$(example_prof_SOURCES)
@@ -535,7 +558,7 @@ top_builddir = @top_builddir@
535 558
 top_srcdir = @top_srcdir@
536 559
 example_name = miscellaneous_ex8
537 560
 install_dir = $(examples_install_path)/miscellaneous/ex8
538  
-data = miscellaneous_ex8.C run.sh unstruct.ucd.gz struct.ucd.gz
  561
+data = miscellaneous_ex8.C meshless_interpolation_function.h run.sh unstruct.ucd.gz struct.ucd.gz
539 562
 sources = $(data) run.sh
540 563
 
541 564
 # conditionally enable this test
149  examples/miscellaneous/miscellaneous_ex8/meshless_interpolation_function.h
... ...
@@ -0,0 +1,149 @@
  1
+// The libMesh Finite Element Library.
  2
+// Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
  3
+
  4
+// This library is free software; you can redistribute it and/or
  5
+// modify it under the terms of the GNU Lesser General Public
  6
+// License as published by the Free Software Foundation; either
  7
+// version 2.1 of the License, or (at your option) any later version.
  8
+
  9
+// This library is distributed in the hope that it will be useful,
  10
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12
+// Lesser General Public License for more details.
  13
+
  14
+// You should have received a copy of the GNU Lesser General Public
  15
+// License along with this library; if not, write to the Free Software
  16
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17
+
  18
+
  19
+
  20
+#ifndef LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
  21
+#define LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
  22
+
  23
+// Local Includes
  24
+#include "libmesh/function_base.h"
  25
+#include "libmesh/meshfree_interpolation.h"
  26
+
  27
+// C++ includes
  28
+#include <cstddef>
  29
+
  30
+namespace libMesh
  31
+{
  32
+
  33
+
  34
+
  35
+// Forward Declarations
  36
+template <typename T>
  37
+class DenseVector;
  38
+
  39
+
  40
+// ------------------------------------------------------------
  41
+// MeshlessInterpolationFunction class definition
  42
+class MeshlessInterpolationFunction : public FunctionBase<Number>
  43
+{
  44
+private:
  45
+  const MeshfreeInterpolation &_mfi;
  46
+  mutable std::vector<Point> _pts;
  47
+  mutable std::vector<Number> _vals;
  48
+  
  49
+public:
  50
+
  51
+  /**
  52
+   * Constructor.  Requires a \p \pMeshlessInterpolation object.
  53
+   */
  54
+  MeshlessInterpolationFunction (const MeshfreeInterpolation &mfi) :
  55
+    _mfi (mfi)
  56
+  {}
  57
+  
  58
+
  59
+  /**
  60
+   * The actual initialization process.
  61
+   */
  62
+  void init ();
  63
+
  64
+  /**
  65
+   * Clears the function.
  66
+   */
  67
+  void clear ();
  68
+
  69
+  /**
  70
+   * Returns a new deep copy of the function.
  71
+   */
  72
+  virtual AutoPtr<FunctionBase<Number> > clone () const;
  73
+
  74
+  /**
  75
+   * @returns the value at point \p p and time
  76
+   * \p time, which defaults to zero.
  77
+   */
  78
+  Number operator() (const Point& p,
  79
+		     const Real time=0.);
  80
+
  81
+  /**
  82
+   * Like before, but returns the values in a
  83
+   * writable reference.
  84
+   */
  85
+  void operator() (const Point& p,
  86
+		   const Real time,
  87
+		   DenseVector<Number>& output);
  88
+
  89
+};
  90
+
  91
+
  92
+
  93
+// ------------------------------------------------------------
  94
+// MeshlessInterpolationFunction inline methods
  95
+inline
  96
+Number MeshlessInterpolationFunction::operator() (const Point& p,
  97
+						  const Real /* time */)
  98
+{
  99
+  _pts.clear();
  100
+  _pts.push_back(p);
  101
+  _vals.resize(1);
  102
+
  103
+  _mfi.interpolate_field_data (_mfi.field_variables(),
  104
+			       _pts, _vals);
  105
+
  106
+  return _vals.front();
  107
+}
  108
+
  109
+
  110
+
  111
+inline
  112
+void MeshlessInterpolationFunction::operator() (const Point& p,
  113
+						const Real time,
  114
+						DenseVector<Number>& output)
  115
+{
  116
+  output.resize(1);
  117
+  output(0) = (*this)(p,time);
  118
+  return;
  119
+}
  120
+
  121
+
  122
+
  123
+inline
  124
+void MeshlessInterpolationFunction::init ()
  125
+{
  126
+}
  127
+
  128
+
  129
+
  130
+inline
  131
+void MeshlessInterpolationFunction::clear ()
  132
+{
  133
+}
  134
+
  135
+
  136
+
  137
+inline
  138
+AutoPtr<FunctionBase<Number> >
  139
+MeshlessInterpolationFunction::clone () const
  140
+{
  141
+  return AutoPtr<FunctionBase<Number> > (new MeshlessInterpolationFunction (_mfi) );
  142
+}
  143
+
  144
+
  145
+} // namespace libMesh
  146
+
  147
+
  148
+#endif // LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
  149
+
35  examples/miscellaneous/miscellaneous_ex8/miscellaneous_ex8.C
@@ -29,6 +29,7 @@
29 29
 #include "libmesh/equation_systems.h"
30 30
 #include "libmesh/numeric_vector.h"
31 31
 #include "libmesh/tecplot_io.h"
  32
+#include "meshless_interpolation_function.h"
32 33
 
33 34
 // C++ includes
34 35
 #include <cstdlib>
@@ -178,7 +179,7 @@ int main(int argc, char** argv)
178 179
     {
179 180
       Mesh mesh_a, mesh_b;
180 181
 
181  
-      mesh_a.read("unstruct.ucd.gz"); mesh_b.read("struct.ucd.gz");
  182
+      mesh_a.read("struct.ucd.gz"); mesh_b.read("unstruct.ucd.gz");
182 183
 
183 184
       // Create equation systems objects.
184 185
       EquationSystems
@@ -192,9 +193,7 @@ int main(int argc, char** argv)
192 193
       sys_b.add_variable ("Cp", FIRST);
193 194
 
194 195
       sys_a.attach_init_function (init_sys);
195  
-
196 196
       es_a.init();
197  
-      es_b.init();
198 197
       
199 198
       // Write out the initial conditions.
200 199
       TecplotIO(mesh_a).write_equation_systems ("src.dat",
@@ -223,31 +222,15 @@ int main(int argc, char** argv)
223 222
 	  }	  	
224 223
       }
225 224
 
226  
-      // We now will loop over every node in the target mesh
227  
-      // and interpolate the solution for inspection.
228  
-      {
229  
-	MeshBase::const_node_iterator nd  = mesh_b.nodes_begin();
230  
-	MeshBase::const_node_iterator end = mesh_b.nodes_end();
231  
-
232  
-	std::vector<Point>  tgt_p(1);
233  
-	std::vector<Number> tgt_v;
234  
-	
235  
-	for (; nd!=end; ++nd)
236  
-	  {
237  
-	    const Node *node(*nd);
238  
-
239  
-	    tgt_p[0] = *node;
240 225
 
241  
-	    idi.interpolate_field_data (field_vars,
242  
-					tgt_p, tgt_v);
243  
-	    
244  
-	    sys_b.solution->set(node->dof_number(0,0,0), tgt_v[0]);
245  
-	  }	  	
246  
-
247  
-	sys_b.solution->close();
248  
-	sys_b.update();
249  
-      }
  226
+      // Create a MeshlessInterpolationFunction that uses our InverseDistanceInterpolation
  227
+      // object
  228
+      MeshlessInterpolationFunction mif(idi);
250 229
 
  230
+      // project the solution onto system b
  231
+      es_b.init();
  232
+      sys_b.project_solution (&mif);
  233
+      
251 234
       // Write the result
252 235
       TecplotIO(mesh_b).write_equation_systems ("dest.dat",
253 236
 						es_b);
6  include/utils/meshfree_interpolation.h
@@ -86,6 +86,12 @@ class MeshfreeInterpolation
86 86
    */
87 87
   void set_field_variables (const std::vector<std::string> &names)
88 88
   { _names = names; }
  89
+
  90
+  /**
  91
+   *@returns the field variables as a read-only reference.
  92
+   */
  93
+  const std::vector<std::string> & field_variables() const
  94
+  { return _names; }
89 95
   
90 96
   /**
91 97
    * @returns a writeable reference to the point list.

0 notes on commit 1e23768

Please sign in to comment.
Something went wrong with that request. Please try again.