Skip to content

Commit

Permalink
use MSI_SCALAR instead of double in some places, also remove (void) e…
Browse files Browse the repository at this point in the history
…xpressions used to suppress warnings, small chnaged to numbering, etc
  • Loading branch information
William Tobin committed Jan 20, 2018
1 parent 48e787f commit dc49148
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 47 deletions.
47 changes: 29 additions & 18 deletions api/msi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "msi_petsc.h"
#include <iostream>
#include <apfMDS.h>
#include <apfArrayData.h>
#include <apfNumbering.h>
#include <apfShape.h>
#include <apfTagData.h>
#include <PCU.h>
#include <vector>
#include <assert.h>
Expand Down Expand Up @@ -60,11 +62,11 @@ void msi_node_dof_range(msi_num * num, msi_ent * ent, int nd, int * frst, int *
*frst = nd_id * nd_dofs;
*lst_p1 = *frst + nd_dofs;
}
void msi_set_node_vals(msi_fld * fld, msi_ent * ent, int nd, double * dofs)
void msi_set_node_vals(msi_fld * fld, msi_ent * ent, int nd, MSI_SCALAR * dofs)
{
apf::setComponents(fld, ent, nd, dofs);
}
void msi_get_node_vals(msi_fld * fld, msi_ent * ent, int nd, double * dofs)
void msi_get_node_vals(msi_fld * fld, msi_ent * ent, int nd, MSI_SCALAR * dofs)
{
apf::getComponents(fld, ent, nd, dofs);
}
Expand Down Expand Up @@ -134,12 +136,9 @@ void msi_field_axpy(MSI_SCALAR a, msi_fld * x, msi_fld * y)
}
msi_fld * msi_create_field(msi_msh * msh, const char * fn, int cmps, int ord)
{
(void)msh;
(void)fn;
(void)cmps;
(void)ord;
// todo : no direct access to tagdata
//return apf::makeField(msh,fn,apf::PACKED,cmps,apf::getLagrange(ord),new apf::TagDataOf<MSI_SCALAR>());
msi_fld * fld = NULL;
fld = apf::makeField(msh,fn,apf::PACKED,cmps,apf::getLagrange(ord),new apf::TagDataOf<MSI_SCALAR>());
apf::freezeFieldData<MSI_SCALAR>(fld);
return NULL;
}
void msi_destroy_field(msi_fld * fld)
Expand All @@ -148,9 +147,12 @@ void msi_destroy_field(msi_fld * fld)
}
msi_num * msi_number_field(msi_fld * fld, msi_num_tp tp)
{
msi_num * num = apf::createNumbering(fld);
msi_num * num = NULL;
if(tp == MSI_NODE_NUMBERING)
apf::numberOwnedNodes(apf::getMesh(fld),apf::getName(fld),apf::getShape(fld));
{
num = apf::numberOwnedNodes(apf::getMesh(fld),apf::getName(fld),apf::getShape(fld));
apf::makeGlobal(num,true);
}
else if (tp == MSI_DOF_NUMBERING)
apf::NaiveOrder(num);
return num;
Expand Down Expand Up @@ -203,9 +205,9 @@ void msi_vec_as_field_storage(msi_vec * vec, msi_fld * fld)
{
msi::vectorFieldData<MSI_SCALAR>(fld,vec);
}
void msi_vec_array_field_storage(msi_vec * vec, msi_fld * fld)
void msi_vec_array_field_storage(msi_vec * vec, msi_num * num, msi_fld * fld)
{
msi::vectorArrayFieldData<MSI_SCALAR>(fld,vec);
msi::vectorArrayFieldData<MSI_SCALAR>(fld,num,vec);
}
void msi_vec_array_field_activate_vec(msi_fld * fld)
{
Expand Down Expand Up @@ -265,13 +267,22 @@ int msi_las_solve(msi_mat * mat, msi_vec * x, msi_vec * y)
slvr->solve(mat,x,y);
return slvr->getIter();
}
void msi_add_matrix_block(msi_mat * mat, msi_num * num, msi_ent * ent, int rwidx, int clidx, MSI_SCALAR * vals)
void msi_add_matrix_block(msi_mat * mat, int brw, int bcl, MSI_SCALAR * vals)
{
(void)mat;
(void)brw;
(void)bcl;
(void)vals;
//ops->assemble(mat,dof_cnt,&dof_ids[0],dof_cnt,&dof_ids[0],vals);
}
void msi_add_matrix_blocks(msi_mat * mat, int cnt_br, int * brws, int cnt_bc, int * bcls, MSI_SCALAR * vals)
{
(void)rwidx;
(void)clidx;
apf::NewArray<int> dof_ids;
int dof_cnt = apf::getElementNumbers(num, ent, dof_ids);
ops->assemble(mat,dof_cnt,&dof_ids[0],dof_cnt,&dof_ids[0],vals);
(void)mat;
(void)cnt_br;
(void)brws;
(void)cnt_bc;
(void)bcls;
(void)vals;
}
void msi_finalize_vector(msi_vec * vec)
{
Expand Down
5 changes: 3 additions & 2 deletions api/msi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ MSI_SCALAR msi_vector_norm(msi_vec * vec);
void msi_matrix_multiply(msi_mat * a, msi_vec * x, msi_vec * y);
void msi_axpy(MSI_SCALAR * a, msi_vec * x, msi_vec * y); // y = ax+y
int msi_las_solve(msi_mat * mat, msi_vec * x, msi_vec * y);
void msi_add_matrix_block(msi_mat * mat, msi_num * num, msi_ent * ent, int rwidx, int clidx, MSI_SCALAR * vals);
void msi_add_matrix_block(msi_mat * mat, int brw, int bcl, MSI_SCALAR * vals);
void msi_add_matrix_blocks(msi_mat * mat, int cnt_br, int * brws, int cnt_bc, int * bcls, MSI_SCALAR * vals);
void msi_finalize_matrix(msi_mat * mat);
void msi_finalize_vector(msi_vec * vec);
// las backend storage api
void msi_vec_as_field_storage(msi_vec * vec, msi_fld * fld);
void msi_vec_array_field_storage(msi_vec * vec, msi_fld * fld);
void msi_vec_array_field_storage(msi_vec * vec, msi_num * num, msi_fld * fld);
void msi_vec_array_field_activate_vec(msi_fld * fld);
void msi_vec_array_field_activate_field(msi_fld * fld);
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/msi_petsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace msi
template <typename T>
void vectorFieldData(msi_fld * fld, msi_vec * vec);
template <typename T>
void vectorArrayFieldData(msi_fld * fld, msi_vec * vec);
void vectorArrayFieldData(msi_fld * fld, msi_num * num, msi_vec * vec);
template <typename T>
void vectorArrayFieldActivateField(msi_fld * fld);
template <typename T>
Expand Down
33 changes: 15 additions & 18 deletions src/msi_petsc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace msi
VecSetOption(*v,VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE);
return reinterpret_cast<msi::Vec*>(v);
}
::Mat * getPetscMat(msi::Mat * m)
inline ::Mat * getPetscMat(msi::Mat * m)
{
return reinterpret_cast<::Mat*>(m);
}
::Vec * getPetscVec(msi::Vec * v)
inline ::Vec * getPetscVec(msi::Vec * v)
{
return reinterpret_cast<::Vec*>(v);
}
Expand Down Expand Up @@ -256,30 +256,27 @@ namespace msi
msi_vec * vec;
T * arr;
msi_num * num;
int frst;
bool valid;
public:
PetscVecArrayDataOf(msi_vec * v)
PetscVecArrayDataOf(msi_vec * v, msi_num * n)
: apf::FieldDataOf<T>()
, vec(v)
, arr(NULL)
, num(NULL)
, num(n)
, frst(0)
, valid(true)
{ }
virtual void init(apf::FieldBase * f)
{
this->field = f;
apf::FieldShape * s = f->getShape();
const char * name = s->getName();
apf::Numbering * n = f->getMesh()->findNumbering(name);
if (!n)
n = numberOverlapNodes(f->getMesh(),name,s);
num = n;
frst = PCU_Exscan_Int(apf::countNodes(num) * apf::countComponents(apf::getField(num)));
// assert that the vector has enough size to store the data
}
virtual ~PetscVecArrayDataOf() { }
virtual bool hasEntity(apf::MeshEntity*)
virtual bool hasEntity(apf::MeshEntity * ent)
{
return true;
return apf::getMesh(num)->isOwned(ent);
}
virtual void removeEntity(apf::MeshEntity*)
{ }
Expand All @@ -289,9 +286,9 @@ namespace msi
std::cerr << "Error! Cannot access field data while underlying vector is active! Call .activateField()" << std::endl;
apf::NewArray<int> dofs;
int dof_cnt = apf::getElementNumbers(num,e,dofs);
// could replace with memcpy if all accesses are contiguous
// need to offset the dof vals by the first local dof value...
for(int ii = 0; ii < dof_cnt; ++ii)
data[ii] = arr[dofs[ii]];
data[ii] = arr[dofs[ii]-frst];
}
virtual void set(apf::MeshEntity * e, T const * data)
{
Expand All @@ -301,7 +298,7 @@ namespace msi
int dof_cnt = apf::getElementNumbers(num,e,dofs);
// could replace with memcpy if all accesses are contiguous
for(int ii = 0; ii < dof_cnt; ++ii)
arr[dofs[ii]] = data[ii];
arr[dofs[ii]-frst] = data[ii];
}
virtual bool isFrozen()
{
Expand All @@ -328,9 +325,9 @@ namespace msi
fld->changeData(newData);
}
template <class T>
void vectorArrayFieldData(msi_fld * fld, Vec * vec)
void vectorArrayFieldData(msi_fld * fld, msi_num * num, Vec * vec)
{
PetscVecArrayDataOf<T>* newData = new PetscVecArrayDataOf<T>(vec);
PetscVecArrayDataOf<T>* newData = new PetscVecArrayDataOf<T>(vec,num);
newData->init(fld);
apf::FieldDataOf<T> * oldData = static_cast<apf::FieldDataOf<T>*>(fld->getData());
apf::copyFieldData<T>(oldData,newData);
Expand All @@ -350,7 +347,7 @@ namespace msi
}
//instantiate the template functions
template void vectorFieldData<MSI_SCALAR>(msi_fld * fld, msi_vec * vec);
template void vectorArrayFieldData<MSI_SCALAR>(msi_fld * fld, msi_vec * vec);
template void vectorArrayFieldData<MSI_SCALAR>(msi_fld * fld, msi_num * num, msi_vec * vec);
template void vectorArrayFieldActivateField<MSI_SCALAR>(msi_fld * fld);
template void vectorArrayFieldActivateVec<MSI_SCALAR>(msi_fld * fld);
}
24 changes: 16 additions & 8 deletions test/petsc/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,26 @@ int main(int argc, char * argv[])
std::cout << "* creating fields - " << dofs_per_nd << " DOFs per node" << std::endl;
msi_fld * bfld = msi_create_field(msh, "b", dofs_per_nd, 1);
msi_fld * cfld = msi_create_field(msh, "c", dofs_per_nd, 1);
msi_fld * xfld = msi_create_field(msh, "x", dofs_per_nd, 1);
msi_ent * lmt = msi_get_local_ent(msh,msh_dm,0);
int nen = msi_nodes_on_ent(bfld,lmt);
int nedofs = nen * dofs_per_nd;
// number and create las objects
msi_num * num = msi_number_field(bfld,MSI_NODE_NUMBERING);

msi_fld * xfld = msi_create_field(msh, "x", dofs_per_nd, 1);
msi_num * num = msi_number_field(xfld,MSI_NODE_NUMBERING);
msi_vec * xvec = msi_create_vector(num);
msi_vec_array_field_storage(xvec,num,xfld);
// operate on the msi_fld
msi_vec_array_field_activate_vec(xfld);
// operate on the msi_vec
msi_vec_array_field_activate_field(xfld);
// operate on the msi_fld


msi_vec * bvec = msi_create_vector(num);
msi_vec * cvec = msi_create_vector(num);
msi_vec * xvec = msi_create_vector(num);
msi_vec_as_field_storage(bvec,bfld);
msi_vec_as_field_storage(cvec,bfld);
msi_vec_as_field_storage(xvec,bfld);
msi_vec_as_field_storage(cvec,cfld);
msi_mat * mlt = msi_create_matrix(num);
msi_mat * slv = msi_create_matrix(num);
std::cout << "* set b field ..." << std::endl;
Expand Down Expand Up @@ -108,15 +116,15 @@ int main(int argc, char * argv[])
int num_lmts = msi_count_local_ents(msh,msh_dm);
for(int idx = 0; idx < num_lmts; ++idx)
{
msi_ent * lmt = msi_get_local_ent(msh,msh_dm,idx);
//msi_ent * lmt = msi_get_local_ent(msh,msh_dm,idx);
std::vector<MSI_SCALAR> tmp_blk = blk;
for(int ii = 0; ii < 1; ++ii)
for(int jj = 0; jj < 1; ++jj)
{
if(ii != jj)
std::transform(tmp_blk.begin(), tmp_blk.end(), tmp_blk.begin(), std::bind1st(std::multiplies<MSI_SCALAR>(),0.5));
msi_add_matrix_block(slv,num,lmt,ii,jj,&tmp_blk[0]);
msi_add_matrix_block(mlt,num,lmt,ii,jj,&tmp_blk[0]);
msi_add_matrix_block(slv,ii,jj,&tmp_blk[0]);
msi_add_matrix_block(mlt,ii,jj,&tmp_blk[0]);
}
}
double t2 = MPI_Wtime();
Expand Down

0 comments on commit dc49148

Please sign in to comment.