void ADF7023_Wait_for_CMD_READY(void) { unsigned char status; int counter = 0; for(;;) { break_loop(); ADF7023_GetStatus(&status); if((status & STATUS_SPI_READY) == 0) { /* The SPI bus is not ready. Continue polling the status word. */ continue; } if(status & STATUS_CMD_READY) { /* The SPI bus is ready and CMD_READY == 1. This is the state we want. */ break; } if((status & STATUS_FW_STATE) == FW_STATE_PHY_OFF) { /* SPI is ready, but CMD_READY == 0 and the radio is in state PHY_OFF. */ /* It seems that the ADF7023 gets stuck in this state sometimes (errata?), so transition to PHY_ON: */ ADF7023_SetCommand_Assume_CMD_READY(CMD_PHY_ON); } } }
void DomainUnstructured::compute_cell_center_coordinates(TabType & coord, entier index_begin) const { const entier dim = nodes_.dimension(1); const entier nb_elem = elements_.dimension(0); const entier nb_som_elem = elements_.dimension(1); const double facteur = 1. / (double) nb_som_elem; double tmp[3]; for (int i = 0; i < nb_elem; i++) { int j, k; tmp[0] = tmp[1] = tmp[2] = 0.; for (j = 0; j < nb_som_elem; j++) { int som = elements_(i, j); for (k = 0; k < loop_max(dim, 3); k++) { tmp[k] += nodes_(som, k); break_loop(k, dim); } } for (k = 0; k < loop_max(dim, 3); k++) { coord(index_begin + i, k) = tmp[k] * facteur; break_loop(k, dim); } } }
void build_geometry_(OperatorRegularize & op, const DomainUnstructured & src, LataDeriv<Domain> & dest_domain) { Journal(verb_level) << "OperatorRegularize domain " << src.id_.name_ << endl; if (src.elt_type_ != Domain::quadri && src.elt_type_ != Domain::hexa) { Journal() << "Error in OperatorRegularize::build_geometry: cannot operate on unstructured mesh with this element type" << endl; throw; } DomainIJK & dest = dest_domain.instancie(DomainIJK); dest.elt_type_ = src.elt_type_; const entier nsom = src.nodes_.dimension(0); const entier dim = src.nodes_.dimension(1); ArrOfInt nb_som_dir(dim); { double product_n = 1.; for (entier i_dim = 0; i_dim < dim; i_dim++) { ArrOfFloat & coord = dest.coord_.add(ArrOfFloat()); coord.resize_array(nsom); entier i; for (i = 0; i < nsom; i++) coord[i] = src.nodes_(i, i_dim); coord.ordonne_array(); retirer_doublons(coord, op.tolerance_); product_n *= coord.size_array(); // Add extended domain layer: if (coord.size_array() > 1) { const entier n = coord.size_array(); const entier l = op.extend_layer_; coord.resize_array(n + l * 2); double x0 = coord[n-1]; double delta = coord[n-2] - x0; for (i = 1; i <= l; i++) coord[n + l + i] = x0 + delta * i; for (i = l-1; i >= 0; i--) coord[i + l] = coord[i]; x0 = coord[l]; delta = coord[l+1] - x0; for (i = 1; i <= l; i++) coord[l - i] = x0 - delta * i; } nb_som_dir[i_dim] = coord.size_array(); } // Verifying that unique has deleted many points... // If well organised, nsom=nx*ny*nz // If chaos, nsom=(nx+ny+nz)/3 // We want to verify that we are nearer to organisation than to chaos ! if (product_n > (double) nsom * (double) nsom - 1.) { Journal() << "Positions do not seam regular !" << endl; throw; } } int i; op.renum_nodes_.resize_array(nsom); int nb_som_ijk = 1; for (i = 0; i < dim; i++) nb_som_ijk *= nb_som_dir[i]; IntTab ijk_indexes; ijk_indexes.resize(nsom, dim); for (i = 0; i < nsom; i++) { entier ijk_index = 0; for (int j = dim-1; j >= 0; j--) { const double x = src.nodes_(i,j); int index = search_in_ordered_vect(x, dest.coord_[j]); if (index < 0) { Journal() << "Error: coordinate (" << i << "," << j << ") = " << x << " not found in regularize" << endl << "Try reducing regularize tolerance value (option regularize=epsilon)" << endl; throw; } ijk_indexes(i, j) = index; ijk_index += index; if (j) ijk_index *= nb_som_dir[j-1]; } op.renum_nodes_[i] = ijk_index; } const int max_index = max_array(nb_som_dir); int nb_elems_ijk = 1; for (i = 0; i < dim; i++) nb_elems_ijk *= nb_som_dir[i] - 1; dest.invalid_connections_.resize_array(nb_elems_ijk); dest.invalid_connections_ = 1; // Everything invalid by default const int nelem = src.elements_.dimension(0); const int nb_som_elem = src.elements_.dimension(1); op.renum_elements_.resize_array(nelem); // Pour chaque element, indice dans le maillage ijk du plus sommet le plus proche de l'origine // (pour les faces...) ArrOfInt idx_elem_som; idx_elem_som.resize_array(nelem); int min_index[3]; for (i = 0; i < nelem; i++) { min_index[0] = min_index[1] = min_index[2] = max_index; for (int j = 0; j < nb_som_elem; j++) { int node = src.elements_(i,j); for (int k = 0; k < loop_max(dim, 3); k++) { int idx = ijk_indexes(node, k); min_index[k] = (idx < min_index[k]) ? idx : min_index[k]; break_loop(k,dim); } } entier idx = 0; entier idx_som = 0; if (dim == 1) { idx = min_index[0]; idx_som = idx; } else if (dim == 2) { idx = min_index[1] * (nb_som_dir[0]-1) + min_index[0]; idx_som = min_index[1] * nb_som_dir[0] + min_index[0]; } else if (dim == 3) { idx = (min_index[2] * (nb_som_dir[1]-1) + min_index[1]) * (nb_som_dir[0]-1) + min_index[0]; idx_som = (min_index[2] * nb_som_dir[1] + min_index[1]) * nb_som_dir[0] + min_index[0]; } else throw; op.renum_elements_[i] = idx; dest.invalid_connections_.clearbit(idx); idx_elem_som[i] = idx_som; } if (src.faces_ok()) { const int nfaces = src.faces_.dimension(0); op.renum_faces_.resize_array(nfaces); op.renum_faces_ = -1; const int nb_elem_face = src.elem_faces_.dimension(1); ArrOfInt delta_dir(dim); delta_dir[0] = 1; for (i = 1; i < dim; i++) delta_dir[i] = delta_dir[i-1] * nb_som_dir[i-1]; for (i = 0; i < nelem; i++) { // Les faces haut, gauche et arriere du cube a l'origine portent le numero 0 // Voir DomaineIJK pour la convention sur la numerotation des faces for (entier j = 0; j < nb_elem_face; j++) { const entier i_face = src.elem_faces_(i, j); entier dir = j % dim; entier index = idx_elem_som[i]; if (j>=dim) index += delta_dir[dir]; // Encodage du numero de la face et de la direction index = (index << 2) + dir; if (op.renum_faces_[i_face] < 0) { op.renum_faces_[i_face] = index; } else if (op.renum_faces_[i_face] != index) { Journal() << "Error in OperatorRegularize: faces renumbering failed" << endl; throw; } } } } op.geom_init_ = 1; }
inline device::~device() { if (loop_running_) { break_loop(); } }