www.mooseframework.org
MultiAppDTKUserObjectEvaluator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "libmesh/libmesh_config.h"
11 
12 #ifdef LIBMESH_TRILINOS_HAVE_DTK
13 
14 // MOOSE includes
16 #include "UserObject.h"
17 #include "Executioner.h"
18 #include "FEProblem.h"
19 #include "MultiApp.h"
20 #include "MooseTypes.h"
21 #include "MooseMesh.h"
22 
23 #include "libmesh/mesh_tools.h"
24 
26  const std::string & user_object_name)
27  : _multi_app(multi_app), _user_object_name(user_object_name)
28 {
29 }
30 
32 
33 DataTransferKit::FieldContainer<double>
34 MultiAppDTKUserObjectEvaluator::evaluate(const Teuchos::ArrayRCP<GlobalOrdinal> & bids,
35  const Teuchos::ArrayRCP<double> & coords)
36 {
37  Teuchos::RCP<const Teuchos::Comm<int>> comm = Teuchos::rcp(new Teuchos::MpiComm<int>(
38  Teuchos::rcp(new Teuchos::OpaqueWrapper<MPI_Comm>(_multi_app.comm()))));
39 
40  int num_values = bids.size();
41 
42  Teuchos::ArrayRCP<double> evaluated_data(num_values);
43 
44  unsigned int dim = 3; // TODO: REPLACE ME!!!!!!!!!
45 
46  for (GlobalOrdinal i = 0; i < static_cast<GlobalOrdinal>(num_values); i++)
47  {
48  // See if this app is on this processor
49  if (std::binary_search(_box_ids.begin(), _box_ids.end(), bids[i]))
50  {
51  GlobalOrdinal app = bids[i];
52 
53  Point p;
54  for (unsigned int j = 0; j < dim; j++)
55  p(j) = coords[(j * num_values) + i];
56 
57  evaluated_data[i] = _multi_app.appUserObjectBase(app, _user_object_name)
58  .spatialValue(p - _multi_app.position(app));
59  }
60  else
61  evaluated_data[i] = 0.0;
62  }
63 
64  return DataTransferKit::FieldContainer<double>(evaluated_data, 1);
65 }
66 
67 Teuchos::RCP<DataTransferKit::GeometryManager<DataTransferKit::Box, long unsigned int>>
69  const Teuchos::RCP<const Teuchos::Comm<int>> & comm)
70 {
71  _boxes.resize(_multi_app.numLocalApps());
73 
74  comm->barrier();
75 
76  for (unsigned int app = 0; app < _multi_app.numLocalApps(); app++)
77  {
78  unsigned int global_app = _multi_app.firstLocalApp() + app;
79 
80  BoundingBox bbox = _multi_app.getBoundingBox(global_app, false);
81 
82  _boxes[app] = DataTransferKit::Box(
83  bbox.min()(0), bbox.min()(1), bbox.min()(2), bbox.max()(0), bbox.max()(1), bbox.max()(2));
84 
85  _box_ids[app] = global_app;
86  }
87 
88  return Teuchos::rcp(new DataTransferKit::GeometryManager<DataTransferKit::Box, GlobalOrdinal>(
89  _boxes, _box_ids, comm, 3));
90 }
91 
92 #endif // LIBMESH_TRILINOS_HAVE_DTK
Point position(unsigned int app)
The physical position of a global App number.
Definition: MultiApp.h:235
virtual BoundingBox getBoundingBox(unsigned int app, bool displaced_mesh)
Get the BoundingBox for the mesh associated with app The bounding box will be shifted to be in the co...
Definition: MultiApp.C:424
Teuchos::ArrayRCP< DataTransferKit::Box > _boxes
MultiAppDTKUserObjectEvaluator(MultiApp &multi_app, const std::string &user_object_name)
Teuchos::RCP< DataTransferKit::GeometryManager< DataTransferKit::Box, GlobalOrdinal > > createSourceGeometry(const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Teuchos::ArrayRCP< GlobalOrdinal > _box_ids
unsigned int numLocalApps()
Definition: MultiApp.h:205
std::string _user_object_name
The name of the UserObject we&#39;re going to be evaluating.
DataTransferKit::FieldContainer< double > evaluate(const Teuchos::ArrayRCP< GlobalOrdinal > &bids, const Teuchos::ArrayRCP< double > &coords)
virtual Real spatialValue(const Point &) const
Optional interface function for "evaluating" a UserObject at a spatial position.
Definition: UserObject.h:83
unsigned int firstLocalApp()
Definition: MultiApp.h:210
MPI_Comm & comm()
Get the MPI communicator this MultiApp is operating on.
Definition: MultiApp.h:269
MPI_Comm comm
MultiApp & _multi_app
The MultiAppUserObject object this object will be evaluating.
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:57
const UserObject & appUserObjectBase(unsigned int app, const std::string &name)
Get a UserObject base for a specific global app.
Definition: MultiApp.C:511