50 .pretty_name(
"Source Mesh")
51 .description(
"Mesh to interpolate from. Warning: this is modified in parallel to make all elements known on each rank.")
55 .pretty_name(
"Target Mesh")
56 .description(
"Mesh to interpolate to")
59 create_static_component<PointInterpolator>(
"PointInterpolator");
82 if(source_dict->discontinuous())
85 point_interpolator->options().set(
"dict", source_dict);
90 target_dict = target_mesh->create_continuous_space(source_dict->name(), source_dict->properties().value<std::string>(
"space_lib_name")).handle<
Dictionary>();
91 BOOST_FOREACH(
const std::string& tag, source_dict->get_tags())
93 target_dict->add_tag(tag);
98 const Field& target_coords = target_dict->coordinates();
99 const Uint nb_target_points = target_coords.
size();
101 std::vector<SpaceElem> space_elems(nb_target_points);
102 std::vector<Uint> points_begin_idxs(nb_target_points, 0);
103 std::vector<Uint> points_end_idxs(nb_target_points, 0);
104 std::vector<Uint> all_points; all_points.reserve(nb_target_points*8);
105 std::vector<Real> all_weights; all_weights.reserve(nb_target_points*8);
106 std::vector<Real> my_missing_points; my_missing_points.reserve(nb_target_points/10);
109 for(
Uint i = 0; i != nb_target_points; ++i)
112 std::vector<Real> weights;
113 std::vector<SpaceElem> dummy_stencil;
115 Eigen::Map<RealVector const> coord(&coordrow[0], dim);
116 bool found = point_interpolator->compute_storage(coord, space_elems[i], dummy_stencil, points, weights);
119 my_missing_points.insert(my_missing_points.end(), coordrow.begin(), coordrow.end());
127 std::vector< std::vector< std::vector<Uint> > > elements_to_send(nb_procs, std::vector< std::vector<Uint> > (source_mesh->elements().size()));
129 std::vector< std::vector<Real> > recv_missing_points;
130 comm.
all_gather(my_missing_points, recv_missing_points);
132 cf3_assert(recv_missing_points.size() == nb_ranks);
134 for(
Uint rank = 0; rank != nb_ranks; ++rank)
136 if(rank == comm.
rank())
138 const std::vector<Real>& other_missing_points = recv_missing_points[rank];
139 cf3_assert(other_missing_points.size() % dim == 0);
140 const Uint missing_end = other_missing_points.size() / dim;
141 for(
Uint missing_idx = 0; missing_idx != missing_end; ++missing_idx)
144 std::vector<Real> weights;
145 std::vector<SpaceElem> dummy_stencil;
147 Eigen::Map<RealVector const> coord(&other_missing_points[missing_idx*dim], dim);
148 bool found = point_interpolator->compute_storage(coord, space_elem, dummy_stencil, points, weights);
156 std::vector< std::vector< std::vector<Uint> > > nodes_to_send;
159 std::vector< std::vector< std::vector<boost::uint64_t> > > imported_elements;
164 std::vector< std::vector< std::vector<boost::uint64_t> > > imported_nodes;
165 adaptor.
send_nodes(nodes_to_send,imported_nodes);
172 common::build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.GrowOverlap",
"grow_overlap")->transform(*source_mesh);
173 CFinfo <<
" + growing overlap layer ... done" <<
CFendl;
177 source_mesh->remove_component(
"octtree");
178 point_interpolator = create_static_component<PointInterpolator>(
"PointInterpolator");
179 point_interpolator->options().set(
"function", std::string(
"cf3.mesh.ShapeFunctionInterpolation"));
180 point_interpolator->options().set(
"dict", source_dict);
184 std::vector<RealVector> perturbations(dim*2,
RealVector(dim));
185 for(
Uint i = 0; i != dim; ++i)
187 perturbations[2*i ].setZero();
188 perturbations[2*i+1].setZero();
189 perturbations[2*i ][i] = 1
e-8;
190 perturbations[2*i+1][i] = -1
e-8;
193 for(
Uint i = 0; i != nb_target_points; ++i)
196 std::vector<Real> weights;
197 std::vector<SpaceElem> dummy_stencil;
199 Eigen::Map<RealVector const> coord(&coordrow[0], dim);
200 bool found = point_interpolator->compute_storage(coord, space_elems[i], dummy_stencil, points, weights);
203 BOOST_FOREACH(
const RealVector& perturbation, perturbations)
205 found = point_interpolator->compute_storage(coord+perturbation, space_elems[i], dummy_stencil, points, weights);
210 if(!found && !target_dict->is_ghost(i))
212 CFerror <<
" Point " << coord.transpose() <<
" was not found in source mesh" <<
CFendl;
216 points_begin_idxs[i] = all_points.size();
217 all_points.insert(all_points.end(), points.begin(), points.end());
218 all_weights.insert(all_weights.end(), weights.begin(), weights.end());
219 points_end_idxs[i] = all_points.size();
223 BOOST_FOREACH(
const Handle<Field>& source_field, source_dict->fields())
228 Handle<Field> target_field(target_dict->get_child(source_field->name()));
231 target_field = target_dict->create_field(source_field->name(), source_field->descriptor().description()).handle<Field>();
232 BOOST_FOREACH(
const std::string& tag, source_field->get_tags())
234 target_field->add_tag(tag);
240 const Uint row_size = source_field->row_size();
242 cf3_assert(nb_target_points == target_array.size());
244 for(
Uint i = 0; i != nb_target_points; ++i)
246 if(target_dict->is_ghost(i))
248 Eigen::Map<RealVector> target_row(&target_array[i][0], row_size);
249 target_row.setZero();
251 const Uint interp_begin = points_begin_idxs[i];
252 const Uint interp_end = points_end_idxs[i];
256 for(
Uint j = interp_begin; j != interp_end; ++j)
258 if(all_points[j] >= source_array.size())
262 Eigen::Map<RealVector const> source_row(&source_array[all_points[j]][0], row_size);
263 target_row += all_weights[j] * source_row;
264 avg_row += source_row;
265 weightsum += all_weights[j];
267 if(weightsum > 1. + 1
e-10)
269 CFerror <<
"Bad weights found, using unweighted average on point " << i <<
CFendl;
270 target_row = avg_row;
274 target_field->parallelize();
275 target_field->synchronize();
#define CFinfo
these are always defined
std::string name(ComponentWrapper &self)
virtual void execute()
execute the action
bool is_null(T ptr)
predicate for comparison to nullptr
TableArray< Real >::type ArrayT
the type of the internal structure of the table
MeshInterpolator(const std::string &name)
Helper class to create the Builder and place it in the factory.
void flush_elements()
Apply all changes to elements.
Entities & support() const
Access the geometric support.
Uint rank() const
Return rank, additionally, if is_init==0.
Real e()
Definition of the Unit charge [C].
Common_API std::string to_str(const T &v)
Converts to std::string.
Uint size() const
Return the number of processes, or 1 if is_init==0.
#define cf3_always_assert(a)
void flush_nodes()
Apply all changes to nodes.
common::ComponentBuilder< MeshInterpolator, common::Action, mesh::actions::LibActions > MeshInterpolator_Builder
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
void find_nodes_to_export(const std::vector< std::vector< std::vector< Uint > > > &exported_elements_loc_id, std::vector< std::vector< std::vector< Uint > > > &exported_nodes_loc_id)
Assemble a change-set of nodes to be sent together with elements.
Handle< Component > get_child(const std::string &name)
TableConstRow< Real >::type ConstRow
the const type of a row in the internal structure of the table
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
void finish()
Apply the changes the mesh adaptor for changes and fix inconsistent state.
Uint row_size(Uint i=0) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
void send_nodes(const std::vector< std::vector< std::vector< Uint > > > &exported_nodes_loc_id, std::vector< std::vector< std::vector< boost::uint64_t > > > &imported_nodes_glb_id)
Send/Receive nodes according to an nodes-changeset.
Component that executes an action. Implementation of the IAction interface as a component, exposing the execute function as a signal.
boost::shared_ptr< Component > remove_component(const std::string &name)
Remove a (sub)component of this component.
unsigned int Uint
typedef for unsigned int
Uint entities_idx() const
void prepare()
Prepare the mesh adaptor for changes.
void send_elements(const std::vector< std::vector< std::vector< Uint > > > &exported_elements_loc_id, std::vector< std::vector< std::vector< boost::uint64_t > > > &imported_elements_glb_id)
Send/Receive elements according to an elements-changeset.
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
static Comm & instance()
Return a reference to the current PE.
T * all_gather(const T *in_values, const int in_n, T *out_values, const int stride=1)
bool is_not_null(T ptr)
predicate for comparison to nullptr